diff options
author | Brad King <brad.king@kitware.com> | 2023-05-10 15:30:48 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-05-31 13:43:03 (GMT) |
commit | e38c05688ed637bdda8e6af5f2d76fc12bee35e3 (patch) | |
tree | cf3297e8dba3a8f59252308b6e7b11a480bbca1b | |
parent | 25c1468314c5f45b254067d882dfc042f9d1c63e (diff) | |
download | CMake-e38c05688ed637bdda8e6af5f2d76fc12bee35e3.zip CMake-e38c05688ed637bdda8e6af5f2d76fc12bee35e3.tar.gz CMake-e38c05688ed637bdda8e6af5f2d76fc12bee35e3.tar.bz2 |
CTest/cmProcess: Adopt field tracking reason for the process timeout
A test process may timeout either because the test timeout was reached,
or the overall stop time was reached. Shorten the lifetime for which
we track this state in `cmCTestRunTest`.
-rw-r--r-- | Source/CTest/cmCTestMultiProcessHandler.cxx | 7 | ||||
-rw-r--r-- | Source/CTest/cmCTestRunTest.cxx | 18 | ||||
-rw-r--r-- | Source/CTest/cmCTestRunTest.h | 11 | ||||
-rw-r--r-- | Source/CTest/cmProcess.h | 9 |
4 files changed, 32 insertions, 13 deletions
diff --git a/Source/CTest/cmCTestMultiProcessHandler.cxx b/Source/CTest/cmCTestMultiProcessHandler.cxx index 44eccb2..7d22a87 100644 --- a/Source/CTest/cmCTestMultiProcessHandler.cxx +++ b/Source/CTest/cmCTestMultiProcessHandler.cxx @@ -634,8 +634,9 @@ void cmCTestMultiProcessHandler::FinishTestProcess( int test = runner->GetIndex(); auto* properties = runner->GetTestProperties(); - bool testResult = runner->EndTest(this->Completed, this->Total, started); - if (runner->TimedOutForStopTime()) { + cmCTestRunTest::EndTestResult testResult = + runner->EndTest(this->Completed, this->Total, started); + if (testResult.StopTimePassed) { this->SetStopTimePassed(); } if (started) { @@ -646,7 +647,7 @@ void cmCTestMultiProcessHandler::FinishTestProcess( } } - if (testResult) { + if (testResult.Passed) { this->Passed->push_back(properties->Name); } else if (!properties->Disabled) { this->Failed->push_back(properties->Name); diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx index cd2b230..2859b82 100644 --- a/Source/CTest/cmCTestRunTest.cxx +++ b/Source/CTest/cmCTestRunTest.cxx @@ -95,16 +95,15 @@ void cmCTestRunTest::CheckOutput(std::string const& line) } } -bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started) +cmCTestRunTest::EndTestResult cmCTestRunTest::EndTest(size_t completed, + size_t total, + bool started) { this->WriteLogOutputTop(completed, total); std::string reason; bool passed = true; cmProcess::State res = started ? this->TestProcess->GetProcessStatus() : cmProcess::State::Error; - if (res != cmProcess::State::Expired) { - this->TimeoutIsForStopTime = false; - } std::int64_t retVal = this->TestProcess->GetExitValue(); bool forceFail = false; bool forceSkip = false; @@ -344,8 +343,15 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started) if (!this->NeedsToRepeat()) { this->TestHandler->TestResults.push_back(this->TestResult); } + cmCTestRunTest::EndTestResult testResult; + testResult.Passed = passed || skipped; + if (res == cmProcess::State::Expired && + this->TestProcess->GetTimeoutReason() == + cmProcess::TimeoutReason::StopTime) { + testResult.StopTimePassed = true; + } this->TestProcess.reset(); - return passed || skipped; + return testResult; } bool cmCTestRunTest::StartAgain(std::unique_ptr<cmCTestRunTest> runner, @@ -772,8 +778,8 @@ bool cmCTestRunTest::ForkProcess() timeRemaining = cmDuration::zero(); } if (!timeout || timeRemaining < *timeout) { - this->TimeoutIsForStopTime = true; timeout = timeRemaining; + this->TestProcess->SetTimeoutReason(cmProcess::TimeoutReason::StopTime); } if (timeout) { diff --git a/Source/CTest/cmCTestRunTest.h b/Source/CTest/cmCTestRunTest.h index 6a507f4..fed7296 100644 --- a/Source/CTest/cmCTestRunTest.h +++ b/Source/CTest/cmCTestRunTest.h @@ -71,10 +71,16 @@ public: std::string const& output, std::string const& detail); + struct EndTestResult + { + bool Passed = false; + bool StopTimePassed = false; + }; + // launch the test process, return whether it started correctly bool StartTest(size_t completed, size_t total); // capture and report the test results - bool EndTest(size_t completed, size_t total, bool started); + EndTestResult EndTest(size_t completed, size_t total, bool started); // Called by ctest -N to log the command string void ComputeArguments(); @@ -90,8 +96,6 @@ public: void FinalizeTest(bool started = true); - bool TimedOutForStopTime() const { return this->TimeoutIsForStopTime; } - void SetUseAllocatedResources(bool use) { this->UseAllocatedResources = use; @@ -120,7 +124,6 @@ private: std::string GetTestPrefix(size_t completed, size_t total) const; cmCTestTestHandler::cmCTestTestProperties* TestProperties; - bool TimeoutIsForStopTime = false; // Pointer back to the "parent"; the handler that invoked this test run cmCTestTestHandler* TestHandler; cmCTest* CTest; diff --git a/Source/CTest/cmProcess.h b/Source/CTest/cmProcess.h index 1578687..c80922d 100644 --- a/Source/CTest/cmProcess.h +++ b/Source/CTest/cmProcess.h @@ -41,6 +41,14 @@ public: // Return true if the process starts bool StartProcess(uv_loop_t& loop, std::vector<size_t>* affinity); + enum class TimeoutReason + { + Normal, + StopTime, + }; + void SetTimeoutReason(TimeoutReason r) { this->TimeoutReason_ = r; } + TimeoutReason GetTimeoutReason() const { return this->TimeoutReason_; } + enum class State { Starting, @@ -79,6 +87,7 @@ public: private: cm::optional<cmDuration> Timeout; + TimeoutReason TimeoutReason_ = TimeoutReason::Normal; std::chrono::steady_clock::time_point StartTime; cmDuration TotalTime; bool ReadHandleClosed = false; |