ctest.cxx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  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. #include "cmCTest.h"
  11. #include "cmSystemTools.h"
  12. // Need these for documentation support.
  13. #include "cmake.h"
  14. #include "cmDocumentation.h"
  15. #include "CTest/cmCTestScriptHandler.h"
  16. #include "CTest/cmCTestLaunch.h"
  17. //----------------------------------------------------------------------------
  18. static const char * cmDocumentationName[][3] =
  19. {
  20. {0,
  21. " ctest - Testing driver provided by CMake.", 0},
  22. {0,0,0}
  23. };
  24. //----------------------------------------------------------------------------
  25. static const char * cmDocumentationUsage[][3] =
  26. {
  27. {0,
  28. " ctest [options]", 0},
  29. {0,0,0}
  30. };
  31. //----------------------------------------------------------------------------
  32. static const char * cmDocumentationDescription[][3] =
  33. {
  34. {0,
  35. "The \"ctest\" executable is the CMake test driver program. "
  36. "CMake-generated build trees created for projects that use "
  37. "the ENABLE_TESTING and ADD_TEST commands have testing support. "
  38. "This program will run the tests and report results.", 0},
  39. {0,0,0}
  40. };
  41. //----------------------------------------------------------------------------
  42. static const char * cmDocumentationOptions[][3] =
  43. {
  44. {"-C <cfg>, --build-config <cfg>", "Choose configuration to test.",
  45. "Some CMake-generated build trees can have multiple build configurations "
  46. "in the same tree. This option can be used to specify which one should "
  47. "be tested. Example configurations are \"Debug\" and \"Release\"."},
  48. {"-V,--verbose", "Enable verbose output from tests.",
  49. "Test output is normally suppressed and only summary information is "
  50. "displayed. This option will show all test output."},
  51. {"-VV,--extra-verbose", "Enable more verbose output from tests.",
  52. "Test output is normally suppressed and only summary information is "
  53. "displayed. This option will show even more test output."},
  54. {"--debug", "Displaying more verbose internals of CTest.",
  55. "This feature will result in large number of output that is mostly "
  56. "useful for debugging dashboard problems."},
  57. {"--output-on-failure", "Output anything outputted by the test program "
  58. "if the test should fail. This option can also be enabled by setting "
  59. "the environment variable CTEST_OUTPUT_ON_FAILURE"},
  60. {"-F", "Enable failover.", "This option allows ctest to resume a test "
  61. "set execution that was previously interrupted. If no interruption "
  62. "occurred, the -F option will have no effect."},
  63. {"-j <jobs>, --parallel <jobs>", "Run the tests in parallel using the"
  64. "given number of jobs.",
  65. "This option tells ctest to run the tests in parallel using given "
  66. "number of jobs."},
  67. {"-Q,--quiet", "Make ctest quiet.",
  68. "This option will suppress all the output. The output log file will "
  69. "still be generated if the --output-log is specified. Options such "
  70. "as --verbose, --extra-verbose, and --debug are ignored if --quiet is "
  71. "specified."},
  72. {"-O <file>, --output-log <file>", "Output to log file",
  73. "This option tells ctest to write all its output to a log file."},
  74. {"-N,--show-only", "Disable actual execution of tests.",
  75. "This option tells ctest to list the tests that would be run but not "
  76. "actually run them. Useful in conjunction with the -R and -E options."},
  77. {"-L <regex>, --label-regex <regex>", "Run tests with labels matching "
  78. "regular expression.",
  79. "This option tells ctest to run only the tests whose labels match the "
  80. "given regular expression."},
  81. {"-R <regex>, --tests-regex <regex>", "Run tests matching regular "
  82. "expression.",
  83. "This option tells ctest to run only the tests whose names match the "
  84. "given regular expression."},
  85. {"-E <regex>, --exclude-regex <regex>", "Exclude tests matching regular "
  86. "expression.",
  87. "This option tells ctest to NOT run the tests whose names match the "
  88. "given regular expression."},
  89. {"-LE <regex>, --label-exclude <regex>", "Exclude tests with labels "
  90. "matching regular expression.",
  91. "This option tells ctest to NOT run the tests whose labels match the "
  92. "given regular expression."},
  93. {"-D <dashboard>, --dashboard <dashboard>", "Execute dashboard test",
  94. "This option tells ctest to perform act as a Dart client and perform "
  95. "a dashboard test. All tests are <Mode><Test>, where Mode can be "
  96. "Experimental, Nightly, and Continuous, and Test can be Start, Update, "
  97. "Configure, Build, Test, Coverage, and Submit."},
  98. {"-D <var>:<type>=<value>", "Define a variable for script mode",
  99. "Pass in variable values on the command line. Use in "
  100. "conjunction with -S to pass variable values to a dashboard script. "
  101. "Parsing -D arguments as variable values is only attempted if "
  102. "the value following -D does not match any of the known dashboard "
  103. "types."},
  104. {"-M <model>, --test-model <model>", "Sets the model for a dashboard",
  105. "This option tells ctest to act as a Dart client "
  106. "where the TestModel can be Experimental, "
  107. "Nightly, and Continuous. Combining -M and -T is similar to -D"},
  108. {"-T <action>, --test-action <action>", "Sets the dashboard action to "
  109. "perform",
  110. "This option tells ctest to act as a Dart client "
  111. "and perform some action such as start, build, test etc. "
  112. "Combining -M and -T is similar to -D"},
  113. {"--track <track>", "Specify the track to submit dashboard to",
  114. "Submit dashboard to specified track instead of default one. By "
  115. "default, the dashboard is submitted to Nightly, Experimental, or "
  116. "Continuous track, but by specifying this option, the track can be "
  117. "arbitrary."},
  118. {"-S <script>, --script <script>", "Execute a dashboard for a "
  119. "configuration",
  120. "This option tells ctest to load in a configuration script which sets "
  121. "a number of parameters such as the binary and source directories. Then "
  122. "ctest will do what is required to create and run a dashboard. This "
  123. "option basically sets up a dashboard and then runs ctest -D with the "
  124. "appropriate options."},
  125. {"-SP <script>, --script-new-process <script>", "Execute a dashboard for a "
  126. "configuration",
  127. "This option does the same operations as -S but it will do them in a "
  128. "separate process. This is primarily useful in cases where the script "
  129. "may modify the environment and you do not want the modified environment "
  130. "to impact other -S scripts."},
  131. {"-A <file>, --add-notes <file>", "Add a notes file with submission",
  132. "This option tells ctest to include a notes file when submitting "
  133. "dashboard. "},
  134. {"-I [Start,End,Stride,test#,test#|Test file], --tests-information",
  135. "Run a specific number of tests by number.",
  136. "This option causes ctest to run tests starting at number Start, ending "
  137. "at number End, and incrementing by Stride. Any additional numbers after "
  138. "Stride are considered individual test numbers. Start, End,or stride "
  139. "can be empty. Optionally a file can be given that contains the same "
  140. "syntax as the command line."},
  141. {"-U, --union", "Take the Union of -I and -R",
  142. "When both -R and -I are specified by default the intersection of "
  143. "tests are run. By specifying -U the union of tests is run instead."},
  144. {"--max-width <width>", "Set the max width for a test name to output",
  145. "Set the maximum width for each test name to show in the output. This "
  146. "allows the user to widen the output to avoid clipping the test name which "
  147. "can be very annoying."},
  148. {"--interactive-debug-mode [0|1]", "Set the interactive mode to 0 or 1.",
  149. "This option causes ctest to run tests in either an interactive mode or "
  150. "a non-interactive mode. On Windows this means that in non-interactive "
  151. "mode, all system debug pop up windows are blocked. In dashboard mode "
  152. "(Experimental, Nightly, Continuous), the default is non-interactive. "
  153. "When just running tests not for a dashboard the default is to allow "
  154. "popups and interactive "
  155. "debugging."},
  156. {"--no-label-summary", "Disable timing summary information for labels.",
  157. "This option tells ctest not to print summary information for each label "
  158. "associated with the tests run. If there are no labels on the "
  159. "tests, nothing extra is printed."},
  160. {"--build-and-test", "Configure, build and run a test.",
  161. "This option tells ctest to configure (i.e. run cmake on), build, and or "
  162. "execute a test. The configure and test steps are optional. The arguments "
  163. "to this command line are the source and binary directories. By default "
  164. "this will run CMake on the Source/Bin directories specified unless "
  165. "--build-nocmake is specified. Both --build-makeprogram and "
  166. "--build-generator MUST be provided to use --built-and-test. If "
  167. "--test-command is specified then that will be run after the build is "
  168. "complete. Other options that affect this mode are --build-target "
  169. "--build-nocmake, --build-run-dir, "
  170. "--build-two-config, --build-exe-dir, --build-project,"
  171. "--build-noclean, --build-options"},
  172. {"--build-target", "Specify a specific target to build.",
  173. "This option goes with the --build-and-test option, if left out the all "
  174. "target is built." },
  175. {"--build-nocmake", "Run the build without running cmake first.",
  176. "Skip the cmake step." },
  177. {"--build-run-dir", "Specify directory to run programs from.",
  178. "Directory where programs will be after it has been compiled." },
  179. {"--build-two-config", "Run CMake twice", "" },
  180. {"--build-exe-dir", "Specify the directory for the executable.", "" },
  181. {"--build-generator", "Specify the generator to use.", "" },
  182. {"--build-generator-toolset", "Specify the generator-specific toolset.",""},
  183. {"--build-project", "Specify the name of the project to build.", "" },
  184. {"--build-makeprogram", "Specify the make program to use.", "" },
  185. {"--build-noclean", "Skip the make clean step.", "" },
  186. {"--build-config-sample",
  187. "A sample executable to use to determine the configuration",
  188. "A sample executable to use to determine the configuration that "
  189. "should be used. e.g. Debug/Release/etc" },
  190. {"--build-options", "Add extra options to the build step.",
  191. "This option must be the last option with the exception of --test-command"
  192. },
  193. {"--test-command", "The test to run with the --build-and-test option.", ""
  194. },
  195. {"--test-timeout", "The time limit in seconds, internal use only.", ""
  196. },
  197. {"--tomorrow-tag", "Nightly or experimental starts with next day tag.",
  198. "This is useful if the build will not finish in one day." },
  199. {"--ctest-config", "The configuration file used to initialize CTest state "
  200. "when submitting dashboards.",
  201. "This option tells CTest to use different initialization file instead of "
  202. "CTestConfiguration.tcl. This way multiple initialization files can be "
  203. "used for example to submit to multiple dashboards." },
  204. {"--overwrite", "Overwrite CTest configuration option.",
  205. "By default ctest uses configuration options from configuration file. "
  206. "This option will overwrite the configuration option." },
  207. {"--extra-submit <file>[;<file>]", "Submit extra files to the dashboard.",
  208. "This option will submit extra files to the dashboard." },
  209. {"--force-new-ctest-process", "Run child CTest instances as new processes",
  210. "By default CTest will run child CTest instances within the same process. "
  211. "If this behavior is not desired, this argument will enforce new "
  212. "processes for child CTest processes." },
  213. {"--schedule-random", "Use a random order for scheduling tests",
  214. "This option will run the tests in a random order. It is commonly used to "
  215. "detect implicit dependencies in a test suite." },
  216. {"--submit-index", "Submit individual dashboard tests with specific index",
  217. "This option allows performing the same CTest action (such as test) "
  218. "multiple times and submit all stages to the same dashboard (Dart2 "
  219. "required). Each execution requires different index." },
  220. {"--timeout <seconds>", "Set a global timeout on all tests.",
  221. "This option will set a global timeout on all tests that do not already "
  222. "have a timeout set on them."},
  223. {"--stop-time <time>", "Set a time at which all tests should stop running.",
  224. "Set a real time of day at which all tests should timeout. Example: "
  225. "7:00:00 -0400. Any time format understood by the curl date parser is "
  226. "accepted. Local time is assumed if no timezone is specified."},
  227. {"--http1.0", "Submit using HTTP 1.0.",
  228. "This option will force CTest to use HTTP 1.0 to submit files to the "
  229. "dashboard, instead of HTTP 1.1."},
  230. {"--no-compress-output", "Do not compress test output when submitting.",
  231. "This flag will turn off automatic compression of test output. Use this "
  232. "to maintain compatibility with an older version of CDash which doesn't "
  233. "support compressed test output."},
  234. {"--print-labels", "Print all available test labels.",
  235. "This option will not run any tests, it will simply print the list of "
  236. "all labels associated with the test set."},
  237. {"--help-command <cmd> [<file>]", "Show help for a single command and exit.",
  238. "Prints the help for the command to stdout or to the specified file." },
  239. {"--help-command-list [<file>]", "List available commands and exit.",
  240. "Prints the list of all available listfile commands to stdout or the "
  241. "specified file." },
  242. {"--help-commands [<file>]", "Print help for all commands and exit.",
  243. "Prints the help for all commands to stdout or to the specified file." },
  244. {0,0,0}
  245. };
  246. //----------------------------------------------------------------------------
  247. static const char * cmDocumentationSeeAlso[][3] =
  248. {
  249. {0, "cmake", 0},
  250. {0, "ccmake", 0},
  251. {0, 0, 0}
  252. };
  253. // this is a test driver program for cmCTest.
  254. int main (int argc, char *argv[])
  255. {
  256. cmSystemTools::DoNotInheritStdPipes();
  257. cmSystemTools::EnableMSVCDebugHook();
  258. cmSystemTools::FindExecutableDirectory(argv[0]);
  259. // Dispatch 'ctest --launch' mode directly.
  260. if(argc >= 2 && strcmp(argv[1], "--launch") == 0)
  261. {
  262. return cmCTestLaunch::Main(argc, argv);
  263. }
  264. int nocwd = 0;
  265. cmCTest inst;
  266. if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 )
  267. {
  268. cmCTestLog(&inst, ERROR_MESSAGE,
  269. "Current working directory cannot be established." << std::endl);
  270. nocwd = 1;
  271. }
  272. // If there is a testing input file, check for documentation options
  273. // only if there are actually arguments. We want running without
  274. // arguments to run tests.
  275. if(argc > 1 || !(cmSystemTools::FileExists("CTestTestfile.cmake") ||
  276. cmSystemTools::FileExists("DartTestfile.txt")))
  277. {
  278. if(argc == 1)
  279. {
  280. cmCTestLog(&inst, ERROR_MESSAGE, "*********************************"
  281. << std::endl
  282. << "No test configuration file found!" << std::endl
  283. << "*********************************" << std::endl);
  284. }
  285. cmDocumentation doc;
  286. doc.addCTestStandardDocSections();
  287. if(doc.CheckOptions(argc, argv) || nocwd)
  288. {
  289. // Construct and print requested documentation.
  290. std::vector<cmDocumentationEntry> commands;
  291. cmCTestScriptHandler* ch =
  292. static_cast<cmCTestScriptHandler*>(inst.GetHandler("script"));
  293. ch->CreateCMake();
  294. ch->GetCommandDocumentation(commands);
  295. doc.SetShowGenerators(false);
  296. doc.SetName("ctest");
  297. doc.SetSection("Name",cmDocumentationName);
  298. doc.SetSection("Usage",cmDocumentationUsage);
  299. doc.SetSection("Description",cmDocumentationDescription);
  300. doc.PrependSection("Options",cmDocumentationOptions);
  301. doc.SetSection("Commands",commands);
  302. doc.SetSeeAlsoList(cmDocumentationSeeAlso);
  303. #ifdef cout
  304. # undef cout
  305. #endif
  306. return doc.PrintRequestedDocumentation(std::cout)? 0:1;
  307. #define cout no_cout_use_cmCTestLog
  308. }
  309. }
  310. #ifdef _WIN32
  311. std::string comspec = "cmw9xcom.exe";
  312. cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
  313. #endif
  314. // copy the args to a vector
  315. std::vector<std::string> args;
  316. for(int i =0; i < argc; ++i)
  317. {
  318. args.push_back(argv[i]);
  319. }
  320. // run ctest
  321. std::string output;
  322. int res = inst.Run(args,&output);
  323. cmCTestLog(&inst, OUTPUT, output);
  324. return res;
  325. }