cmCTestRunTest.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 <cmStandardIncludes.h>
  13. #include <cmCTestTestHandler.h>
  14. #include <cmProcess.h>
  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. cmCTestRunTest(cmCTestTestHandler* handler);
  24. ~cmCTestRunTest();
  25. void SetNumberOfRuns(int n) {this->NumberOfRunsLeft = n;}
  26. void SetRunUntilFailOn() { this->RunUntilFail = true;}
  27. void SetTestProperties(cmCTestTestHandler::cmCTestTestProperties * prop)
  28. { this->TestProperties = prop; }
  29. cmCTestTestHandler::cmCTestTestProperties * GetTestProperties()
  30. { return this->TestProperties; }
  31. void SetIndex(int i) { this->Index = i; }
  32. int GetIndex() { return this->Index; }
  33. std::string GetProcessOutput() { return this->ProcessOutput; }
  34. bool IsStopTimePassed() { return this->StopTimePassed; }
  35. cmCTestTestHandler::cmCTestTestResult GetTestResults()
  36. { return this->TestResult; }
  37. // Read and store output. Returns true if it must be called again.
  38. bool CheckOutput();
  39. // Compresses the output, writing to CompressedOutput
  40. void CompressOutput();
  41. //launch the test process, return whether it started correctly
  42. bool StartTest(size_t total);
  43. //capture and report the test results
  44. bool EndTest(size_t completed, size_t total, bool started);
  45. //Called by ctest -N to log the command string
  46. void ComputeArguments();
  47. void ComputeWeightedCost();
  48. bool StartAgain();
  49. private:
  50. bool NeedsToRerun();
  51. void DartProcessing();
  52. void ExeNotFound(std::string exe);
  53. // Figures out a final timeout which is min(STOP_TIME, NOW+TIMEOUT)
  54. double ResolveTimeout();
  55. bool ForkProcess(double testTimeOut, bool explicitTimeout,
  56. std::vector<std::string>* environment);
  57. void WriteLogOutputTop(size_t completed, size_t total);
  58. //Run post processing of the process output for MemCheck
  59. void MemCheckPostProcess();
  60. cmCTestTestHandler::cmCTestTestProperties * TestProperties;
  61. //Pointer back to the "parent"; the handler that invoked this test run
  62. cmCTestTestHandler * TestHandler;
  63. cmCTest * CTest;
  64. cmProcess * TestProcess;
  65. //If the executable to run is ctest, don't create a new process;
  66. //just instantiate a new cmTest. (Can be disabled for a single test
  67. //if this option is set to false.)
  68. //bool OptimizeForCTest;
  69. bool UsePrefixCommand;
  70. std::string PrefixCommand;
  71. std::string ProcessOutput;
  72. std::string CompressedOutput;
  73. double CompressionRatio;
  74. //The test results
  75. cmCTestTestHandler::cmCTestTestResult TestResult;
  76. int Index;
  77. std::string StartTime;
  78. std::string ActualCommand;
  79. std::vector<std::string> Arguments;
  80. bool StopTimePassed;
  81. bool RunUntilFail;
  82. int NumberOfRunsLeft;
  83. bool RunAgain;
  84. size_t TotalNumberOfTests;
  85. };
  86. inline int getNumWidth(size_t n)
  87. {
  88. int numWidth = 1;
  89. if(n >= 10)
  90. {
  91. numWidth = 2;
  92. }
  93. if(n >= 100)
  94. {
  95. numWidth = 3;
  96. }
  97. return numWidth;
  98. }
  99. #endif