cmCTestMultiProcessHandler.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 PrintOutputAsJson();
  48. void PrintTestList();
  49. void PrintLabels();
  50. void SetPassFailVectors(std::vector<std::string>* passed,
  51. std::vector<std::string>* failed)
  52. {
  53. this->Passed = passed;
  54. this->Failed = failed;
  55. }
  56. void SetTestResults(std::vector<cmCTestTestHandler::cmCTestTestResult>* r)
  57. {
  58. this->TestResults = r;
  59. }
  60. void SetCTest(cmCTest* ctest) { this->CTest = ctest; }
  61. void SetTestHandler(cmCTestTestHandler* handler)
  62. {
  63. this->TestHandler = handler;
  64. }
  65. cmCTestTestHandler* GetTestHandler() { return this->TestHandler; }
  66. void SetQuiet(bool b) { this->Quiet = b; }
  67. protected:
  68. // Start the next test or tests as many as are allowed by
  69. // ParallelLevel
  70. void StartNextTests();
  71. bool StartTestProcess(int test);
  72. bool StartTest(int test);
  73. // Mark the checkpoint for the given test
  74. void WriteCheckpoint(int index);
  75. void UpdateCostData();
  76. void ReadCostData();
  77. // Return index of a test based on its name
  78. int SearchByName(std::string const& name);
  79. void CreateTestCostList();
  80. void GetAllTestDependencies(int test, TestList& dependencies);
  81. void CreateSerialTestCostList();
  82. void CreateParallelTestCostList();
  83. // Removes the checkpoint file
  84. void MarkFinished();
  85. void EraseTest(int index);
  86. void FinishTestProcess(cmCTestRunTest* runner, bool started);
  87. static void OnTestLoadRetryCB(uv_timer_t* timer);
  88. void RemoveTest(int index);
  89. // Check if we need to resume an interrupted test set
  90. void CheckResume();
  91. // Check if there are any circular dependencies
  92. bool CheckCycles();
  93. int FindMaxIndex();
  94. inline size_t GetProcessorsUsed(int index);
  95. std::string GetName(int index);
  96. bool CheckStopTimePassed();
  97. void SetStopTimePassed();
  98. void LockResources(int index);
  99. void UnlockResources(int index);
  100. // map from test number to set of depend tests
  101. TestMap Tests;
  102. TestList SortedTests;
  103. // Total number of tests we'll be running
  104. size_t Total;
  105. // Number of tests that are complete
  106. size_t Completed;
  107. size_t RunningCount;
  108. std::set<size_t> ProcessorsAvailable;
  109. size_t HaveAffinity;
  110. bool StopTimePassed = false;
  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. unsigned long FakeLoadForTesting;
  124. uv_loop_t Loop;
  125. cm::uv_timer_ptr TestLoadRetryTimer;
  126. cmCTestTestHandler* TestHandler;
  127. cmCTest* CTest;
  128. bool HasCycles;
  129. bool Quiet;
  130. bool SerialTestRunning;
  131. };
  132. #endif