cmCTestRunTest.h 3.4 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 <cmath>
  7. #include <set>
  8. #include <stddef.h>
  9. #include <string>
  10. #include <vector>
  11. #include "cmCTestTestHandler.h"
  12. #include "cmDuration.h"
  13. #include "cmProcess.h" // IWYU pragma: keep (for unique_ptr)
  14. class cmCTest;
  15. class cmCTestMultiProcessHandler;
  16. /** \class cmRunTest
  17. * \brief represents a single test to be run
  18. *
  19. * cmRunTest contains the information related to running a single test
  20. */
  21. class cmCTestRunTest
  22. {
  23. public:
  24. explicit cmCTestRunTest(cmCTestMultiProcessHandler& multiHandler);
  25. ~cmCTestRunTest() = default;
  26. void SetNumberOfRuns(int n) { this->NumberOfRunsLeft = n; }
  27. void SetRunUntilFailOn() { this->RunUntilFail = true; }
  28. void SetTestProperties(cmCTestTestHandler::cmCTestTestProperties* prop)
  29. {
  30. this->TestProperties = prop;
  31. }
  32. cmCTestTestHandler::cmCTestTestProperties* GetTestProperties()
  33. {
  34. return this->TestProperties;
  35. }
  36. void SetIndex(int i) { this->Index = i; }
  37. int GetIndex() { return this->Index; }
  38. void AddFailedDependency(const std::string& failedTest)
  39. {
  40. this->FailedDependencies.insert(failedTest);
  41. }
  42. std::string GetProcessOutput() { return this->ProcessOutput; }
  43. cmCTestTestHandler::cmCTestTestResult GetTestResults()
  44. {
  45. return this->TestResult;
  46. }
  47. // Read and store output. Returns true if it must be called again.
  48. void CheckOutput(std::string const& line);
  49. // Compresses the output, writing to CompressedOutput
  50. void CompressOutput();
  51. // launch the test process, return whether it started correctly
  52. bool StartTest(size_t completed, size_t total);
  53. // capture and report the test results
  54. bool EndTest(size_t completed, size_t total, bool started);
  55. // Called by ctest -N to log the command string
  56. void ComputeArguments();
  57. void ComputeWeightedCost();
  58. bool StartAgain(size_t completed);
  59. void StartFailure(std::string const& output);
  60. cmCTest* GetCTest() const { return this->CTest; }
  61. void FinalizeTest();
  62. bool TimedOutForStopTime() const { return this->TimeoutIsForStopTime; }
  63. private:
  64. bool NeedsToRerun();
  65. void DartProcessing();
  66. void ExeNotFound(std::string exe);
  67. bool ForkProcess(cmDuration testTimeOut, bool explicitTimeout,
  68. std::vector<std::string>* environment,
  69. std::vector<size_t>* affinity);
  70. void WriteLogOutputTop(size_t completed, size_t total);
  71. // Run post processing of the process output for MemCheck
  72. void MemCheckPostProcess();
  73. cmCTestTestHandler::cmCTestTestProperties* TestProperties;
  74. bool TimeoutIsForStopTime = false;
  75. // Pointer back to the "parent"; the handler that invoked this test run
  76. cmCTestTestHandler* TestHandler;
  77. cmCTest* CTest;
  78. std::unique_ptr<cmProcess> TestProcess;
  79. std::string ProcessOutput;
  80. std::string CompressedOutput;
  81. double CompressionRatio;
  82. // The test results
  83. cmCTestTestHandler::cmCTestTestResult TestResult;
  84. cmCTestMultiProcessHandler& MultiTestHandler;
  85. int Index;
  86. std::set<std::string> FailedDependencies;
  87. std::string StartTime;
  88. std::string ActualCommand;
  89. std::vector<std::string> Arguments;
  90. bool RunUntilFail;
  91. int NumberOfRunsLeft;
  92. bool RunAgain;
  93. size_t TotalNumberOfTests;
  94. };
  95. inline int getNumWidth(size_t n)
  96. {
  97. return static_cast<int>(std::log10(n)) + 1;
  98. }
  99. #endif