cmCTestMultiProcessHandler.h 4.2 KB

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