ctest.cxx 13 KB

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