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
);
42 nobug_resource_list ((struct nobug_resource_dump_context
)
43 {&nobug_flag_NOBUG_ON
,
44 NOBUG_RESOURCE_LOG_LEVEL
,
47 nobug_resource_dump_all ((struct nobug_resource_dump_context
)
48 {&nobug_flag_NOBUG_ON
,
52 ret
= nobug_resource_forget (rec
);
56 TEST(resource_memory_trace
)
58 nobug_resource_init ();
60 ECHO ("initial free resource records %u", nobug_resource_record_available ());
61 ECHO ("initial free resource users %u", nobug_resource_user_available ());
62 ECHO ("initial free resource nodes %u", nobug_resource_node_available ());
64 struct nobug_resource_record
* rec
=
65 nobug_resource_announce ("test", "test", 0, NOBUG_CONTEXT
);
67 ECHO ("after announce free resource records %u", nobug_resource_record_available ());
68 ECHO ("after announce free resource users %u", nobug_resource_user_available ());
69 ECHO ("after announce free resource nodes %u", nobug_resource_node_available ());
71 struct nobug_resource_user
* user
=
72 nobug_resource_enter (rec
,
74 NOBUG_RESOURCE_EXCLUSIVE
,
77 ECHO ("after enter free resource records %u", nobug_resource_record_available ());
78 ECHO ("after enter free resource users %u", nobug_resource_user_available ());
79 ECHO ("after enter free resource nodes %u", nobug_resource_node_available ());
81 if (nobug_resource_leave (user
) == 1)
83 ECHO ("after leave free resource records %u", nobug_resource_record_available ());
84 ECHO ("after leave free resource users %u", nobug_resource_user_available ());
85 ECHO ("after leave free resource nodes %u", nobug_resource_node_available ());
87 ret
= nobug_resource_forget (rec
);
89 ECHO ("after forget free resource records %u", nobug_resource_record_available ());
90 ECHO ("after forget free resource users %u", nobug_resource_user_available ());
91 ECHO ("after forget free resource nodes %u", nobug_resource_node_available ());
96 TEST(resource_enterleave
)
98 nobug_resource_init ();
100 struct nobug_resource_record
* rec
=
101 nobug_resource_announce ("test", "test", 0, NOBUG_CONTEXT
);
103 struct nobug_resource_user
* user
=
104 nobug_resource_enter (rec
,
106 NOBUG_RESOURCE_EXCLUSIVE
,
109 nobug_resource_list ((struct nobug_resource_dump_context
)
110 {&nobug_flag_NOBUG_ON
,
111 NOBUG_RESOURCE_LOG_LEVEL
,
114 nobug_resource_dump_all ((struct nobug_resource_dump_context
)
115 {&nobug_flag_NOBUG_ON
,
119 if (nobug_resource_leave (user
) == 1)
120 ret
= nobug_resource_forget (rec
);
125 TEST(resource_statechange
)
127 nobug_resource_init ();
128 struct nobug_resource_record
* rec
=
129 nobug_resource_announce ("test", "test", 0, NOBUG_CONTEXT
);
131 nobug_resource_list ((struct nobug_resource_dump_context
)
132 {&nobug_flag_NOBUG_ON
,
133 NOBUG_RESOURCE_LOG_LEVEL
,
136 struct nobug_resource_user
* user
=
137 nobug_resource_enter (rec
,
139 NOBUG_RESOURCE_WAITING
,
142 nobug_resource_dump_all ((struct nobug_resource_dump_context
)
143 {&nobug_flag_NOBUG_ON
,
147 if (nobug_resource_state (user
, NOBUG_RESOURCE_EXCLUSIVE
))
149 nobug_resource_dump_all ((struct nobug_resource_dump_context
)
150 {&nobug_flag_NOBUG_ON
,
154 if (nobug_resource_leave (user
) == 1)
155 ret
= nobug_resource_forget (rec
);
159 nobug_destroy(NOBUG_CONTEXT
);