cmCTestMultiProcessHandler.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. void SetTestLoad(unsigned long load);
  36. virtual void RunTests();
  37. void PrintTestList();
  38. void PrintLabels();
  39. void SetPassFailVectors(std::vector<std::string>* passed,
  40. std::vector<std::string>* failed)
  41. {
  42. this->Passed = passed;
  43. this->Failed = failed;
  44. }
  45. void SetTestResults(std::vector<cmCTestTestHandler::cmCTestTestResult>* r)
  46. { this->TestResults = r; }
  47. void SetCTest(cmCTest* ctest) { this->CTest = ctest;}
  48. void SetTestHandler(cmCTestTestHandler * handler)
  49. { this->TestHandler = handler; }
  50. cmCTestTestHandler * GetTestHandler()
  51. { return this->TestHandler; }
  52. void SetQuiet(bool b) { this->Quiet = b; }
  53. protected:
  54. // Start the next test or tests as many as are allowed by
  55. // ParallelLevel
  56. void StartNextTests();
  57. void StartTestProcess(int test);
  58. bool StartTest(int test);
  59. // Mark the checkpoint for the given test
  60. void WriteCheckpoint(int index);
  61. void UpdateCostData();
  62. void ReadCostData();
  63. // Return index of a test based on its name
  64. int SearchByName(std::string name);
  65. void CreateTestCostList();
  66. void GetAllTestDependencies(int test, TestList& dependencies);
  67. void CreateSerialTestCostList();
  68. void CreateParallelTestCostList();
  69. // Removes the checkpoint file
  70. void MarkFinished();
  71. void EraseTest(int index);
  72. // Return true if there are still tests running
  73. // check all running processes for output and exit case
  74. bool CheckOutput();
  75. void RemoveTest(int index);
  76. //Check if we need to resume an interrupted test set
  77. void CheckResume();
  78. //Check if there are any circular dependencies
  79. bool CheckCycles();
  80. int FindMaxIndex();
  81. inline size_t GetProcessorsUsed(int index);
  82. std::string GetName(int index);
  83. void LockResources(int index);
  84. void UnlockResources(int index);
  85. // map from test number to set of depend tests
  86. TestMap Tests;
  87. TestList SortedTests;
  88. //Total number of tests we'll be running
  89. size_t Total;
  90. //Number of tests that are complete
  91. size_t Completed;
  92. size_t RunningCount;
  93. bool StopTimePassed;
  94. //list of test properties (indices concurrent to the test map)
  95. PropertiesMap Properties;
  96. std::map<int, bool> TestRunningMap;
  97. std::map<int, bool> TestFinishMap;
  98. std::map<int, std::string> TestOutput;
  99. std::vector<std::string>* Passed;
  100. std::vector<std::string>* Failed;
  101. std::vector<std::string> LastTestsFailed;
  102. std::set<std::string> LockedResources;
  103. std::vector<cmCTestTestHandler::cmCTestTestResult>* TestResults;
  104. size_t ParallelLevel; // max number of process that can be run at once
  105. unsigned long TestLoad;
  106. std::set<cmCTestRunTest*> RunningTests; // current running tests
  107. cmCTestTestHandler * TestHandler;
  108. cmCTest* CTest;
  109. bool HasCycles;
  110. bool Quiet;
  111. bool SerialTestRunning;
  112. };
  113. #endif