ctest.cxx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCTest.h"
  14. #include "cmSystemTools.h"
  15. // Need these for documentation support.
  16. #include "cmake.h"
  17. #include "cmDocumentation.h"
  18. //----------------------------------------------------------------------------
  19. static const cmDocumentationEntry cmDocumentationName[] =
  20. {
  21. {0,
  22. " ctest - Testing driver provided by CMake.", 0},
  23. {0,0,0}
  24. };
  25. //----------------------------------------------------------------------------
  26. static const cmDocumentationEntry cmDocumentationUsage[] =
  27. {
  28. {0,
  29. " ctest [options]", 0},
  30. {0,0,0}
  31. };
  32. //----------------------------------------------------------------------------
  33. static const cmDocumentationEntry cmDocumentationDescription[] =
  34. {
  35. {0,
  36. "The \"ctest\" executable is the CMake test driver program. "
  37. "CMake-generated build trees created for projects that use "
  38. "the ENABLE_TESTING and ADD_TEST commands have testing support. "
  39. "This program will run the tests and report results.", 0},
  40. {0,0,0}
  41. };
  42. //----------------------------------------------------------------------------
  43. static const cmDocumentationEntry cmDocumentationOptions[] =
  44. {
  45. {"-C <cfg>, --build-config <cfg>", "Choose configuration to test.",
  46. "Some CMake-generated build trees can have multiple build configurations "
  47. "in the same tree. This option can be used to specify which one should "
  48. "be tested. Example configurations are \"Debug\" and \"Release\"."},
  49. {"-V,--verbose", "Enable verbose output from tests.",
  50. "Test output is normally suppressed and only summary information is "
  51. "displayed. This option will show all test output."},
  52. {"-VV,--extra-verbose", "Enable more verbose output from tests.",
  53. "Test output is normally suppressed and only summary information is "
  54. "displayed. This option will show even more test output."},
  55. {"--debug", "Displaying more verbose internals of CTest.",
  56. "This feature will result in large number of output that is mostly "
  57. "useful for debugging dashboard problems."},
  58. {"-Q,--quiet", "Make ctest quiet.",
  59. "This option will suppress all the output. The output log file will "
  60. "still be generated if the --output-log is specified. Options such "
  61. "as --verbose, --extra-verbose, and --debug are ignored if --quiet is "
  62. "specified."},
  63. {"-O <file>, --output-log <file>", "Output to log file",
  64. "This option tells ctest to write all its output to a log file."},
  65. {"-N,--show-only", "Disable actual execution of tests.",
  66. "This option tells ctest to list the tests that would be run but not "
  67. "actually run them. Useful in conjunction with the -R and -E options."},
  68. {"-R <regex>, --tests-regex <regex>", "Run tests matching regular "
  69. "expression.",
  70. "This option tells ctest to run only the tests whose names match the "
  71. "given regular expression."},
  72. {"-E <regex>, --exclude-regex <regex>", "Exclude tests matching regular "
  73. "expression.",
  74. "This option tells ctest to NOT run the tests whose names match the "
  75. "given regular expression."},
  76. {"-D <dashboard>, --dashboard <dashboard>", "Execute dashboard test",
  77. "This option tells ctest to perform act as a Dart client and perform "
  78. "a dashboard test. All tests are <Mode><Test>, where Mode can be "
  79. "Experimental, Nightly, and Continuous, and Test can be Start, Update, "
  80. "Configure, Build, Test, Coverage, and Submit."},
  81. {"-M <model>, --test-model <model>", "Sets the model for a dashboard",
  82. "This option tells ctest to act as a Dart client "
  83. "where the TestModel can be Experimental, "
  84. "Nightly, and Continuous. Combining -M and -T is similar to -D"},
  85. {"-T <action>, --test-action <action>", "Sets the dashboard action to "
  86. "perform",
  87. "This option tells ctest to act as a Dart client "
  88. "and perform some action such as start, build, test etc. "
  89. "Combining -M and -T is similar to -D"},
  90. {"--track <track>", "Specify the track to submit dashboard to",
  91. "Submit dashboard to specified track instead of default one. By "
  92. "default, the dashboard is submitted to Nightly, Experimental, or "
  93. "Continuous track, but by specifying this option, the track can be "
  94. "arbitrary."},
  95. {"-S <script>, --script <script>", "Execute a dashboard for a "
  96. "configuration",
  97. "This option tells ctest to load in a configuration script which sets "
  98. "a number of parameters such as the binary and source directories. Then "
  99. "ctest will do what is required to create and run a dashboard. This "
  100. "option basically sets up a dashboard and then runs ctest -D with the "
  101. "appropriate options."},
  102. {"-SP <script>, --script-new-process <script>", "Execute a dashboard for a "
  103. "configuration",
  104. "This option does the same operations as -S but it will do them in a "
  105. "seperate process. This is primarily useful in cases where the script "
  106. "may modify the environment and you do not want the modified enviroment "
  107. "to impact other -S scripts."},
  108. {"-A <file>, --add-notes <file>", "Add a notes file with submission",
  109. "This option tells ctest to include a notes file when submitting "
  110. "dashboard. "},
  111. {"-I [Start,End,Stride,test#,test#|Test file], --tests-information",
  112. "Run a specific number of tests by number.",
  113. "This option causes ctest to run tests starting at number Start, ending "
  114. "at number End, and incrementing by Stride. Any additional numbers after "
  115. "Stride are considered individual test numbers. Start, End,or stride "
  116. "can be empty. Optionally a file can be given that contains the same "
  117. "syntax as the command line."},
  118. {"-U, --union", "Take the Union of -I and -R",
  119. "When both -R and -I are specified by default the intersection of "
  120. "tests are run. By specifying -U the union of tests is run instead."},
  121. {"--interactive-debug-mode [0|1]", "Set the interactive mode to 0 or 1.",
  122. "This option causes ctest to run tests in either an interactive mode or "
  123. "a non-interactive mode. On Windows this means that in non-interactive "
  124. "mode, all system debug pop up windows are blocked. In dashboard mode "
  125. "(Experimental, Nightly, Continuous), the default is non-interactive. "
  126. "When just running tests not for a dashboard the default is to allow "
  127. "popups and interactive "
  128. "debugging."},
  129. {"--build-and-test", "Configure, build and run a test.",
  130. "This option tells ctest to configure (i.e. run cmake on), build, and or "
  131. "execute a test. The configure and test steps are optional. The arguments "
  132. "to this command line are the source and binary directories. By default "
  133. "this will run CMake on the Source/Bin directories specified unless "
  134. "--build-nocmake is specified. Both --build-makeprogram and "
  135. "--build-generator MUST be provided to use --built-and-test. If "
  136. "--test-command is specified then that will be run after the build is "
  137. "complete. Other options that affect this mode are --build-target "
  138. "--build-nocmake, --build-run-dir, "
  139. "--build-two-config, --build-exe-dir, --build-project,"
  140. "--build-noclean, --build-options"},
  141. {"--build-target", "Specify a specific target to build.",
  142. "This option goes with the --build-and-test option, if left out the all "
  143. "target is built." },
  144. {"--build-nocmake", "Run the build without running cmake first.",
  145. "Skip the cmake step." },
  146. {"--build-run-dir", "Specify directory to run programs from.",
  147. "Directory where programs will be after it has been compiled." },
  148. {"--build-two-config", "Run CMake twice", "" },
  149. {"--build-exe-dir", "Specify the directory for the executable.", "" },
  150. {"--build-generator", "Specify the generator to use.", "" },
  151. {"--build-project", "Specify the name of the project to build.", "" },
  152. {"--build-makeprogram", "Specify the make program to use.", "" },
  153. {"--build-noclean", "Skip the make clean step.", "" },
  154. {"--build-options", "Add extra options to the build step.",
  155. "This option must be the last option with the exception of --test-command"
  156. },
  157. {"--test-command", "The test to run with the --build-and-test option.", ""
  158. },
  159. {"--tomorrow-tag", "Nightly or experimental starts with next day tag.",
  160. "This is useful if the build will not finish in one day." },
  161. {"--ctest-config", "The configuration file used to initialize CTest state "
  162. "when submitting dashboards.",
  163. "This option tells CTest to use different initialization file instead of "
  164. "DartConfiguration.tcl. This way multiple initialization files can be "
  165. "used for example to submit to multiple dashboards." },
  166. {"--overwrite", "Overwrite CTest configuration option.",
  167. "By default ctest uses configuration options from configuration file. "
  168. "This option will overwrite the configuration option." },
  169. {"--extra-submit <file>[;<file>]", "Submit extra files to the dashboard.",
  170. "This option will submit extra files to the dashboard." },
  171. {"--force-new-ctest-process", "Run child CTest instances as new processes",
  172. "By default CTest will run child CTest instances within the same process. "
  173. "If this behavior is not desired, this argument will enforce new "
  174. "processes for child CTest processes." },
  175. {"--submit-index", "Submit individual dashboard tests with specific index",
  176. "This option allows performing the same CTest action (such as test) "
  177. "multiple times and submit all stages to the same dashboard (Dart2 "
  178. "required). Each execution requires different index." },
  179. {0,0,0}
  180. };
  181. //----------------------------------------------------------------------------
  182. static const cmDocumentationEntry cmDocumentationSeeAlso[] =
  183. {
  184. {0, "cmake", 0},
  185. {0, "ccmake", 0},
  186. {0, 0, 0}
  187. };
  188. // this is a test driver program for cmCTest.
  189. int main (int argc, char *argv[])
  190. {
  191. cmSystemTools::EnableMSVCDebugHook();
  192. int nocwd = 0;
  193. cmCTest inst;
  194. if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 )
  195. {
  196. cmCTestLog(&inst, ERROR_MESSAGE,
  197. "Current working directory cannot be established." << std::endl);
  198. nocwd = 1;
  199. }
  200. // If there is a testing input file, check for documentation options
  201. // only if there are actually arguments. We want running without
  202. // arguments to run tests.
  203. if(argc > 1 || !cmSystemTools::FileExists("DartTestfile.txt") &&
  204. !cmSystemTools::FileExists("CTestTestfile.cmake"))
  205. {
  206. if(argc == 1)
  207. {
  208. cmCTestLog(&inst, ERROR_MESSAGE, "*********************************"
  209. << std::endl
  210. << "No test configuration file found!" << std::endl
  211. << "*********************************" << std::endl);
  212. }
  213. cmDocumentation doc;
  214. if(doc.CheckOptions(argc, argv) || nocwd)
  215. {
  216. // Construct and print requested documentation.
  217. doc.SetName("ctest");
  218. doc.SetNameSection(cmDocumentationName);
  219. doc.SetUsageSection(cmDocumentationUsage);
  220. doc.SetDescriptionSection(cmDocumentationDescription);
  221. doc.SetOptionsSection(cmDocumentationOptions);
  222. doc.SetSeeAlsoList(cmDocumentationSeeAlso);
  223. #ifdef cout
  224. # undef cout
  225. #endif
  226. return doc.PrintRequestedDocumentation(std::cout)? 0:1;
  227. #define cout no_cout_use_cmCTestLog
  228. }
  229. }
  230. #ifdef _WIN32
  231. std::string comspec = "cmw9xcom.exe";
  232. cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
  233. #endif
  234. // copy the args to a vector
  235. std::vector<std::string> args;
  236. for(int i =0; i < argc; ++i)
  237. {
  238. args.push_back(argv[i]);
  239. }
  240. // run ctest
  241. std::string output;
  242. int res = inst.Run(args,&output);
  243. cmCTestLog(&inst, OUTPUT, output);
  244. return res;
  245. }