ctest.cxx 7.5 KB

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