mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-16 05:26:58 +08:00
cmCTest: Move timing functions from cmCTestScriptHandler to cmCTest
This commit is contained in:
@@ -200,6 +200,9 @@ bool cmCTestHandlerCommand::InitialPass(std::vector<std::string> const& args,
|
||||
return false;
|
||||
}
|
||||
|
||||
// reread time limit, as the variable may have been modified.
|
||||
this->CTest->SetTimeLimit(this->Makefile->GetDefinition("CTEST_TIME_LIMIT"));
|
||||
|
||||
int res = handler->ProcessHandler();
|
||||
if (!this->ReturnValue.empty()) {
|
||||
this->Makefile->AddDefinition(this->ReturnValue, std::to_string(res));
|
||||
|
@@ -2,6 +2,7 @@
|
||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||
#include "cmCTestScriptHandler.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdlib>
|
||||
#include <map>
|
||||
#include <ratio>
|
||||
@@ -37,7 +38,6 @@
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmUVHandlePtr.h"
|
||||
#include "cmUVProcessChain.h"
|
||||
#include "cmValue.h"
|
||||
#include "cmake.h"
|
||||
|
||||
cmCTestScriptHandler::cmCTestScriptHandler() = default;
|
||||
@@ -46,9 +46,6 @@ void cmCTestScriptHandler::Initialize()
|
||||
{
|
||||
this->Superclass::Initialize();
|
||||
|
||||
// what time in seconds did this script start running
|
||||
this->ScriptStartTime = std::chrono::steady_clock::time_point();
|
||||
|
||||
this->Makefile.reset();
|
||||
this->ParentMakefile = nullptr;
|
||||
|
||||
@@ -87,8 +84,7 @@ void cmCTestScriptHandler::UpdateElapsedTime()
|
||||
{
|
||||
if (this->Makefile) {
|
||||
// set the current elapsed time
|
||||
auto itime = cmDurationTo<unsigned int>(std::chrono::steady_clock::now() -
|
||||
this->ScriptStartTime);
|
||||
auto itime = cmDurationTo<unsigned int>(this->CTest->GetElapsedTime());
|
||||
auto timeString = std::to_string(itime);
|
||||
this->Makefile->AddDefinition("CTEST_ELAPSED_TIME", timeString);
|
||||
}
|
||||
@@ -341,8 +337,6 @@ int cmCTestScriptHandler::RunConfigurationScript(
|
||||
|
||||
int result;
|
||||
|
||||
this->ScriptStartTime = std::chrono::steady_clock::now();
|
||||
|
||||
// read in the script
|
||||
if (pscope) {
|
||||
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
||||
@@ -371,22 +365,3 @@ bool cmCTestScriptHandler::RunScript(cmCTest* ctest, cmMakefile* mf,
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
cmDuration cmCTestScriptHandler::GetRemainingTimeAllowed()
|
||||
{
|
||||
if (!this->Makefile) {
|
||||
return cmCTest::MaxDuration();
|
||||
}
|
||||
|
||||
cmValue timelimitS = this->Makefile->GetDefinition("CTEST_TIME_LIMIT");
|
||||
|
||||
if (!timelimitS) {
|
||||
return cmCTest::MaxDuration();
|
||||
}
|
||||
|
||||
auto timelimit = cmDuration(atof(timelimitS->c_str()));
|
||||
|
||||
auto duration = std::chrono::duration_cast<cmDuration>(
|
||||
std::chrono::steady_clock::now() - this->ScriptStartTime);
|
||||
return (timelimit - duration);
|
||||
}
|
||||
|
@@ -4,13 +4,11 @@
|
||||
|
||||
#include "cmConfigure.h" // IWYU pragma: keep
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "cmCTestGenericHandler.h"
|
||||
#include "cmDuration.h"
|
||||
|
||||
class cmCTest;
|
||||
class cmCTestCommand;
|
||||
@@ -48,13 +46,6 @@ public:
|
||||
*/
|
||||
void UpdateElapsedTime();
|
||||
|
||||
/**
|
||||
* Return the time remaianing that the script is allowed to run in
|
||||
* seconds if the user has set the variable CTEST_TIME_LIMIT. If that has
|
||||
* not been set it returns a very large value.
|
||||
*/
|
||||
cmDuration GetRemainingTimeAllowed();
|
||||
|
||||
cmCTestScriptHandler();
|
||||
cmCTestScriptHandler(const cmCTestScriptHandler&) = delete;
|
||||
const cmCTestScriptHandler& operator=(const cmCTestScriptHandler&) = delete;
|
||||
@@ -80,10 +71,6 @@ private:
|
||||
std::vector<std::string> ConfigurationScripts;
|
||||
std::vector<bool> ScriptProcessScope;
|
||||
|
||||
// what time in seconds did this script start running
|
||||
std::chrono::steady_clock::time_point ScriptStartTime =
|
||||
std::chrono::steady_clock::time_point();
|
||||
|
||||
std::unique_ptr<cmMakefile> Makefile;
|
||||
cmMakefile* ParentMakefile = nullptr;
|
||||
std::unique_ptr<cmGlobalGenerator> GlobalGenerator;
|
||||
|
@@ -180,6 +180,10 @@ struct cmCTest::Private
|
||||
|
||||
cmDuration GlobalTimeout = cmDuration::zero();
|
||||
|
||||
std::chrono::steady_clock::time_point StartTime =
|
||||
std::chrono::steady_clock::now();
|
||||
cmDuration TimeLimit = cmCTest::MaxDuration();
|
||||
|
||||
int MaxTestNameWidth = 30;
|
||||
|
||||
cm::optional<size_t> ParallelLevel = 1;
|
||||
@@ -838,6 +842,7 @@ int cmCTest::ProcessSteps()
|
||||
script.CreateCMake();
|
||||
cmMakefile& mf = *script.GetMakefile();
|
||||
this->ReadCustomConfigurationFileTree(this->Impl->BinaryDir, &mf);
|
||||
this->SetTimeLimit(mf.GetDefinition("CTEST_TIME_LIMIT"));
|
||||
this->SetCMakeVariables(mf);
|
||||
std::vector<cmListFileArgument> args{
|
||||
cmListFileArgument("RETURN_VALUE", cmListFileArgument::Unquoted, 0),
|
||||
@@ -3690,9 +3695,21 @@ std::string cmCTest::GetColorCode(Color color) const
|
||||
return "";
|
||||
}
|
||||
|
||||
cmDuration cmCTest::GetRemainingTimeAllowed()
|
||||
void cmCTest::SetTimeLimit(cmValue val)
|
||||
{
|
||||
return this->GetScriptHandler()->GetRemainingTimeAllowed();
|
||||
this->Impl->TimeLimit =
|
||||
val ? cmDuration(atof(val->c_str())) : cmCTest::MaxDuration();
|
||||
}
|
||||
|
||||
cmDuration cmCTest::GetElapsedTime() const
|
||||
{
|
||||
return std::chrono::duration_cast<cmDuration>(
|
||||
std::chrono::steady_clock::now() - this->Impl->StartTime);
|
||||
}
|
||||
|
||||
cmDuration cmCTest::GetRemainingTimeAllowed() const
|
||||
{
|
||||
return this->Impl->TimeLimit - this->GetElapsedTime();
|
||||
}
|
||||
|
||||
cmDuration cmCTest::MaxDuration()
|
||||
|
@@ -30,6 +30,7 @@ class cmCTestSubmitHandler;
|
||||
class cmCTestUploadHandler;
|
||||
class cmGeneratedFileStream;
|
||||
class cmMakefile;
|
||||
class cmValue;
|
||||
class cmXMLWriter;
|
||||
|
||||
/** \class cmCTest
|
||||
@@ -166,12 +167,15 @@ public:
|
||||
/** base64 encode a file */
|
||||
std::string Base64EncodeFile(std::string const& file);
|
||||
|
||||
void SetTimeLimit(cmValue val);
|
||||
cmDuration GetElapsedTime() const;
|
||||
|
||||
/**
|
||||
* Return the time remaining that the script is allowed to run in
|
||||
* seconds if the user has set the variable CTEST_TIME_LIMIT. If that has
|
||||
* not been set it returns a very large duration.
|
||||
*/
|
||||
cmDuration GetRemainingTimeAllowed();
|
||||
cmDuration GetRemainingTimeAllowed() const;
|
||||
|
||||
static cmDuration MaxDuration();
|
||||
|
||||
|
Reference in New Issue
Block a user