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