cmCTestMultiProcessHandler.h 4.0 KB

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