cmCTestRunTest.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmCTestRunTest_h
  4. #define cmCTestRunTest_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include <map>
  7. #include <memory>
  8. #include <set>
  9. #include <string>
  10. #include <vector>
  11. #include <stddef.h>
  12. #include "cmCTestMultiProcessHandler.h"
  13. #include "cmCTestTestHandler.h"
  14. #include "cmDuration.h"
  15. #include "cmProcess.h"
  16. class cmCTest;
  17. /** \class cmRunTest
  18. * \brief represents a single test to be run
  19. *
  20. * cmRunTest contains the information related to running a single test
  21. */
  22. class cmCTestRunTest
  23. {
  24. public:
  25. explicit cmCTestRunTest(cmCTestMultiProcessHandler& multiHandler);
  26. void SetNumberOfRuns(int n) { this->NumberOfRunsLeft = n; }
  27. void SetRunUntilFailOn() { this->RunUntilFail = true; }
  28. void SetTestProperties(cmCTestTestHandler::cmCTestTestProperties* prop)
  29. {
  30. this->TestProperties = prop;
  31. }
  32. cmCTestTestHandler::cmCTestTestProperties* GetTestProperties()
  33. {
  34. return this->TestProperties;
  35. }
  36. void SetIndex(int i) { this->Index = i; }
  37. int GetIndex() { return this->Index; }
  38. void AddFailedDependency(const std::string& failedTest)
  39. {
  40. this->FailedDependencies.insert(failedTest);
  41. }
  42. std::string GetProcessOutput() { return this->ProcessOutput; }
  43. cmCTestTestHandler::cmCTestTestResult GetTestResults()
  44. {
  45. return this->TestResult;
  46. }
  47. // Read and store output. Returns true if it must be called again.
  48. void CheckOutput(std::string const& line);
  49. // launch the test process, return whether it started correctly
  50. bool StartTest(size_t completed, size_t total);
  51. // capture and report the test results
  52. bool EndTest(size_t completed, size_t total, bool started);
  53. // Called by ctest -N to log the command string
  54. void ComputeArguments();
  55. void ComputeWeightedCost();
  56. bool StartAgain(size_t completed);
  57. void StartFailure(std::string const& output);
  58. cmCTest* GetCTest() const { return this->CTest; }
  59. std::string& GetActualCommand() { return this->ActualCommand; }
  60. const std::vector<std::string>& GetArguments() { return this->Arguments; }
  61. void FinalizeTest();
  62. bool TimedOutForStopTime() const { return this->TimeoutIsForStopTime; }
  63. void SetUseAllocatedHardware(bool use) { this->UseAllocatedHardware = use; }
  64. void SetAllocatedHardware(
  65. const std::vector<
  66. std::map<std::string,
  67. std::vector<cmCTestMultiProcessHandler::HardwareAllocation>>>&
  68. hardware)
  69. {
  70. this->AllocatedHardware = hardware;
  71. }
  72. private:
  73. bool NeedsToRerun();
  74. void DartProcessing();
  75. void ExeNotFound(std::string exe);
  76. bool ForkProcess(cmDuration testTimeOut, bool explicitTimeout,
  77. std::vector<std::string>* environment,
  78. std::vector<size_t>* affinity);
  79. void WriteLogOutputTop(size_t completed, size_t total);
  80. // Run post processing of the process output for MemCheck
  81. void MemCheckPostProcess();
  82. void SetupHardwareEnvironment();
  83. // Returns "completed/total Test #Index: "
  84. std::string GetTestPrefix(size_t completed, size_t total) const;
  85. cmCTestTestHandler::cmCTestTestProperties* TestProperties;
  86. bool TimeoutIsForStopTime = false;
  87. // Pointer back to the "parent"; the handler that invoked this test run
  88. cmCTestTestHandler* TestHandler;
  89. cmCTest* CTest;
  90. std::unique_ptr<cmProcess> TestProcess;
  91. std::string ProcessOutput;
  92. // The test results
  93. cmCTestTestHandler::cmCTestTestResult TestResult;
  94. cmCTestMultiProcessHandler& MultiTestHandler;
  95. int Index;
  96. std::set<std::string> FailedDependencies;
  97. std::string StartTime;
  98. std::string ActualCommand;
  99. std::vector<std::string> Arguments;
  100. bool UseAllocatedHardware = false;
  101. std::vector<std::map<
  102. std::string, std::vector<cmCTestMultiProcessHandler::HardwareAllocation>>>
  103. AllocatedHardware;
  104. bool RunUntilFail = false; // default to run the test once
  105. int NumberOfRunsLeft = 1; // default to 1 run of the test
  106. bool RunAgain = false; // default to not having to run again
  107. size_t TotalNumberOfTests;
  108. };
  109. inline int getNumWidth(size_t n)
  110. {
  111. int w = 1;
  112. while (n >= 10) {
  113. n /= 10;
  114. ++w;
  115. }
  116. return w;
  117. }
  118. #endif