cmCTestRunTest.h 3.2 KB

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