5 enum nobug_resource_state threadenter
;
8 void* threadfn(void* nop
)
11 RESOURCE_HANDLE_INIT(e
);
12 ECHO ("thread startup");
14 if (threadenter
!= NOBUG_RESOURCE_WAITING
)
16 ECHO ("enter via wait");
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
);
24 ECHO ("enter direct");
25 // RESOURCE_ENTER(NOBUG_ON, t, "thread", threadenter, e);
26 // RESOURCE_LEAVE(NOBUG_ON, e);
28 ECHO ("thread finished");
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
,
48 nobug_resource_dump_all ((struct nobug_resource_dump_context
)
49 {&nobug_flag_NOBUG_ON
,
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
,
76 NOBUG_RESOURCE_EXCLUSIVE
,
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
,
109 NOBUG_RESOURCE_EXCLUSIVE
,
112 nobug_resource_list ((struct nobug_resource_dump_context
)
113 {&nobug_flag_NOBUG_ON
,
114 NOBUG_RESOURCE_LOG_LEVEL
,
117 nobug_resource_dump_all ((struct nobug_resource_dump_context
)
118 {&nobug_flag_NOBUG_ON
,
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
,
140 struct nobug_resource_user
* user
=
141 nobug_resource_enter (rec
,
143 NOBUG_RESOURCE_WAITING
,
146 nobug_resource_dump_all ((struct nobug_resource_dump_context
)
147 {&nobug_flag_NOBUG_ON
,
151 if (nobug_resource_state (user
, NOBUG_RESOURCE_EXCLUSIVE
))
153 nobug_resource_dump_all ((struct nobug_resource_dump_context
)
154 {&nobug_flag_NOBUG_ON
,
158 if (nobug_resource_leave (user
) == 1)
159 ret
= nobug_resource_forget (rec
);
163 nobug_destroy(NOBUG_CONTEXT
);