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

Function kernel_task_test

tests/system_test/kernel_task_test.cpp:51–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49} // namespace
50
51auto kernel_task_test() -> bool {
52 klog::Info("kernel_task_test: start");
53 g_task_a_counter = 0;
54 g_task_b_counter = 0;
55
56 // 创建线程 A
57 auto task_a = kstd::make_unique<TaskControlBlock>("Task A", 10, thread_func_a,
58 (void*)100);
59 TaskManagerSingleton::instance().AddTask(std::move(task_a));
60
61 // 创建线程 B
62 auto task_b = kstd::make_unique<TaskControlBlock>("Task B", 10, thread_func_b,
63 (void*)200);
64 TaskManagerSingleton::instance().AddTask(std::move(task_b));
65
66 klog::Info("Main: Waiting for tasks...");
67
68 // Wait for tasks to finish (or reach expected count)
69 int timeout = 200; // 200 * 50ms = 10s roughly
70 while (timeout > 0) {
71 (void)sys_sleep(50);
72 if (g_task_a_counter >= 5 && g_task_b_counter >= 5) {
73 break;
74 }
75 timeout--;
76 }
77
78 EXPECT_GT(timeout, 0, "Tasks should complete before timeout");
79 EXPECT_EQ(g_task_a_counter, 5, "Task A count");
80 EXPECT_EQ(g_task_b_counter, 5, "Task B count");
81
82 klog::Info("kernel_task_test: PASS");
83 return true;
84}

Callers

nothing calls this directly

Calls 3

InfoFunction · 0.85
sys_sleepFunction · 0.85
AddTaskMethod · 0.80

Tested by

no test coverage detected