ctest.cxx 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include <cstring>
  4. #include <iostream>
  5. #include <string>
  6. #include <vector>
  7. #include "cmsys/Encoding.hxx"
  8. #include "cmCTest.h"
  9. #include "cmConsoleBuf.h"
  10. #include "cmDocumentation.h"
  11. #include "cmDocumentationEntry.h"
  12. #include "cmSystemTools.h"
  13. #include "CTest/cmCTestLaunch.h"
  14. namespace {
  15. const cmDocumentationEntry cmDocumentationName = {
  16. {},
  17. " ctest - Testing driver provided by CMake."
  18. };
  19. const cmDocumentationEntry cmDocumentationUsage = { {}, " ctest [options]" };
  20. const cmDocumentationEntry cmDocumentationOptions[] = {
  21. { "--preset <preset>, --preset=<preset>",
  22. "Read arguments from a test preset." },
  23. { "--list-presets", "List available test presets." },
  24. { "-C <cfg>, --build-config <cfg>", "Choose configuration to test." },
  25. { "--progress", "Enable short progress output from tests." },
  26. { "-V,--verbose", "Enable verbose output from tests." },
  27. { "-VV,--extra-verbose", "Enable more verbose output from tests." },
  28. { "--debug", "Displaying more verbose internals of CTest." },
  29. { "--output-on-failure",
  30. "Output anything outputted by the test program "
  31. "if the test should fail." },
  32. { "--stop-on-failure", "Stop running the tests after one has failed." },
  33. { "--test-output-size-passed <size>",
  34. "Limit the output for passed tests "
  35. "to <size> bytes" },
  36. { "--test-output-size-failed <size>",
  37. "Limit the output for failed tests "
  38. "to <size> bytes" },
  39. { "--test-output-truncation <mode>",
  40. "Truncate 'tail' (default), 'middle' or 'head' of test output once "
  41. "maximum output size is reached" },
  42. { "-F", "Enable failover." },
  43. { "-j [<level>], --parallel [<level>]",
  44. "Run tests in parallel, "
  45. "optionally limited to a given level of parallelism." },
  46. { "-Q,--quiet", "Make ctest quiet." },
  47. { "-O <file>, --output-log <file>", "Output to log file" },
  48. { "--output-junit <file>", "Output test results to JUnit XML file." },
  49. { "-N,--show-only[=format]",
  50. "Disable actual execution of tests. The optional 'format' defines the "
  51. "format of the test information and can be 'human' for the current text "
  52. "format or 'json-v1' for json format. Defaults to 'human'." },
  53. { "-L <regex>, --label-regex <regex>",
  54. "Run tests with labels matching regular expression. "
  55. "With multiple -L, run tests where each "
  56. "regular expression matches at least one label." },
  57. { "-R <regex>, --tests-regex <regex>",
  58. "Run tests matching regular "
  59. "expression." },
  60. { "-E <regex>, --exclude-regex <regex>",
  61. "Exclude tests matching regular "
  62. "expression." },
  63. { "-LE <regex>, --label-exclude <regex>",
  64. "Exclude tests with labels matching regular expression. "
  65. "With multiple -LE, exclude tests where each "
  66. "regular expression matches at least one label." },
  67. { "-FA <regex>, --fixture-exclude-any <regex>",
  68. "Do not automatically "
  69. "add any tests for "
  70. "fixtures matching "
  71. "regular expression." },
  72. { "-FS <regex>, --fixture-exclude-setup <regex>",
  73. "Do not automatically "
  74. "add setup tests for "
  75. "fixtures matching "
  76. "regular expression." },
  77. { "-FC <regex>, --fixture-exclude-cleanup <regex>",
  78. "Do not automatically "
  79. "add cleanup tests for "
  80. "fixtures matching "
  81. "regular expression." },
  82. { "-D <dashboard>, --dashboard <dashboard>", "Execute dashboard test" },
  83. { "-D <var>:<type>=<value>", "Define a variable for script mode" },
  84. { "-M <model>, --test-model <model>", "Sets the model for a dashboard" },
  85. { "-T <action>, --test-action <action>",
  86. "Sets the dashboard action to "
  87. "perform" },
  88. { "--group <group>",
  89. "Specify what build group on the dashboard you'd like to "
  90. "submit results to." },
  91. { "-S <script>, --script <script>",
  92. "Execute a dashboard for a "
  93. "configuration" },
  94. { "-SP <script>, --script-new-process <script>",
  95. "Execute a dashboard for a "
  96. "configuration" },
  97. { "-A <file>, --add-notes <file>", "Add a notes file with submission" },
  98. { "-I [Start,End,Stride,test#,test#|Test file], --tests-information",
  99. "Run a specific number of tests by number." },
  100. { "-U, --union", "Take the Union of -I and -R" },
  101. { "--rerun-failed", "Run only the tests that failed previously" },
  102. { "--tests-from-file <file>", "Run the tests listed in the given file" },
  103. { "--exclude-from-file <file>",
  104. "Run tests except those listed in the given file" },
  105. { "--repeat until-fail:<n>, --repeat-until-fail <n>",
  106. "Require each test to run <n> times without failing in order to pass" },
  107. { "--repeat until-pass:<n>",
  108. "Allow each test to run up to <n> times in order to pass" },
  109. { "--repeat after-timeout:<n>",
  110. "Allow each test to run up to <n> times if it times out" },
  111. { "--max-width <width>", "Set the max width for a test name to output" },
  112. { "--interactive-debug-mode [0|1]", "Set the interactive mode to 0 or 1." },
  113. { "--resource-spec-file <file>", "Set the resource spec file to use." },
  114. { "--no-label-summary", "Disable timing summary information for labels." },
  115. { "--no-subproject-summary",
  116. "Disable timing summary information for "
  117. "subprojects." },
  118. { "--test-dir <dir>", "Specify the directory in which to look for tests." },
  119. { "--build-and-test", "Configure, build and run a test." },
  120. { "--build-target", "Specify a specific target to build." },
  121. { "--build-nocmake", "Run the build without running cmake first." },
  122. { "--build-run-dir", "Specify directory to run programs from." },
  123. { "--build-two-config", "Run CMake twice" },
  124. { "--build-exe-dir", "Specify the directory for the executable." },
  125. { "--build-generator", "Specify the generator to use." },
  126. { "--build-generator-platform", "Specify the generator-specific platform." },
  127. { "--build-generator-toolset", "Specify the generator-specific toolset." },
  128. { "--build-project", "Specify the name of the project to build." },
  129. { "--build-makeprogram", "Specify the make program to use." },
  130. { "--build-noclean", "Skip the make clean step." },
  131. { "--build-config-sample",
  132. "A sample executable to use to determine the configuration" },
  133. { "--build-options", "Add extra options to the build step." },
  134. { "--test-command", "The test to run with the --build-and-test option." },
  135. { "--test-timeout", "The time limit in seconds, internal use only." },
  136. { "--test-load", "CPU load threshold for starting new parallel tests." },
  137. { "--tomorrow-tag", "Nightly or experimental starts with next day tag." },
  138. { "--overwrite", "Overwrite CTest configuration option." },
  139. { "--extra-submit <file>[;<file>]", "Submit extra files to the dashboard." },
  140. { "--http-header <header>", "Append HTTP header when submitting" },
  141. { "--schedule-random", "Use a random order for scheduling tests" },
  142. { "--submit-index",
  143. "Submit individual dashboard tests with specific index" },
  144. { "--timeout <seconds>", "Set the default test timeout." },
  145. { "--stop-time <time>",
  146. "Set a time at which all tests should stop running." },
  147. { "--http1.0", "Submit using HTTP 1.0." },
  148. { "--no-compress-output", "Do not compress test output when submitting." },
  149. { "--print-labels", "Print all available test labels." },
  150. { "--no-tests=<[error|ignore]>",
  151. "Regard no tests found either as 'error' or 'ignore' it." }
  152. };
  153. } // anonymous namespace
  154. // this is a test driver program for cmCTest.
  155. int main(int argc, char const* const* argv)
  156. {
  157. cmSystemTools::EnsureStdPipes();
  158. // Replace streambuf so we can output Unicode to console
  159. cmConsoleBuf consoleBuf;
  160. consoleBuf.SetUTF8Pipes();
  161. cmsys::Encoding::CommandLineArguments encoding_args =
  162. cmsys::Encoding::CommandLineArguments::Main(argc, argv);
  163. argc = encoding_args.argc();
  164. argv = encoding_args.argv();
  165. cmSystemTools::InitializeLibUV();
  166. cmSystemTools::FindCMakeResources(argv[0]);
  167. // Dispatch 'ctest --launch' mode directly.
  168. if (argc >= 2 && strcmp(argv[1], "--launch") == 0) {
  169. return cmCTestLaunch::Main(argc, argv);
  170. }
  171. if (cmSystemTools::GetLogicalWorkingDirectory().empty()) {
  172. std::cerr << "Current working directory cannot be established.\n";
  173. return 1;
  174. }
  175. // If there is a testing input file, check for documentation options
  176. // only if there are actually arguments. We want running without
  177. // arguments to run tests.
  178. if (argc > 1 ||
  179. !(cmSystemTools::FileExists("CTestTestfile.cmake") ||
  180. cmSystemTools::FileExists("DartTestfile.txt"))) {
  181. if (argc == 1) {
  182. std::cerr << "*********************************\n"
  183. "No test configuration file found!\n"
  184. "*********************************\n";
  185. }
  186. cmDocumentation doc;
  187. doc.addCTestStandardDocSections();
  188. if (doc.CheckOptions(argc, argv)) {
  189. doc.SetShowGenerators(false);
  190. doc.SetName("ctest");
  191. doc.SetSection("Name", cmDocumentationName);
  192. doc.SetSection("Usage", cmDocumentationUsage);
  193. doc.PrependSection("Options", cmDocumentationOptions);
  194. return !doc.PrintRequestedDocumentation(std::cout);
  195. }
  196. }
  197. // copy the args to a vector
  198. auto args = std::vector<std::string>(argv, argv + argc);
  199. // run ctest
  200. return cmCTest{}.Run(args);
  201. }