cmCTestMultiProcessHandler.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmCTestMultiProcessHandler_h
  14. #define cmCTestMultiProcessHandler_h
  15. #include <set>
  16. #include <map>
  17. #include <string>
  18. #include <vector>
  19. class cmProcess;
  20. #include <cmStandardIncludes.h>
  21. #include <cmCTestTestHandler.h>
  22. /** \class cmCTestMultiProcessHandler
  23. * \brief run parallel ctest
  24. *
  25. * cmCTestMultiProcessHandler
  26. */
  27. class cmCTestMultiProcessHandler
  28. {
  29. public:
  30. struct TestSet : public std::set<int> {};
  31. struct TestMap : public std::map<int, TestSet> {};
  32. cmCTestMultiProcessHandler();
  33. // Set the tests
  34. void SetTests(TestMap& tests,
  35. std::map<int, cmStdString>& testNames);
  36. // Set the max number of tests that can be run at the same time.
  37. void SetParallelLevel(size_t);
  38. void RunTests();
  39. void PrintTests();
  40. void SetCTestCommand(const char* c) { this->CTestCommand = c;}
  41. void SetTestCacheFile(const char* c) { this->CTestCacheFile = c;}
  42. void SetPassFailVectors(std::vector<cmStdString>* passed,
  43. std::vector<cmStdString>* failed)
  44. {
  45. this->Passed = passed;
  46. this->Failed = failed;
  47. }
  48. void SetTestResults(std::vector<cmCTestTestHandler::cmCTestTestResult>* r)
  49. {
  50. this->TestResults = r;
  51. }
  52. void SetCTest(cmCTest* ctest) { this->CTest = ctest;}
  53. protected:
  54. cmCTest* CTest;
  55. // Start the next test or tests as many as are allowed by
  56. // ParallelLevel
  57. void StartNextTests();
  58. void StartTestProcess(int test);
  59. bool StartTest(int test);
  60. void EndTest(cmProcess*);
  61. // Return true if there are still tests running
  62. // check all running processes for output and exit case
  63. bool CheckOutput();
  64. // map from test number to set of depend tests
  65. TestMap Tests;
  66. std::map<int, cmStdString> TestNames;
  67. std::map<int, bool> TestRunningMap;
  68. std::map<int, bool> TestFinishMap;
  69. std::map<int, cmStdString> TestOutput;
  70. std::string CTestCommand;
  71. std::string CTestCacheFile;
  72. std::vector<cmStdString>* Passed;
  73. std::vector<cmStdString>* Failed;
  74. std::vector<cmCTestTestHandler::cmCTestTestResult>* TestResults;
  75. int ProcessId;
  76. size_t ParallelLevel; // max number of process that can be run at once
  77. std::set<cmProcess*> RunningTests; // current running tests
  78. };
  79. #endif