* @brief 线程组系统测试入口 */
| 241 | * @brief 线程组系统测试入口 |
| 242 | */ |
| 243 | auto thread_group_test() -> bool { |
| 244 | klog::Info("=== Thread Group System Test Suite ==="); |
| 245 | |
| 246 | g_tests_completed = 0; |
| 247 | g_tests_failed = 0; |
| 248 | |
| 249 | struct SubTest { |
| 250 | const char* name; |
| 251 | void (*func)(void*); |
| 252 | }; |
| 253 | |
| 254 | SubTest sub_tests[] = { |
| 255 | {"TestThreadGroupBasic", test_thread_group_basic}, |
| 256 | {"TestThreadGroupDynamic", test_thread_group_dynamic}, |
| 257 | {"TestThreadGroupConcurrentExit", test_thread_group_concurrent_exit}, |
| 258 | }; |
| 259 | |
| 260 | constexpr int kExpectedTests = 3; |
| 261 | |
| 262 | // 顺序执行:子测试共享 g_thread_completed,并行会导致交叉计数 |
| 263 | for (int i = 0; i < kExpectedTests; ++i) { |
| 264 | auto task = kstd::make_unique<TaskControlBlock>(sub_tests[i].name, 10, |
| 265 | sub_tests[i].func, nullptr); |
| 266 | TaskManagerSingleton::instance().AddTask(std::move(task)); |
| 267 | |
| 268 | // 等待当前子测试完成后再启动下一个 |
| 269 | int timeout = 400; |
| 270 | while (timeout > 0 && g_tests_completed < i + 1) { |
| 271 | (void)sys_sleep(50); |
| 272 | timeout--; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | EXPECT_EQ(g_tests_completed.load(), kExpectedTests, |
| 277 | "All thread group tests should complete"); |
| 278 | EXPECT_EQ(g_tests_failed.load(), 0, "No thread group tests should fail"); |
| 279 | |
| 280 | klog::Info("Thread Group System Test Suite: COMPLETED"); |
| 281 | return true; |
| 282 | } |