cmCTestTestHandler.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmCTestTestHandler_h
  14. #define cmCTestTestHandler_h
  15. #include "cmCTestGenericHandler.h"
  16. #include <cmsys/RegularExpression.hxx>
  17. class cmMakefile;
  18. /** \class cmCTestTestHandler
  19. * \brief A class that handles ctest -S invocations
  20. *
  21. */
  22. class cmCTestTestHandler : public cmCTestGenericHandler
  23. {
  24. public:
  25. cmTypeMacro(cmCTestTestHandler, cmCTestGenericHandler);
  26. /**
  27. * The main entry point for this class
  28. */
  29. int ProcessHandler();
  30. /**
  31. * When both -R and -I are used should te resulting test list be the
  32. * intersection or the union of the lists. By default it is the
  33. * intersection.
  34. */
  35. void SetUseUnion(bool val) { this->UseUnion = val; }
  36. /**
  37. * This method is called when reading CTest custom file
  38. */
  39. void PopulateCustomVectors(cmMakefile *mf);
  40. ///! Control the use of the regular expresisons, call these methods to turn
  41. ///them on
  42. void UseIncludeRegExp();
  43. void UseExcludeRegExp();
  44. void SetIncludeRegExp(const char *);
  45. void SetExcludeRegExp(const char *);
  46. ///! pass the -I argument down
  47. void SetTestsToRunInformation(const char*);
  48. cmCTestTestHandler();
  49. /*
  50. * Add the test to the list of tests to be executed
  51. */
  52. bool AddTest(const std::vector<std::string>& args);
  53. /*
  54. * Set tests properties
  55. */
  56. bool SetTestsProperties(const std::vector<std::string>& args);
  57. void Initialize();
  58. struct cmCTestTestProperties
  59. {
  60. cmStdString Name;
  61. cmStdString Directory;
  62. std::vector<std::string> Args;
  63. std::vector<std::string> Depends;
  64. std::vector<std::pair<cmsys::RegularExpression,
  65. std::string> > ErrorRegularExpressions;
  66. std::vector<std::pair<cmsys::RegularExpression,
  67. std::string> > RequiredRegularExpressions;
  68. std::map<cmStdString, cmStdString> Measurements;
  69. bool IsInBasedOnREOptions;
  70. bool WillFail;
  71. double Timeout;
  72. int Index;
  73. };
  74. struct cmCTestTestResult
  75. {
  76. std::string Name;
  77. std::string Path;
  78. std::string FullCommandLine;
  79. double ExecutionTime;
  80. int ReturnValue;
  81. int Status;
  82. std::string CompletionStatus;
  83. std::string Output;
  84. std::string RegressionImages;
  85. int TestCount;
  86. cmCTestTestProperties* Properties;
  87. };
  88. // add configuraitons to a search path for an executable
  89. static void AddConfigurations(cmCTest *ctest,
  90. std::vector<std::string> &attempted,
  91. std::vector<std::string> &attemptedConfigs,
  92. std::string filepath,
  93. std::string &filename);
  94. // full signature static method to find an executable
  95. static std::string FindExecutable(cmCTest *ctest,
  96. const char *testCommand,
  97. std::string &resultingConfig,
  98. std::vector<std::string> &extraPaths,
  99. std::vector<std::string> &failed);
  100. protected:
  101. // comput a final test list
  102. virtual int PreProcessHandler();
  103. virtual int PostProcessHandler();
  104. virtual void GenerateTestCommand(std::vector<const char*>& args);
  105. int ExecuteCommands(std::vector<cmStdString>& vec);
  106. //! Clean test output to specified length
  107. bool CleanTestOutput(std::string& output, size_t length);
  108. double ElapsedTestingTime;
  109. typedef std::vector<cmCTestTestResult> TestResultsVector;
  110. TestResultsVector TestResults;
  111. std::vector<cmStdString> CustomTestsIgnore;
  112. std::string StartTest;
  113. std::string EndTest;
  114. unsigned int StartTestTime;
  115. unsigned int EndTestTime;
  116. bool MemCheck;
  117. int CustomMaximumPassedTestOutputSize;
  118. int CustomMaximumFailedTestOutputSize;
  119. protected:
  120. /**
  121. * Run one test
  122. */
  123. virtual void ProcessOneTest(cmCTestTestProperties *props,
  124. std::vector<cmStdString> &passed,
  125. std::vector<cmStdString> &failed,
  126. int count, int tmsize);
  127. public:
  128. enum { // Program statuses
  129. NOT_RUN = 0,
  130. TIMEOUT,
  131. SEGFAULT,
  132. ILLEGAL,
  133. INTERRUPT,
  134. NUMERICAL,
  135. OTHER_FAULT,
  136. FAILED,
  137. BAD_COMMAND,
  138. COMPLETED
  139. };
  140. private:
  141. /**
  142. * Generate the Dart compatible output
  143. */
  144. virtual void GenerateDartOutput(std::ostream& os);
  145. /**
  146. * Run the tests for a directory and any subdirectories
  147. */
  148. void ProcessDirectory(std::vector<cmStdString> &passed,
  149. std::vector<cmStdString> &failed);
  150. typedef std::vector<cmCTestTestProperties> ListOfTests;
  151. /**
  152. * Get the list of tests in directory and subdirectories.
  153. */
  154. void GetListOfTests();
  155. // compute the lists of tests that will actually run
  156. // based on union regex and -I stuff
  157. void ComputeTestList();
  158. // Save the state of the test list and return the file
  159. // name it was saved to
  160. std::string SaveTestList();
  161. void LoadTestList();
  162. bool GetValue(const char* tag,
  163. std::string& value,
  164. std::ifstream& fin);
  165. bool GetValue(const char* tag,
  166. int& value,
  167. std::ifstream& fin);
  168. bool GetValue(const char* tag,
  169. size_t& value,
  170. std::ifstream& fin);
  171. bool GetValue(const char* tag,
  172. bool& value,
  173. std::ifstream& fin);
  174. bool GetValue(const char* tag,
  175. double& value,
  176. std::ifstream& fin);
  177. // run in -j N mode
  178. void ProcessParallel(std::vector<cmStdString> &passed,
  179. std::vector<cmStdString> &failed);
  180. /**
  181. * Find the executable for a test
  182. */
  183. std::string FindTheExecutable(const char *exe);
  184. const char* GetTestStatus(int status);
  185. void ExpandTestsToRunInformation(size_t numPossibleTests);
  186. std::vector<cmStdString> CustomPreTest;
  187. std::vector<cmStdString> CustomPostTest;
  188. std::vector<int> TestsToRun;
  189. bool UseIncludeRegExpFlag;
  190. bool UseExcludeRegExpFlag;
  191. bool UseExcludeRegExpFirst;
  192. std::string IncludeRegExp;
  193. std::string ExcludeRegExp;
  194. cmsys::RegularExpression IncludeTestsRegularExpression;
  195. cmsys::RegularExpression ExcludeTestsRegularExpression;
  196. std::string GenerateRegressionImages(const std::string& xml);
  197. std::string TestsToRunString;
  198. bool UseUnion;
  199. ListOfTests TestList;
  200. size_t TotalNumberOfTests;
  201. cmsys::RegularExpression DartStuff;
  202. std::ostream* LogFile;
  203. };
  204. #endif