ctest.cxx 12 KB

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