cmCTestSleepCommand.cxx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCTestSleepCommand.h"
  14. #include "cmCTestScriptHandler.h"
  15. #include <stdlib.h> // required for atoi
  16. bool cmCTestSleepCommand::InitialPass(
  17. std::vector<std::string> const& args)
  18. {
  19. if (args.size() < 1)
  20. {
  21. this->SetError("called with incorrect number of arguments");
  22. return false;
  23. }
  24. // sleep for specified seconds
  25. unsigned int time1 = atoi(args[0].c_str());
  26. if(args.size() == 1 )
  27. {
  28. cmCTestScriptHandler::SleepInSeconds(time1);
  29. // update the elapsed time since it could have slept for a while
  30. m_CTestScriptHandler->UpdateElapsedTime();
  31. return true;
  32. }
  33. // sleep up to a duration
  34. if(args.size() == 3 )
  35. {
  36. unsigned int duration = atoi(args[1].c_str());
  37. unsigned int time2 = atoi(args[2].c_str());
  38. if (time1 + duration > time2)
  39. {
  40. duration = (time1 + duration - time2);
  41. cmCTestScriptHandler::SleepInSeconds(duration);
  42. // update the elapsed time since it could have slept for a while
  43. m_CTestScriptHandler->UpdateElapsedTime();
  44. }
  45. return true;
  46. }
  47. this->SetError("called with incorrect number of arguments");
  48. return false;
  49. }