eina/tests: add basic Eina_Barrier test
authorUlisses Furquim <ulisses@profusion.mobi>
Tue, 8 Jan 2013 14:10:33 +0000 (14:10 +0000)
committerUlisses Furquim <ulisses@profusion.mobi>
Tue, 8 Jan 2013 14:10:33 +0000 (14:10 +0000)
Also rearranged test suite creation to allow setting the timeout in
the build callback.

SVN revision: 82415

src/Makefile_Eina.am
src/tests/eina/eina_suite.c
src/tests/eina/eina_suite.h
src/tests/eina/eina_test_barrier.c [new file with mode: 0644]

index eca0bfe..51c32cb 100644 (file)
@@ -276,7 +276,8 @@ tests/eina/eina_test_str.c \
 tests/eina/eina_test_quadtree.c \
 tests/eina/eina_test_simple_xml_parser.c \
 tests/eina/eina_test_value.c \
-tests/eina/eina_test_cow.c
+tests/eina/eina_test_cow.c \
+tests/eina/eina_test_barrier.c
 # tests/eina/eina_test_model.c
 
 tests_eina_eina_suite_CPPFLAGS = \
index cceda02..93c6b40 100644 (file)
@@ -71,6 +71,7 @@ static const Eina_Test_Case etc[] = {
    { "COW", eina_test_cow },
    // Disabling Eina_Model test
    //   { "Model", eina_test_model },
+   { "Barrier", eina_test_barrier },
    { NULL, NULL }
 };
 
@@ -111,11 +112,10 @@ eina_build_suite(int argc, const char **argv)
            continue;
 
         tc = tcase_create(etc[i].test_case);
+        tcase_set_timeout(tc, 0);
 
         etc[i].build(tc);
-
         suite_add_tcase(s, tc);
-        tcase_set_timeout(tc, 0);
      }
 
    return s;
index b85dad2..bdef0d5 100644 (file)
@@ -58,5 +58,6 @@ void eina_test_simple_xml_parser(TCase *tc);
 void eina_test_value(TCase *tc);
 void eina_test_model(TCase *tc);
 void eina_test_cow(TCase *tc);
+void eina_test_barrier(TCase *tc);
 
 #endif /* EINA_SUITE_H_ */
diff --git a/src/tests/eina/eina_test_barrier.c b/src/tests/eina/eina_test_barrier.c
new file mode 100644 (file)
index 0000000..997b0fd
--- /dev/null
@@ -0,0 +1,94 @@
+/* EINA - EFL data type library
+ * Copyright (C) 2013 ProFUSION embedded systems
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library;
+ * if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <unistd.h>
+
+#include "eina_suite.h"
+#include "Eina.h"
+
+static Eina_Thread wk1, wk2, wk3, wk4, wk5;
+static Eina_Barrier barrier;
+
+static void *
+wk_func(void *data EINA_UNUSED, Eina_Thread thread EINA_UNUSED)
+{
+    eina_barrier_wait(&barrier);
+    return NULL;
+}
+
+static void *
+wk1_func(void *data EINA_UNUSED, Eina_Thread thread EINA_UNUSED)
+{
+    sleep(1);
+    eina_barrier_wait(&barrier);
+    return NULL;
+}
+
+static void *
+wk2_func(void *data EINA_UNUSED, Eina_Thread thread EINA_UNUSED)
+{
+    sleep(2);
+    eina_barrier_wait(&barrier);
+    return NULL;
+}
+
+static void *
+wk3_func(void *data EINA_UNUSED, Eina_Thread thread EINA_UNUSED)
+{
+    sleep(3);
+    eina_barrier_wait(&barrier);
+    return NULL;
+}
+
+START_TEST(eina_barrier_test_simple)
+{
+    eina_init();
+    eina_threads_init();
+
+    eina_barrier_new(&barrier, 6);
+    eina_thread_create(&wk1, EINA_THREAD_NORMAL, 0, wk_func, NULL);
+    eina_thread_create(&wk2, EINA_THREAD_NORMAL, 0, wk_func, NULL);
+    eina_thread_create(&wk3, EINA_THREAD_NORMAL, 0, wk1_func, NULL);
+    eina_thread_create(&wk4, EINA_THREAD_NORMAL, 0, wk2_func, NULL);
+    eina_thread_create(&wk5, EINA_THREAD_NORMAL, 0, wk3_func, NULL);
+
+    eina_barrier_wait(&barrier);
+
+    eina_thread_join(wk1);
+    eina_thread_join(wk2);
+    eina_thread_join(wk3);
+    eina_thread_join(wk4);
+    eina_thread_join(wk5);
+
+    eina_barrier_free(&barrier);
+
+    eina_threads_shutdown();
+    eina_shutdown();
+}
+END_TEST
+
+void
+eina_test_barrier(TCase *tc)
+{
+   tcase_set_timeout(tc, 6);
+   tcase_add_test(tc, eina_barrier_test_simple);
+}