cmake/Source/CTest/cmCTestSleepCommand.cxx

44 lines
1.3 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCTestSleepCommand.h"
#include "cmCTestScriptHandler.h"
2016-10-30 18:24:19 +01:00
#include <stdlib.h>
class cmExecutionStatus;
2016-07-09 11:21:54 +02:00
bool cmCTestSleepCommand::InitialPass(std::vector<std::string> const& args,
2016-10-30 18:24:19 +01:00
cmExecutionStatus& /*unused*/)
{
2016-10-30 18:24:19 +01:00
if (args.empty()) {
this->SetError("called with incorrect number of arguments");
return false;
2016-07-09 11:21:54 +02:00
}
// sleep for specified seconds
unsigned int time1 = atoi(args[0].c_str());
2016-07-09 11:21:54 +02:00
if (args.size() == 1) {
cmCTestScriptHandler::SleepInSeconds(time1);
// update the elapsed time since it could have slept for a while
this->CTestScriptHandler->UpdateElapsedTime();
return true;
2016-07-09 11:21:54 +02:00
}
// sleep up to a duration
2016-07-09 11:21:54 +02:00
if (args.size() == 3) {
unsigned int duration = atoi(args[1].c_str());
unsigned int time2 = atoi(args[2].c_str());
2016-07-09 11:21:54 +02:00
if (time1 + duration > time2) {
duration = (time1 + duration - time2);
cmCTestScriptHandler::SleepInSeconds(duration);
// update the elapsed time since it could have slept for a while
this->CTestScriptHandler->UpdateElapsedTime();
}
2016-07-09 11:21:54 +02:00
return true;
}
2013-03-16 19:13:01 +02:00
this->SetError("called with incorrect number of arguments");
return false;
}