cmCTestMultiProcessHandler.h 3.7 KB

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