cmCTestTestHandler.h 8.1 KB

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