ctest.cxx 12 KB

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