ctest.cxx 9.3 KB

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