SimpleKernel 1.17.0
Loading...
Searching...
No Matches
exit_system_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_cstdio"
#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 "task_messages.hpp"
Include dependency graph for exit_system_test.cpp:

Go to the source code of this file.

Functions

auto exit_system_test () -> bool
 Exit 系统测试入口
 

Function Documentation

◆ exit_system_test()

auto exit_system_test ( ) -> bool

Exit 系统测试入口

Definition at line 452 of file exit_system_test.cpp.

452 {
453 klog::Info("===== Exit System Test Start =====");
454
455 // 重置全局计数器
456 g_tests_completed = 0;
457 g_tests_failed = 0;
458 g_exit_test_counter = 0;
459
460 auto& task_mgr = TaskManagerSingleton::instance();
461
462 // 测试 1: Normal exit
463 auto test1 = kstd::make_unique<TaskControlBlock>("TestExitNormal", 10,
464 test_exit_normal, nullptr);
465 task_mgr.AddTask(std::move(test1));
466
467 // 测试 2: Exit with error
468 auto test2 = kstd::make_unique<TaskControlBlock>(
469 "TestExitWithError", 10, test_exit_with_error, nullptr);
470 task_mgr.AddTask(std::move(test2));
471
472 // 测试 3: Thread exit
473 auto test3 = kstd::make_unique<TaskControlBlock>("TestThreadExit", 10,
474 test_thread_exit, nullptr);
475 task_mgr.AddTask(std::move(test3));
476
477 // 测试 4: Orphan exit
478 auto test4 = kstd::make_unique<TaskControlBlock>("TestOrphanExit", 10,
479 test_orphan_exit, nullptr);
480 task_mgr.AddTask(std::move(test4));
481
482 // 测试 5: Zombie process
483 auto test5 = kstd::make_unique<TaskControlBlock>(
484 "TestZombieProcess", 10, test_zombie_process, nullptr);
485 task_mgr.AddTask(std::move(test5));
486
487 klog::Info("Waiting for all 5 sub-tests to complete...");
488
489 // 等待所有子测试完成(每个子测试在退出前会增加 g_tests_completed)
490 // 超时: 200 * 50ms = 10s
491 int timeout = 200;
492 while (timeout > 0) {
493 (void)sys_sleep(50);
494 if (g_tests_completed.load() >= 5) {
495 break;
496 }
497 timeout--;
498 }
499
500 klog::Info("Exit System Test: completed={}, failed={}",
501 g_tests_completed.load(), g_tests_failed.load());
502
503 EXPECT_EQ(g_tests_completed, 5, "All 5 sub-tests completed");
504 EXPECT_EQ(g_tests_failed, 0, "No sub-tests failed");
505
506 klog::Info("===== Exit System Test End =====");
507 return true;
508}
auto Info(etl::format_string< Args... > fmt, Args &&... args) -> void
以 INFO 级别记录日志
auto sys_sleep(uint64_t ms) -> int
休眠指定毫秒数
Definition syscall.cpp:90
#define EXPECT_EQ(val1, val2, msg)
Here is the call graph for this function: