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

Function yield_test

tests/system_test/yield_test.cpp:52–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50} // namespace
51
52auto yield_test() -> bool {
53 klog::Info("yield_test: start");
54 auto& tm = TaskManagerSingleton::instance();
55
56 // Test 1: basic yield returns 0
57 g_yield_ret = -1;
58 auto t1 = kstd::make_unique<TaskControlBlock>("YieldBasic", 10,
59 yield_basic_work, nullptr);
60 tm.AddTask(std::move(t1));
61
62 int timeout = 100;
63 while (timeout-- > 0 && g_yield_ret.load() == -1) {
64 (void)sys_sleep(50);
65 }
66 EXPECT_EQ(g_yield_ret.load(), 0, "sys_yield should return 0");
67
68 // Test 2: yield fairness — both tasks make progress
69 g_a_count = 0;
70 g_b_count = 0;
71 g_fairness_done = false;
72
73 auto ta =
74 kstd::make_unique<TaskControlBlock>("YieldA", 10, yield_task_a, nullptr);
75 auto tb =
76 kstd::make_unique<TaskControlBlock>("YieldB", 10, yield_task_b, nullptr);
77 tm.AddTask(std::move(ta));
78 tm.AddTask(std::move(tb));
79
80 timeout = 100;
81 while (timeout-- > 0 && !g_fairness_done.load()) {
82 (void)sys_sleep(50);
83 }
84 EXPECT_EQ(g_a_count.load(), 10, "Task A should complete 10 iterations");
85 EXPECT_EQ(g_b_count.load(), 10, "Task B should complete 10 iterations");
86
87 klog::Info("yield_test: PASS");
88 return true;
89}

Callers

nothing calls this directly

Calls 3

InfoFunction · 0.85
sys_sleepFunction · 0.85
AddTaskMethod · 0.80

Tested by

no test coverage detected