cmCTestTestHandler.h 7.9 KB

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