| 214 | } // namespace |
| 215 | |
| 216 | auto balance_test() -> bool { |
| 217 | klog::Info("===== Balance System Test Start ====="); |
| 218 | |
| 219 | auto core_count = BasicInfoSingleton::instance().core_count; |
| 220 | if (core_count < 2) { |
| 221 | klog::Info("Skipping balance tests: need >= 2 cores, have {}", core_count); |
| 222 | return true; |
| 223 | } |
| 224 | |
| 225 | g_tests_completed = 0; |
| 226 | g_tests_failed = 0; |
| 227 | |
| 228 | auto& tm = TaskManagerSingleton::instance(); |
| 229 | |
| 230 | auto t1 = kstd::make_unique<TaskControlBlock>( |
| 231 | "TestBalImbalance", 10, test_balance_imbalanced_load, nullptr); |
| 232 | tm.AddTask(std::move(t1)); |
| 233 | |
| 234 | auto t2 = kstd::make_unique<TaskControlBlock>( |
| 235 | "TestBalAffinity", 10, test_balance_respects_affinity, nullptr); |
| 236 | tm.AddTask(std::move(t2)); |
| 237 | |
| 238 | constexpr int kExpectedTests = 2; |
| 239 | int timeout = 600; |
| 240 | while (timeout > 0) { |
| 241 | (void)sys_sleep(50); |
| 242 | if (g_tests_completed.load() >= kExpectedTests) { |
| 243 | break; |
| 244 | } |
| 245 | timeout--; |
| 246 | } |
| 247 | |
| 248 | EXPECT_EQ(g_tests_completed.load(), kExpectedTests, |
| 249 | "All balance sub-tests completed"); |
| 250 | EXPECT_EQ(g_tests_failed.load(), 0, "No balance sub-tests failed"); |
| 251 | |
| 252 | klog::Info("===== Balance System Test End ====="); |
| 253 | return true; |
| 254 | } |