ctest.cxx 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 "cmsys/Encoding.hxx"
  4. #include "cmCTest.h"
  5. #include "cmDocumentation.h"
  6. #include "cmSystemTools.h"
  7. #include "CTest/cmCTestLaunch.h"
  8. #include "CTest/cmCTestScriptHandler.h"
  9. #if defined(_WIN32) && !defined(CMAKE_BOOTSTRAP)
  10. # include "cmsys/ConsoleBuf.hxx"
  11. #endif
  12. #include <cstring>
  13. #include <iostream>
  14. #include <string>
  15. #include <vector>
  16. static const char* cmDocumentationName[][2] = {
  17. { nullptr, " ctest - Testing driver provided by CMake." },
  18. { nullptr, nullptr }
  19. };
  20. static const char* cmDocumentationUsage[][2] = { { nullptr,
  21. " ctest [options]" },
  22. { nullptr, nullptr } };
  23. static const char* cmDocumentationOptions[][2] = {
  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. { "--test-output-size-passed <size>",
  33. "Limit the output for passed tests "
  34. "to <size> bytes" },
  35. { "--test-output-size-failed <size>",
  36. "Limit the output for failed tests "
  37. "to <size> bytes" },
  38. { "-F", "Enable failover." },
  39. { "-j <jobs>, --parallel <jobs>",
  40. "Run the tests in parallel using the "
  41. "given number of jobs." },
  42. { "-Q,--quiet", "Make ctest quiet." },
  43. { "-O <file>, --output-log <file>", "Output to log file" },
  44. { "-N,--show-only[=format]",
  45. "Disable actual execution of tests. The optional 'format' defines the "
  46. "format of the test information and can be 'human' for the current text "
  47. "format or 'json-v1' for json format. Defaults to 'human'." },
  48. { "-L <regex>, --label-regex <regex>",
  49. "Run tests with labels matching "
  50. "regular expression." },
  51. { "-R <regex>, --tests-regex <regex>",
  52. "Run tests matching regular "
  53. "expression." },
  54. { "-E <regex>, --exclude-regex <regex>",
  55. "Exclude tests matching regular "
  56. "expression." },
  57. { "-LE <regex>, --label-exclude <regex>",
  58. "Exclude tests with labels "
  59. "matching regular expression." },
  60. { "-FA <regex>, --fixture-exclude-any <regex>",
  61. "Do not automatically "
  62. "add any tests for "
  63. "fixtures matching "
  64. "regular expression." },
  65. { "-FS <regex>, --fixture-exclude-setup <regex>",
  66. "Do not automatically "
  67. "add setup tests for "
  68. "fixtures matching "
  69. "regular expression." },
  70. { "-FC <regex>, --fixture-exclude-cleanup <regex>",
  71. "Do not automatically "
  72. "add cleanup tests for "
  73. "fixtures matching "
  74. "regular expression." },
  75. { "-D <dashboard>, --dashboard <dashboard>", "Execute dashboard test" },
  76. { "-D <var>:<type>=<value>", "Define a variable for script mode" },
  77. { "-M <model>, --test-model <model>", "Sets the model for a dashboard" },
  78. { "-T <action>, --test-action <action>",
  79. "Sets the dashboard action to "
  80. "perform" },
  81. { "--group <group>",
  82. "Specify what build group on the dashboard you'd like to "
  83. "submit results to." },
  84. { "-S <script>, --script <script>",
  85. "Execute a dashboard for a "
  86. "configuration" },
  87. { "-SP <script>, --script-new-process <script>",
  88. "Execute a dashboard for a "
  89. "configuration" },
  90. { "-A <file>, --add-notes <file>", "Add a notes file with submission" },
  91. { "-I [Start,End,Stride,test#,test#|Test file], --tests-information",
  92. "Run a specific number of tests by number." },
  93. { "-U, --union", "Take the Union of -I and -R" },
  94. { "--rerun-failed", "Run only the tests that failed previously" },
  95. { "--repeat-until-fail <n>",
  96. "Require each test to run <n> "
  97. "times without failing in order to pass" },
  98. { "--max-width <width>", "Set the max width for a test name to output" },
  99. { "--interactive-debug-mode [0|1]", "Set the interactive mode to 0 or 1." },
  100. { "--resource-spec-file <file>", "Set the resource spec file to use." },
  101. { "--no-label-summary", "Disable timing summary information for labels." },
  102. { "--no-subproject-summary",
  103. "Disable timing summary information for "
  104. "subprojects." },
  105. { "--build-and-test", "Configure, build and run a test." },
  106. { "--build-target", "Specify a specific target to build." },
  107. { "--build-nocmake", "Run the build without running cmake first." },
  108. { "--build-run-dir", "Specify directory to run programs from." },
  109. { "--build-two-config", "Run CMake twice" },
  110. { "--build-exe-dir", "Specify the directory for the executable." },
  111. { "--build-generator", "Specify the generator to use." },
  112. { "--build-generator-platform", "Specify the generator-specific platform." },
  113. { "--build-generator-toolset", "Specify the generator-specific toolset." },
  114. { "--build-project", "Specify the name of the project to build." },
  115. { "--build-makeprogram", "Specify the make program to use." },
  116. { "--build-noclean", "Skip the make clean step." },
  117. { "--build-config-sample",
  118. "A sample executable to use to determine the configuration" },
  119. { "--build-options", "Add extra options to the build step." },
  120. { "--test-command", "The test to run with the --build-and-test option." },
  121. { "--test-timeout", "The time limit in seconds, internal use only." },
  122. { "--test-load", "CPU load threshold for starting new parallel tests." },
  123. { "--tomorrow-tag", "Nightly or experimental starts with next day tag." },
  124. { "--overwrite", "Overwrite CTest configuration option." },
  125. { "--extra-submit <file>[;<file>]", "Submit extra files to the dashboard." },
  126. { "--force-new-ctest-process",
  127. "Run child CTest instances as new processes" },
  128. { "--schedule-random", "Use a random order for scheduling tests" },
  129. { "--submit-index",
  130. "Submit individual dashboard tests with specific index" },
  131. { "--timeout <seconds>", "Set the default test timeout." },
  132. { "--stop-time <time>",
  133. "Set a time at which all tests should stop running." },
  134. { "--http1.0", "Submit using HTTP 1.0." },
  135. { "--no-compress-output", "Do not compress test output when submitting." },
  136. { "--print-labels", "Print all available test labels." },
  137. { nullptr, nullptr }
  138. };
  139. // this is a test driver program for cmCTest.
  140. int main(int argc, char const* const* argv)
  141. {
  142. cmSystemTools::EnsureStdPipes();
  143. #if defined(_WIN32) && !defined(CMAKE_BOOTSTRAP)
  144. // Replace streambuf so we can output Unicode to console
  145. cmsys::ConsoleBuf::Manager consoleOut(std::cout);
  146. consoleOut.SetUTF8Pipes();
  147. cmsys::ConsoleBuf::Manager consoleErr(std::cerr, true);
  148. consoleErr.SetUTF8Pipes();
  149. #endif
  150. cmsys::Encoding::CommandLineArguments encoding_args =
  151. cmsys::Encoding::CommandLineArguments::Main(argc, argv);
  152. argc = encoding_args.argc();
  153. argv = encoding_args.argv();
  154. cmSystemTools::DoNotInheritStdPipes();
  155. cmSystemTools::EnableMSVCDebugHook();
  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. }