cmCTestRunTest.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. 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. void CheckOutput(std::string const& line);
  47. // launch the test process, return whether it started correctly
  48. bool StartTest(size_t completed, size_t total);
  49. // capture and report the test results
  50. bool EndTest(size_t completed, size_t total, bool started);
  51. // Called by ctest -N to log the command string
  52. void ComputeArguments();
  53. void ComputeWeightedCost();
  54. bool StartAgain(size_t completed);
  55. void StartFailure(std::string const& output);
  56. cmCTest* GetCTest() const { return this->CTest; }
  57. std::string& GetActualCommand() { return this->ActualCommand; }
  58. const std::vector<std::string>& GetArguments() { return this->Arguments; }
  59. void FinalizeTest();
  60. bool TimedOutForStopTime() const { return this->TimeoutIsForStopTime; }
  61. private:
  62. bool NeedsToRerun();
  63. void DartProcessing();
  64. void ExeNotFound(std::string exe);
  65. bool ForkProcess(cmDuration testTimeOut, bool explicitTimeout,
  66. std::vector<std::string>* environment,
  67. std::vector<size_t>* affinity);
  68. void WriteLogOutputTop(size_t completed, size_t total);
  69. // Run post processing of the process output for MemCheck
  70. void MemCheckPostProcess();
  71. // Returns "completed/total Test #Index: "
  72. std::string GetTestPrefix(size_t completed, size_t total) const;
  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. // The test results
  81. cmCTestTestHandler::cmCTestTestResult TestResult;
  82. cmCTestMultiProcessHandler& MultiTestHandler;
  83. int Index;
  84. std::set<std::string> FailedDependencies;
  85. std::string StartTime;
  86. std::string ActualCommand;
  87. std::vector<std::string> Arguments;
  88. bool RunUntilFail;
  89. int NumberOfRunsLeft;
  90. bool RunAgain;
  91. size_t TotalNumberOfTests;
  92. };
  93. inline int getNumWidth(size_t n)
  94. {
  95. int w = 1;
  96. while (n >= 10) {
  97. n /= 10;
  98. ++w;
  99. }
  100. return w;
  101. }
  102. #endif