summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-12-15 12:49:26 (GMT)
committerBrad King <brad.king@kitware.com>2018-01-08 17:55:00 (GMT)
commit2567e5df69c1a4276c5e51dfa6c49482b24b1545 (patch)
tree6e37780463de7b012829388d4873f3624392f3b3
parent1138feb38f4e6d259ded23312b7f0f2184ac816a (diff)
downloadCMake-2567e5df69c1a4276c5e51dfa6c49482b24b1545.zip
CMake-2567e5df69c1a4276c5e51dfa6c49482b24b1545.tar.gz
CMake-2567e5df69c1a4276c5e51dfa6c49482b24b1545.tar.bz2
cmCTest: Refactor stop time calculations
Calculate the stop time up front instead of re-parsing its string for every test.
-rw-r--r--Source/CTest/cmCTestRunTest.cxx43
-rw-r--r--Source/cmCTest.cxx71
-rw-r--r--Source/cmCTest.h10
3 files changed, 42 insertions, 82 deletions
diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx
index 0a27138..8050b9a 100644
--- a/Source/CTest/cmCTestRunTest.cxx
+++ b/Source/CTest/cmCTestRunTest.cxx
@@ -9,7 +9,6 @@
#include "cmSystemTools.h"
#include "cmWorkingDirectory.h"
-#include "cm_curl.h"
#include "cm_zlib.h"
#include "cmsys/Base64.h"
#include "cmsys/Process.h"
@@ -18,7 +17,6 @@
#include <iomanip>
#include <sstream>
#include <stdio.h>
-#include <time.h>
#include <utility>
cmCTestRunTest::cmCTestRunTest(cmCTestTestHandler* handler)
@@ -607,48 +605,13 @@ std::chrono::duration<double> cmCTestRunTest::ResolveTimeout()
{
auto timeout = this->TestProperties->Timeout;
- if (this->CTest->GetStopTime().empty()) {
+ std::chrono::system_clock::time_point stop_time = this->CTest->GetStopTime();
+ if (stop_time == std::chrono::system_clock::time_point()) {
return timeout;
}
- struct tm* lctime;
- time_t current_time = time(nullptr);
- lctime = gmtime(&current_time);
- int gm_hour = lctime->tm_hour;
- time_t gm_time = mktime(lctime);
- lctime = localtime(&current_time);
- int local_hour = lctime->tm_hour;
- int tzone_offset = local_hour - gm_hour;
- if (gm_time > current_time && gm_hour < local_hour) {
- // this means gm_time is on the next day
- tzone_offset -= 24;
- } else if (gm_time < current_time && gm_hour > local_hour) {
- // this means gm_time is on the previous day
- tzone_offset += 24;
- }
-
- tzone_offset *= 100;
- char buf[1024];
- // add todays year day and month to the time in str because
- // curl_getdate no longer assumes the day is today
- sprintf(buf, "%d%02d%02d %s %+05i", lctime->tm_year + 1900,
- lctime->tm_mon + 1, lctime->tm_mday,
- this->CTest->GetStopTime().c_str(), tzone_offset);
-
- time_t stop_time_t = curl_getdate(buf, &current_time);
- if (stop_time_t == -1) {
- return timeout;
- }
-
- auto stop_time = std::chrono::system_clock::from_time_t(stop_time_t);
-
- // the stop time refers to the next day
- if (this->CTest->NextDayStopTime) {
- stop_time += std::chrono::hours(24);
- }
auto stop_timeout =
- (stop_time - std::chrono::system_clock::from_time_t(current_time)) %
- std::chrono::hours(24);
+ (stop_time - std::chrono::system_clock::now()) % std::chrono::hours(24);
if (stop_timeout <= std::chrono::duration<double>::zero()) {
cmCTestLog(this->CTest, ERROR_MESSAGE, "The stop time has been passed. "
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx
index 339bf5a..fd7c5e8 100644
--- a/Source/cmCTest.cxx
+++ b/Source/cmCTest.cxx
@@ -281,8 +281,6 @@ cmCTest::cmCTest()
this->GlobalTimeout = std::chrono::duration<double>::zero();
this->CompressXMLFiles = false;
this->ScheduleType.clear();
- this->StopTime.clear();
- this->NextDayStopTime = false;
this->OutputLogFile = nullptr;
this->OutputLogFileLastTag = -1;
this->SuppressUpdatingCTestConfiguration = false;
@@ -2268,10 +2266,41 @@ void cmCTest::SetNotesFiles(const char* notes)
this->NotesFiles = notes;
}
-void cmCTest::SetStopTime(std::string const& time)
+void cmCTest::SetStopTime(std::string const& time_str)
{
- this->StopTime = time;
- this->DetermineNextDayStop();
+
+ struct tm* lctime;
+ time_t current_time = time(nullptr);
+ lctime = gmtime(&current_time);
+ int gm_hour = lctime->tm_hour;
+ time_t gm_time = mktime(lctime);
+ lctime = localtime(&current_time);
+ int local_hour = lctime->tm_hour;
+
+ int tzone_offset = local_hour - gm_hour;
+ if (gm_time > current_time && gm_hour < local_hour) {
+ // this means gm_time is on the next day
+ tzone_offset -= 24;
+ } else if (gm_time < current_time && gm_hour > local_hour) {
+ // this means gm_time is on the previous day
+ tzone_offset += 24;
+ }
+
+ tzone_offset *= 100;
+ char buf[1024];
+ sprintf(buf, "%d%02d%02d %s %+05i", lctime->tm_year + 1900,
+ lctime->tm_mon + 1, lctime->tm_mday, time_str.c_str(), tzone_offset);
+
+ time_t stop_time = curl_getdate(buf, &current_time);
+ if (stop_time == -1) {
+ this->StopTime = std::chrono::system_clock::time_point();
+ return;
+ }
+ this->StopTime = std::chrono::system_clock::from_time_t(stop_time);
+
+ if (stop_time < current_time) {
+ this->StopTime += std::chrono::hours(24);
+ }
}
int cmCTest::ReadCustomConfigurationFileTree(const char* dir, cmMakefile* mf)
@@ -2429,38 +2458,6 @@ void cmCTest::EmptyCTestConfiguration()
this->CTestConfiguration.clear();
}
-void cmCTest::DetermineNextDayStop()
-{
- struct tm* lctime;
- time_t current_time = time(nullptr);
- lctime = gmtime(&current_time);
- int gm_hour = lctime->tm_hour;
- time_t gm_time = mktime(lctime);
- lctime = localtime(&current_time);
- int local_hour = lctime->tm_hour;
-
- int tzone_offset = local_hour - gm_hour;
- if (gm_time > current_time && gm_hour < local_hour) {
- // this means gm_time is on the next day
- tzone_offset -= 24;
- } else if (gm_time < current_time && gm_hour > local_hour) {
- // this means gm_time is on the previous day
- tzone_offset += 24;
- }
-
- tzone_offset *= 100;
- char buf[1024];
- sprintf(buf, "%d%02d%02d %s %+05i", lctime->tm_year + 1900,
- lctime->tm_mon + 1, lctime->tm_mday, this->StopTime.c_str(),
- tzone_offset);
-
- time_t stop_time = curl_getdate(buf, &current_time);
-
- if (stop_time < current_time) {
- this->NextDayStopTime = true;
- }
-}
-
void cmCTest::SetCTestConfiguration(const char* name, const char* value,
bool suppress)
{
diff --git a/Source/cmCTest.h b/Source/cmCTest.h
index e1cf25e..61487f1 100644
--- a/Source/cmCTest.h
+++ b/Source/cmCTest.h
@@ -226,7 +226,10 @@ public:
bool ShouldCompressTestOutput();
bool CompressString(std::string& str);
- std::string GetStopTime() { return this->StopTime; }
+ std::chrono::system_clock::time_point GetStopTime()
+ {
+ return this->StopTime;
+ }
void SetStopTime(std::string const& time);
/** Used for parallel ctest job scheduling */
@@ -464,8 +467,7 @@ private:
bool RepeatUntilFail;
std::string ConfigType;
std::string ScheduleType;
- std::string StopTime;
- bool NextDayStopTime;
+ std::chrono::system_clock::time_point StopTime;
bool Verbose;
bool ExtraVerbose;
bool ProduceXML;
@@ -481,8 +483,6 @@ private:
int GenerateNotesFile(const char* files);
- void DetermineNextDayStop();
-
// these are helper classes
typedef std::map<std::string, cmCTestGenericHandler*> t_TestingHandlers;
t_TestingHandlers TestingHandlers;