cmCTestTestHandler.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. bool CompressOutput;
  128. std::string CompletionStatus;
  129. std::string Output;
  130. std::string DartString;
  131. int TestCount;
  132. cmCTestTestProperties* Properties;
  133. };
  134. struct cmCTestTestResultLess
  135. {
  136. bool operator()(const cmCTestTestResult& lhs,
  137. const cmCTestTestResult& rhs) const
  138. {
  139. return lhs.TestCount < rhs.TestCount;
  140. }
  141. };
  142. // add configurations to a search path for an executable
  143. static void AddConfigurations(cmCTest* ctest,
  144. std::vector<std::string>& attempted,
  145. std::vector<std::string>& attemptedConfigs,
  146. std::string filepath, std::string& filename);
  147. // full signature static method to find an executable
  148. static std::string FindExecutable(cmCTest* ctest, const char* testCommand,
  149. std::string& resultingConfig,
  150. std::vector<std::string>& extraPaths,
  151. std::vector<std::string>& failed);
  152. typedef std::vector<cmCTestTestProperties> ListOfTests;
  153. protected:
  154. // compute a final test list
  155. virtual int PreProcessHandler();
  156. virtual int PostProcessHandler();
  157. virtual void GenerateTestCommand(std::vector<std::string>& args, int test);
  158. int ExecuteCommands(std::vector<std::string>& vec);
  159. void WriteTestResultHeader(cmXMLWriter& xml, cmCTestTestResult* result);
  160. void WriteTestResultFooter(cmXMLWriter& xml, cmCTestTestResult* result);
  161. // Write attached test files into the xml
  162. void AttachFiles(cmXMLWriter& xml, cmCTestTestResult* result);
  163. //! Clean test output to specified length
  164. bool CleanTestOutput(std::string& output, size_t length);
  165. double ElapsedTestingTime;
  166. typedef std::vector<cmCTestTestResult> TestResultsVector;
  167. TestResultsVector TestResults;
  168. std::vector<std::string> CustomTestsIgnore;
  169. std::string StartTest;
  170. std::string EndTest;
  171. unsigned int StartTestTime;
  172. unsigned int EndTestTime;
  173. bool MemCheck;
  174. int CustomMaximumPassedTestOutputSize;
  175. int CustomMaximumFailedTestOutputSize;
  176. int MaxIndex;
  177. public:
  178. enum
  179. { // Program statuses
  180. NOT_RUN = 0,
  181. TIMEOUT,
  182. SEGFAULT,
  183. ILLEGAL,
  184. INTERRUPT,
  185. NUMERICAL,
  186. OTHER_FAULT,
  187. FAILED,
  188. BAD_COMMAND,
  189. COMPLETED
  190. };
  191. private:
  192. /**
  193. * Generate the Dart compatible output
  194. */
  195. virtual void GenerateDartOutput(cmXMLWriter& xml);
  196. void PrintLabelSummary();
  197. /**
  198. * Run the tests for a directory and any subdirectories
  199. */
  200. void ProcessDirectory(std::vector<std::string>& passed,
  201. std::vector<std::string>& failed);
  202. /**
  203. * Get the list of tests in directory and subdirectories.
  204. */
  205. void GetListOfTests();
  206. // compute the lists of tests that will actually run
  207. // based on union regex and -I stuff
  208. void ComputeTestList();
  209. // compute the lists of tests that will actually run
  210. // based on LastTestFailed.log
  211. void ComputeTestListForRerunFailed();
  212. // add required setup/cleanup tests not already in the
  213. // list of tests to be run and update dependencies between
  214. // tests to account for fixture setup/cleanup
  215. void UpdateForFixtures(ListOfTests& tests) const;
  216. void UpdateMaxTestNameWidth();
  217. bool GetValue(const char* tag, std::string& value, std::istream& fin);
  218. bool GetValue(const char* tag, int& value, std::istream& fin);
  219. bool GetValue(const char* tag, size_t& value, std::istream& fin);
  220. bool GetValue(const char* tag, bool& value, std::istream& fin);
  221. bool GetValue(const char* tag, double& value, std::istream& fin);
  222. /**
  223. * Find the executable for a test
  224. */
  225. std::string FindTheExecutable(const char* exe);
  226. const char* GetTestStatus(int status);
  227. void ExpandTestsToRunInformation(size_t numPossibleTests);
  228. void ExpandTestsToRunInformationForRerunFailed();
  229. std::vector<std::string> CustomPreTest;
  230. std::vector<std::string> CustomPostTest;
  231. std::vector<int> TestsToRun;
  232. bool UseIncludeLabelRegExpFlag;
  233. bool UseExcludeLabelRegExpFlag;
  234. bool UseIncludeRegExpFlag;
  235. bool UseExcludeRegExpFlag;
  236. bool UseExcludeRegExpFirst;
  237. std::string IncludeLabelRegExp;
  238. std::string ExcludeLabelRegExp;
  239. std::string IncludeRegExp;
  240. std::string ExcludeRegExp;
  241. std::string ExcludeFixtureRegExp;
  242. std::string ExcludeFixtureSetupRegExp;
  243. std::string ExcludeFixtureCleanupRegExp;
  244. cmsys::RegularExpression IncludeLabelRegularExpression;
  245. cmsys::RegularExpression ExcludeLabelRegularExpression;
  246. cmsys::RegularExpression IncludeTestsRegularExpression;
  247. cmsys::RegularExpression ExcludeTestsRegularExpression;
  248. void GenerateRegressionImages(cmXMLWriter& xml, const std::string& dart);
  249. cmsys::RegularExpression DartStuff1;
  250. void CheckLabelFilter(cmCTestTestProperties& it);
  251. void CheckLabelFilterExclude(cmCTestTestProperties& it);
  252. void CheckLabelFilterInclude(cmCTestTestProperties& it);
  253. std::string TestsToRunString;
  254. bool UseUnion;
  255. ListOfTests TestList;
  256. size_t TotalNumberOfTests;
  257. cmsys::RegularExpression DartStuff;
  258. std::ostream* LogFile;
  259. bool RerunFailed;
  260. };
  261. #endif