* @brief Wait 系统测试入口 */
| 330 | * @brief Wait 系统测试入口 |
| 331 | */ |
| 332 | auto wait_test() -> bool { |
| 333 | klog::Info("=== Wait System Test Suite ==="); |
| 334 | |
| 335 | g_tests_completed = 0; |
| 336 | g_tests_failed = 0; |
| 337 | |
| 338 | auto& task_mgr = TaskManagerSingleton::instance(); |
| 339 | |
| 340 | // 测试 1: 基本 wait 功能 |
| 341 | auto test1 = kstd::make_unique<TaskControlBlock>("TestWaitBasic", 10, |
| 342 | test_wait_basic, nullptr); |
| 343 | task_mgr.AddTask(std::move(test1)); |
| 344 | |
| 345 | // 测试 2: 等待任意子进程 |
| 346 | auto test2 = kstd::make_unique<TaskControlBlock>( |
| 347 | "TestWaitAnyChild", 10, test_wait_any_child, nullptr); |
| 348 | task_mgr.AddTask(std::move(test2)); |
| 349 | |
| 350 | // 测试 3: 非阻塞 wait |
| 351 | auto test3 = kstd::make_unique<TaskControlBlock>("TestWaitNoHang", 10, |
| 352 | test_wait_no_hang, nullptr); |
| 353 | task_mgr.AddTask(std::move(test3)); |
| 354 | |
| 355 | // 测试 4: 进程组 wait |
| 356 | auto test4 = kstd::make_unique<TaskControlBlock>( |
| 357 | "TestWaitProcessGroup", 10, test_wait_process_group, nullptr); |
| 358 | task_mgr.AddTask(std::move(test4)); |
| 359 | |
| 360 | // 测试 5: 僵尸进程回收 |
| 361 | auto test5 = kstd::make_unique<TaskControlBlock>( |
| 362 | "TestWaitZombieReap", 10, test_wait_zombie_reap, nullptr); |
| 363 | task_mgr.AddTask(std::move(test5)); |
| 364 | |
| 365 | // 同步等待所有测试完成 |
| 366 | constexpr int kExpectedTests = 5; |
| 367 | int timeout = 400; |
| 368 | while (timeout > 0) { |
| 369 | (void)sys_sleep(50); |
| 370 | if (g_tests_completed >= kExpectedTests) { |
| 371 | break; |
| 372 | } |
| 373 | timeout--; |
| 374 | } |
| 375 | |
| 376 | EXPECT_EQ(g_tests_completed.load(), kExpectedTests, |
| 377 | "All wait tests should complete"); |
| 378 | EXPECT_EQ(g_tests_failed.load(), 0, "No wait tests should fail"); |
| 379 | |
| 380 | klog::Info("Wait System Test Suite: COMPLETED"); |
| 381 | return true; |
| 382 | } |