cmCTestRunTest.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmCTestRunTest_h
  11. #define cmCTestRunTest_h
  12. #include <cmConfigure.h> // IWYU pragma: keep
  13. #include <cmCTestTestHandler.h>
  14. #include <stddef.h>
  15. #include <string>
  16. #include <vector>
  17. class cmCTest;
  18. class cmProcess;
  19. /** \class cmRunTest
  20. * \brief represents a single test to be run
  21. *
  22. * cmRunTest contains the information related to running a single test
  23. */
  24. class cmCTestRunTest
  25. {
  26. public:
  27. cmCTestRunTest(cmCTestTestHandler* handler);
  28. ~cmCTestRunTest();
  29. void SetNumberOfRuns(int n) { this->NumberOfRunsLeft = n; }
  30. void SetRunUntilFailOn() { this->RunUntilFail = true; }
  31. void SetTestProperties(cmCTestTestHandler::cmCTestTestProperties* prop)
  32. {
  33. this->TestProperties = prop;
  34. }
  35. cmCTestTestHandler::cmCTestTestProperties* GetTestProperties()
  36. {
  37. return this->TestProperties;
  38. }
  39. void SetIndex(int i) { this->Index = i; }
  40. int GetIndex() { return this->Index; }
  41. std::string GetProcessOutput() { return this->ProcessOutput; }
  42. bool IsStopTimePassed() { return this->StopTimePassed; }
  43. cmCTestTestHandler::cmCTestTestResult GetTestResults()
  44. {
  45. return this->TestResult;
  46. }
  47. // Read and store output. Returns true if it must be called again.
  48. bool CheckOutput();
  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 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();
  59. private:
  60. bool NeedsToRerun();
  61. void DartProcessing();
  62. void ExeNotFound(std::string exe);
  63. // Figures out a final timeout which is min(STOP_TIME, NOW+TIMEOUT)
  64. double ResolveTimeout();
  65. bool ForkProcess(double testTimeOut, bool explicitTimeout,
  66. std::vector<std::string>* environment);
  67. void WriteLogOutputTop(size_t completed, size_t total);
  68. // Run post processing of the process output for MemCheck
  69. void MemCheckPostProcess();
  70. cmCTestTestHandler::cmCTestTestProperties* TestProperties;
  71. // Pointer back to the "parent"; the handler that invoked this test run
  72. cmCTestTestHandler* TestHandler;
  73. cmCTest* CTest;
  74. cmProcess* TestProcess;
  75. // If the executable to run is ctest, don't create a new process;
  76. // just instantiate a new cmTest. (Can be disabled for a single test
  77. // if this option is set to false.)
  78. // bool OptimizeForCTest;
  79. bool UsePrefixCommand;
  80. std::string PrefixCommand;
  81. std::string ProcessOutput;
  82. std::string CompressedOutput;
  83. double CompressionRatio;
  84. // The test results
  85. cmCTestTestHandler::cmCTestTestResult TestResult;
  86. int Index;
  87. std::string StartTime;
  88. std::string ActualCommand;
  89. std::vector<std::string> Arguments;
  90. bool StopTimePassed;
  91. bool RunUntilFail;
  92. int NumberOfRunsLeft;
  93. bool RunAgain;
  94. size_t TotalNumberOfTests;
  95. };
  96. inline int getNumWidth(size_t n)
  97. {
  98. int numWidth = 1;
  99. if (n >= 10) {
  100. numWidth = 2;
  101. }
  102. if (n >= 100) {
  103. numWidth = 3;
  104. }
  105. return numWidth;
  106. }
  107. #endif