cmCTestRunTest.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 "cmCTest.h"
  13. #include "cmCTestMultiProcessHandler.h"
  14. #include "cmCTestTestHandler.h"
  15. #include "cmDuration.h"
  16. #include "cmProcess.h"
  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)
  27. {
  28. this->NumberOfRunsLeft = n;
  29. this->NumberOfRunsTotal = n;
  30. }
  31. void SetRerunMode(cmCTest::Rerun r) { this->RerunMode = r; }
  32. void SetTestProperties(cmCTestTestHandler::cmCTestTestProperties* prop)
  33. {
  34. this->TestProperties = prop;
  35. }
  36. cmCTestTestHandler::cmCTestTestProperties* GetTestProperties()
  37. {
  38. return this->TestProperties;
  39. }
  40. void SetIndex(int i) { this->Index = i; }
  41. int GetIndex() { return this->Index; }
  42. void AddFailedDependency(const std::string& failedTest)
  43. {
  44. this->FailedDependencies.insert(failedTest);
  45. }
  46. std::string GetProcessOutput() { return this->ProcessOutput; }
  47. cmCTestTestHandler::cmCTestTestResult GetTestResults()
  48. {
  49. return this->TestResult;
  50. }
  51. // Read and store output. Returns true if it must be called again.
  52. void CheckOutput(std::string const& line);
  53. // launch the test process, return whether it started correctly
  54. bool StartTest(size_t completed, size_t total);
  55. // capture and report the test results
  56. bool EndTest(size_t completed, size_t total, bool started);
  57. // Called by ctest -N to log the command string
  58. void ComputeArguments();
  59. void ComputeWeightedCost();
  60. bool StartAgain(size_t completed);
  61. void StartFailure(std::string const& output);
  62. cmCTest* GetCTest() const { return this->CTest; }
  63. std::string& GetActualCommand() { return this->ActualCommand; }
  64. const std::vector<std::string>& GetArguments() { return this->Arguments; }
  65. void FinalizeTest();
  66. bool TimedOutForStopTime() const { return this->TimeoutIsForStopTime; }
  67. void SetUseAllocatedHardware(bool use) { this->UseAllocatedHardware = use; }
  68. void SetAllocatedHardware(
  69. const std::vector<
  70. std::map<std::string,
  71. std::vector<cmCTestMultiProcessHandler::HardwareAllocation>>>&
  72. hardware)
  73. {
  74. this->AllocatedHardware = hardware;
  75. }
  76. private:
  77. bool NeedsToRerun();
  78. void DartProcessing();
  79. void ExeNotFound(std::string exe);
  80. bool ForkProcess(cmDuration testTimeOut, bool explicitTimeout,
  81. std::vector<std::string>* environment,
  82. std::vector<size_t>* affinity);
  83. void WriteLogOutputTop(size_t completed, size_t total);
  84. // Run post processing of the process output for MemCheck
  85. void MemCheckPostProcess();
  86. void SetupHardwareEnvironment();
  87. // Returns "completed/total Test #Index: "
  88. std::string GetTestPrefix(size_t completed, size_t total) const;
  89. cmCTestTestHandler::cmCTestTestProperties* TestProperties;
  90. bool TimeoutIsForStopTime = false;
  91. // Pointer back to the "parent"; the handler that invoked this test run
  92. cmCTestTestHandler* TestHandler;
  93. cmCTest* CTest;
  94. std::unique_ptr<cmProcess> TestProcess;
  95. std::string ProcessOutput;
  96. // The test results
  97. cmCTestTestHandler::cmCTestTestResult TestResult;
  98. cmCTestMultiProcessHandler& MultiTestHandler;
  99. int Index;
  100. std::set<std::string> FailedDependencies;
  101. std::string StartTime;
  102. std::string ActualCommand;
  103. std::vector<std::string> Arguments;
  104. bool UseAllocatedHardware = false;
  105. std::vector<std::map<
  106. std::string, std::vector<cmCTestMultiProcessHandler::HardwareAllocation>>>
  107. AllocatedHardware;
  108. cmCTest::Rerun RerunMode = cmCTest::Rerun::Never;
  109. int NumberOfRunsLeft = 1; // default to 1 run of the test
  110. int NumberOfRunsTotal = 1; // default to 1 run of the test
  111. bool RunAgain = false; // default to not having to run again
  112. size_t TotalNumberOfTests;
  113. };
  114. inline int getNumWidth(size_t n)
  115. {
  116. int w = 1;
  117. while (n >= 10) {
  118. n /= 10;
  119. ++w;
  120. }
  121. return w;
  122. }
  123. #endif