cmCTestMultiProcessHandler.h 3.9 KB

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