cmCTestRunTest.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 <chrono>
  7. #include <set>
  8. #include <stddef.h>
  9. #include <string>
  10. #include <vector>
  11. #include "cmCTestTestHandler.h"
  12. class cmCTest;
  13. class cmProcess;
  14. /** \class cmRunTest
  15. * \brief represents a single test to be run
  16. *
  17. * cmRunTest contains the information related to running a single test
  18. */
  19. class cmCTestRunTest
  20. {
  21. public:
  22. cmCTestRunTest(cmCTestTestHandler* handler);
  23. ~cmCTestRunTest();
  24. void SetNumberOfRuns(int n) { this->NumberOfRunsLeft = n; }
  25. void SetRunUntilFailOn() { this->RunUntilFail = true; }
  26. void SetTestProperties(cmCTestTestHandler::cmCTestTestProperties* prop)
  27. {
  28. this->TestProperties = prop;
  29. }
  30. cmCTestTestHandler::cmCTestTestProperties* GetTestProperties()
  31. {
  32. return this->TestProperties;
  33. }
  34. void SetIndex(int i) { this->Index = i; }
  35. int GetIndex() { return this->Index; }
  36. void AddFailedDependency(const std::string& failedTest)
  37. {
  38. this->FailedDependencies.insert(failedTest);
  39. }
  40. std::string GetProcessOutput() { return this->ProcessOutput; }
  41. bool IsStopTimePassed() { return this->StopTimePassed; }
  42. cmCTestTestHandler::cmCTestTestResult GetTestResults()
  43. {
  44. return this->TestResult;
  45. }
  46. // Read and store output. Returns true if it must be called again.
  47. bool CheckOutput();
  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 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();
  58. private:
  59. bool NeedsToRerun();
  60. void DartProcessing();
  61. void ExeNotFound(std::string exe);
  62. // Figures out a final timeout which is min(STOP_TIME, NOW+TIMEOUT)
  63. std::chrono::duration<double> ResolveTimeout();
  64. bool ForkProcess(std::chrono::duration<double> testTimeOut,
  65. bool explicitTimeout,
  66. std::vector<std::string>* environment);
  67. void WriteLogOutputTop(size_t completed, size_t total);
  68. // Run post processing of the process output for MemCheck
  69. void MemCheckPostProcess();
  70. cmCTestTestHandler::cmCTestTestProperties* TestProperties;
  71. // Pointer back to the "parent"; the handler that invoked this test run
  72. cmCTestTestHandler* TestHandler;
  73. cmCTest* CTest;
  74. cmProcess* TestProcess;
  75. // If the executable to run is ctest, don't create a new process;
  76. // just instantiate a new cmTest. (Can be disabled for a single test
  77. // if this option is set to false.)
  78. // bool OptimizeForCTest;
  79. bool UsePrefixCommand;
  80. std::string PrefixCommand;
  81. std::string ProcessOutput;
  82. std::string CompressedOutput;
  83. double CompressionRatio;
  84. // The test results
  85. cmCTestTestHandler::cmCTestTestResult TestResult;
  86. int Index;
  87. std::set<std::string> FailedDependencies;
  88. std::string StartTime;
  89. std::string ActualCommand;
  90. std::vector<std::string> Arguments;
  91. bool StopTimePassed;
  92. bool RunUntilFail;
  93. int NumberOfRunsLeft;
  94. bool RunAgain;
  95. size_t TotalNumberOfTests;
  96. };
  97. inline int getNumWidth(size_t n)
  98. {
  99. int numWidth = 1;
  100. if (n >= 10) {
  101. numWidth = 2;
  102. }
  103. if (n >= 100) {
  104. numWidth = 3;
  105. }
  106. return numWidth;
  107. }
  108. #endif