cmCTestTestHandler.h 8.8 KB

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