Browse Source

cmCTestMultiProcessHandler: Stop searching for tests when limit is reached

Avoid an extra loop iteration if we have no room for more tests.
Brad King 2 years ago
parent
commit
8f1e8af0cc

+ 8 - 4
Source/CTest/cmCTestMultiProcessHandler.cxx

@@ -542,7 +542,7 @@ void cmCTestMultiProcessHandler::StartNextTests()
 
   // Start tests in the preferred order, each subject to readiness checks.
   auto ti = this->OrderedTests.begin();
-  while (ti != this->OrderedTests.end()) {
+  while (numToStart > 0 && ti != this->OrderedTests.end()) {
     // Increment the test iterator now because the current list
     // entry may be deleted below.
     int test = *ti++;
@@ -584,8 +584,6 @@ void cmCTestMultiProcessHandler::StartNextTests()
 
     if (this->StartTest(test)) {
       numToStart -= processors;
-    } else if (numToStart == 0) {
-      break;
     }
   }
 
@@ -606,7 +604,7 @@ void cmCTestMultiProcessHandler::StartNextTests()
     } else if (onlyRunSerialTestsLeft) {
       cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
                  "Only RUN_SERIAL tests remain, awaiting available slot.");
-    } else {
+    } else if (!testWithMinProcessors.empty()) {
       /* clang-format off */
       cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
                  "System Load: " << systemLoad << ", "
@@ -614,6 +612,12 @@ void cmCTestMultiProcessHandler::StartNextTests()
                  "Smallest test " << testWithMinProcessors <<
                  " requires " << minProcessorsRequired);
       /* clang-format on */
+    } else {
+      /* clang-format off */
+      cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+                 "System Load: " << systemLoad << ", "
+                 "Max Allowed Load: " << this->TestLoad);
+      /* clang-format on */
     }
     cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "*****" << std::endl);
 

+ 1 - 0
Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake

@@ -243,6 +243,7 @@ set(ENV{__CTEST_FAKE_LOAD_AVERAGE_FOR_TESTING} 7)
 
 # Verify that new tests are not started when the load average exceeds
 # our threshold and that they then run once the load average drops.
+run_TestLoad(test-load-wait0 5)
 run_TestLoad(test-load-wait1 8)
 
 # Verify that warning message is displayed but tests still start when

+ 21 - 0
Tests/RunCMake/CTestCommandLine/test-load-wait0-stdout.txt

@@ -0,0 +1,21 @@
+Test project [^
+]*/Tests/RunCMake/CTestCommandLine/TestLoad(
+[^*][^
+]*)*
+\*\*\*\*\* WAITING, System Load: 7, Max Allowed Load: 5\*\*\*\*\*
+test 1
+    Start 1: TestLoad1
++(
+[^*][^
+]*)*
+test 2
+    Start 2: TestLoad2
++(
+[^*][^
+]*)*
+1/2 Test #[1-2]: TestLoad[1-2] ........................   Passed +[0-9.]+ sec(
+[^*][^
+]*)*
+2/2 Test #[1-2]: TestLoad[1-2] ........................   Passed +[0-9.]+ sec
++
+100% tests passed, 0 tests failed out of 2

+ 15 - 0
Tests/RunCMake/ctest_test/CTestTestLoadWait0-stdout.txt

@@ -0,0 +1,15 @@
+Test project [^
+]*/Tests/RunCMake/ctest_test/CTestTestLoadWait0-build(
+[^*][^
+]*)*
+\*\*\*\*\* WAITING, System Load: 7, Max Allowed Load: 6\*\*\*\*\*
+test 1
+    Start 1: RunCMakeVersion
++(
+[^*][^
+]*)*
+1/1 Test #1: RunCMakeVersion ..................   Passed +[0-9.]+ sec
++
+100% tests passed, 0 tests failed out of 1
++
+Total Test time \(real\) = +[0-9.]+ sec$

+ 3 - 0
Tests/RunCMake/ctest_test/RunCMakeTest.cmake

@@ -26,6 +26,7 @@ run_ctest_test(TestLoadPass TEST_LOAD 8)
 
 # Verify that new tests are not started when the load average exceeds
 # our threshold and that they then run once the load average drops.
+run_ctest_test(TestLoadWait0 TEST_LOAD 4 PARALLEL_LEVEL 8)
 run_ctest_test(TestLoadWait1 TEST_LOAD 8 PARALLEL_LEVEL 8)
 
 # Verify that when an invalid "TEST_LOAD" value is given, a warning
@@ -39,6 +40,8 @@ run_ctest_test(CTestTestLoadPass)
 
 # Verify that new tests are not started when the load average exceeds
 # our threshold and that they then run once the load average drops.
+set(CASE_CTEST_TEST_LOAD 6)
+run_ctest_test(CTestTestLoadWait0 PARALLEL_LEVEL 8)
 set(CASE_CTEST_TEST_LOAD 8)
 run_ctest_test(CTestTestLoadWait1 PARALLEL_LEVEL 8)
 

+ 15 - 0
Tests/RunCMake/ctest_test/TestLoadWait0-stdout.txt

@@ -0,0 +1,15 @@
+Test project [^
+]*/Tests/RunCMake/ctest_test/TestLoadWait0-build(
+[^*][^
+]*)*
+\*\*\*\*\* WAITING, System Load: 7, Max Allowed Load: 4\*\*\*\*\*
+test 1
+    Start 1: RunCMakeVersion
++(
+[^*][^
+]*)*
+1/1 Test #1: RunCMakeVersion ..................   Passed +[0-9.]+ sec
++
+100% tests passed, 0 tests failed out of 1
++
+Total Test time \(real\) = +[0-9.]+ sec$