ctest.cxx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. {"-S <ConfigScript>", "Execute a dashboard for a configuration",
  68. "This option tells ctest to load in a configuration script which sets "
  69. "a number of parameters such as the binary and source directories. Then "
  70. "ctest will do what is required to create and run a dashboard. This "
  71. "option basically sets up a dashboard and then runs ctest -D with the "
  72. "appropriate options."},
  73. {"-A <Notes file>", "Add a notes file with submission",
  74. "This option tells ctest to include a notes file when submitting dashboard. "},
  75. {0,0,0}
  76. };
  77. //----------------------------------------------------------------------------
  78. static const cmDocumentationEntry cmDocumentationSeeAlso[] =
  79. {
  80. {0, "cmake", 0},
  81. {0, "ccmake", 0},
  82. {0, 0, 0}
  83. };
  84. // this is a test driver program for cmCTest.
  85. int main (int argc, char *argv[])
  86. {
  87. cmSystemTools::EnableMSVCDebugHook();
  88. // If there is a testing input file, check for documentation options
  89. // only if there are actually arguments. We want running without
  90. // arguments to run tests.
  91. if(argc > 1 || !cmSystemTools::FileExists("DartTestfile.txt"))
  92. {
  93. if(argc == 1)
  94. {
  95. std::cout << "*********************************" << std::endl;
  96. std::cout << "No test configuration file found!" << std::endl;
  97. std::cout << "*********************************" << std::endl;
  98. }
  99. cmDocumentation doc;
  100. if(doc.CheckOptions(argc, argv))
  101. {
  102. // Construct and print requested documentation.
  103. doc.SetName("ctest");
  104. doc.SetNameSection(cmDocumentationName);
  105. doc.SetUsageSection(cmDocumentationUsage);
  106. doc.SetDescriptionSection(cmDocumentationDescription);
  107. doc.SetOptionsSection(cmDocumentationOptions);
  108. doc.SetSeeAlsoList(cmDocumentationSeeAlso);
  109. return doc.PrintRequestedDocumentation(std::cout)? 0:1;
  110. }
  111. }
  112. cmCTest inst;
  113. // look at the args
  114. std::vector<std::string> args;
  115. for(int i =0; i < argc; ++i)
  116. {
  117. args.push_back(argv[i]);
  118. }
  119. #ifdef _WIN32
  120. std::string comspec = "cmw9xcom.exe";
  121. cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
  122. #endif
  123. for(unsigned int i=1; i < args.size(); ++i)
  124. {
  125. std::string arg = args[i];
  126. if(arg.find("-C",0) == 0 && i < args.size() - 1)
  127. {
  128. inst.m_ConfigType = args[i+1];
  129. }
  130. if( arg.find("-V",0) == 0 || arg.find("--verbose",0) == 0 )
  131. {
  132. inst.m_Verbose = true;
  133. }
  134. if( arg.find("-N",0) == 0 || arg.find("--show-only",0) == 0 )
  135. {
  136. inst.m_ShowOnly = true;
  137. }
  138. if( arg.find("-S",0) == 0 && i < args.size() - 1 )
  139. {
  140. inst.m_RunConfigurationScript = true;
  141. inst.m_ConfigurationScript = args[i+1];
  142. }
  143. if( arg.find("-D",0) == 0 && i < args.size() - 1 )
  144. {
  145. inst.m_DartMode = true;
  146. std::string targ = args[i+1];
  147. if ( targ == "Experimental" )
  148. {
  149. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  150. inst.SetTest("Start");
  151. inst.SetTest("Configure");
  152. inst.SetTest("Build");
  153. inst.SetTest("Test");
  154. inst.SetTest("Coverage");
  155. inst.SetTest("Submit");
  156. }
  157. else if ( targ == "ExperimentalStart" )
  158. {
  159. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  160. inst.SetTest("Start");
  161. }
  162. else if ( targ == "ExperimentalUpdate" )
  163. {
  164. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  165. inst.SetTest("Update");
  166. }
  167. else if ( targ == "ExperimentalConfigure" )
  168. {
  169. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  170. inst.SetTest("Configure");
  171. }
  172. else if ( targ == "ExperimentalBuild" )
  173. {
  174. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  175. inst.SetTest("Build");
  176. }
  177. else if ( targ == "ExperimentalTest" )
  178. {
  179. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  180. inst.SetTest("Test");
  181. }
  182. else if ( targ == "ExperimentalMemCheck" || targ == "ExperimentalPurify" )
  183. {
  184. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  185. inst.SetTest("MemCheck");
  186. }
  187. else if ( targ == "ExperimentalCoverage" )
  188. {
  189. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  190. inst.SetTest("Coverage");
  191. }
  192. else if ( targ == "ExperimentalSubmit" )
  193. {
  194. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  195. inst.SetTest("Submit");
  196. }
  197. else if ( targ == "Continuous" )
  198. {
  199. inst.SetTestModel(cmCTest::CONTINUOUS);
  200. inst.SetTest("Start");
  201. inst.SetTest("Update");
  202. inst.SetTest("Configure");
  203. inst.SetTest("Build");
  204. inst.SetTest("Test");
  205. inst.SetTest("Coverage");
  206. inst.SetTest("Submit");
  207. }
  208. else if ( targ == "ContinuousStart" )
  209. {
  210. inst.SetTestModel(cmCTest::CONTINUOUS);
  211. inst.SetTest("Start");
  212. }
  213. else if ( targ == "ContinuousUpdate" )
  214. {
  215. inst.SetTestModel(cmCTest::CONTINUOUS);
  216. inst.SetTest("Update");
  217. }
  218. else if ( targ == "ContinuousConfigure" )
  219. {
  220. inst.SetTestModel(cmCTest::CONTINUOUS);
  221. inst.SetTest("Configure");
  222. }
  223. else if ( targ == "ContinuousBuild" )
  224. {
  225. inst.SetTestModel(cmCTest::CONTINUOUS);
  226. inst.SetTest("Build");
  227. }
  228. else if ( targ == "ContinuousTest" )
  229. {
  230. inst.SetTestModel(cmCTest::CONTINUOUS);
  231. inst.SetTest("Test");
  232. }
  233. else if ( targ == "ContinuousMemCheck" || targ == "ContinuousPurify" )
  234. {
  235. inst.SetTestModel(cmCTest::CONTINUOUS);
  236. inst.SetTest("MemCheck");
  237. }
  238. else if ( targ == "ContinuousCoverage" )
  239. {
  240. inst.SetTestModel(cmCTest::CONTINUOUS);
  241. inst.SetTest("Coverage");
  242. }
  243. else if ( targ == "ContinuousSubmit" )
  244. {
  245. inst.SetTestModel(cmCTest::CONTINUOUS);
  246. inst.SetTest("Submit");
  247. }
  248. else if ( targ == "Nightly" )
  249. {
  250. inst.SetTestModel(cmCTest::NIGHTLY);
  251. inst.SetTest("Start");
  252. inst.SetTest("Update");
  253. inst.SetTest("Configure");
  254. inst.SetTest("Build");
  255. inst.SetTest("Test");
  256. inst.SetTest("Coverage");
  257. inst.SetTest("Submit");
  258. }
  259. else if ( targ == "NightlyStart" )
  260. {
  261. inst.SetTestModel(cmCTest::NIGHTLY);
  262. inst.SetTest("Start");
  263. }
  264. else if ( targ == "NightlyUpdate" )
  265. {
  266. inst.SetTestModel(cmCTest::NIGHTLY);
  267. inst.SetTest("Update");
  268. }
  269. else if ( targ == "NightlyConfigure" )
  270. {
  271. inst.SetTestModel(cmCTest::NIGHTLY);
  272. inst.SetTest("Configure");
  273. }
  274. else if ( targ == "NightlyBuild" )
  275. {
  276. inst.SetTestModel(cmCTest::NIGHTLY);
  277. inst.SetTest("Build");
  278. }
  279. else if ( targ == "NightlyTest" )
  280. {
  281. inst.SetTestModel(cmCTest::NIGHTLY);
  282. inst.SetTest("Test");
  283. }
  284. else if ( targ == "NightlyMemCheck" || targ == "NightlyPurify" )
  285. {
  286. inst.SetTestModel(cmCTest::NIGHTLY);
  287. inst.SetTest("MemCheck");
  288. }
  289. else if ( targ == "NightlyCoverage" )
  290. {
  291. inst.SetTestModel(cmCTest::NIGHTLY);
  292. inst.SetTest("Coverage");
  293. }
  294. else if ( targ == "NightlySubmit" )
  295. {
  296. inst.SetTestModel(cmCTest::NIGHTLY);
  297. inst.SetTest("Submit");
  298. }
  299. else if ( targ == "MemoryCheck" )
  300. {
  301. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  302. inst.SetTest("Start");
  303. inst.SetTest("Configure");
  304. inst.SetTest("Build");
  305. inst.SetTest("MemCheck");
  306. inst.SetTest("Coverage");
  307. inst.SetTest("Submit");
  308. }
  309. else if ( targ == "NightlyMemoryCheck" )
  310. {
  311. inst.SetTestModel(cmCTest::NIGHTLY);
  312. inst.SetTest("Start");
  313. inst.SetTest("Update");
  314. inst.SetTest("Configure");
  315. inst.SetTest("Build");
  316. inst.SetTest("MemCheck");
  317. inst.SetTest("Coverage");
  318. inst.SetTest("Submit");
  319. }
  320. }
  321. if( ( arg.find("-T",0) == 0 ) &&
  322. (i < args.size() -1) )
  323. {
  324. inst.m_DartMode = true;
  325. inst.SetTest(args[i+1].c_str());
  326. }
  327. if( ( arg.find("-M",0) == 0 || arg.find("--test-model",0) == 0 ) &&
  328. (i < args.size() -1) )
  329. {
  330. std::string& str = args[i+1];
  331. if ( str == "NIGHTLY" || str == "nightly" || str == "Nightly" )
  332. {
  333. inst.SetTestModel(cmCTest::NIGHTLY);
  334. }
  335. else if ( str == "CONTINUOUS" || str == "continuous" ||
  336. str == "Continuous" )
  337. {
  338. inst.SetTestModel(cmCTest::CONTINUOUS);
  339. std::cout << "Continuous" << std::endl;
  340. }
  341. else
  342. {
  343. inst.SetTestModel(cmCTest::EXPERIMENTAL);
  344. }
  345. }
  346. if(arg.find("-R",0) == 0 && i < args.size() - 1)
  347. {
  348. inst.m_UseIncludeRegExp = true;
  349. inst.m_IncludeRegExp = args[i+1];
  350. }
  351. if(arg.find("-E",0) == 0 && i < args.size() - 1)
  352. {
  353. inst.m_UseExcludeRegExp = true;
  354. inst.m_ExcludeRegExp = args[i+1];
  355. inst.m_UseExcludeRegExpFirst = inst.m_UseIncludeRegExp ? false : true;
  356. }
  357. if(arg.find("-A",0) == 0 && i < args.size() - 1)
  358. {
  359. inst.m_DartMode = true;
  360. inst.SetTest("Notes");
  361. inst.Initialize();
  362. int ires = inst.GenerateNotesFile(args[i+1].c_str());
  363. inst.Finalize();
  364. return ires;
  365. }
  366. }
  367. // call process directory
  368. int res;
  369. if (inst.m_RunConfigurationScript)
  370. {
  371. res = inst.RunConfigurationScript();
  372. }
  373. else
  374. {
  375. inst.Initialize();
  376. res = inst.ProcessTests();
  377. inst.Finalize();
  378. }
  379. return res;
  380. }