MCPcopy Create free account
hub / github.com/Simple-XX/SimpleKernel / test_mutex_ordering

Function test_mutex_ordering

tests/system_test/mutex_test.cpp:247–293  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

245}
246
247void test_mutex_ordering(void* /*arg*/) {
248 klog::Info("=== Mutex Ordering Test ===");
249
250 Mutex mtx("ordering_test");
251 std::atomic<int> sequence{0};
252 bool passed = true;
253
254 OrderingArgs ctx_first;
255 ctx_first.mtx = &mtx;
256 ctx_first.sequence = &sequence;
257 ctx_first.task_id = 1;
258
259 OrderingArgs ctx_second;
260 ctx_second.mtx = &mtx;
261 ctx_second.sequence = &sequence;
262 ctx_second.task_id = 2;
263
264 auto first_task = kstd::make_unique<TaskControlBlock>(
265 "OrderFirst", 10, ordering_first, reinterpret_cast<void*>(&ctx_first));
266 auto second_task = kstd::make_unique<TaskControlBlock>(
267 "OrderSecond", 10, ordering_second, reinterpret_cast<void*>(&ctx_second));
268
269 TaskManagerSingleton::instance().AddTask(std::move(first_task));
270 TaskManagerSingleton::instance().AddTask(std::move(second_task));
271
272 int timeout = 100;
273 while (timeout > 0 && sequence.load() != 2) {
274 (void)sys_sleep(50);
275 timeout--;
276 }
277
278 if (sequence.load() != 2) {
279 klog::Err("test_mutex_ordering: FAIL — final sequence={}, expected 2",
280 sequence.load());
281 passed = false;
282 }
283
284 if (passed) {
285 klog::Info("Mutex Ordering Test: PASSED");
286 } else {
287 klog::Err("Mutex Ordering Test: FAILED");
288 g_tests_failed++;
289 }
290
291 g_tests_completed++;
292 sys_exit(0);
293}
294
295} // namespace
296

Callers

nothing calls this directly

Calls 5

InfoFunction · 0.85
sys_sleepFunction · 0.85
ErrFunction · 0.85
sys_exitFunction · 0.85
AddTaskMethod · 0.80

Tested by

no test coverage detected