ctest.cxx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 useful "
  57. "for debugging dashboard problems."},
  58. {"-Q,--quiet", "Make ctest quiet.",
  59. "This option will suppress all the output. The output log file will still be "
  60. "generated if the --output-log is specified. Options such as --verbose, "
  61. "--extra-verbose, and --debug are ignored if --quiet is specified."},
  62. {"-O <file>, --output-log <file>", "Output to log file",
  63. "This option tells ctest to write all its output to a log file."},
  64. {"-N,--show-only", "Disable actual execution of tests.",
  65. "This option tells ctest to list the tests that would be run but not "
  66. "actually run them. Useful in conjunction with the -R and -E options."},
  67. {"-R <regex>, --tests-regex <regex>", "Run tests matching regular expression.",
  68. "This option tells ctest to run only the tests whose names match the "
  69. "given regular expression."},
  70. {"-E <regex>, --exclude-regex <regex>", "Exclude tests matching regular expression.",
  71. "This option tells ctest to NOT run the tests whose names match the "
  72. "given regular expression."},
  73. {"-D <dashboard>, --dashboard <dashboard>", "Execute dashboard test",
  74. "This option tells ctest to perform act as a Dart client and perform "
  75. "a dashboard test. All tests are <Mode><Test>, where Mode can be Experimental, "
  76. "Nightly, and Continuous, and Test can be Start, Update, Configure, "
  77. "Build, Test, Coverage, and Submit."},
  78. {"-M <model>, --test-model <model>", "Sets the model for a dashboard",
  79. "This option tells ctest to act as a Dart client "
  80. "where the TestModel can be Experimental, "
  81. "Nightly, and Continuous. Combining -M and -T is similar to -D"},
  82. {"-T <action>, --test-action <action>", "Sets the dashboard action to perform",
  83. "This option tells ctest to act as a Dart client "
  84. "and perform some action such as start, build, test etc. "
  85. "Combining -M and -T is similar to -D"},
  86. {"-S <script>, --script <script>", "Execute a dashboard for a configuration",
  87. "This option tells ctest to load in a configuration script which sets "
  88. "a number of parameters such as the binary and source directories. Then "
  89. "ctest will do what is required to create and run a dashboard. This "
  90. "option basically sets up a dashboard and then runs ctest -D with the "
  91. "appropriate options."},
  92. {"-A <file>, --add-notes <file>", "Add a notes file with submission",
  93. "This option tells ctest to include a notes file when submitting dashboard. "},
  94. {"-I [Start,End,Stride,test#,test#|Test file], --tests-information",
  95. "Run a specific number of tests by number.",
  96. "This option causes ctest to run tests starting at number Start, ending "
  97. "at number End, and incrementing by Stride. Any additional numbers after "
  98. "Stride are considered individual test numbers. Start, End,or stride "
  99. "can be empty. Optionally a file can be given that contains the same "
  100. "syntax as the command line."},
  101. {"-U, --union", "Take the Union of -I and -R",
  102. "When both -R and -I are specified by default the intersection of "
  103. "tests are run. By specifying -U the union of tests is run instead."},
  104. {"--interactive-debug-mode [0|1]", "Set the interactive mode to 0 or 1.",
  105. "This option causes ctest to run tests in either an interactive mode or "
  106. "a non-interactive mode. On Windows this means that in non-interactive "
  107. "mode, all system debug pop up windows are blocked. In dashboard mode "
  108. "(Experimental, Nightly, Continuous), the default is non-interactive. "
  109. "When just running tests not for a dashboard the default is to allow "
  110. "popups and interactive "
  111. "debugging."},
  112. {"--build-and-test", "Configure, build and run a test.",
  113. "This option tells ctest to configure (i.e. run cmake on), build, and or "
  114. "execute a test. The configure and test steps are optional. The arguments "
  115. "to this command line are the source and binary directories. By default "
  116. "this will run CMake on the Source/Bin directories specified unless "
  117. "--build-nocmake is specified. Both --build-makeprogram and "
  118. "--build-generator MUST be provided to use --built-and-test. If "
  119. "--test-command is specified then that will be run after the build is "
  120. "complete. Other options that affect this mode are --build-target "
  121. "--build-nocmake, --build-run-dir, "
  122. "--build-two-config, --build-exe-dir, --build-project,"
  123. "--build-noclean, --build-options"},
  124. {"--build-target", "Specify a specific target to build.",
  125. "This option goes with the --build-and-test option, if left out the all target is built." },
  126. {"--build-nocmake", "Run the build without running cmake first.",
  127. "Skip the cmake step." },
  128. {"--build-run-dir", "Specify directory to run programs from.",
  129. "Directory where programs will be after it has been compiled." },
  130. {"--build-two-config", "Run CMake twice", "" },
  131. {"--build-exe-dir", "Specify the directory for the executable.", "" },
  132. {"--build-generator", "Specify the generator to use.", "" },
  133. {"--build-project", "Specify the name of the project to build.", "" },
  134. {"--build-makeprogram", "Specify the make program to use.", "" },
  135. {"--build-noclean", "Skip the make clean step.", "" },
  136. {"--build-options", "Add extra options to the build step.",
  137. "This option must be the last option with the exception of --test-command" },
  138. {"--test-command", "The test to run with the --build-and-test option.", "" },
  139. {"--tomorrow-tag", "Nightly or experimental starts with next day tag.",
  140. "This is useful if the build will not finish in one day." },
  141. {"--ctest-config", "The configuration file used to initialize CTest state when submitting dashboards.",
  142. "This option tells CTest to use different initialization file instead of "
  143. "DartConfiguration.tcl. This way multiple initialization files can be used "
  144. "for example to submit to multiple dashboards." },
  145. {"--overwrite", "Overwrite CTest configuration option.",
  146. "By default ctest uses configuration options from configuration file. "
  147. "This option will overwrite the configuration option." },
  148. {"--extra-submit <file>[;<file>]", "Submit extra files to the dashboard.",
  149. "This option will submit extra files to the dashboard." },
  150. {"--force-new-ctest-process", "Run child CTest instances as new processes",
  151. "By default CTest will run child CTest instances within the same process. "
  152. "If this behavior is not desired, this argument will enforce new processes "
  153. "for child CTest processes." },
  154. {"--submit-index", "Submit individual dashboard tests with specific index",
  155. "This option allows performing the same CTest action (such as test) multiple "
  156. "times and submit all stages to the same dashboard (Dart2 required). "
  157. "Each execution requires different index." },
  158. {0,0,0}
  159. };
  160. //----------------------------------------------------------------------------
  161. static const cmDocumentationEntry cmDocumentationSeeAlso[] =
  162. {
  163. {0, "cmake", 0},
  164. {0, "ccmake", 0},
  165. {0, 0, 0}
  166. };
  167. // this is a test driver program for cmCTest.
  168. int main (int argc, char *argv[])
  169. {
  170. cmSystemTools::EnableMSVCDebugHook();
  171. int nocwd = 0;
  172. cmCTest inst;
  173. if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 )
  174. {
  175. cmCTestLog(&inst, ERROR_MESSAGE, "Current working directory cannot be established." << std::endl);
  176. nocwd = 1;
  177. }
  178. // If there is a testing input file, check for documentation options
  179. // only if there are actually arguments. We want running without
  180. // arguments to run tests.
  181. if(argc > 1 || !cmSystemTools::FileExists("DartTestfile.txt") &&
  182. !cmSystemTools::FileExists("CTestTestfile.cmake"))
  183. {
  184. if(argc == 1)
  185. {
  186. cmCTestLog(&inst, ERROR_MESSAGE, "*********************************" << std::endl
  187. << "No test configuration file found!" << std::endl
  188. << "*********************************" << std::endl);
  189. }
  190. cmDocumentation doc;
  191. if(doc.CheckOptions(argc, argv) || nocwd)
  192. {
  193. // Construct and print requested documentation.
  194. doc.SetName("ctest");
  195. doc.SetNameSection(cmDocumentationName);
  196. doc.SetUsageSection(cmDocumentationUsage);
  197. doc.SetDescriptionSection(cmDocumentationDescription);
  198. doc.SetOptionsSection(cmDocumentationOptions);
  199. doc.SetSeeAlsoList(cmDocumentationSeeAlso);
  200. #ifdef cout
  201. # undef cout
  202. #endif
  203. return doc.PrintRequestedDocumentation(std::cout)? 0:1;
  204. #define cout no_cout_use_cmCTestLog
  205. }
  206. }
  207. #ifdef _WIN32
  208. std::string comspec = "cmw9xcom.exe";
  209. cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
  210. #endif
  211. // copy the args to a vector
  212. std::vector<std::string> args;
  213. for(int i =0; i < argc; ++i)
  214. {
  215. args.push_back(argv[i]);
  216. }
  217. // run ctest
  218. std::string output;
  219. int res = inst.Run(args,&output);
  220. cmCTestLog(&inst, OUTPUT, output);
  221. cmListFileCache::ClearCache();
  222. return res;
  223. }