cmCTestSleepCommand.cxx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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
  14. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  15. {
  16. if (args.size() < 1)
  17. {
  18. this->SetError("called with incorrect number of arguments");
  19. return false;
  20. }
  21. // sleep for specified seconds
  22. unsigned int time1 = atoi(args[0].c_str());
  23. if(args.size() == 1 )
  24. {
  25. cmCTestScriptHandler::SleepInSeconds(time1);
  26. // update the elapsed time since it could have slept for a while
  27. this->CTestScriptHandler->UpdateElapsedTime();
  28. return true;
  29. }
  30. // sleep up to a duration
  31. if(args.size() == 3 )
  32. {
  33. unsigned int duration = atoi(args[1].c_str());
  34. unsigned int time2 = atoi(args[2].c_str());
  35. if (time1 + duration > time2)
  36. {
  37. duration = (time1 + duration - time2);
  38. cmCTestScriptHandler::SleepInSeconds(duration);
  39. // update the elapsed time since it could have slept for a while
  40. this->CTestScriptHandler->UpdateElapsedTime();
  41. }
  42. return true;
  43. }
  44. this->SetError("called with incorrect number of arguments");
  45. return false;
  46. }