cmCTestTestHandler.h 8.9 KB

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