fix tables
[nobug.git] / tests / test_nobug_resources_basic.c
blob92284612bcb37cbdfc5c3391aed50d5e61770c8a
1 #include "test.h"
2 #include "nobug.h"
4 RESOURCE_HANDLE(t);
5 enum nobug_resource_state threadenter;
8 void* threadfn(void* nop)
10 RESOURCE_HANDLE(e);
11 RESOURCE_HANDLE_INIT(e);
12 ECHO ("thread startup");
14 if (threadenter != NOBUG_RESOURCE_WAITING)
16 ECHO ("enter via wait");
17 #if 0
18 RESOURCE_ENTER(NOBUG_ON, t, "thread", NOBUG_RESOURCE_WAITING, e);
19 NOBUG_RESOURCE_STATE(NOBUG_ON, threadenter, e);
20 RESOURCE_LEAVE(NOBUG_ON, e);
21 #endif
24 ECHO ("enter direct");
25 // RESOURCE_ENTER(NOBUG_ON, t, "thread", threadenter, e);
26 // RESOURCE_LEAVE(NOBUG_ON, e);
28 ECHO ("thread finished");
29 return nop;
33 TESTS_BEGIN
34 ECHO ("testing");
36 TEST(resourcerecord_basic)
38 nobug_resource_init ();
39 struct nobug_resource_record* rec =
40 nobug_resource_announce ("test", "test", 0, NOBUG_CONTEXT);
41 nobug_resource_announce_complete ();
43 nobug_resource_list ((struct nobug_resource_dump_context)
44 {&nobug_flag_NOBUG_ON,
45 NOBUG_RESOURCE_LOG_LEVEL,
46 NOBUG_CONTEXT});
48 nobug_resource_dump_all ((struct nobug_resource_dump_context)
49 {&nobug_flag_NOBUG_ON,
50 LOG_EMERG,
51 NOBUG_CONTEXT});
53 ret = nobug_resource_forget (rec);
57 TEST(resource_memory_trace)
59 nobug_resource_init ();
61 ECHO ("initial free resource records %u", nobug_resource_record_available ());
62 ECHO ("initial free resource users %u", nobug_resource_user_available ());
63 ECHO ("initial free resource nodes %u", nobug_resource_node_available ());
65 struct nobug_resource_record* rec =
66 nobug_resource_announce ("test", "test", 0, NOBUG_CONTEXT);
67 nobug_resource_announce_complete ();
69 ECHO ("after announce free resource records %u", nobug_resource_record_available ());
70 ECHO ("after announce free resource users %u", nobug_resource_user_available ());
71 ECHO ("after announce free resource nodes %u", nobug_resource_node_available ());
73 struct nobug_resource_user* user =
74 nobug_resource_enter (rec,
75 "user",
76 NOBUG_RESOURCE_EXCLUSIVE,
77 NOBUG_CONTEXT);
79 ECHO ("after enter free resource records %u", nobug_resource_record_available ());
80 ECHO ("after enter free resource users %u", nobug_resource_user_available ());
81 ECHO ("after enter free resource nodes %u", nobug_resource_node_available ());
83 if (nobug_resource_leave (user) == 1)
85 ECHO ("after leave free resource records %u", nobug_resource_record_available ());
86 ECHO ("after leave free resource users %u", nobug_resource_user_available ());
87 ECHO ("after leave free resource nodes %u", nobug_resource_node_available ());
89 ret = nobug_resource_forget (rec);
91 ECHO ("after forget free resource records %u", nobug_resource_record_available ());
92 ECHO ("after forget free resource users %u", nobug_resource_user_available ());
93 ECHO ("after forget free resource nodes %u", nobug_resource_node_available ());
98 TEST(resource_enterleave)
100 nobug_resource_init ();
102 struct nobug_resource_record* rec =
103 nobug_resource_announce ("test", "test", 0, NOBUG_CONTEXT);
104 nobug_resource_announce_complete ();
106 struct nobug_resource_user* user =
107 nobug_resource_enter (rec,
108 "user",
109 NOBUG_RESOURCE_EXCLUSIVE,
110 NOBUG_CONTEXT);
112 nobug_resource_list ((struct nobug_resource_dump_context)
113 {&nobug_flag_NOBUG_ON,
114 NOBUG_RESOURCE_LOG_LEVEL,
115 NOBUG_CONTEXT});
117 nobug_resource_dump_all ((struct nobug_resource_dump_context)
118 {&nobug_flag_NOBUG_ON,
119 LOG_EMERG,
120 NOBUG_CONTEXT});
122 if (nobug_resource_leave (user) == 1)
123 ret = nobug_resource_forget (rec);
128 TEST(resource_statechange)
130 nobug_resource_init ();
131 struct nobug_resource_record* rec =
132 nobug_resource_announce ("test", "test", 0, NOBUG_CONTEXT);
133 nobug_resource_announce_complete ();
135 nobug_resource_list ((struct nobug_resource_dump_context)
136 {&nobug_flag_NOBUG_ON,
137 NOBUG_RESOURCE_LOG_LEVEL,
138 NOBUG_CONTEXT});
140 struct nobug_resource_user* user =
141 nobug_resource_enter (rec,
142 "user",
143 NOBUG_RESOURCE_WAITING,
144 NOBUG_CONTEXT);
146 nobug_resource_dump_all ((struct nobug_resource_dump_context)
147 {&nobug_flag_NOBUG_ON,
148 LOG_EMERG,
149 NOBUG_CONTEXT});
151 if (nobug_resource_state (user, NOBUG_RESOURCE_EXCLUSIVE))
153 nobug_resource_dump_all ((struct nobug_resource_dump_context)
154 {&nobug_flag_NOBUG_ON,
155 LOG_EMERG,
156 NOBUG_CONTEXT});
158 if (nobug_resource_leave (user) == 1)
159 ret = nobug_resource_forget (rec);
163 nobug_destroy(NOBUG_CONTEXT);
165 TESTS_END