cmCTestTestHandler.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmCTestTestHandler_h
  14. #define cmCTestTestHandler_h
  15. #include "cmCTestGenericHandler.h"
  16. #include <cmsys/RegularExpression.hxx>
  17. class cmMakefile;
  18. /** \class cmCTestTestHandler
  19. * \brief A class that handles ctest -S invocations
  20. *
  21. */
  22. class cmCTestTestHandler : public cmCTestGenericHandler
  23. {
  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. ///! pass the -I argument down
  47. void SetTestsToRunInformation(const char*);
  48. cmCTestTestHandler();
  49. /*
  50. * Add the test to the list of tests to be executed
  51. */
  52. bool AddTest(const std::vector<std::string>& args);
  53. /*
  54. * Set tests properties
  55. */
  56. bool SetTestsProperties(const std::vector<std::string>& args);
  57. void Initialize();
  58. // NOTE: This struct is Saved/Restored
  59. // in cmCTestTestHandler, if you add to this class
  60. // then you must add the new members to that code or
  61. // ctest -j N will break for that feature
  62. struct cmCTestTestProperties
  63. {
  64. cmStdString Name;
  65. cmStdString Directory;
  66. std::vector<std::string> Args;
  67. std::vector<std::string> Depends;
  68. std::vector<std::pair<cmsys::RegularExpression,
  69. std::string> > ErrorRegularExpressions;
  70. std::vector<std::pair<cmsys::RegularExpression,
  71. std::string> > RequiredRegularExpressions;
  72. std::map<cmStdString, cmStdString> Measurements;
  73. bool IsInBasedOnREOptions;
  74. bool WillFail;
  75. double Timeout;
  76. int Index;
  77. std::vector<std::string> Environment;
  78. std::vector<std::string> Labels;
  79. };
  80. struct cmCTestTestResult
  81. {
  82. std::string Name;
  83. std::string Path;
  84. std::string FullCommandLine;
  85. double ExecutionTime;
  86. int ReturnValue;
  87. int Status;
  88. std::string CompletionStatus;
  89. std::string Output;
  90. std::string RegressionImages;
  91. int TestCount;
  92. cmCTestTestProperties* Properties;
  93. };
  94. // add configuraitons to a search path for an executable
  95. static void AddConfigurations(cmCTest *ctest,
  96. std::vector<std::string> &attempted,
  97. std::vector<std::string> &attemptedConfigs,
  98. std::string filepath,
  99. std::string &filename);
  100. // full signature static method to find an executable
  101. static std::string FindExecutable(cmCTest *ctest,
  102. const char *testCommand,
  103. std::string &resultingConfig,
  104. std::vector<std::string> &extraPaths,
  105. std::vector<std::string> &failed);
  106. protected:
  107. // comput a final test list
  108. virtual int PreProcessHandler();
  109. virtual int PostProcessHandler();
  110. virtual void GenerateTestCommand(std::vector<const char*>& args);
  111. int ExecuteCommands(std::vector<cmStdString>& vec);
  112. //! Clean test output to specified length
  113. bool CleanTestOutput(std::string& output, size_t length);
  114. double ElapsedTestingTime;
  115. typedef std::vector<cmCTestTestResult> TestResultsVector;
  116. TestResultsVector TestResults;
  117. std::vector<cmStdString> CustomTestsIgnore;
  118. std::string StartTest;
  119. std::string EndTest;
  120. unsigned int StartTestTime;
  121. unsigned int EndTestTime;
  122. bool MemCheck;
  123. int CustomMaximumPassedTestOutputSize;
  124. int CustomMaximumFailedTestOutputSize;
  125. protected:
  126. /**
  127. * Run one test
  128. */
  129. virtual void ProcessOneTest(cmCTestTestProperties *props,
  130. std::vector<cmStdString> &passed,
  131. std::vector<cmStdString> &failed,
  132. int count, int tmsize);
  133. public:
  134. enum { // Program statuses
  135. NOT_RUN = 0,
  136. TIMEOUT,
  137. SEGFAULT,
  138. ILLEGAL,
  139. INTERRUPT,
  140. NUMERICAL,
  141. OTHER_FAULT,
  142. FAILED,
  143. BAD_COMMAND,
  144. COMPLETED
  145. };
  146. private:
  147. /**
  148. * Generate the Dart compatible output
  149. */
  150. virtual void GenerateDartOutput(std::ostream& os);
  151. /**
  152. * Run the tests for a directory and any subdirectories
  153. */
  154. void ProcessDirectory(std::vector<cmStdString> &passed,
  155. std::vector<cmStdString> &failed);
  156. typedef std::vector<cmCTestTestProperties> ListOfTests;
  157. /**
  158. * Get the list of tests in directory and subdirectories.
  159. */
  160. void GetListOfTests();
  161. // compute the lists of tests that will actually run
  162. // based on union regex and -I stuff
  163. void ComputeTestList();
  164. // Save the state of the test list and return the file
  165. // name it was saved to
  166. std::string SaveTestList();
  167. void LoadTestList();
  168. bool GetValue(const char* tag,
  169. std::string& value,
  170. std::ifstream& fin);
  171. bool GetValue(const char* tag,
  172. int& value,
  173. std::ifstream& fin);
  174. bool GetValue(const char* tag,
  175. size_t& value,
  176. std::ifstream& fin);
  177. bool GetValue(const char* tag,
  178. bool& value,
  179. std::ifstream& fin);
  180. bool GetValue(const char* tag,
  181. double& value,
  182. std::ifstream& fin);
  183. // run in -j N mode
  184. void ProcessParallel(std::vector<cmStdString> &passed,
  185. std::vector<cmStdString> &failed);
  186. /**
  187. * Find the executable for a test
  188. */
  189. std::string FindTheExecutable(const char *exe);
  190. const char* GetTestStatus(int status);
  191. void ExpandTestsToRunInformation(size_t numPossibleTests);
  192. std::vector<cmStdString> CustomPreTest;
  193. std::vector<cmStdString> CustomPostTest;
  194. std::vector<int> TestsToRun;
  195. bool UseIncludeRegExpFlag;
  196. bool UseExcludeRegExpFlag;
  197. bool UseExcludeRegExpFirst;
  198. std::string IncludeRegExp;
  199. std::string ExcludeRegExp;
  200. cmsys::RegularExpression IncludeTestsRegularExpression;
  201. cmsys::RegularExpression ExcludeTestsRegularExpression;
  202. std::string GenerateRegressionImages(const std::string& xml);
  203. std::string TestsToRunString;
  204. bool UseUnion;
  205. ListOfTests TestList;
  206. size_t TotalNumberOfTests;
  207. cmsys::RegularExpression DartStuff;
  208. std::ostream* LogFile;
  209. };
  210. #endif