ctest.cxx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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., Insight Consortium. 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. #include "cmCTest.h"
  14. #include "cmSystemTools.h"
  15. // Need these for documentation support.
  16. #include "cmake.h"
  17. #include "cmDocumentation.h"
  18. //----------------------------------------------------------------------------
  19. static const cmDocumentationEntry cmDocumentationName[] =
  20. {
  21. {0,
  22. " ctest - Testing driver provided by CMake.", 0},
  23. {0,0,0}
  24. };
  25. //----------------------------------------------------------------------------
  26. static const cmDocumentationEntry cmDocumentationUsage[] =
  27. {
  28. {0,
  29. " ctest [options]", 0},
  30. {0,0,0}
  31. };
  32. //----------------------------------------------------------------------------
  33. static const cmDocumentationEntry cmDocumentationDescription[] =
  34. {
  35. {0,
  36. "The \"ctest\" executable is the CMake test driver program. "
  37. "CMake-generated build trees created for projects that use "
  38. "the ENABLE_TESTING and ADD_TEST commands have testing support. "
  39. "This program will run the tests and report results.", 0},
  40. CMAKE_STANDARD_INTRODUCTION,
  41. {0,0,0}
  42. };
  43. //----------------------------------------------------------------------------
  44. static const cmDocumentationEntry cmDocumentationOptions[] =
  45. {
  46. {"-C <config>", "Choose configuration to test.",
  47. "Some CMake-generated build trees can have multiple build configurations "
  48. "in the same tree. This option can be used to specify which one should "
  49. "be tested. Example configurations are \"Debug\" and \"Release\"."},
  50. {"-V,--verbose", "Enable verbose output from tests.",
  51. "Test output is normally suppressed and only summary information is "
  52. "displayed. This option will show all test output."},
  53. {"-N,--show-only", "Disable actual execution of tests.",
  54. "This option tells ctest to list the tests that would be run but not "
  55. "actually run them. Useful in conjunction with the -R and -E options."},
  56. {"-R <regex>", "Run tests matching regular expression.",
  57. "This option tells ctest to run only the tests whose names match the "
  58. "given regular expression."},
  59. {"-E <regex>", "Exclude tests matching regular expression.",
  60. "This option tells ctest to NOT run the tests whose names match the "
  61. "given regular expression."},
  62. {"-D <DashboardTest>", "Execute dashboard test",
  63. "This option tells ctest to perform act as a Dart client and perform "
  64. "a dashboard test. All tests are ModeTest, where Mode can be Experimental, "
  65. "Nightly, and Continuous, and Test can be Start, Update, Configure, "
  66. "Build, Test, Coverage, and Submit."},
  67. {0,0,0}
  68. };
  69. //----------------------------------------------------------------------------
  70. static const cmDocumentationEntry cmDocumentationSeeAlso[] =
  71. {
  72. {0, "cmake", 0},
  73. {0, "ccmake", 0},
  74. {0, 0, 0}
  75. };
  76. // this is a test driver program for cmCTest.
  77. int main (int argc, char *argv[])
  78. {
  79. cmSystemTools::EnableMSVCDebugHook();
  80. // If there is a testing input file, check for documentation options
  81. // only if there are actually arguments. We want running without
  82. // arguments to run tests.
  83. if(argc > 1 || !cmSystemTools::FileExists("DartTestfile.txt"))
  84. {
  85. if(argc == 1)
  86. {
  87. std::cout << "*********************************" << std::endl;
  88. std::cout << "No test configuration file found!" << std::endl;
  89. std::cout << "*********************************" << std::endl;
  90. }
  91. cmDocumentation doc;
  92. if(doc.CheckOptions(argc, argv))
  93. {
  94. // Construct and print requested documentation.
  95. doc.SetName("ctest");
  96. doc.SetNameSection(cmDocumentationName);
  97. doc.SetUsageSection(cmDocumentationUsage);
  98. doc.SetDescriptionSection(cmDocumentationDescription);
  99. doc.SetOptionsSection(cmDocumentationOptions);
  100. doc.SetSeeAlsoList(cmDocumentationSeeAlso);
  101. return doc.PrintRequestedDocumentation(std::cout)? 0:1;
  102. }
  103. }
  104. cmCTest inst;
  105. // look at the args
  106. std::vector<std::string> args;
  107. for(int i =0; i < argc; ++i)
  108. {
  109. args.push_back(argv[i]);
  110. }
  111. #ifdef _WIN32
  112. std::string comspec = "cmw9xcom.exe";
  113. cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
  114. #endif
  115. for(unsigned int i=1; i < args.size(); ++i)
  116. {
  117. std::string arg = args[i];
  118. if(arg.find("-C",0) == 0 && i < args.size() - 1)
  119. {
  120. inst.m_ConfigType = args[i+1];
  121. }
  122. if( arg.find("-V",0) == 0 || arg.find("--verbose",0) == 0 )
  123. {
  124. inst.m_Verbose = true;
  125. }
  126. if( arg.find("-N",0) == 0 || arg.find("--show-only",0) == 0 )
  127. {
  128. inst.m_ShowOnly = true;
  129. }
  130. if( arg.find("-D",0) == 0 && i < args.size() - 1 )
  131. {
  132. inst.m_DartMode = true;
  133. std::string targ = args[i+1];
  134. if ( targ == "Experimental" )
  135. {
  136. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  137. inst.SetTest("Start");
  138. inst.SetTest("Configure");
  139. inst.SetTest("Build");
  140. inst.SetTest("Test");
  141. inst.SetTest("Coverage");
  142. inst.SetTest("Submit");
  143. }
  144. else if ( targ == "ExperimentalStart" )
  145. {
  146. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  147. inst.SetTest("Start");
  148. }
  149. else if ( targ == "ExperimentalUpdate" )
  150. {
  151. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  152. inst.SetTest("Update");
  153. }
  154. else if ( targ == "ExperimentalConfigure" )
  155. {
  156. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  157. inst.SetTest("Configure");
  158. }
  159. else if ( targ == "ExperimentalBuild" )
  160. {
  161. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  162. inst.SetTest("Build");
  163. }
  164. else if ( targ == "ExperimentalTest" )
  165. {
  166. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  167. inst.SetTest("Test");
  168. }
  169. else if ( targ == "ExperimentalPurify" )
  170. {
  171. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  172. inst.SetTest("Purify");
  173. }
  174. else if ( targ == "ExperimentalCoverage" )
  175. {
  176. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  177. inst.SetTest("Coverage");
  178. }
  179. else if ( targ == "ExperimentalSubmit" )
  180. {
  181. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  182. inst.SetTest("Submit");
  183. }
  184. else if ( targ == "Continuous" )
  185. {
  186. inst.SetTestModel(cmCTest::CONTINUOUS);
  187. inst.SetTest("Start");
  188. inst.SetTest("Update");
  189. inst.SetTest("Configure");
  190. inst.SetTest("Build");
  191. inst.SetTest("Test");
  192. inst.SetTest("Coverage");
  193. inst.SetTest("Submit");
  194. }
  195. else if ( targ == "ContinuousStart" )
  196. {
  197. inst.SetTestModel(cmCTest::CONTINUOUS);
  198. inst.SetTest("Start");
  199. }
  200. else if ( targ == "ContinuousUpdate" )
  201. {
  202. inst.SetTestModel(cmCTest::CONTINUOUS);
  203. inst.SetTest("Update");
  204. }
  205. else if ( targ == "ContinuousConfigure" )
  206. {
  207. inst.SetTestModel(cmCTest::CONTINUOUS);
  208. inst.SetTest("Configure");
  209. }
  210. else if ( targ == "ContinuousBuild" )
  211. {
  212. inst.SetTestModel(cmCTest::CONTINUOUS);
  213. inst.SetTest("Build");
  214. }
  215. else if ( targ == "ContinuousTest" )
  216. {
  217. inst.SetTestModel(cmCTest::CONTINUOUS);
  218. inst.SetTest("Test");
  219. }
  220. else if ( targ == "ContinuousPurify" )
  221. {
  222. inst.SetTestModel(cmCTest::CONTINUOUS);
  223. inst.SetTest("Purify");
  224. }
  225. else if ( targ == "ContinuousCoverage" )
  226. {
  227. inst.SetTestModel(cmCTest::CONTINUOUS);
  228. inst.SetTest("Coverage");
  229. }
  230. else if ( targ == "ContinuousSubmit" )
  231. {
  232. inst.SetTestModel(cmCTest::CONTINUOUS);
  233. inst.SetTest("Submit");
  234. }
  235. else if ( targ == "Nightly" )
  236. {
  237. inst.SetTestModel(cmCTest::NIGHTLY);
  238. inst.SetTest("Start");
  239. inst.SetTest("Update");
  240. inst.SetTest("Configure");
  241. inst.SetTest("Build");
  242. inst.SetTest("Test");
  243. inst.SetTest("Coverage");
  244. inst.SetTest("Submit");
  245. }
  246. else if ( targ == "NightlyStart" )
  247. {
  248. inst.SetTestModel(cmCTest::NIGHTLY);
  249. inst.SetTest("Start");
  250. }
  251. else if ( targ == "NightlyUpdate" )
  252. {
  253. inst.SetTestModel(cmCTest::NIGHTLY);
  254. inst.SetTest("Update");
  255. }
  256. else if ( targ == "NightlyConfigure" )
  257. {
  258. inst.SetTestModel(cmCTest::NIGHTLY);
  259. inst.SetTest("Configure");
  260. }
  261. else if ( targ == "NightlyBuild" )
  262. {
  263. inst.SetTestModel(cmCTest::NIGHTLY);
  264. inst.SetTest("Build");
  265. }
  266. else if ( targ == "NightlyTest" )
  267. {
  268. inst.SetTestModel(cmCTest::NIGHTLY);
  269. inst.SetTest("Test");
  270. }
  271. else if ( targ == "NightlyPurify" )
  272. {
  273. inst.SetTestModel(cmCTest::NIGHTLY);
  274. inst.SetTest("Purify");
  275. }
  276. else if ( targ == "NightlyCoverage" )
  277. {
  278. inst.SetTestModel(cmCTest::NIGHTLY);
  279. inst.SetTest("Coverage");
  280. }
  281. else if ( targ == "NightlySubmit" )
  282. {
  283. inst.SetTestModel(cmCTest::NIGHTLY);
  284. inst.SetTest("Submit");
  285. }
  286. else if ( targ == "MemoryCheck" )
  287. {
  288. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  289. inst.SetTest("Start");
  290. inst.SetTest("Configure");
  291. inst.SetTest("Build");
  292. inst.SetTest("Purify");
  293. inst.SetTest("Coverage");
  294. inst.SetTest("Submit");
  295. }
  296. else if ( targ == "NightlyMemoryCheck" )
  297. {
  298. inst.SetTestModel(cmCTest::NIGHTLY);
  299. inst.SetTest("Start");
  300. inst.SetTest("Update");
  301. inst.SetTest("Configure");
  302. inst.SetTest("Build");
  303. inst.SetTest("Purify");
  304. inst.SetTest("Coverage");
  305. inst.SetTest("Submit");
  306. }
  307. }
  308. if( ( arg.find("-T",0) == 0 ) &&
  309. (i < args.size() -1) )
  310. {
  311. inst.m_DartMode = true;
  312. inst.SetTest(args[i+1].c_str());
  313. }
  314. if( ( arg.find("-M",0) == 0 || arg.find("--test-model",0) == 0 ) &&
  315. (i < args.size() -1) )
  316. {
  317. std::string& str = args[i+1];
  318. if ( str == "NIGHTLY" || str == "nightly" || str == "Nightly" )
  319. {
  320. inst.SetTestModel(cmCTest::NIGHTLY);
  321. }
  322. else if ( str == "CONTINUOUS" || str == "continuous" ||
  323. str == "Continuous" )
  324. {
  325. inst.SetTestModel(cmCTest::CONTINUOUS);
  326. std::cout << "Continuous" << std::endl;
  327. }
  328. else
  329. {
  330. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  331. }
  332. }
  333. if(arg.find("-R",0) == 0 && i < args.size() - 1)
  334. {
  335. inst.m_UseIncludeRegExp = true;
  336. inst.m_IncludeRegExp = args[i+1];
  337. }
  338. if(arg.find("-E",0) == 0 && i < args.size() - 1)
  339. {
  340. inst.m_UseExcludeRegExp = true;
  341. inst.m_ExcludeRegExp = args[i+1];
  342. inst.m_UseExcludeRegExpFirst = inst.m_UseIncludeRegExp ? false : true;
  343. }
  344. }
  345. // call process directory
  346. inst.Initialize();
  347. int res = inst.ProcessTests();
  348. inst.Finalize();
  349. return res;
  350. }