summaryrefslogtreecommitdiffstats
path: root/Source/CTest/cmCTestSubmitHandler.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/cmCTestSubmitHandler.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/cmCTestSubmitHandler.cxx')
-rw-r--r--Source/CTest/cmCTestSubmitHandler.cxx36
1 files changed, 21 insertions, 15 deletions
diff --git a/Source/CTest/cmCTestSubmitHandler.cxx b/Source/CTest/cmCTestSubmitHandler.cxx
index 719688c..6534fd1 100644
--- a/Source/CTest/cmCTestSubmitHandler.cxx
+++ b/Source/CTest/cmCTestSubmitHandler.cxx
@@ -6,6 +6,7 @@
#include "cm_jsoncpp_reader.h"
#include "cm_jsoncpp_value.h"
#include "cmsys/Process.h"
+#include <chrono>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
@@ -496,10 +497,11 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix,
? ""
: this->GetOption("RetryCount");
- int delay = retryDelay.empty()
- ? atoi(this->CTest->GetCTestConfiguration("CTestSubmitRetryDelay")
- .c_str())
- : atoi(retryDelay.c_str());
+ auto delay = std::chrono::duration<double>(
+ retryDelay.empty()
+ ? atoi(this->CTest->GetCTestConfiguration("CTestSubmitRetryDelay")
+ .c_str())
+ : atoi(retryDelay.c_str()));
int count = retryCount.empty()
? atoi(this->CTest->GetCTestConfiguration("CTestSubmitRetryCount")
.c_str())
@@ -507,12 +509,12 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix,
for (int i = 0; i < count; i++) {
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
- " Submit failed, waiting " << delay
+ " Submit failed, waiting " << delay.count()
<< " seconds...\n",
this->Quiet);
- double stop = cmSystemTools::GetTime() + delay;
- while (cmSystemTools::GetTime() < stop) {
+ auto stop = std::chrono::steady_clock::now() + delay;
+ while (std::chrono::steady_clock::now() < stop) {
cmSystemTools::Delay(100);
}
@@ -1031,11 +1033,15 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
std::string retryCountString = this->GetOption("RetryCount") == nullptr
? ""
: this->GetOption("RetryCount");
- unsigned long retryDelay = 0;
+ auto retryDelay = std::chrono::seconds(0);
if (!retryDelayString.empty()) {
- if (!cmSystemTools::StringToULong(retryDelayString.c_str(), &retryDelay)) {
+ unsigned long retryDelayValue = 0;
+ if (!cmSystemTools::StringToULong(retryDelayString.c_str(),
+ &retryDelayValue)) {
cmCTestLog(this->CTest, WARNING, "Invalid value for 'RETRY_DELAY' : "
<< retryDelayString << std::endl);
+ } else {
+ retryDelay = std::chrono::seconds(retryDelayValue);
}
}
unsigned long retryCount = 0;
@@ -1087,12 +1093,12 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
// If request failed, wait and retry.
for (unsigned long i = 0; i < retryCount; i++) {
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
- " Request failed, waiting " << retryDelay
+ " Request failed, waiting " << retryDelay.count()
<< " seconds...\n",
this->Quiet);
- double stop = cmSystemTools::GetTime() + static_cast<double>(retryDelay);
- while (cmSystemTools::GetTime() < stop) {
+ auto stop = std::chrono::steady_clock::now() + retryDelay;
+ while (std::chrono::steady_clock::now() < stop) {
cmSystemTools::Delay(100);
}
@@ -1161,12 +1167,12 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
// If upload failed, wait and retry.
for (unsigned long i = 0; i < retryCount; i++) {
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
- " Upload failed, waiting " << retryDelay
+ " Upload failed, waiting " << retryDelay.count()
<< " seconds...\n",
this->Quiet);
- double stop = cmSystemTools::GetTime() + static_cast<double>(retryDelay);
- while (cmSystemTools::GetTime() < stop) {
+ auto stop = std::chrono::steady_clock::now() + retryDelay;
+ while (std::chrono::steady_clock::now() < stop) {
cmSystemTools::Delay(100);
}