ctest.cxx 7.7 KB

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