cmCTestSleepCommand.cxx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmCTestSleepCommand.h"
  4. #include "cmCTestScriptHandler.h"
  5. #include <stdlib.h>
  6. class cmExecutionStatus;
  7. bool cmCTestSleepCommand::InitialPass(std::vector<std::string> const& args,
  8. cmExecutionStatus& /*unused*/)
  9. {
  10. if (args.empty()) {
  11. this->SetError("called with incorrect number of arguments");
  12. return false;
  13. }
  14. // sleep for specified seconds
  15. unsigned int time1 = atoi(args[0].c_str());
  16. if (args.size() == 1) {
  17. cmCTestScriptHandler::SleepInSeconds(time1);
  18. // update the elapsed time since it could have slept for a while
  19. this->CTestScriptHandler->UpdateElapsedTime();
  20. return true;
  21. }
  22. // sleep up to a duration
  23. if (args.size() == 3) {
  24. unsigned int duration = atoi(args[1].c_str());
  25. unsigned int time2 = atoi(args[2].c_str());
  26. if (time1 + duration > time2) {
  27. duration = (time1 + duration - time2);
  28. cmCTestScriptHandler::SleepInSeconds(duration);
  29. // update the elapsed time since it could have slept for a while
  30. this->CTestScriptHandler->UpdateElapsedTime();
  31. }
  32. return true;
  33. }
  34. this->SetError("called with incorrect number of arguments");
  35. return false;
  36. }