fix tables
[nobug.git] / tests / test_nobug_resources.c
blob4f4ab263c33e84b70becffcd6c08139cdb9547e1
1 #include "test.h"
2 #include "nobug.h"
5 TESTS_BEGIN
7 TEST(resources_announce_forget)
9 RESOURCE_HANDLE(t1);
10 RESOURCE_HANDLE_INIT (t1);
11 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
12 RESOURCE_FORGET(NOBUG_ON, t1);
13 RESOURCE_DUMPALL(NOBUG_ON);
16 /* Basic enter/leave tests */
17 TEST(resources_enter_exclusive_leave)
19 RESOURCE_HANDLE(t1);
20 RESOURCE_HANDLE_INIT (t1);
21 RESOURCE_USER(e1);
22 RESOURCE_USER_INIT (e1);
23 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
25 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_EXCLUSIVE, e1);
26 RESOURCE_LEAVE(NOBUG_ON, e1);
28 RESOURCE_DUMPALL(NOBUG_ON);
29 RESOURCE_FORGET(NOBUG_ON, t1);
30 RESOURCE_DUMPALL(NOBUG_ON);
33 TEST(resources_enter_waiting_leave)
35 RESOURCE_HANDLE(t1);
36 RESOURCE_HANDLE_INIT (t1);
37 RESOURCE_USER(e1);
38 RESOURCE_USER_INIT (e1);
39 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
41 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_WAITING, e1);
42 RESOURCE_LEAVE(NOBUG_ON, e1);
44 RESOURCE_DUMPALL(NOBUG_ON);
45 RESOURCE_FORGET(NOBUG_ON, t1);
46 RESOURCE_DUMPALL(NOBUG_ON);
49 TEST(resources_enter_recursive_leave)
51 RESOURCE_HANDLE(t1);
52 RESOURCE_HANDLE_INIT (t1);
53 RESOURCE_USER(e1);
54 RESOURCE_USER_INIT (e1);
55 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
57 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_RECURSIVE, e1);
58 RESOURCE_LEAVE(NOBUG_ON, e1);
60 RESOURCE_DUMPALL(NOBUG_ON);
61 RESOURCE_FORGET(NOBUG_ON, t1);
62 RESOURCE_DUMPALL(NOBUG_ON);
65 /* leaving too much tests */
66 TEST(resources_enter_exclusive_leave2)
68 RESOURCE_HANDLE(t1);
69 RESOURCE_HANDLE_INIT (t1);
70 RESOURCE_USER(e1);
71 RESOURCE_USER_INIT (e1);
72 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
74 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_EXCLUSIVE, e1);
75 RESOURCE_LEAVE(NOBUG_ON, e1);
76 RESOURCE_LEAVE(NOBUG_ON, e1);
78 RESOURCE_DUMPALL(NOBUG_ON);
79 RESOURCE_FORGET(NOBUG_ON, t1);
80 RESOURCE_DUMPALL(NOBUG_ON);
83 TEST(resources_enter_waiting_leave2)
85 RESOURCE_HANDLE(t1);
86 RESOURCE_HANDLE_INIT (t1);
87 RESOURCE_USER(e1);
88 RESOURCE_USER_INIT (e1);
89 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
91 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_WAITING, e1);
92 RESOURCE_LEAVE(NOBUG_ON, e1);
93 RESOURCE_LEAVE(NOBUG_ON, e1);
95 RESOURCE_DUMPALL(NOBUG_ON);
96 RESOURCE_FORGET(NOBUG_ON, t1);
97 RESOURCE_DUMPALL(NOBUG_ON);
100 TEST(resources_enter_recursive_leave2)
102 RESOURCE_HANDLE(t1);
103 RESOURCE_HANDLE_INIT (t1);
104 RESOURCE_USER(e1);
105 RESOURCE_USER_INIT (e1);
106 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
108 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_RECURSIVE, e1);
109 RESOURCE_LEAVE(NOBUG_ON, e1);
110 RESOURCE_LEAVE(NOBUG_ON, e1);
112 RESOURCE_DUMPALL(NOBUG_ON);
113 RESOURCE_FORGET(NOBUG_ON, t1);
114 RESOURCE_DUMPALL(NOBUG_ON);
119 /* forgot to leave tests */
120 TEST(resources_enter_exclusive)
122 RESOURCE_HANDLE(t1);
123 RESOURCE_HANDLE_INIT (t1);
124 RESOURCE_USER(e1);
125 RESOURCE_USER_INIT (e1);
126 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
128 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_EXCLUSIVE, e1);
130 RESOURCE_DUMPALL(NOBUG_ON);
131 RESOURCE_FORGET(NOBUG_ON, t1);
132 RESOURCE_DUMPALL(NOBUG_ON);
135 TEST(resources_enter_waiting)
137 RESOURCE_HANDLE(t1);
138 RESOURCE_HANDLE_INIT (t1);
139 RESOURCE_USER(e1);
140 RESOURCE_USER_INIT (e1);
141 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
143 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_WAITING, e1);
145 RESOURCE_DUMPALL(NOBUG_ON);
146 RESOURCE_FORGET(NOBUG_ON, t1);
147 RESOURCE_DUMPALL(NOBUG_ON);
150 TEST(resources_enter_recursive)
152 RESOURCE_HANDLE(t1);
153 RESOURCE_HANDLE_INIT (t1);
154 RESOURCE_USER(e1);
155 RESOURCE_USER_INIT (e1);
156 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
158 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_RECURSIVE, e1);
160 RESOURCE_DUMPALL(NOBUG_ON);
161 RESOURCE_FORGET(NOBUG_ON, t1);
162 RESOURCE_DUMPALL(NOBUG_ON);
166 /* State without enter tests */
167 TEST(resources_state_exclusive)
169 RESOURCE_HANDLE(t1);
170 RESOURCE_HANDLE_INIT (t1);
171 RESOURCE_USER(e1);
172 RESOURCE_USER_INIT (e1);
173 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
175 RESOURCE_STATE(NOBUG_ON, NOBUG_RESOURCE_EXCLUSIVE, e1);
177 RESOURCE_DUMPALL(NOBUG_ON);
178 RESOURCE_FORGET(NOBUG_ON, t1);
179 RESOURCE_DUMPALL(NOBUG_ON);
182 TEST(resources_state_waiting)
184 RESOURCE_HANDLE(t1);
185 RESOURCE_HANDLE_INIT (t1);
186 RESOURCE_USER(e1);
187 RESOURCE_USER_INIT (e1);
188 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
190 RESOURCE_STATE(NOBUG_ON, NOBUG_RESOURCE_WAITING, e1);
192 RESOURCE_DUMPALL(NOBUG_ON);
193 RESOURCE_FORGET(NOBUG_ON, t1);
194 RESOURCE_DUMPALL(NOBUG_ON);
197 TEST(resources_state_recursive)
199 RESOURCE_HANDLE(t1);
200 RESOURCE_HANDLE_INIT (t1);
201 RESOURCE_USER(e1);
202 RESOURCE_USER_INIT (e1);
203 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
205 RESOURCE_STATE(NOBUG_ON, NOBUG_RESOURCE_RECURSIVE, e1);
207 RESOURCE_DUMPALL(NOBUG_ON);
208 RESOURCE_FORGET(NOBUG_ON, t1);
209 RESOURCE_DUMPALL(NOBUG_ON);
213 /* waiting transistions valid tests */
214 TEST(resources_enter_waiting_state_exclusive)
216 RESOURCE_HANDLE(t1);
217 RESOURCE_HANDLE_INIT (t1);
218 RESOURCE_USER(e1);
219 RESOURCE_USER_INIT (e1);
220 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
222 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_WAITING, e1);
223 RESOURCE_STATE(NOBUG_ON, NOBUG_RESOURCE_EXCLUSIVE, e1);
224 RESOURCE_LEAVE(NOBUG_ON, e1);
226 RESOURCE_DUMPALL(NOBUG_ON);
227 RESOURCE_FORGET(NOBUG_ON, t1);
228 RESOURCE_DUMPALL(NOBUG_ON);
231 TEST(resources_enter_waiting_state_recursive)
233 RESOURCE_HANDLE(t1);
234 RESOURCE_HANDLE_INIT (t1);
235 RESOURCE_USER(e1);
236 RESOURCE_USER_INIT (e1);
237 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
239 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_WAITING, e1);
240 RESOURCE_STATE(NOBUG_ON, NOBUG_RESOURCE_RECURSIVE, e1);
241 RESOURCE_LEAVE(NOBUG_ON, e1);
243 RESOURCE_DUMPALL(NOBUG_ON);
244 RESOURCE_FORGET(NOBUG_ON, t1);
245 RESOURCE_DUMPALL(NOBUG_ON);
249 TEST(resources_enter_waiting_enter_waiting)
251 RESOURCE_HANDLE(t1);
252 RESOURCE_HANDLE_INIT (t1);
253 RESOURCE_USER(e1);
254 RESOURCE_USER_INIT (e1);
255 RESOURCE_USER(e2);
256 RESOURCE_USER_INIT (e2);
257 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
259 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_WAITING, e1);
260 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_WAITING, e2);
261 RESOURCE_LEAVE(NOBUG_ON, e1);
262 RESOURCE_LEAVE(NOBUG_ON, e2);
264 RESOURCE_DUMPALL(NOBUG_ON);
265 RESOURCE_FORGET(NOBUG_ON, t1);
266 RESOURCE_DUMPALL(NOBUG_ON);
269 TEST(resources_enter_waiting_enter_recursive)
271 RESOURCE_HANDLE(t1);
272 RESOURCE_HANDLE_INIT (t1);
273 RESOURCE_USER(e1);
274 RESOURCE_USER_INIT (e1);
275 RESOURCE_USER(e2);
276 RESOURCE_USER_INIT (e2);
277 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
279 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_WAITING, e1);
280 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_RECURSIVE, e2);
281 RESOURCE_LEAVE(NOBUG_ON, e1);
282 RESOURCE_LEAVE(NOBUG_ON, e2);
284 RESOURCE_FORGET(NOBUG_ON, t1);
285 RESOURCE_DUMPALL(NOBUG_ON);
288 TEST(resources_enter_waiting_enter_exclusive)
290 RESOURCE_HANDLE(t1);
291 RESOURCE_HANDLE_INIT (t1);
292 RESOURCE_USER(e1);
293 RESOURCE_USER_INIT (e1);
294 RESOURCE_USER(e2);
295 RESOURCE_USER_INIT (e2);
296 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
298 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_WAITING, e1);
299 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_EXCLUSIVE, e2);
300 RESOURCE_LEAVE(NOBUG_ON, e1);
301 RESOURCE_LEAVE(NOBUG_ON, e2);
303 RESOURCE_FORGET(NOBUG_ON, t1);
304 RESOURCE_DUMPALL(NOBUG_ON);
309 /*exclusive tests*/
310 TEST(resources_enter_exclusive_state_waiting)
312 RESOURCE_HANDLE(t1);
313 RESOURCE_HANDLE_INIT (t1);
314 RESOURCE_USER(e1);
315 RESOURCE_USER_INIT (e1);
316 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
318 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_EXCLUSIVE, e1);
319 RESOURCE_STATE(NOBUG_ON, NOBUG_RESOURCE_WAITING, e1);
320 RESOURCE_LEAVE(NOBUG_ON, e1);
322 RESOURCE_FORGET(NOBUG_ON, t1);
323 RESOURCE_DUMPALL(NOBUG_ON);
326 TEST(resources_enter_exclusive_state_recursive)
328 RESOURCE_HANDLE(t1);
329 RESOURCE_HANDLE_INIT (t1);
330 RESOURCE_USER(e1);
331 RESOURCE_USER_INIT (e1);
332 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
334 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_EXCLUSIVE, e1);
335 RESOURCE_STATE(NOBUG_ON, NOBUG_RESOURCE_RECURSIVE, e1);
337 RESOURCE_DUMPALL(NOBUG_ON);
338 RESOURCE_FORGET(NOBUG_ON, t1);
339 RESOURCE_DUMPALL(NOBUG_ON);
342 TEST(resources_enter_exclusive_state_exclusive)
344 RESOURCE_HANDLE(t1);
345 RESOURCE_HANDLE_INIT (t1);
346 RESOURCE_USER(e1);
347 RESOURCE_USER_INIT (e1);
348 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
350 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_EXCLUSIVE, e1);
351 RESOURCE_STATE(NOBUG_ON, NOBUG_RESOURCE_EXCLUSIVE, e1);
353 RESOURCE_DUMPALL(NOBUG_ON);
354 RESOURCE_FORGET(NOBUG_ON, t1);
355 RESOURCE_DUMPALL(NOBUG_ON);
358 TEST(resources_enter_exclusive_enter_waiting)
360 RESOURCE_HANDLE(t1);
361 RESOURCE_HANDLE_INIT (t1);
362 RESOURCE_USER(e1);
363 RESOURCE_USER_INIT (e1);
364 RESOURCE_USER(e2);
365 RESOURCE_USER_INIT (e2);
366 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
368 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_EXCLUSIVE, e1);
369 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_WAITING, e2);
370 RESOURCE_LEAVE(NOBUG_ON, e1);
371 RESOURCE_LEAVE(NOBUG_ON, e2);
373 RESOURCE_FORGET(NOBUG_ON, t1);
376 TEST(resources_enter_exclusive_enter_recursive)
378 RESOURCE_HANDLE(t1);
379 RESOURCE_HANDLE_INIT (t1);
380 RESOURCE_USER(e1);
381 RESOURCE_USER_INIT (e1);
382 RESOURCE_USER(e2);
383 RESOURCE_USER_INIT (e2);
384 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
386 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_EXCLUSIVE, e1);
387 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_RECURSIVE, e2);
389 RESOURCE_DUMPALL(NOBUG_ON);
390 RESOURCE_FORGET(NOBUG_ON, t1);
391 RESOURCE_DUMPALL(NOBUG_ON);
394 TEST(resources_enter_exclusive_enter_exclusive)
396 RESOURCE_HANDLE(t1);
397 RESOURCE_HANDLE_INIT (t1);
398 RESOURCE_USER(e1);
399 RESOURCE_USER_INIT (e1);
400 RESOURCE_USER(e2);
401 RESOURCE_USER_INIT (e2);
402 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
404 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_EXCLUSIVE, e1);
405 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_EXCLUSIVE, e2);
407 RESOURCE_DUMPALL(NOBUG_ON);
408 RESOURCE_FORGET(NOBUG_ON, t1);
409 RESOURCE_DUMPALL(NOBUG_ON);
412 /*recursive tests*/
413 TEST(resources_enter_recursive_state_waiting)
415 RESOURCE_HANDLE(t1);
416 RESOURCE_HANDLE_INIT (t1);
417 RESOURCE_USER(e1);
418 RESOURCE_USER_INIT (e1);
419 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
421 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_RECURSIVE, e1);
422 RESOURCE_STATE(NOBUG_ON, NOBUG_RESOURCE_WAITING, e1);
423 RESOURCE_LEAVE(NOBUG_ON, e1);
425 RESOURCE_FORGET(NOBUG_ON, t1);
428 TEST(resources_enter_recursive_state_recursive)
430 RESOURCE_HANDLE(t1);
431 RESOURCE_HANDLE_INIT (t1);
432 RESOURCE_USER(e1);
433 RESOURCE_USER_INIT (e1);
434 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
436 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_RECURSIVE, e1);
437 RESOURCE_STATE(NOBUG_ON, NOBUG_RESOURCE_RECURSIVE, e1);
439 RESOURCE_DUMPALL(NOBUG_ON);
440 RESOURCE_FORGET(NOBUG_ON, t1);
441 RESOURCE_DUMPALL(NOBUG_ON);
444 TEST(resources_enter_recursive_state_exclusive)
446 RESOURCE_HANDLE(t1);
447 RESOURCE_HANDLE_INIT (t1);
448 RESOURCE_USER(e1);
449 RESOURCE_USER_INIT (e1);
450 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
452 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_RECURSIVE, e1);
453 RESOURCE_STATE(NOBUG_ON, NOBUG_RESOURCE_EXCLUSIVE, e1);
455 RESOURCE_DUMPALL(NOBUG_ON);
456 RESOURCE_FORGET(NOBUG_ON, t1);
457 RESOURCE_DUMPALL(NOBUG_ON);
460 TEST(resources_enter_recursive_enter_waiting)
462 RESOURCE_HANDLE(t1);
463 RESOURCE_HANDLE_INIT (t1);
464 RESOURCE_USER(e1);
465 RESOURCE_USER_INIT (e1);
466 RESOURCE_USER(e2);
467 RESOURCE_USER_INIT (e2);
468 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
470 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_RECURSIVE, e1);
471 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_WAITING, e2);
472 RESOURCE_LEAVE(NOBUG_ON, e1);
473 RESOURCE_LEAVE(NOBUG_ON, e2);
475 RESOURCE_DUMPALL(NOBUG_ON);
476 RESOURCE_FORGET(NOBUG_ON, t1);
477 RESOURCE_DUMPALL(NOBUG_ON);
481 TEST(resources_enter_recursive_enter_exclusive)
483 RESOURCE_HANDLE(t1);
484 RESOURCE_HANDLE_INIT (t1);
485 RESOURCE_USER(e1);
486 RESOURCE_USER_INIT (e1);
487 RESOURCE_USER(e2);
488 RESOURCE_USER_INIT (e2);
489 RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1);
491 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_RECURSIVE, e1);
492 RESOURCE_ENTER(NOBUG_ON, t1, "user1", NOBUG_RESOURCE_EXCLUSIVE, e2);
494 RESOURCE_DUMPALL(NOBUG_ON);
495 RESOURCE_FORGET(NOBUG_ON, t1);
496 RESOURCE_DUMPALL(NOBUG_ON);
499 TESTS_END