ctest.cxx 9.0 KB

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