ctest.cxx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. {"--max-width <width>", "Set the max width for a test name to output"},
  72. {"--interactive-debug-mode [0|1]", "Set the interactive mode to 0 or 1."},
  73. {"--no-label-summary", "Disable timing summary information for labels."},
  74. {"--build-and-test", "Configure, build and run a test."},
  75. {"--build-target", "Specify a specific target to build."},
  76. {"--build-nocmake", "Run the build without running cmake first."},
  77. {"--build-run-dir", "Specify directory to run programs from."},
  78. {"--build-two-config", "Run CMake twice"},
  79. {"--build-exe-dir", "Specify the directory for the executable."},
  80. {"--build-generator", "Specify the generator to use."},
  81. {"--build-generator-toolset", "Specify the generator-specific toolset."},
  82. {"--build-project", "Specify the name of the project to build."},
  83. {"--build-makeprogram", "Specify the make program to use."},
  84. {"--build-noclean", "Skip the make clean step."},
  85. {"--build-config-sample",
  86. "A sample executable to use to determine the configuration"},
  87. {"--build-options", "Add extra options to the build step."},
  88. {"--test-command", "The test to run with the --build-and-test option."},
  89. {"--test-timeout", "The time limit in seconds, internal use only."},
  90. {"--tomorrow-tag", "Nightly or experimental starts with next day tag."},
  91. {"--ctest-config", "The configuration file used to initialize CTest state "
  92. "when submitting dashboards."},
  93. {"--overwrite", "Overwrite CTest configuration option."},
  94. {"--extra-submit <file>[;<file>]", "Submit extra files to the dashboard."},
  95. {"--force-new-ctest-process", "Run child CTest instances as new processes"},
  96. {"--schedule-random", "Use a random order for scheduling tests"},
  97. {"--submit-index", "Submit individual dashboard tests with specific index"},
  98. {"--timeout <seconds>", "Set a global timeout on all tests."},
  99. {"--stop-time <time>",
  100. "Set a time at which all tests should stop running."},
  101. {"--http1.0", "Submit using HTTP 1.0."},
  102. {"--no-compress-output", "Do not compress test output when submitting."},
  103. {"--print-labels", "Print all available test labels."},
  104. {0,0}
  105. };
  106. // this is a test driver program for cmCTest.
  107. int main (int argc, char const* const* argv)
  108. {
  109. cmsys::Encoding::CommandLineArguments encoding_args =
  110. cmsys::Encoding::CommandLineArguments::Main(argc, argv);
  111. argc = encoding_args.argc();
  112. argv = encoding_args.argv();
  113. cmSystemTools::DoNotInheritStdPipes();
  114. cmSystemTools::EnableMSVCDebugHook();
  115. cmSystemTools::FindCMakeResources(argv[0]);
  116. // Dispatch 'ctest --launch' mode directly.
  117. if(argc >= 2 && strcmp(argv[1], "--launch") == 0)
  118. {
  119. return cmCTestLaunch::Main(argc, argv);
  120. }
  121. cmCTest inst;
  122. if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 )
  123. {
  124. cmCTestLog(&inst, ERROR_MESSAGE,
  125. "Current working directory cannot be established." << std::endl);
  126. return 1;
  127. }
  128. // If there is a testing input file, check for documentation options
  129. // only if there are actually arguments. We want running without
  130. // arguments to run tests.
  131. if(argc > 1 || !(cmSystemTools::FileExists("CTestTestfile.cmake") ||
  132. cmSystemTools::FileExists("DartTestfile.txt")))
  133. {
  134. if(argc == 1)
  135. {
  136. cmCTestLog(&inst, ERROR_MESSAGE, "*********************************"
  137. << std::endl
  138. << "No test configuration file found!" << std::endl
  139. << "*********************************" << std::endl);
  140. }
  141. cmDocumentation doc;
  142. doc.addCTestStandardDocSections();
  143. if(doc.CheckOptions(argc, argv))
  144. {
  145. cmake hcm;
  146. hcm.AddCMakePaths();
  147. // Construct and print requested documentation.
  148. cmCTestScriptHandler* ch =
  149. static_cast<cmCTestScriptHandler*>(inst.GetHandler("script"));
  150. ch->CreateCMake();
  151. doc.SetShowGenerators(false);
  152. doc.SetName("ctest");
  153. doc.SetSection("Name",cmDocumentationName);
  154. doc.SetSection("Usage",cmDocumentationUsage);
  155. doc.PrependSection("Options",cmDocumentationOptions);
  156. #ifdef cout
  157. # undef cout
  158. #endif
  159. return doc.PrintRequestedDocumentation(std::cout)? 0:1;
  160. #define cout no_cout_use_cmCTestLog
  161. }
  162. }
  163. // copy the args to a vector
  164. std::vector<std::string> args;
  165. for(int i =0; i < argc; ++i)
  166. {
  167. args.push_back(argv[i]);
  168. }
  169. // run ctest
  170. std::string output;
  171. int res = inst.Run(args,&output);
  172. cmCTestLog(&inst, OUTPUT, output);
  173. return res;
  174. }