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

Function test_mutex_basic_lock_unlock

tests/system_test/mutex_test.cpp:27–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25// =========================================================================
26
27void test_mutex_basic_lock_unlock(void* /*arg*/) {
28 klog::Info("=== Mutex Basic Lock/Unlock Test ===");
29
30 Mutex mtx("basic_test");
31 bool passed = true;
32
33 if (mtx.IsLockedByCurrentTask()) {
34 klog::Err("test_mutex_basic: FAIL — mutex locked before Lock()");
35 passed = false;
36 }
37
38 auto lock_result = mtx.Lock();
39 if (!lock_result.has_value()) {
40 klog::Err("test_mutex_basic: FAIL — Lock() returned error");
41 passed = false;
42 }
43
44 if (!mtx.IsLockedByCurrentTask()) {
45 klog::Err(
46 "test_mutex_basic: FAIL — IsLockedByCurrentTask false after Lock");
47 passed = false;
48 }
49
50 auto unlock_result = mtx.UnLock();
51 if (!unlock_result.has_value()) {
52 klog::Err("test_mutex_basic: FAIL — UnLock() returned error");
53 passed = false;
54 }
55
56 if (mtx.IsLockedByCurrentTask()) {
57 klog::Err(
58 "test_mutex_basic: FAIL — IsLockedByCurrentTask true after UnLock");
59 passed = false;
60 }
61
62 if (passed) {
63 klog::Info("Mutex Basic Lock/Unlock Test: PASSED");
64 } else {
65 klog::Err("Mutex Basic Lock/Unlock Test: FAILED");
66 g_tests_failed++;
67 }
68
69 g_tests_completed++;
70 sys_exit(0);
71}
72
73// =========================================================================
74// test_mutex_trylock

Callers

nothing calls this directly

Calls 6

InfoFunction · 0.85
ErrFunction · 0.85
sys_exitFunction · 0.85
IsLockedByCurrentTaskMethod · 0.80
LockMethod · 0.45
UnLockMethod · 0.45

Tested by

no test coverage detected