cmCTestRunTest.h 3.2 KB

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