cmCTestTestHandler.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc.
  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 cmCTestTestHandler_h
  11. #define cmCTestTestHandler_h
  12. #include "cmCTestGenericHandler.h"
  13. #include <cmsys/RegularExpression.hxx>
  14. class cmMakefile;
  15. /** \class cmCTestTestHandler
  16. * \brief A class that handles ctest -S invocations
  17. *
  18. */
  19. class cmCTestTestHandler : public cmCTestGenericHandler
  20. {
  21. friend class cmCTestRunTest;
  22. friend class cmCTestMultiProcessHandler;
  23. friend class cmCTestBatchTestHandler;
  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. * Set whether or not CTest should only execute the tests that failed
  38. * on the previous run. By default this is false.
  39. */
  40. void SetRerunFailed(bool val) { this->RerunFailed = val; }
  41. /**
  42. * This method is called when reading CTest custom file
  43. */
  44. void PopulateCustomVectors(cmMakefile *mf);
  45. ///! Control the use of the regular expresisons, call these methods to turn
  46. ///them on
  47. void UseIncludeRegExp();
  48. void UseExcludeRegExp();
  49. void SetIncludeRegExp(const char *);
  50. void SetExcludeRegExp(const char *);
  51. void SetMaxIndex(int n) {this->MaxIndex = n;}
  52. int GetMaxIndex() {return this->MaxIndex;}
  53. ///! pass the -I argument down
  54. void SetTestsToRunInformation(const char*);
  55. cmCTestTestHandler();
  56. /*
  57. * Add the test to the list of tests to be executed
  58. */
  59. bool AddTest(const std::vector<std::string>& args);
  60. /*
  61. * Set tests properties
  62. */
  63. bool SetTestsProperties(const std::vector<std::string>& args);
  64. void Initialize();
  65. // NOTE: This struct is Saved/Restored
  66. // in cmCTestTestHandler, if you add to this class
  67. // then you must add the new members to that code or
  68. // ctest -j N will break for that feature
  69. struct cmCTestTestProperties
  70. {
  71. std::string Name;
  72. std::string Directory;
  73. std::vector<std::string> Args;
  74. std::vector<std::string> RequiredFiles;
  75. std::vector<std::string> Depends;
  76. std::vector<std::string> AttachedFiles;
  77. std::vector<std::string> AttachOnFail;
  78. std::vector<std::pair<cmsys::RegularExpression,
  79. std::string> > ErrorRegularExpressions;
  80. std::vector<std::pair<cmsys::RegularExpression,
  81. std::string> > RequiredRegularExpressions;
  82. std::map<std::string, std::string> Measurements;
  83. bool IsInBasedOnREOptions;
  84. bool WillFail;
  85. float Cost;
  86. int PreviousRuns;
  87. bool RunSerial;
  88. double Timeout;
  89. bool ExplicitTimeout;
  90. int Index;
  91. //Requested number of process slots
  92. int Processors;
  93. // return code of test which will mark test as "not run"
  94. int SkipReturnCode;
  95. std::vector<std::string> Environment;
  96. std::vector<std::string> Labels;
  97. std::set<std::string> LockedResources;
  98. };
  99. struct cmCTestTestResult
  100. {
  101. std::string Name;
  102. std::string Path;
  103. std::string Reason;
  104. std::string FullCommandLine;
  105. double ExecutionTime;
  106. int ReturnValue;
  107. int Status;
  108. bool CompressOutput;
  109. std::string CompletionStatus;
  110. std::string Output;
  111. std::string RegressionImages;
  112. int TestCount;
  113. cmCTestTestProperties* Properties;
  114. };
  115. struct cmCTestTestResultLess
  116. {
  117. bool operator() (const cmCTestTestResult &lhs,
  118. const cmCTestTestResult &rhs) const
  119. {
  120. return lhs.TestCount < rhs.TestCount;
  121. }
  122. };
  123. // add configurations to a search path for an executable
  124. static void AddConfigurations(cmCTest *ctest,
  125. std::vector<std::string> &attempted,
  126. std::vector<std::string> &attemptedConfigs,
  127. std::string filepath,
  128. std::string &filename);
  129. // full signature static method to find an executable
  130. static std::string FindExecutable(cmCTest *ctest,
  131. const char *testCommand,
  132. std::string &resultingConfig,
  133. std::vector<std::string> &extraPaths,
  134. std::vector<std::string> &failed);
  135. typedef std::vector<cmCTestTestProperties> ListOfTests;
  136. protected:
  137. // compute a final test list
  138. virtual int PreProcessHandler();
  139. virtual int PostProcessHandler();
  140. virtual void GenerateTestCommand(std::vector<std::string>& args, int test);
  141. int ExecuteCommands(std::vector<std::string>& vec);
  142. void WriteTestResultHeader(std::ostream& os, cmCTestTestResult* result);
  143. void WriteTestResultFooter(std::ostream& os, cmCTestTestResult* result);
  144. // Write attached test files into the xml
  145. void AttachFiles(std::ostream& os, cmCTestTestResult* result);
  146. //! Clean test output to specified length
  147. bool CleanTestOutput(std::string& output, size_t length);
  148. double ElapsedTestingTime;
  149. typedef std::vector<cmCTestTestResult> TestResultsVector;
  150. TestResultsVector TestResults;
  151. std::vector<std::string> CustomTestsIgnore;
  152. std::string StartTest;
  153. std::string EndTest;
  154. unsigned int StartTestTime;
  155. unsigned int EndTestTime;
  156. bool MemCheck;
  157. int CustomMaximumPassedTestOutputSize;
  158. int CustomMaximumFailedTestOutputSize;
  159. int MaxIndex;
  160. public:
  161. enum { // Program statuses
  162. NOT_RUN = 0,
  163. TIMEOUT,
  164. SEGFAULT,
  165. ILLEGAL,
  166. INTERRUPT,
  167. NUMERICAL,
  168. OTHER_FAULT,
  169. FAILED,
  170. BAD_COMMAND,
  171. COMPLETED
  172. };
  173. private:
  174. /**
  175. * Generate the Dart compatible output
  176. */
  177. virtual void GenerateDartOutput(std::ostream& os);
  178. void PrintLabelSummary();
  179. /**
  180. * Run the tests for a directory and any subdirectories
  181. */
  182. void ProcessDirectory(std::vector<std::string> &passed,
  183. std::vector<std::string> &failed);
  184. /**
  185. * Get the list of tests in directory and subdirectories.
  186. */
  187. void GetListOfTests();
  188. // compute the lists of tests that will actually run
  189. // based on union regex and -I stuff
  190. void ComputeTestList();
  191. // compute the lists of tests that will actually run
  192. // based on LastTestFailed.log
  193. void ComputeTestListForRerunFailed();
  194. void UpdateMaxTestNameWidth();
  195. bool GetValue(const char* tag,
  196. std::string& value,
  197. std::istream& fin);
  198. bool GetValue(const char* tag,
  199. int& value,
  200. std::istream& fin);
  201. bool GetValue(const char* tag,
  202. size_t& value,
  203. std::istream& fin);
  204. bool GetValue(const char* tag,
  205. bool& value,
  206. std::istream& fin);
  207. bool GetValue(const char* tag,
  208. double& value,
  209. std::istream& fin);
  210. /**
  211. * Find the executable for a test
  212. */
  213. std::string FindTheExecutable(const char *exe);
  214. const char* GetTestStatus(int status);
  215. void ExpandTestsToRunInformation(size_t numPossibleTests);
  216. void ExpandTestsToRunInformationForRerunFailed();
  217. std::vector<std::string> CustomPreTest;
  218. std::vector<std::string> CustomPostTest;
  219. std::vector<int> TestsToRun;
  220. bool UseIncludeLabelRegExpFlag;
  221. bool UseExcludeLabelRegExpFlag;
  222. bool UseIncludeRegExpFlag;
  223. bool UseExcludeRegExpFlag;
  224. bool UseExcludeRegExpFirst;
  225. std::string IncludeLabelRegExp;
  226. std::string ExcludeLabelRegExp;
  227. std::string IncludeRegExp;
  228. std::string ExcludeRegExp;
  229. cmsys::RegularExpression IncludeLabelRegularExpression;
  230. cmsys::RegularExpression ExcludeLabelRegularExpression;
  231. cmsys::RegularExpression IncludeTestsRegularExpression;
  232. cmsys::RegularExpression ExcludeTestsRegularExpression;
  233. std::string GenerateRegressionImages(const std::string& xml);
  234. cmsys::RegularExpression DartStuff1;
  235. void CheckLabelFilter(cmCTestTestProperties& it);
  236. void CheckLabelFilterExclude(cmCTestTestProperties& it);
  237. void CheckLabelFilterInclude(cmCTestTestProperties& it);
  238. std::string TestsToRunString;
  239. bool UseUnion;
  240. ListOfTests TestList;
  241. size_t TotalNumberOfTests;
  242. cmsys::RegularExpression DartStuff;
  243. std::ostream* LogFile;
  244. bool RerunFailed;
  245. };
  246. #endif