cmCTestRunTest.h 3.5 KB

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