cmCTestRunTest.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 <set>
  7. #include <stddef.h>
  8. #include <string>
  9. #include <vector>
  10. #include "cmCTestTestHandler.h"
  11. #include "cmDuration.h"
  12. #include "cmProcess.h" // IWYU pragma: keep (for unique_ptr)
  13. class cmCTest;
  14. class cmCTestMultiProcessHandler;
  15. /** \class cmRunTest
  16. * \brief represents a single test to be run
  17. *
  18. * cmRunTest contains the information related to running a single test
  19. */
  20. class cmCTestRunTest
  21. {
  22. public:
  23. explicit cmCTestRunTest(cmCTestMultiProcessHandler& multiHandler);
  24. ~cmCTestRunTest() = default;
  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. // Compresses the output, writing to CompressedOutput
  49. void CompressOutput();
  50. // launch the test process, return whether it started correctly
  51. bool StartTest(size_t completed, size_t total);
  52. // capture and report the test results
  53. bool EndTest(size_t completed, size_t total, bool started);
  54. // Called by ctest -N to log the command string
  55. void ComputeArguments();
  56. void ComputeWeightedCost();
  57. bool StartAgain(size_t completed);
  58. void StartFailure(std::string const& output);
  59. cmCTest* GetCTest() const { return this->CTest; }
  60. std::string& GetActualCommand() { return this->ActualCommand; }
  61. const std::vector<std::string>& GetArguments() { return this->Arguments; }
  62. void FinalizeTest();
  63. bool TimedOutForStopTime() const { return this->TimeoutIsForStopTime; }
  64. private:
  65. bool NeedsToRerun();
  66. void DartProcessing();
  67. void ExeNotFound(std::string exe);
  68. bool ForkProcess(cmDuration testTimeOut, bool explicitTimeout,
  69. std::vector<std::string>* environment,
  70. std::vector<size_t>* affinity);
  71. void WriteLogOutputTop(size_t completed, size_t total);
  72. // Run post processing of the process output for MemCheck
  73. void MemCheckPostProcess();
  74. // Returns "completed/total Test #Index: "
  75. std::string GetTestPrefix(size_t completed, size_t total) const;
  76. cmCTestTestHandler::cmCTestTestProperties* TestProperties;
  77. bool TimeoutIsForStopTime = false;
  78. // Pointer back to the "parent"; the handler that invoked this test run
  79. cmCTestTestHandler* TestHandler;
  80. cmCTest* CTest;
  81. std::unique_ptr<cmProcess> TestProcess;
  82. std::string ProcessOutput;
  83. std::string CompressedOutput;
  84. double CompressionRatio;
  85. // The test results
  86. cmCTestTestHandler::cmCTestTestResult TestResult;
  87. cmCTestMultiProcessHandler& MultiTestHandler;
  88. int Index;
  89. std::set<std::string> FailedDependencies;
  90. std::string StartTime;
  91. std::string ActualCommand;
  92. std::vector<std::string> Arguments;
  93. bool RunUntilFail;
  94. int NumberOfRunsLeft;
  95. bool RunAgain;
  96. size_t TotalNumberOfTests;
  97. };
  98. inline int getNumWidth(size_t n)
  99. {
  100. int w = 1;
  101. while (n >= 10) {
  102. n /= 10;
  103. ++w;
  104. }
  105. return w;
  106. }
  107. #endif