summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlisses Furquim <ulisses@profusion.mobi>2013-01-08 14:10:33 +0000
committerUlisses Furquim <ulisses@profusion.mobi>2013-01-08 14:10:33 +0000
commiteade5b825179c9ce5112c8b875521f99e00017b0 (patch)
treef1cdda0a0beed9a321dc65a69b6e048b849ad0b7
parent457f91573a3bed0acd1507e04df8974836226ffc (diff)
eina/tests: add basic Eina_Barrier test
Also rearranged test suite creation to allow setting the timeout in the build callback. SVN revision: 82415
Diffstat (limited to '')
-rw-r--r--src/Makefile_Eina.am3
-rw-r--r--src/tests/eina/eina_suite.c4
-rw-r--r--src/tests/eina/eina_suite.h1
-rw-r--r--src/tests/eina/eina_test_barrier.c94
4 files changed, 99 insertions, 3 deletions
diff --git a/src/Makefile_Eina.am b/src/Makefile_Eina.am
index eca0bfe429..51c32cb689 100644
--- a/src/Makefile_Eina.am
+++ b/src/Makefile_Eina.am
@@ -276,7 +276,8 @@ tests/eina/eina_test_str.c \
276tests/eina/eina_test_quadtree.c \ 276tests/eina/eina_test_quadtree.c \
277tests/eina/eina_test_simple_xml_parser.c \ 277tests/eina/eina_test_simple_xml_parser.c \
278tests/eina/eina_test_value.c \ 278tests/eina/eina_test_value.c \
279tests/eina/eina_test_cow.c 279tests/eina/eina_test_cow.c \
280tests/eina/eina_test_barrier.c
280# tests/eina/eina_test_model.c 281# tests/eina/eina_test_model.c
281 282
282tests_eina_eina_suite_CPPFLAGS = \ 283tests_eina_eina_suite_CPPFLAGS = \
diff --git a/src/tests/eina/eina_suite.c b/src/tests/eina/eina_suite.c
index cceda023ae..93c6b403ea 100644
--- a/src/tests/eina/eina_suite.c
+++ b/src/tests/eina/eina_suite.c
@@ -71,6 +71,7 @@ static const Eina_Test_Case etc[] = {
71 { "COW", eina_test_cow }, 71 { "COW", eina_test_cow },
72 // Disabling Eina_Model test 72 // Disabling Eina_Model test
73 // { "Model", eina_test_model }, 73 // { "Model", eina_test_model },
74 { "Barrier", eina_test_barrier },
74 { NULL, NULL } 75 { NULL, NULL }
75}; 76};
76 77
@@ -111,11 +112,10 @@ eina_build_suite(int argc, const char **argv)
111 continue; 112 continue;
112 113
113 tc = tcase_create(etc[i].test_case); 114 tc = tcase_create(etc[i].test_case);
115 tcase_set_timeout(tc, 0);
114 116
115 etc[i].build(tc); 117 etc[i].build(tc);
116
117 suite_add_tcase(s, tc); 118 suite_add_tcase(s, tc);
118 tcase_set_timeout(tc, 0);
119 } 119 }
120 120
121 return s; 121 return s;
diff --git a/src/tests/eina/eina_suite.h b/src/tests/eina/eina_suite.h
index b85dad2de3..bdef0d5f26 100644
--- a/src/tests/eina/eina_suite.h
+++ b/src/tests/eina/eina_suite.h
@@ -58,5 +58,6 @@ void eina_test_simple_xml_parser(TCase *tc);
58void eina_test_value(TCase *tc); 58void eina_test_value(TCase *tc);
59void eina_test_model(TCase *tc); 59void eina_test_model(TCase *tc);
60void eina_test_cow(TCase *tc); 60void eina_test_cow(TCase *tc);
61void eina_test_barrier(TCase *tc);
61 62
62#endif /* EINA_SUITE_H_ */ 63#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
index 0000000000..997b0fd7bf
--- /dev/null
+++ b/src/tests/eina/eina_test_barrier.c
@@ -0,0 +1,94 @@
1/* EINA - EFL data type library
2 * Copyright (C) 2013 ProFUSION embedded systems
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifdef HAVE_CONFIG_H
20# include "config.h"
21#endif
22
23#include <unistd.h>
24
25#include "eina_suite.h"
26#include "Eina.h"
27
28static Eina_Thread wk1, wk2, wk3, wk4, wk5;
29static Eina_Barrier barrier;
30
31static void *
32wk_func(void *data EINA_UNUSED, Eina_Thread thread EINA_UNUSED)
33{
34 eina_barrier_wait(&barrier);
35 return NULL;
36}
37
38static void *
39wk1_func(void *data EINA_UNUSED, Eina_Thread thread EINA_UNUSED)
40{
41 sleep(1);
42 eina_barrier_wait(&barrier);
43 return NULL;
44}
45
46static void *
47wk2_func(void *data EINA_UNUSED, Eina_Thread thread EINA_UNUSED)
48{
49 sleep(2);
50 eina_barrier_wait(&barrier);
51 return NULL;
52}
53
54static void *
55wk3_func(void *data EINA_UNUSED, Eina_Thread thread EINA_UNUSED)
56{
57 sleep(3);
58 eina_barrier_wait(&barrier);
59 return NULL;
60}
61
62START_TEST(eina_barrier_test_simple)
63{
64 eina_init();
65 eina_threads_init();
66
67 eina_barrier_new(&barrier, 6);
68 eina_thread_create(&wk1, EINA_THREAD_NORMAL, 0, wk_func, NULL);
69 eina_thread_create(&wk2, EINA_THREAD_NORMAL, 0, wk_func, NULL);
70 eina_thread_create(&wk3, EINA_THREAD_NORMAL, 0, wk1_func, NULL);
71 eina_thread_create(&wk4, EINA_THREAD_NORMAL, 0, wk2_func, NULL);
72 eina_thread_create(&wk5, EINA_THREAD_NORMAL, 0, wk3_func, NULL);
73
74 eina_barrier_wait(&barrier);
75
76 eina_thread_join(wk1);
77 eina_thread_join(wk2);
78 eina_thread_join(wk3);
79 eina_thread_join(wk4);
80 eina_thread_join(wk5);
81
82 eina_barrier_free(&barrier);
83
84 eina_threads_shutdown();
85 eina_shutdown();
86}
87END_TEST
88
89void
90eina_test_barrier(TCase *tc)
91{
92 tcase_set_timeout(tc, 6);
93 tcase_add_test(tc, eina_barrier_test_simple);
94}