cmCTestSleepCommand.cxx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmCTestSleepCommand.h"
  11. #include "cmCTestScriptHandler.h"
  12. #include <stdlib.h> // required for atoi
  13. bool cmCTestSleepCommand::InitialPass(std::vector<std::string> const& args,
  14. cmExecutionStatus& /*unused*/)
  15. {
  16. if (args.empty()) {
  17. this->SetError("called with incorrect number of arguments");
  18. return false;
  19. }
  20. // sleep for specified seconds
  21. unsigned int time1 = atoi(args[0].c_str());
  22. if (args.size() == 1) {
  23. cmCTestScriptHandler::SleepInSeconds(time1);
  24. // update the elapsed time since it could have slept for a while
  25. this->CTestScriptHandler->UpdateElapsedTime();
  26. return true;
  27. }
  28. // sleep up to a duration
  29. if (args.size() == 3) {
  30. unsigned int duration = atoi(args[1].c_str());
  31. unsigned int time2 = atoi(args[2].c_str());
  32. if (time1 + duration > time2) {
  33. duration = (time1 + duration - time2);
  34. cmCTestScriptHandler::SleepInSeconds(duration);
  35. // update the elapsed time since it could have slept for a while
  36. this->CTestScriptHandler->UpdateElapsedTime();
  37. }
  38. return true;
  39. }
  40. this->SetError("called with incorrect number of arguments");
  41. return false;
  42. }