| 348 | } // namespace |
| 349 | |
| 350 | auto spinlock_test() -> bool { |
| 351 | bool ret = true; |
| 352 | size_t core_id = cpu_io::GetCurrentCoreId(); |
| 353 | |
| 354 | // 单元测试仅在核心 0 上运行,以避免日志混乱 |
| 355 | if (core_id == 0) { |
| 356 | klog::Info("Starting spinlock_test"); |
| 357 | ret = ret && test_basic_lock(); |
| 358 | ret = ret && test_recursive_lock(); |
| 359 | ret = ret && test_lock_guard(); |
| 360 | ret = ret && test_interrupt_restore(); |
| 361 | } |
| 362 | |
| 363 | // SMP (多核) 测试在所有核心上运行 |
| 364 | // 使用顺序执行以确保如果前一个测试失败,屏障不会死锁 |
| 365 | if (!spinlock_smp_test()) ret = false; |
| 366 | if (!spinlock_smp_buffer_test()) ret = false; |
| 367 | if (!spinlock_smp_string_test()) ret = false; |
| 368 | |
| 369 | if (core_id == 0) { |
| 370 | if (ret) { |
| 371 | klog::Info("spinlock_test passed"); |
| 372 | } else { |
| 373 | klog::Err("spinlock_test failed"); |
| 374 | } |
| 375 | } |
| 376 | return ret; |
| 377 | } |
nothing calls this directly
no test coverage detected