| 360 | } |
| 361 | |
| 362 | void test_clone_flags_auto_completion(void* /*arg*/) { |
| 363 | klog::Info("=== Clone Flags Auto Completion Test ==="); |
| 364 | |
| 365 | bool passed = true; |
| 366 | g_flags_done = 0; |
| 367 | g_flags_value = 0; |
| 368 | |
| 369 | { |
| 370 | CloneFlags empty_flags{}; |
| 371 | if (empty_flags.value() != 0) { |
| 372 | klog::Err("Default CloneFlags is not 0"); |
| 373 | passed = false; |
| 374 | } |
| 375 | |
| 376 | CloneFlags combined = static_cast<CloneFlags>( |
| 377 | clone_flag::kThread | clone_flag::kVm | clone_flag::kFiles); |
| 378 | if (!(combined & clone_flag::kThread)) { |
| 379 | klog::Err("kThread not set in combined flags"); |
| 380 | passed = false; |
| 381 | } |
| 382 | if (!(combined & clone_flag::kVm)) { |
| 383 | klog::Err("kVm not set in combined flags"); |
| 384 | passed = false; |
| 385 | } |
| 386 | if (!(combined & clone_flag::kFiles)) { |
| 387 | klog::Err("kFiles not set in combined flags"); |
| 388 | passed = false; |
| 389 | } |
| 390 | if (combined & clone_flag::kSighand) { |
| 391 | klog::Err("kSighand unexpectedly set"); |
| 392 | passed = false; |
| 393 | } |
| 394 | if (combined & clone_flag::kParent) { |
| 395 | klog::Err("kParent unexpectedly set"); |
| 396 | passed = false; |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | { |
| 401 | uint64_t expected_flags = |
| 402 | clone_flag::kThread | clone_flag::kVm | clone_flag::kSighand; |
| 403 | auto task = kstd::make_unique<TaskControlBlock>( |
| 404 | "FlagsTask", 10, flags_reporter_work, nullptr); |
| 405 | task->aux->clone_flags = static_cast<CloneFlags>(expected_flags); |
| 406 | TaskManagerSingleton::instance().AddTask(std::move(task)); |
| 407 | |
| 408 | for (int i = 0; i < 100 && g_flags_done.load() == 0; ++i) { |
| 409 | (void)sys_sleep(10); |
| 410 | } |
| 411 | |
| 412 | uint64_t reported = g_flags_value.load(); |
| 413 | if (reported != expected_flags) { |
| 414 | klog::Err( |
| 415 | "Flags not preserved through AddTask: got 0x{:x} expected " |
| 416 | "0x{:x}", |
| 417 | reported, expected_flags); |
| 418 | passed = false; |
| 419 | } |