summaryrefslogtreecommitdiffstats
path: root/Source/CTest/cmCTestBuildAndTestHandler.cxx
diff options
context:
space:
mode:
authorWouter Klouwen <wouter.klouwen@youview.com>2017-11-03 13:25:33 (GMT)
committerWouter Klouwen <wouter.klouwen@youview.com>2017-11-14 13:30:14 (GMT)
commite8a4036e9621d567fa47a118aa5583f85fae811a (patch)
tree904b467a4470c1d48d435334b8406902bac690b3 /Source/CTest/cmCTestBuildAndTestHandler.cxx
parentb77501d4c7341337174f29cae623d8e1905af29a (diff)
downloadCMake-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/cmCTestBuildAndTestHandler.cxx')
-rw-r--r--Source/CTest/cmCTestBuildAndTestHandler.cxx23
1 files changed, 14 insertions, 9 deletions
diff --git a/Source/CTest/cmCTestBuildAndTestHandler.cxx b/Source/CTest/cmCTestBuildAndTestHandler.cxx
index a0d68a0..b603758 100644
--- a/Source/CTest/cmCTestBuildAndTestHandler.cxx
+++ b/Source/CTest/cmCTestBuildAndTestHandler.cxx
@@ -10,6 +10,7 @@
#include "cmake.h"
#include "cmsys/Process.h"
+#include <chrono>
#include <stdlib.h>
cmCTestBuildAndTestHandler::cmCTestBuildAndTestHandler()
@@ -192,7 +193,7 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
// we need to honor the timeout specified, the timeout include cmake, build
// and test time
- double clock_start = cmSystemTools::GetTime();
+ auto clock_start = std::chrono::steady_clock::now();
// make sure the binary dir is there
out << "Internal cmake changing into directory: " << this->BinaryDir
@@ -222,10 +223,12 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
this->BuildTargets.push_back("");
}
for (std::string const& tar : this->BuildTargets) {
- double remainingTime = 0;
+ std::chrono::duration<double> remainingTime = std::chrono::seconds(0);
if (this->Timeout > 0) {
- remainingTime = this->Timeout - cmSystemTools::GetTime() + clock_start;
- if (remainingTime <= 0) {
+ remainingTime = std::chrono::duration<double>(this->Timeout) -
+ std::chrono::duration_cast<std::chrono::seconds>(
+ std::chrono::steady_clock::now() - clock_start);
+ if (remainingTime <= std::chrono::seconds(0)) {
if (outstring) {
*outstring = "--build-and-test timeout exceeded. ";
}
@@ -248,7 +251,7 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
int retVal = cm.GetGlobalGenerator()->Build(
this->SourceDir, this->BinaryDir, this->BuildProject, tar, output,
this->BuildMakeProgram, config, !this->BuildNoClean, false, false,
- remainingTime);
+ remainingTime.count());
out << output;
// if the build failed then return
if (retVal) {
@@ -320,10 +323,12 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
out << "\n";
// how much time is remaining
- double remainingTime = 0;
+ std::chrono::duration<double> remainingTime = std::chrono::seconds(0);
if (this->Timeout > 0) {
- remainingTime = this->Timeout - cmSystemTools::GetTime() + clock_start;
- if (remainingTime <= 0) {
+ remainingTime = std::chrono::duration<double>(this->Timeout) -
+ std::chrono::duration_cast<std::chrono::seconds>(
+ std::chrono::steady_clock::now() - clock_start);
+ if (remainingTime <= std::chrono::seconds(0)) {
if (outstring) {
*outstring = "--build-and-test timeout exceeded. ";
}
@@ -332,7 +337,7 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
}
int runTestRes = this->CTest->RunTest(testCommand, &outs, &retval, nullptr,
- remainingTime, nullptr);
+ remainingTime.count(), nullptr);
if (runTestRes != cmsysProcess_State_Exited || retval != 0) {
out << "Test command failed: " << testCommand[0] << "\n";