ctest.cxx 8.2 KB

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