cmCTestRunTest.h 3.2 KB

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