diff options
author | Brad King <brad.king@kitware.com> | 2018-09-11 12:12:03 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2018-09-11 12:12:09 (GMT) |
commit | c669b59095bf01ab0e254949989677496946ec08 (patch) | |
tree | 1f5f0f4c5ce14a08eba26c263ba204e7f241a4ae /Source/CTest/cmCTestMultiProcessHandler.cxx | |
parent | 78d165c9905f73237229497772769a6dc2c32982 (diff) | |
parent | 292ec157b67b5570d5bc2e00bba554cc157d9dae (diff) | |
download | CMake-c669b59095bf01ab0e254949989677496946ec08.zip CMake-c669b59095bf01ab0e254949989677496946ec08.tar.gz CMake-c669b59095bf01ab0e254949989677496946ec08.tar.bz2 |
Merge topic 'ctest-fix-test-load'
292ec157b6 CTest: Fix --test-load regression
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2362
Diffstat (limited to 'Source/CTest/cmCTestMultiProcessHandler.cxx')
-rw-r--r-- | Source/CTest/cmCTestMultiProcessHandler.cxx | 59 |
1 files changed, 39 insertions, 20 deletions
diff --git a/Source/CTest/cmCTestMultiProcessHandler.cxx b/Source/CTest/cmCTestMultiProcessHandler.cxx index 52db9d4..54b4be2 100644 --- a/Source/CTest/cmCTestMultiProcessHandler.cxx +++ b/Source/CTest/cmCTestMultiProcessHandler.cxx @@ -5,7 +5,6 @@ #include "cmAffinity.h" #include "cmCTest.h" #include "cmCTestRunTest.h" -#include "cmCTestScriptHandler.h" #include "cmCTestTestHandler.h" #include "cmSystemTools.h" #include "cmWorkingDirectory.h" @@ -52,6 +51,7 @@ cmCTestMultiProcessHandler::cmCTestMultiProcessHandler() { this->ParallelLevel = 1; this->TestLoad = 0; + this->FakeLoadForTesting = 0; this->Completed = 0; this->RunningCount = 0; this->ProcessorsAvailable = cmAffinity::GetProcessorsAvailable(); @@ -96,6 +96,16 @@ void cmCTestMultiProcessHandler::SetParallelLevel(size_t level) void cmCTestMultiProcessHandler::SetTestLoad(unsigned long load) { this->TestLoad = load; + + std::string fake_load_value; + if (cmSystemTools::GetEnv("__CTEST_FAKE_LOAD_AVERAGE_FOR_TESTING", + fake_load_value)) { + if (!cmSystemTools::StringToULong(fake_load_value.c_str(), + &this->FakeLoadForTesting)) { + cmSystemTools::Error("Failed to parse fake load value: ", + fake_load_value.c_str()); + } + } } void cmCTestMultiProcessHandler::RunTests() @@ -258,12 +268,19 @@ bool cmCTestMultiProcessHandler::StartTest(int test) void cmCTestMultiProcessHandler::StartNextTests() { - size_t numToStart = 0; + if (this->TestLoadRetryTimer.get() != nullptr) { + // This timer may be waiting to call StartNextTests again. + // Since we have been called it is no longer needed. + uv_timer_stop(this->TestLoadRetryTimer); + } if (this->Tests.empty()) { + this->TestLoadRetryTimer.reset(); return; } + size_t numToStart = 0; + if (this->RunningCount < this->ParallelLevel) { numToStart = this->ParallelLevel - this->RunningCount; } @@ -279,7 +296,6 @@ void cmCTestMultiProcessHandler::StartNextTests() } bool allTestsFailedTestLoadCheck = false; - bool usedFakeLoadForTesting = false; size_t minProcessorsRequired = this->ParallelLevel; std::string testWithMinProcessors; @@ -292,15 +308,11 @@ void cmCTestMultiProcessHandler::StartNextTests() allTestsFailedTestLoadCheck = true; // Check for a fake load average value used in testing. - std::string fake_load_value; - if (cmSystemTools::GetEnv("__CTEST_FAKE_LOAD_AVERAGE_FOR_TESTING", - fake_load_value)) { - usedFakeLoadForTesting = true; - if (!cmSystemTools::StringToULong(fake_load_value.c_str(), - &systemLoad)) { - cmSystemTools::Error("Failed to parse fake load value: ", - fake_load_value.c_str()); - } + if (this->FakeLoadForTesting > 0) { + systemLoad = this->FakeLoadForTesting; + // Drop the fake load for the next iteration to a value low enough + // that the next iteration will start tests. + this->FakeLoadForTesting = 1; } // If it's not set, look up the true load average. else { @@ -384,18 +396,25 @@ void cmCTestMultiProcessHandler::StartNextTests() } cmCTestLog(this->CTest, HANDLER_OUTPUT, "*****" << std::endl); - if (usedFakeLoadForTesting) { - // Break out of the infinite loop of waiting for our fake load - // to come down. - this->StopTimePassed = true; - } else { - // Wait between 1 and 5 seconds before trying again. - cmCTestScriptHandler::SleepInSeconds(cmSystemTools::RandomSeed() % 5 + - 1); + // Wait between 1 and 5 seconds before trying again. + unsigned int milliseconds = (cmSystemTools::RandomSeed() % 5 + 1) * 1000; + if (this->FakeLoadForTesting) { + milliseconds = 10; + } + if (this->TestLoadRetryTimer.get() == nullptr) { + this->TestLoadRetryTimer.init(this->Loop, this); } + this->TestLoadRetryTimer.start( + &cmCTestMultiProcessHandler::OnTestLoadRetryCB, milliseconds, 0); } } +void cmCTestMultiProcessHandler::OnTestLoadRetryCB(uv_timer_t* timer) +{ + auto self = static_cast<cmCTestMultiProcessHandler*>(timer->data); + self->StartNextTests(); +} + void cmCTestMultiProcessHandler::FinishTestProcess(cmCTestRunTest* runner, bool started) { |