FIX: forgot to make valgrind optional
[nobug.git] / tests / test_nobug_resources_threaded.c
bloba3cd8a1b86eefe69ff09e8afc6d39ff13b2048f4
1 #include "test.h"
2 #include "nobug.h"
4 RESOURCE_HANDLE(t);
6 void* threadfn(void* nop)
8 enum nobug_resource_state threadenter = (enum nobug_resource_state) nop;
9 NOBUG_THREAD_ID_SET("thread");
11 RESOURCE_USER(e);
12 RESOURCE_USER_INIT(e);
13 ECHO ("thread startup");
15 if (threadenter != NOBUG_RESOURCE_WAITING)
17 ECHO ("enter via wait");
18 RESOURCE_WAIT(NOBUG_ON, t, "thread", e)
19 NOBUG_RESOURCE_STATE(NOBUG_ON, threadenter, e);
21 else
23 ECHO ("enter direct");
24 RESOURCE_ENTER(NOBUG_ON, t, "thread", threadenter, e);
27 RESOURCE_LEAVE(NOBUG_ON, e);
29 ECHO ("thread finished");
30 return nop;
33 TESTS_BEGIN
34 NOBUG_THREAD_ID_SET("main");
35 ECHO ("testing");
37 RESOURCE_HANDLE_INIT (t);
38 RESOURCE_ANNOUNCE(NOBUG_ON, "type", "test", main, t);
40 TEST(resourcethreaded_waiting_waiting)
42 RESOURCE_USER(e);
43 RESOURCE_USER_INIT(e);
44 RESOURCE_ENTER(NOBUG_ON, t, "main", NOBUG_RESOURCE_WAITING, e);
46 ECHO ("create thread");
47 pthread_t h;
48 pthread_create (&h, NULL, threadfn, (void*)NOBUG_RESOURCE_WAITING);
50 pthread_join (h, NULL);
51 ECHO ("thread joined");
53 RESOURCE_LEAVE(NOBUG_ON, e);
56 TEST(resourcethreaded_waiting_exclusive)
58 RESOURCE_USER(e);
59 RESOURCE_USER_INIT(e);
60 RESOURCE_ENTER(NOBUG_ON, t, "main", NOBUG_RESOURCE_WAITING, e);
62 ECHO ("create thread");
63 pthread_t h;
64 pthread_create (&h, NULL, threadfn, (void*)NOBUG_RESOURCE_EXCLUSIVE);
65 pthread_join (h, NULL);
66 ECHO ("thread joined");
68 RESOURCE_LEAVE(NOBUG_ON, e);
71 TEST(resourcethreaded_waiting_recursive)
73 RESOURCE_USER(e);
74 RESOURCE_USER_INIT(e);
75 RESOURCE_ENTER(NOBUG_ON, t, "main", NOBUG_RESOURCE_WAITING, e);
77 ECHO ("create thread");
78 pthread_t h;
79 pthread_create (&h, NULL, threadfn, (void*)NOBUG_RESOURCE_RECURSIVE);
80 pthread_join (h, NULL);
81 ECHO ("thread joined");
83 RESOURCE_LEAVE(NOBUG_ON, e);
86 TEST(resourcethreaded_waiting_shared)
88 RESOURCE_USER(e);
89 RESOURCE_USER_INIT(e);
90 RESOURCE_ENTER(NOBUG_ON, t, "main", NOBUG_RESOURCE_WAITING, e);
92 ECHO ("create thread");
93 pthread_t h;
94 pthread_create (&h, NULL, threadfn, (void*)NOBUG_RESOURCE_SHARED);
95 pthread_join (h, NULL);
96 ECHO ("thread joined");
98 RESOURCE_LEAVE(NOBUG_ON, e);
104 TEST(resourcethreaded_exclusive_waiting)
106 RESOURCE_USER(e);
107 RESOURCE_USER_INIT(e);
108 RESOURCE_ENTER(NOBUG_ON, t, "main", NOBUG_RESOURCE_EXCLUSIVE, e);
110 ECHO ("create thread");
111 pthread_t h;
112 pthread_create (&h, NULL, threadfn, (void*)NOBUG_RESOURCE_WAITING);
113 pthread_join (h, NULL);
114 ECHO ("thread joined");
116 RESOURCE_LEAVE(NOBUG_ON, e);
119 TEST(resourcethreaded_exclusive_exclusive)
121 RESOURCE_USER(e);
122 RESOURCE_USER_INIT(e);
123 RESOURCE_ENTER(NOBUG_ON, t, "main", NOBUG_RESOURCE_EXCLUSIVE, e);
125 ECHO ("create thread");
126 pthread_t h;
127 pthread_create (&h, NULL, threadfn, (void*)NOBUG_RESOURCE_EXCLUSIVE);
128 pthread_join (h, NULL);
129 ECHO ("thread joined");
131 RESOURCE_LEAVE(NOBUG_ON, e);
134 TEST(resourcethreaded_exclusive_recursive)
136 RESOURCE_USER(e);
137 RESOURCE_USER_INIT(e);
138 RESOURCE_ENTER(NOBUG_ON, t, "main", NOBUG_RESOURCE_EXCLUSIVE, e);
140 ECHO ("create thread");
141 pthread_t h;
142 pthread_create (&h, NULL, threadfn, (void*)NOBUG_RESOURCE_RECURSIVE);
143 pthread_join (h, NULL);
144 ECHO ("thread joined");
146 RESOURCE_LEAVE(NOBUG_ON, e);
149 TEST(resourcethreaded_exclusive_shared)
151 RESOURCE_USER(e);
152 RESOURCE_USER_INIT(e);
153 RESOURCE_ENTER(NOBUG_ON, t, "main", NOBUG_RESOURCE_EXCLUSIVE, e);
155 ECHO ("create thread");
156 pthread_t h;
157 pthread_create (&h, NULL, threadfn, (void*)NOBUG_RESOURCE_SHARED);
158 pthread_join (h, NULL);
159 ECHO ("thread joined");
161 RESOURCE_LEAVE(NOBUG_ON, e);
167 TEST(resourcethreaded_recursive_waiting)
169 RESOURCE_USER(e);
170 RESOURCE_USER_INIT(e);
171 RESOURCE_ENTER(NOBUG_ON, t, "main", NOBUG_RESOURCE_RECURSIVE, e);
173 ECHO ("create thread");
174 pthread_t h;
175 pthread_create (&h, NULL, threadfn, (void*)NOBUG_RESOURCE_WAITING);
176 pthread_join (h, NULL);
177 ECHO ("thread joined");
179 RESOURCE_LEAVE(NOBUG_ON, e);
182 TEST(resourcethreaded_recursive_exclusive)
184 RESOURCE_USER(e);
185 RESOURCE_USER_INIT(e);
186 RESOURCE_ENTER(NOBUG_ON, t, "main", NOBUG_RESOURCE_RECURSIVE, e);
188 ECHO ("create thread");
189 pthread_t h;
190 pthread_create (&h, NULL, threadfn, (void*)NOBUG_RESOURCE_EXCLUSIVE);
191 pthread_join (h, NULL);
192 ECHO ("thread joined");
194 RESOURCE_LEAVE(NOBUG_ON, e);
197 TEST(resourcethreaded_recursive_recursive)
199 RESOURCE_USER(e);
200 RESOURCE_USER_INIT(e);
201 RESOURCE_ENTER(NOBUG_ON, t, "main", NOBUG_RESOURCE_RECURSIVE, e);
203 ECHO ("create thread");
204 pthread_t h;
205 pthread_create (&h, NULL, threadfn, (void*)NOBUG_RESOURCE_RECURSIVE);
206 pthread_join (h, NULL);
207 ECHO ("thread joined");
209 RESOURCE_LEAVE(NOBUG_ON, e);
212 TEST(resourcethreaded_recursive_shared)
214 RESOURCE_USER(e);
215 RESOURCE_USER_INIT(e);
216 RESOURCE_ENTER(NOBUG_ON, t, "main", NOBUG_RESOURCE_RECURSIVE, e);
218 ECHO ("create thread");
219 pthread_t h;
220 pthread_create (&h, NULL, threadfn, (void*)NOBUG_RESOURCE_SHARED);
221 pthread_join (h, NULL);
222 ECHO ("thread joined");
224 RESOURCE_LEAVE(NOBUG_ON, e);
230 TEST(resourcethreaded_shared_waiting)
232 RESOURCE_USER(e);
233 RESOURCE_USER_INIT(e);
234 RESOURCE_ENTER(NOBUG_ON, t, "main", NOBUG_RESOURCE_SHARED, e);
236 ECHO ("create thread");
237 pthread_t h;
238 pthread_create (&h, NULL, threadfn, (void*)NOBUG_RESOURCE_WAITING);
239 pthread_join (h, NULL);
240 ECHO ("thread joined");
242 RESOURCE_LEAVE(NOBUG_ON, e);
245 TEST(resourcethreaded_shared_exclusive)
247 RESOURCE_USER(e);
248 RESOURCE_USER_INIT(e);
249 RESOURCE_ENTER(NOBUG_ON, t, "main", NOBUG_RESOURCE_SHARED, e);
251 ECHO ("create thread");
252 pthread_t h;
253 pthread_create (&h, NULL, threadfn, (void*)NOBUG_RESOURCE_EXCLUSIVE);
254 pthread_join (h, NULL);
255 ECHO ("thread joined");
257 RESOURCE_LEAVE(NOBUG_ON, e);
260 TEST(resourcethreaded_shared_recursive)
262 RESOURCE_USER(e);
263 RESOURCE_USER_INIT(e);
264 RESOURCE_ENTER(NOBUG_ON, t, "main", NOBUG_RESOURCE_SHARED, e);
266 ECHO ("create thread");
267 pthread_t h;
268 pthread_create (&h, NULL, threadfn, (void*)NOBUG_RESOURCE_RECURSIVE);
269 pthread_join (h, NULL);
270 ECHO ("thread joined");
272 RESOURCE_LEAVE(NOBUG_ON, e);
275 TEST(resourcethreaded_shared_shared)
277 RESOURCE_USER(e);
278 RESOURCE_USER_INIT(e);
279 RESOURCE_ENTER(NOBUG_ON, t, "main", NOBUG_RESOURCE_SHARED, e);
281 ECHO ("create thread");
282 pthread_t h;
283 pthread_create (&h, NULL, threadfn, (void*)NOBUG_RESOURCE_SHARED);
284 pthread_join (h, NULL);
285 ECHO ("thread joined");
287 RESOURCE_LEAVE(NOBUG_ON, e);
290 RESOURCE_FORGET(NOBUG_ON, t);
291 TESTS_END