cmCTestMultiProcessHandler.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #ifndef cmCTestMultiProcessHandler_h
  14. #define cmCTestMultiProcessHandler_h
  15. #include <cmStandardIncludes.h>
  16. #include <cmCTestTestHandler.h>
  17. #include <cmCTestRunTest.h>
  18. /** \class cmCTestMultiProcessHandler
  19. * \brief run parallel ctest
  20. *
  21. * cmCTestMultiProcessHandler
  22. */
  23. class cmCTestMultiProcessHandler
  24. {
  25. public:
  26. struct TestSet : public std::set<int> {};
  27. struct TestMap : public std::map<int, TestSet> {};
  28. struct PropertiesMap : public
  29. std::map<int, cmCTestTestHandler::cmCTestTestProperties*> {};
  30. cmCTestMultiProcessHandler();
  31. // Set the tests
  32. void SetTests(TestMap& tests, TestMap& expensiveTests,
  33. PropertiesMap& properties);
  34. // Set the max number of tests that can be run at the same time.
  35. void SetParallelLevel(size_t);
  36. void RunTests();
  37. void PrintTestList();
  38. void SubmitBatchTests();
  39. void SetPassFailVectors(std::vector<cmStdString>* passed,
  40. std::vector<cmStdString>* failed)
  41. {
  42. this->Passed = passed;
  43. this->Failed = failed;
  44. }
  45. void SetTestResults(std::vector<cmCTestTestHandler::cmCTestTestResult>* r)
  46. {
  47. this->TestResults = r;
  48. }
  49. void SetCTest(cmCTest* ctest) { this->CTest = ctest;}
  50. void SetTestHandler(cmCTestTestHandler * handler)
  51. { this->TestHandler = handler; }
  52. cmCTestTestHandler * GetTestHandler()
  53. { return this->TestHandler; }
  54. protected:
  55. cmCTest* CTest;
  56. // Start the next test or tests as many as are allowed by
  57. // ParallelLevel
  58. void StartNextTests();
  59. void StartTestProcess(int test);
  60. bool StartTest(int test);
  61. // Mark the checkpoint for the given test
  62. void WriteCheckpoint(int index);
  63. // Removes the checkpoint file
  64. void MarkFinished();
  65. // Return true if there are still tests running
  66. // check all running processes for output and exit case
  67. bool CheckOutput();
  68. void RemoveTest(int index);
  69. //Check if we need to resume an interrupted test set
  70. void CheckResume();
  71. int FindMaxIndex();
  72. inline size_t GetProcessorsUsed(int index);
  73. // map from test number to set of depend tests
  74. TestMap Tests;
  75. TestMap ExpensiveTests;
  76. //Total number of tests we'll be running
  77. size_t Total;
  78. //Number of tests that are complete
  79. size_t Completed;
  80. size_t RunningCount;
  81. //list of test properties (indices concurrent to the test map)
  82. PropertiesMap Properties;
  83. std::map<int, bool> TestRunningMap;
  84. std::map<int, bool> TestFinishMap;
  85. std::map<int, cmStdString> TestOutput;
  86. std::vector<cmStdString>* Passed;
  87. std::vector<cmStdString>* Failed;
  88. std::vector<cmCTestTestHandler::cmCTestTestResult>* TestResults;
  89. size_t ParallelLevel; // max number of process that can be run at once
  90. std::set<cmCTestRunTest*> RunningTests; // current running tests
  91. cmCTestTestHandler * TestHandler;
  92. };
  93. #endif