cmCTestTestHandler.h 8.9 KB

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