cmCTestRunTest.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. explicit cmCTestRunTest(cmCTestTestHandler* handler);
  23. ~cmCTestRunTest() = default;
  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. 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. bool ForkProcess(std::chrono::duration<double> testTimeOut,
  62. bool explicitTimeout,
  63. std::vector<std::string>* environment);
  64. void WriteLogOutputTop(size_t completed, size_t total);
  65. // Run post processing of the process output for MemCheck
  66. void MemCheckPostProcess();
  67. cmCTestTestHandler::cmCTestTestProperties* TestProperties;
  68. // Pointer back to the "parent"; the handler that invoked this test run
  69. cmCTestTestHandler* TestHandler;
  70. cmCTest* CTest;
  71. cmProcess* TestProcess;
  72. std::string ProcessOutput;
  73. std::string CompressedOutput;
  74. double CompressionRatio;
  75. // The test results
  76. cmCTestTestHandler::cmCTestTestResult TestResult;
  77. int Index;
  78. std::set<std::string> FailedDependencies;
  79. std::string StartTime;
  80. std::string ActualCommand;
  81. std::vector<std::string> Arguments;
  82. bool RunUntilFail;
  83. int NumberOfRunsLeft;
  84. bool RunAgain;
  85. size_t TotalNumberOfTests;
  86. };
  87. inline int getNumWidth(size_t n)
  88. {
  89. int numWidth = 1;
  90. if (n >= 10) {
  91. numWidth = 2;
  92. }
  93. if (n >= 100) {
  94. numWidth = 3;
  95. }
  96. return numWidth;
  97. }
  98. #endif