cmCTestMultiProcessHandler.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. #ifndef cmCTestMultiProcessHandler_h
  11. #define cmCTestMultiProcessHandler_h
  12. #include <cmCTestTestHandler.h>
  13. #include <cmCTestRunTest.h>
  14. /** \class cmCTestMultiProcessHandler
  15. * \brief run parallel ctest
  16. *
  17. * cmCTestMultiProcessHandler
  18. */
  19. class cmCTestMultiProcessHandler
  20. {
  21. friend class TestComparator;
  22. public:
  23. struct TestSet : public std::set<int>
  24. {
  25. };
  26. struct TestMap : public std::map<int, TestSet>
  27. {
  28. };
  29. struct TestList : public std::vector<int>
  30. {
  31. };
  32. struct PropertiesMap
  33. : public std::map<int, cmCTestTestHandler::cmCTestTestProperties*>
  34. {
  35. };
  36. cmCTestMultiProcessHandler();
  37. virtual ~cmCTestMultiProcessHandler();
  38. // Set the tests
  39. void SetTests(TestMap& tests, PropertiesMap& properties);
  40. // Set the max number of tests that can be run at the same time.
  41. void SetParallelLevel(size_t);
  42. void SetTestLoad(unsigned long load);
  43. virtual void RunTests();
  44. void PrintTestList();
  45. void PrintLabels();
  46. void SetPassFailVectors(std::vector<std::string>* passed,
  47. std::vector<std::string>* failed)
  48. {
  49. this->Passed = passed;
  50. this->Failed = failed;
  51. }
  52. void SetTestResults(std::vector<cmCTestTestHandler::cmCTestTestResult>* r)
  53. {
  54. this->TestResults = r;
  55. }
  56. void SetCTest(cmCTest* ctest) { this->CTest = ctest; }
  57. void SetTestHandler(cmCTestTestHandler* handler)
  58. {
  59. this->TestHandler = handler;
  60. }
  61. cmCTestTestHandler* GetTestHandler() { return this->TestHandler; }
  62. void SetQuiet(bool b) { this->Quiet = b; }
  63. protected:
  64. // Start the next test or tests as many as are allowed by
  65. // ParallelLevel
  66. void StartNextTests();
  67. void StartTestProcess(int test);
  68. bool StartTest(int test);
  69. // Mark the checkpoint for the given test
  70. void WriteCheckpoint(int index);
  71. void UpdateCostData();
  72. void ReadCostData();
  73. // Return index of a test based on its name
  74. int SearchByName(std::string const& name);
  75. void CreateTestCostList();
  76. void GetAllTestDependencies(int test, TestList& dependencies);
  77. void CreateSerialTestCostList();
  78. void CreateParallelTestCostList();
  79. // Removes the checkpoint file
  80. void MarkFinished();
  81. void EraseTest(int index);
  82. // Return true if there are still tests running
  83. // check all running processes for output and exit case
  84. bool CheckOutput();
  85. void RemoveTest(int index);
  86. // Check if we need to resume an interrupted test set
  87. void CheckResume();
  88. // Check if there are any circular dependencies
  89. bool CheckCycles();
  90. int FindMaxIndex();
  91. inline size_t GetProcessorsUsed(int index);
  92. std::string GetName(int index);
  93. void LockResources(int index);
  94. void UnlockResources(int index);
  95. // map from test number to set of depend tests
  96. TestMap Tests;
  97. TestList SortedTests;
  98. // Total number of tests we'll be running
  99. size_t Total;
  100. // Number of tests that are complete
  101. size_t Completed;
  102. size_t RunningCount;
  103. bool StopTimePassed;
  104. // list of test properties (indices concurrent to the test map)
  105. PropertiesMap Properties;
  106. std::map<int, bool> TestRunningMap;
  107. std::map<int, bool> TestFinishMap;
  108. std::map<int, std::string> TestOutput;
  109. std::vector<std::string>* Passed;
  110. std::vector<std::string>* Failed;
  111. std::vector<std::string> LastTestsFailed;
  112. std::set<std::string> LockedResources;
  113. std::vector<cmCTestTestHandler::cmCTestTestResult>* TestResults;
  114. size_t ParallelLevel; // max number of process that can be run at once
  115. unsigned long TestLoad;
  116. std::set<cmCTestRunTest*> RunningTests; // current running tests
  117. cmCTestTestHandler* TestHandler;
  118. cmCTest* CTest;
  119. bool HasCycles;
  120. bool Quiet;
  121. bool SerialTestRunning;
  122. };
  123. #endif