diff options
author | Wouter Klouwen <wouter.klouwen@youview.com> | 2017-11-03 13:25:33 (GMT) |
---|---|---|
committer | Wouter Klouwen <wouter.klouwen@youview.com> | 2017-11-14 13:30:14 (GMT) |
commit | e8a4036e9621d567fa47a118aa5583f85fae811a (patch) | |
tree | 904b467a4470c1d48d435334b8406902bac690b3 /Source/CTest/cmCTestRunTest.cxx | |
parent | b77501d4c7341337174f29cae623d8e1905af29a (diff) | |
download | CMake-e8a4036e9621d567fa47a118aa5583f85fae811a.zip CMake-e8a4036e9621d567fa47a118aa5583f85fae811a.tar.gz CMake-e8a4036e9621d567fa47a118aa5583f85fae811a.tar.bz2 |
CTest: use std::chrono::steady_clock for time keeping
It was reported in issue #17345 that CTest does not use monotonic time
to report test duration. Monotonic clocks are not affected by large NTP
adjustments or things like daylight savings time.
As CMake 3.10 requires C++11, which introduced std::chrono, this commit
moves the time keeping in CTest from cmSystemTools::GetTime() to
std::chrono::steady_clock.
Fixes: #17345
Diffstat (limited to 'Source/CTest/cmCTestRunTest.cxx')
-rw-r--r-- | Source/CTest/cmCTestRunTest.cxx | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx index abdb643..99531af 100644 --- a/Source/CTest/cmCTestRunTest.cxx +++ b/Source/CTest/cmCTestRunTest.cxx @@ -14,6 +14,7 @@ #include "cmsys/Base64.h" #include "cmsys/Process.h" #include "cmsys/RegularExpression.hxx" +#include <chrono> #include <iomanip> #include <sstream> #include <stdio.h> @@ -46,11 +47,12 @@ cmCTestRunTest::~cmCTestRunTest() bool cmCTestRunTest::CheckOutput() { // Read lines for up to 0.1 seconds of total time. - double timeout = 0.1; - double timeEnd = cmSystemTools::GetTime() + timeout; + std::chrono::duration<double> timeout = std::chrono::milliseconds(100); + auto timeEnd = std::chrono::steady_clock::now() + timeout; std::string line; - while ((timeout = timeEnd - cmSystemTools::GetTime(), timeout > 0)) { - int p = this->TestProcess->GetNextOutputLine(line, timeout); + while ((timeout = timeEnd - std::chrono::steady_clock::now(), + timeout > std::chrono::seconds(0))) { + int p = this->TestProcess->GetNextOutputLine(line, timeout.count()); if (p == cmsysProcess_Pipe_None) { // Process has terminated and all output read. return false; |