cmCTestMultiProcessHandler.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 "cm_uv.h"
  13. class cmCTest;
  14. class cmCTestRunTest;
  15. /** \class cmCTestMultiProcessHandler
  16. * \brief run parallel ctest
  17. *
  18. * cmCTestMultiProcessHandler
  19. */
  20. class cmCTestMultiProcessHandler
  21. {
  22. friend class TestComparator;
  23. friend class cmCTestRunTest;
  24. public:
  25. struct TestSet : public std::set<int>
  26. {
  27. };
  28. struct TestMap : public std::map<int, TestSet>
  29. {
  30. };
  31. struct TestList : public std::vector<int>
  32. {
  33. };
  34. struct PropertiesMap
  35. : public std::map<int, cmCTestTestHandler::cmCTestTestProperties*>
  36. {
  37. };
  38. cmCTestMultiProcessHandler();
  39. virtual ~cmCTestMultiProcessHandler();
  40. // Set the tests
  41. void SetTests(TestMap& tests, PropertiesMap& properties);
  42. // Set the max number of tests that can be run at the same time.
  43. void SetParallelLevel(size_t);
  44. void SetTestLoad(unsigned long load);
  45. virtual void RunTests();
  46. void PrintTestList();
  47. void PrintLabels();
  48. void SetPassFailVectors(std::vector<std::string>* passed,
  49. std::vector<std::string>* failed)
  50. {
  51. this->Passed = passed;
  52. this->Failed = failed;
  53. }
  54. void SetTestResults(std::vector<cmCTestTestHandler::cmCTestTestResult>* r)
  55. {
  56. this->TestResults = r;
  57. }
  58. void SetCTest(cmCTest* ctest) { this->CTest = ctest; }
  59. void SetTestHandler(cmCTestTestHandler* handler)
  60. {
  61. this->TestHandler = handler;
  62. }
  63. cmCTestTestHandler* GetTestHandler() { return this->TestHandler; }
  64. void SetQuiet(bool b) { this->Quiet = b; }
  65. protected:
  66. // Start the next test or tests as many as are allowed by
  67. // ParallelLevel
  68. void StartNextTests();
  69. bool StartTestProcess(int test);
  70. bool StartTest(int test);
  71. // Mark the checkpoint for the given test
  72. void WriteCheckpoint(int index);
  73. void UpdateCostData();
  74. void ReadCostData();
  75. // Return index of a test based on its name
  76. int SearchByName(std::string const& name);
  77. void CreateTestCostList();
  78. void GetAllTestDependencies(int test, TestList& dependencies);
  79. void CreateSerialTestCostList();
  80. void CreateParallelTestCostList();
  81. // Removes the checkpoint file
  82. void MarkFinished();
  83. void EraseTest(int index);
  84. void FinishTestProcess(cmCTestRunTest* runner, bool started);
  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. uv_loop_t Loop;
  117. cmCTestTestHandler* TestHandler;
  118. cmCTest* CTest;
  119. bool HasCycles;
  120. bool Quiet;
  121. bool SerialTestRunning;
  122. };
  123. #endif