SimpleKernel 1.17.0
Loading...
Searching...
No Matches
kernel_task_test.cpp File Reference
#include <cpu_io.h>
#include <atomic>
#include <cstddef>
#include <cstdint>
#include "arch.h"
#include "basic_info.hpp"
#include "kernel.h"
#include "kstd_cstring"
#include "kstd_libcxx.h"
#include "kstd_memory"
#include "sk_stdlib.h"
#include "syscall.hpp"
#include "system_test.h"
#include "task_control_block.hpp"
#include "task_manager.hpp"
Include dependency graph for kernel_task_test.cpp:

Go to the source code of this file.

Functions

auto kernel_task_test () -> bool
 

Function Documentation

◆ kernel_task_test()

auto kernel_task_test ( ) -> bool

Definition at line 51 of file kernel_task_test.cpp.

51 {
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}
auto Info(etl::format_string< Args... > fmt, Args &&... args) -> void
以 INFO 级别记录日志
auto sys_sleep(uint64_t ms) -> int
休眠指定毫秒数
Definition syscall.cpp:90
#define EXPECT_GT(val1, val2, msg)
#define EXPECT_EQ(val1, val2, msg)
Here is the call graph for this function: