1
0

cmCTestRunTest.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 <map>
  7. #include <memory>
  8. #include <set>
  9. #include <string>
  10. #include <vector>
  11. #include <stddef.h>
  12. #include "cmCTest.h"
  13. #include "cmCTestMultiProcessHandler.h"
  14. #include "cmCTestTestHandler.h"
  15. #include "cmDuration.h"
  16. #include "cmProcess.h"
  17. /** \class cmRunTest
  18. * \brief represents a single test to be run
  19. *
  20. * cmRunTest contains the information related to running a single test
  21. */
  22. class cmCTestRunTest
  23. {
  24. public:
  25. explicit cmCTestRunTest(cmCTestMultiProcessHandler& multiHandler);
  26. void SetNumberOfRuns(int n)
  27. {
  28. this->NumberOfRunsLeft = n;
  29. this->NumberOfRunsTotal = n;
  30. }
  31. void SetRepeatMode(cmCTest::Repeat r) { this->RepeatMode = r; }
  32. void SetTestProperties(cmCTestTestHandler::cmCTestTestProperties* prop)
  33. {
  34. this->TestProperties = prop;
  35. }
  36. cmCTestTestHandler::cmCTestTestProperties* GetTestProperties()
  37. {
  38. return this->TestProperties;
  39. }
  40. void SetIndex(int i) { this->Index = i; }
  41. int GetIndex() { return this->Index; }
  42. void AddFailedDependency(const std::string& failedTest)
  43. {
  44. this->FailedDependencies.insert(failedTest);
  45. }
  46. std::string GetProcessOutput() { return this->ProcessOutput; }
  47. cmCTestTestHandler::cmCTestTestResult GetTestResults()
  48. {
  49. return this->TestResult;
  50. }
  51. // Read and store output. Returns true if it must be called again.
  52. void CheckOutput(std::string const& line);
  53. // launch the test process, return whether it started correctly
  54. bool StartTest(size_t completed, size_t total);
  55. // capture and report the test results
  56. bool EndTest(size_t completed, size_t total, bool started);
  57. // Called by ctest -N to log the command string
  58. void ComputeArguments();
  59. void ComputeWeightedCost();
  60. bool StartAgain(size_t completed);
  61. void StartFailure(std::string const& output);
  62. cmCTest* GetCTest() const { return this->CTest; }
  63. std::string& GetActualCommand() { return this->ActualCommand; }
  64. const std::vector<std::string>& GetArguments() { return this->Arguments; }
  65. void FinalizeTest();
  66. bool TimedOutForStopTime() const { return this->TimeoutIsForStopTime; }
  67. void SetUseAllocatedResources(bool use)
  68. {
  69. this->UseAllocatedResources = use;
  70. }
  71. void SetAllocatedResources(
  72. const std::vector<
  73. std::map<std::string,
  74. std::vector<cmCTestMultiProcessHandler::ResourceAllocation>>>&
  75. resources)
  76. {
  77. this->AllocatedResources = resources;
  78. }
  79. private:
  80. bool NeedsToRepeat();
  81. void DartProcessing();
  82. void ExeNotFound(std::string exe);
  83. bool ForkProcess(cmDuration testTimeOut, bool explicitTimeout,
  84. std::vector<std::string>* environment,
  85. std::vector<size_t>* affinity);
  86. void WriteLogOutputTop(size_t completed, size_t total);
  87. // Run post processing of the process output for MemCheck
  88. void MemCheckPostProcess();
  89. void SetupResourcesEnvironment();
  90. // Returns "completed/total Test #Index: "
  91. std::string GetTestPrefix(size_t completed, size_t total) const;
  92. cmCTestTestHandler::cmCTestTestProperties* TestProperties;
  93. bool TimeoutIsForStopTime = false;
  94. // Pointer back to the "parent"; the handler that invoked this test run
  95. cmCTestTestHandler* TestHandler;
  96. cmCTest* CTest;
  97. std::unique_ptr<cmProcess> TestProcess;
  98. std::string ProcessOutput;
  99. // The test results
  100. cmCTestTestHandler::cmCTestTestResult TestResult;
  101. cmCTestMultiProcessHandler& MultiTestHandler;
  102. int Index;
  103. std::set<std::string> FailedDependencies;
  104. std::string StartTime;
  105. std::string ActualCommand;
  106. std::vector<std::string> Arguments;
  107. bool UseAllocatedResources = false;
  108. std::vector<std::map<
  109. std::string, std::vector<cmCTestMultiProcessHandler::ResourceAllocation>>>
  110. AllocatedResources;
  111. cmCTest::Repeat RepeatMode = cmCTest::Repeat::Never;
  112. int NumberOfRunsLeft = 1; // default to 1 run of the test
  113. int NumberOfRunsTotal = 1; // default to 1 run of the test
  114. bool RunAgain = false; // default to not having to run again
  115. size_t TotalNumberOfTests;
  116. };
  117. inline int getNumWidth(size_t n)
  118. {
  119. int w = 1;
  120. while (n >= 10) {
  121. n /= 10;
  122. ++w;
  123. }
  124. return w;
  125. }
  126. #endif