ctest.cxx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. {"-Q,--quiet", "Make ctest quiet.",
  64. "This option will suppress all the output. The output log file will "
  65. "still be generated if the --output-log is specified. Options such "
  66. "as --verbose, --extra-verbose, and --debug are ignored if --quiet is "
  67. "specified."},
  68. {"-O <file>, --output-log <file>", "Output to log file",
  69. "This option tells ctest to write all its output to a log file."},
  70. {"-N,--show-only", "Disable actual execution of tests.",
  71. "This option tells ctest to list the tests that would be run but not "
  72. "actually run them. Useful in conjunction with the -R and -E options."},
  73. {"-L <regex>, --label-regex <regex>", "Run tests with labels matching "
  74. "regular expression.",
  75. "This option tells ctest to run only the tests whose labels match the "
  76. "given regular expression."},
  77. {"-R <regex>, --tests-regex <regex>", "Run tests matching regular "
  78. "expression.",
  79. "This option tells ctest to run only the tests whose names match the "
  80. "given regular expression."},
  81. {"-E <regex>, --exclude-regex <regex>", "Exclude tests matching regular "
  82. "expression.",
  83. "This option tells ctest to NOT run the tests whose names match the "
  84. "given regular expression."},
  85. {"-LE <regex>, --label-exclude <regex>", "Exclude tests with labels "
  86. "matching regular expression.",
  87. "This option tells ctest to NOT run the tests whose labels match the "
  88. "given regular expression."},
  89. {"-D <dashboard>, --dashboard <dashboard>", "Execute dashboard test",
  90. "This option tells ctest to perform act as a Dart client and perform "
  91. "a dashboard test. All tests are <Mode><Test>, where Mode can be "
  92. "Experimental, Nightly, and Continuous, and Test can be Start, Update, "
  93. "Configure, Build, Test, Coverage, and Submit."},
  94. {"-M <model>, --test-model <model>", "Sets the model for a dashboard",
  95. "This option tells ctest to act as a Dart client "
  96. "where the TestModel can be Experimental, "
  97. "Nightly, and Continuous. Combining -M and -T is similar to -D"},
  98. {"-T <action>, --test-action <action>", "Sets the dashboard action to "
  99. "perform",
  100. "This option tells ctest to act as a Dart client "
  101. "and perform some action such as start, build, test etc. "
  102. "Combining -M and -T is similar to -D"},
  103. {"--track <track>", "Specify the track to submit dashboard to",
  104. "Submit dashboard to specified track instead of default one. By "
  105. "default, the dashboard is submitted to Nightly, Experimental, or "
  106. "Continuous track, but by specifying this option, the track can be "
  107. "arbitrary."},
  108. {"-S <script>, --script <script>", "Execute a dashboard for a "
  109. "configuration",
  110. "This option tells ctest to load in a configuration script which sets "
  111. "a number of parameters such as the binary and source directories. Then "
  112. "ctest will do what is required to create and run a dashboard. This "
  113. "option basically sets up a dashboard and then runs ctest -D with the "
  114. "appropriate options."},
  115. {"-SP <script>, --script-new-process <script>", "Execute a dashboard for a "
  116. "configuration",
  117. "This option does the same operations as -S but it will do them in a "
  118. "seperate process. This is primarily useful in cases where the script "
  119. "may modify the environment and you do not want the modified enviroment "
  120. "to impact other -S scripts."},
  121. {"-A <file>, --add-notes <file>", "Add a notes file with submission",
  122. "This option tells ctest to include a notes file when submitting "
  123. "dashboard. "},
  124. {"-I [Start,End,Stride,test#,test#|Test file], --tests-information",
  125. "Run a specific number of tests by number.",
  126. "This option causes ctest to run tests starting at number Start, ending "
  127. "at number End, and incrementing by Stride. Any additional numbers after "
  128. "Stride are considered individual test numbers. Start, End,or stride "
  129. "can be empty. Optionally a file can be given that contains the same "
  130. "syntax as the command line."},
  131. {"-U, --union", "Take the Union of -I and -R",
  132. "When both -R and -I are specified by default the intersection of "
  133. "tests are run. By specifying -U the union of tests is run instead."},
  134. {"--max-width <width>", "Set the max width for a test name to output",
  135. "Set the maximum width for each test name to show in the output. This "
  136. "allows the user to widen the output to avoid cliping the test name which "
  137. "can be very annoying."},
  138. {"--interactive-debug-mode [0|1]", "Set the interactive mode to 0 or 1.",
  139. "This option causes ctest to run tests in either an interactive mode or "
  140. "a non-interactive mode. On Windows this means that in non-interactive "
  141. "mode, all system debug pop up windows are blocked. In dashboard mode "
  142. "(Experimental, Nightly, Continuous), the default is non-interactive. "
  143. "When just running tests not for a dashboard the default is to allow "
  144. "popups and interactive "
  145. "debugging."},
  146. {"--no-label-summary", "Disable timing summary information for labels.",
  147. "This option tells ctest to not print summary information for each label "
  148. "associated with the tests run. If there are no labels on the "
  149. "tests, nothing extra is printed."},
  150. {"--build-and-test", "Configure, build and run a test.",
  151. "This option tells ctest to configure (i.e. run cmake on), build, and or "
  152. "execute a test. The configure and test steps are optional. The arguments "
  153. "to this command line are the source and binary directories. By default "
  154. "this will run CMake on the Source/Bin directories specified unless "
  155. "--build-nocmake is specified. Both --build-makeprogram and "
  156. "--build-generator MUST be provided to use --built-and-test. If "
  157. "--test-command is specified then that will be run after the build is "
  158. "complete. Other options that affect this mode are --build-target "
  159. "--build-nocmake, --build-run-dir, "
  160. "--build-two-config, --build-exe-dir, --build-project,"
  161. "--build-noclean, --build-options"},
  162. {"--build-target", "Specify a specific target to build.",
  163. "This option goes with the --build-and-test option, if left out the all "
  164. "target is built." },
  165. {"--build-nocmake", "Run the build without running cmake first.",
  166. "Skip the cmake step." },
  167. {"--build-run-dir", "Specify directory to run programs from.",
  168. "Directory where programs will be after it has been compiled." },
  169. {"--build-two-config", "Run CMake twice", "" },
  170. {"--build-exe-dir", "Specify the directory for the executable.", "" },
  171. {"--build-generator", "Specify the generator to use.", "" },
  172. {"--build-project", "Specify the name of the project to build.", "" },
  173. {"--build-makeprogram", "Specify the make program to use.", "" },
  174. {"--build-noclean", "Skip the make clean step.", "" },
  175. {"--build-config-sample",
  176. "A sample executable to use to determine the configuraiton",
  177. "A sample executable to use to determine the configuraiton that "
  178. "should be used. e.g. Debug/Release/etc" },
  179. {"--build-options", "Add extra options to the build step.",
  180. "This option must be the last option with the exception of --test-command"
  181. },
  182. {"--test-command", "The test to run with the --build-and-test option.", ""
  183. },
  184. {"--test-timeout", "The time limit in seconds, internal use only.", ""
  185. },
  186. {"--tomorrow-tag", "Nightly or experimental starts with next day tag.",
  187. "This is useful if the build will not finish in one day." },
  188. {"--ctest-config", "The configuration file used to initialize CTest state "
  189. "when submitting dashboards.",
  190. "This option tells CTest to use different initialization file instead of "
  191. "CTestConfiguration.tcl. This way multiple initialization files can be "
  192. "used for example to submit to multiple dashboards." },
  193. {"--overwrite", "Overwrite CTest configuration option.",
  194. "By default ctest uses configuration options from configuration file. "
  195. "This option will overwrite the configuration option." },
  196. {"--extra-submit <file>[;<file>]", "Submit extra files to the dashboard.",
  197. "This option will submit extra files to the dashboard." },
  198. {"--force-new-ctest-process", "Run child CTest instances as new processes",
  199. "By default CTest will run child CTest instances within the same process. "
  200. "If this behavior is not desired, this argument will enforce new "
  201. "processes for child CTest processes." },
  202. {"--submit-index", "Submit individual dashboard tests with specific index",
  203. "This option allows performing the same CTest action (such as test) "
  204. "multiple times and submit all stages to the same dashboard (Dart2 "
  205. "required). Each execution requires different index." },
  206. {0,0,0}
  207. };
  208. //----------------------------------------------------------------------------
  209. static const char * cmDocumentationSeeAlso[][3] =
  210. {
  211. {0, "cmake", 0},
  212. {0, "ccmake", 0},
  213. {0, 0, 0}
  214. };
  215. // this is a test driver program for cmCTest.
  216. int main (int argc, char *argv[])
  217. {
  218. cmSystemTools::DoNotInheritStdPipes();
  219. cmSystemTools::EnableMSVCDebugHook();
  220. cmSystemTools::FindExecutableDirectory(argv[0]);
  221. // Dispatch 'ctest --launch' mode directly.
  222. if(argc >= 2 && strcmp(argv[1], "--launch") == 0)
  223. {
  224. return cmCTestLaunch::Main(argc, argv);
  225. }
  226. int nocwd = 0;
  227. cmCTest inst;
  228. if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 )
  229. {
  230. cmCTestLog(&inst, ERROR_MESSAGE,
  231. "Current working directory cannot be established." << std::endl);
  232. nocwd = 1;
  233. }
  234. // If there is a testing input file, check for documentation options
  235. // only if there are actually arguments. We want running without
  236. // arguments to run tests.
  237. if(argc > 1 || !(cmSystemTools::FileExists("CTestTestfile.cmake") ||
  238. cmSystemTools::FileExists("DartTestfile.txt")))
  239. {
  240. if(argc == 1)
  241. {
  242. cmCTestLog(&inst, ERROR_MESSAGE, "*********************************"
  243. << std::endl
  244. << "No test configuration file found!" << std::endl
  245. << "*********************************" << std::endl);
  246. }
  247. cmDocumentation doc;
  248. if(doc.CheckOptions(argc, argv) || nocwd)
  249. {
  250. // Construct and print requested documentation.
  251. std::vector<cmDocumentationEntry> commands;
  252. cmCTestScriptHandler* ch =
  253. static_cast<cmCTestScriptHandler*>(inst.GetHandler("script"));
  254. ch->CreateCMake();
  255. ch->GetCommandDocumentation(commands);
  256. doc.SetName("ctest");
  257. doc.SetSection("Name",cmDocumentationName);
  258. doc.SetSection("Usage",cmDocumentationUsage);
  259. doc.SetSection("Description",cmDocumentationDescription);
  260. doc.SetSection("Options",cmDocumentationOptions);
  261. doc.SetSection("Commands",commands);
  262. doc.SetSeeAlsoList(cmDocumentationSeeAlso);
  263. #ifdef cout
  264. # undef cout
  265. #endif
  266. return doc.PrintRequestedDocumentation(std::cout)? 0:1;
  267. #define cout no_cout_use_cmCTestLog
  268. }
  269. }
  270. #ifdef _WIN32
  271. std::string comspec = "cmw9xcom.exe";
  272. cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
  273. #endif
  274. // copy the args to a vector
  275. std::vector<std::string> args;
  276. for(int i =0; i < argc; ++i)
  277. {
  278. args.push_back(argv[i]);
  279. }
  280. // run ctest
  281. std::string output;
  282. int res = inst.Run(args,&output);
  283. cmCTestLog(&inst, OUTPUT, output);
  284. return res;
  285. }