cmCTestTestHandler.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. // add configuraitons to a search path for an executable
  109. static void AddConfigurations(cmCTest *ctest,
  110. std::vector<std::string> &attempted,
  111. std::vector<std::string> &attemptedConfigs,
  112. std::string filepath,
  113. std::string &filename);
  114. // full signature static method to find an executable
  115. static std::string FindExecutable(cmCTest *ctest,
  116. const char *testCommand,
  117. std::string &resultingConfig,
  118. std::vector<std::string> &extraPaths,
  119. std::vector<std::string> &failed);
  120. typedef std::vector<cmCTestTestProperties> ListOfTests;
  121. protected:
  122. // comput a final test list
  123. virtual int PreProcessHandler();
  124. virtual int PostProcessHandler();
  125. virtual void GenerateTestCommand(std::vector<std::string>& args);
  126. int ExecuteCommands(std::vector<cmStdString>& vec);
  127. void WriteTestResultHeader(std::ostream& os, cmCTestTestResult* result);
  128. void WriteTestResultFooter(std::ostream& os, cmCTestTestResult* result);
  129. // Write attached test files into the xml
  130. void AttachFiles(std::ostream& os, cmCTestTestResult* result);
  131. // Helper function to encode attached test files
  132. std::string EncodeFile(std::string file);
  133. //! Clean test output to specified length
  134. bool CleanTestOutput(std::string& output, size_t length);
  135. double ElapsedTestingTime;
  136. typedef std::vector<cmCTestTestResult> TestResultsVector;
  137. TestResultsVector TestResults;
  138. std::vector<cmStdString> CustomTestsIgnore;
  139. std::string StartTest;
  140. std::string EndTest;
  141. unsigned int StartTestTime;
  142. unsigned int EndTestTime;
  143. bool MemCheck;
  144. int CustomMaximumPassedTestOutputSize;
  145. int CustomMaximumFailedTestOutputSize;
  146. int MaxIndex;
  147. public:
  148. enum { // Program statuses
  149. NOT_RUN = 0,
  150. TIMEOUT,
  151. SEGFAULT,
  152. ILLEGAL,
  153. INTERRUPT,
  154. NUMERICAL,
  155. OTHER_FAULT,
  156. FAILED,
  157. BAD_COMMAND,
  158. COMPLETED
  159. };
  160. private:
  161. /**
  162. * Generate the Dart compatible output
  163. */
  164. virtual void GenerateDartOutput(std::ostream& os);
  165. void PrintLabelSummary();
  166. /**
  167. * Run the tests for a directory and any subdirectories
  168. */
  169. void ProcessDirectory(std::vector<cmStdString> &passed,
  170. std::vector<cmStdString> &failed);
  171. /**
  172. * Get the list of tests in directory and subdirectories.
  173. */
  174. void GetListOfTests();
  175. // compute the lists of tests that will actually run
  176. // based on union regex and -I stuff
  177. void ComputeTestList();
  178. bool GetValue(const char* tag,
  179. std::string& value,
  180. std::ifstream& fin);
  181. bool GetValue(const char* tag,
  182. int& value,
  183. std::ifstream& fin);
  184. bool GetValue(const char* tag,
  185. size_t& value,
  186. std::ifstream& fin);
  187. bool GetValue(const char* tag,
  188. bool& value,
  189. std::ifstream& fin);
  190. bool GetValue(const char* tag,
  191. double& value,
  192. std::ifstream& fin);
  193. /**
  194. * Find the executable for a test
  195. */
  196. std::string FindTheExecutable(const char *exe);
  197. const char* GetTestStatus(int status);
  198. void ExpandTestsToRunInformation(size_t numPossibleTests);
  199. std::vector<cmStdString> CustomPreTest;
  200. std::vector<cmStdString> CustomPostTest;
  201. std::vector<int> TestsToRun;
  202. bool UseIncludeLabelRegExpFlag;
  203. bool UseExcludeLabelRegExpFlag;
  204. bool UseIncludeRegExpFlag;
  205. bool UseExcludeRegExpFlag;
  206. bool UseExcludeRegExpFirst;
  207. std::string IncludeLabelRegExp;
  208. std::string ExcludeLabelRegExp;
  209. std::string IncludeRegExp;
  210. std::string ExcludeRegExp;
  211. cmsys::RegularExpression IncludeLabelRegularExpression;
  212. cmsys::RegularExpression ExcludeLabelRegularExpression;
  213. cmsys::RegularExpression IncludeTestsRegularExpression;
  214. cmsys::RegularExpression ExcludeTestsRegularExpression;
  215. std::string GenerateRegressionImages(const std::string& xml);
  216. cmsys::RegularExpression DartStuff1;
  217. void CheckLabelFilter(cmCTestTestProperties& it);
  218. void CheckLabelFilterExclude(cmCTestTestProperties& it);
  219. void CheckLabelFilterInclude(cmCTestTestProperties& it);
  220. std::string TestsToRunString;
  221. bool UseUnion;
  222. ListOfTests TestList;
  223. size_t TotalNumberOfTests;
  224. cmsys::RegularExpression DartStuff;
  225. std::ostream* LogFile;
  226. };
  227. #endif