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

Function exit_test

tests/system_test/exit_test.cpp:450–506  ·  view source on GitHub ↗

* @brief Exit 系统测试入口 */

Source from the content-addressed store, hash-verified

448 * @brief Exit 系统测试入口
449 */
450auto exit_test() -> bool {
451 klog::Info("===== Exit System Test Start =====");
452
453 // 重置全局计数器
454 g_tests_completed = 0;
455 g_tests_failed = 0;
456 g_exit_test_counter = 0;
457
458 auto& task_mgr = TaskManagerSingleton::instance();
459
460 // 测试 1: Normal exit
461 auto test1 = kstd::make_unique<TaskControlBlock>("TestExitNormal", 10,
462 test_exit_normal, nullptr);
463 task_mgr.AddTask(std::move(test1));
464
465 // 测试 2: Exit with error
466 auto test2 = kstd::make_unique<TaskControlBlock>(
467 "TestExitWithError", 10, test_exit_with_error, nullptr);
468 task_mgr.AddTask(std::move(test2));
469
470 // 测试 3: Thread exit
471 auto test3 = kstd::make_unique<TaskControlBlock>("TestThreadExit", 10,
472 test_thread_exit, nullptr);
473 task_mgr.AddTask(std::move(test3));
474
475 // 测试 4: Orphan exit
476 auto test4 = kstd::make_unique<TaskControlBlock>("TestOrphanExit", 10,
477 test_orphan_exit, nullptr);
478 task_mgr.AddTask(std::move(test4));
479
480 // 测试 5: Zombie process
481 auto test5 = kstd::make_unique<TaskControlBlock>(
482 "TestZombieProcess", 10, test_zombie_process, nullptr);
483 task_mgr.AddTask(std::move(test5));
484
485 klog::Info("Waiting for all 5 sub-tests to complete...");
486
487 // 等待所有子测试完成(每个子测试在退出前会增加 g_tests_completed)
488 // 超时: 200 * 50ms = 10s
489 int timeout = 200;
490 while (timeout > 0) {
491 (void)sys_sleep(50);
492 if (g_tests_completed.load() >= 5) {
493 break;
494 }
495 timeout--;
496 }
497
498 klog::Info("Exit System Test: completed={}, failed={}",
499 g_tests_completed.load(), g_tests_failed.load());
500
501 EXPECT_EQ(g_tests_completed, 5, "All 5 sub-tests completed");
502 EXPECT_EQ(g_tests_failed, 0, "No sub-tests failed");
503
504 klog::Info("===== Exit System Test End =====");
505 return true;
506}

Callers

nothing calls this directly

Calls 3

InfoFunction · 0.85
sys_sleepFunction · 0.85
AddTaskMethod · 0.80

Tested by

no test coverage detected