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