cmCTestMultiProcessHandler.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. cmCTest* CTest;
  51. // Start the next test or tests as many as are allowed by
  52. // ParallelLevel
  53. void StartNextTests();
  54. void StartTestProcess(int test);
  55. bool StartTest(int test);
  56. // Mark the checkpoint for the given test
  57. void WriteCheckpoint(int index);
  58. void WriteCostData(int index, float cost);
  59. void ReadCostData();
  60. void CreateTestCostList();
  61. // Removes the checkpoint file
  62. void MarkFinished();
  63. void EraseTest(int index);
  64. // Return true if there are still tests running
  65. // check all running processes for output and exit case
  66. bool CheckOutput();
  67. void RemoveTest(int index);
  68. //Check if we need to resume an interrupted test set
  69. void CheckResume();
  70. int FindMaxIndex();
  71. inline size_t GetProcessorsUsed(int index);
  72. // map from test number to set of depend tests
  73. TestMap Tests;
  74. TestCostMap TestCosts;
  75. //Total number of tests we'll be running
  76. size_t Total;
  77. //Number of tests that are complete
  78. size_t Completed;
  79. size_t RunningCount;
  80. //list of test properties (indices concurrent to the test map)
  81. PropertiesMap Properties;
  82. std::map<int, bool> TestRunningMap;
  83. std::map<int, bool> TestFinishMap;
  84. std::map<int, cmStdString> TestOutput;
  85. std::vector<cmStdString>* Passed;
  86. std::vector<cmStdString>* Failed;
  87. std::vector<cmCTestTestHandler::cmCTestTestResult>* TestResults;
  88. size_t ParallelLevel; // max number of process that can be run at once
  89. std::set<cmCTestRunTest*> RunningTests; // current running tests
  90. cmCTestTestHandler * TestHandler;
  91. };
  92. #endif