ctest_test.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. ctest_test
  2. ----------
  3. Perform the :ref:`CTest Test Step` as a :ref:`Dashboard Client`.
  4. .. code-block:: cmake
  5. ctest_test([BUILD <build-dir>] [APPEND]
  6. [START <start-number>]
  7. [END <end-number>]
  8. [STRIDE <stride-number>]
  9. [EXCLUDE <exclude-regex>]
  10. [INCLUDE <include-regex>]
  11. [EXCLUDE_LABEL <label-exclude-regex>]
  12. [INCLUDE_LABEL <label-include-regex>]
  13. [EXCLUDE_FROM_FILE <filename>]
  14. [INCLUDE_FROM_FILE <filename>]
  15. [EXCLUDE_FIXTURE <regex>]
  16. [EXCLUDE_FIXTURE_SETUP <regex>]
  17. [EXCLUDE_FIXTURE_CLEANUP <regex>]
  18. [PARALLEL_LEVEL [<level>]]
  19. [RESOURCE_SPEC_FILE <file>]
  20. [TEST_LOAD <threshold>]
  21. [SCHEDULE_RANDOM <ON|OFF>]
  22. [STOP_ON_FAILURE]
  23. [STOP_TIME <time-of-day>]
  24. [RETURN_VALUE <result-var>]
  25. [CAPTURE_CMAKE_ERROR <result-var>]
  26. [REPEAT <mode>:<n>]
  27. [OUTPUT_JUNIT <file>]
  28. [QUIET]
  29. )
  30. ..
  31. NOTE If updating the argument list here, please also update the argument
  32. list documentation for :command:`ctest_memcheck` as well.
  33. Run tests in the project build tree and store results in
  34. ``Test.xml`` for submission with the :command:`ctest_submit` command.
  35. The options are:
  36. ``BUILD <build-dir>``
  37. Specify the top-level build directory. If not given, the
  38. :variable:`CTEST_BINARY_DIRECTORY` variable is used.
  39. ``APPEND``
  40. Mark ``Test.xml`` for append to results previously submitted to a
  41. dashboard server since the last :command:`ctest_start` call.
  42. Append semantics are defined by the dashboard server in use.
  43. This does *not* cause results to be appended to a ``.xml`` file
  44. produced by a previous call to this command.
  45. ``START <start-number>``
  46. Specify the beginning of a range of test numbers.
  47. ``END <end-number>``
  48. Specify the end of a range of test numbers.
  49. ``STRIDE <stride-number>``
  50. Specify the stride by which to step across a range of test numbers.
  51. ``EXCLUDE <exclude-regex>``
  52. Specify a regular expression matching test names to exclude.
  53. ``INCLUDE <include-regex>``
  54. Specify a regular expression matching test names to include.
  55. Tests not matching this expression are excluded.
  56. ``EXCLUDE_LABEL <label-exclude-regex>``
  57. Specify a regular expression matching test labels to exclude.
  58. ``INCLUDE_LABEL <label-include-regex>``
  59. Specify a regular expression matching test labels to include.
  60. Tests not matching this expression are excluded.
  61. ``EXCLUDE_FROM_FILE <filename>``
  62. .. versionadded:: 3.29
  63. Do NOT run tests listed with their exact name in the given file.
  64. ``INCLUDE_FROM_FILE <filename>``
  65. .. versionadded:: 3.29
  66. Only run the tests listed with their exact name in the given file.
  67. ``EXCLUDE_FIXTURE <regex>``
  68. .. versionadded:: 3.7
  69. If a test in the set of tests to be executed requires a particular fixture,
  70. that fixture's setup and cleanup tests would normally be added to the test
  71. set automatically. This option prevents adding setup or cleanup tests for
  72. fixtures matching the ``<regex>``. Note that all other fixture behavior is
  73. retained, including test dependencies and skipping tests that have fixture
  74. setup tests that fail.
  75. ``EXCLUDE_FIXTURE_SETUP <regex>``
  76. .. versionadded:: 3.7
  77. Same as ``EXCLUDE_FIXTURE`` except only matching setup tests are excluded.
  78. ``EXCLUDE_FIXTURE_CLEANUP <regex>``
  79. .. versionadded:: 3.7
  80. Same as ``EXCLUDE_FIXTURE`` except only matching cleanup tests are excluded.
  81. ``PARALLEL_LEVEL [<level>]``
  82. Run tests in parallel, limited to a given level of parallelism.
  83. .. versionadded:: 3.29
  84. The ``<level>`` may be omitted, or ``0``, to let ctest use a default
  85. level of parallelism, or unbounded parallelism, respectively, as
  86. documented by the :option:`ctest --parallel` option.
  87. ``RESOURCE_SPEC_FILE <file>``
  88. .. versionadded:: 3.16
  89. Specify a
  90. :ref:`resource specification file <ctest-resource-specification-file>`. See
  91. :ref:`ctest-resource-allocation` for more information.
  92. ``TEST_LOAD <threshold>``
  93. .. versionadded:: 3.4
  94. While running tests in parallel, try not to start tests when they
  95. may cause the CPU load to pass above a given threshold. If not
  96. specified the :variable:`CTEST_TEST_LOAD` variable will be checked,
  97. and then the :option:`--test-load <ctest --test-load>` command-line
  98. argument to :manual:`ctest(1)`. See also the ``TestLoad`` setting
  99. in the :ref:`CTest Test Step`.
  100. ``REPEAT <mode>:<n>``
  101. .. versionadded:: 3.17
  102. Run tests repeatedly based on the given ``<mode>`` up to ``<n>`` times.
  103. The modes are:
  104. ``UNTIL_FAIL``
  105. Require each test to run ``<n>`` times without failing in order to pass.
  106. This is useful in finding sporadic failures in test cases.
  107. ``UNTIL_PASS``
  108. Allow each test to run up to ``<n>`` times in order to pass.
  109. Repeats tests if they fail for any reason.
  110. This is useful in tolerating sporadic failures in test cases.
  111. ``AFTER_TIMEOUT``
  112. Allow each test to run up to ``<n>`` times in order to pass.
  113. Repeats tests only if they timeout.
  114. This is useful in tolerating sporadic timeouts in test cases
  115. on busy machines.
  116. ``SCHEDULE_RANDOM <ON|OFF>``
  117. Launch tests in a random order. This may be useful for detecting
  118. implicit test dependencies.
  119. ``STOP_ON_FAILURE``
  120. .. versionadded:: 3.18
  121. Stop the execution of the tests once one has failed.
  122. ``STOP_TIME <time-of-day>``
  123. Specify a time of day at which the tests should all stop running.
  124. ``RETURN_VALUE <result-var>``
  125. Store in the ``<result-var>`` variable ``0`` if all tests passed.
  126. Store non-zero if anything went wrong.
  127. ``CAPTURE_CMAKE_ERROR <result-var>``
  128. .. versionadded:: 3.7
  129. Store in the ``<result-var>`` variable -1 if there are any errors running
  130. the command and prevent ctest from returning non-zero if an error occurs.
  131. ``OUTPUT_JUNIT <file>``
  132. .. versionadded:: 3.21
  133. Write test results to ``<file>`` in JUnit XML format. If ``<file>`` is a
  134. relative path, it will be placed in the build directory. If ``<file>``
  135. already exists, it will be overwritten. Note that the resulting JUnit XML
  136. file is **not** uploaded to CDash because it would be redundant with
  137. CTest's ``Test.xml`` file.
  138. ``QUIET``
  139. .. versionadded:: 3.3
  140. Suppress any CTest-specific non-error messages that would have otherwise
  141. been printed to the console. Output from the underlying test command is not
  142. affected. Summary info detailing the percentage of passing tests is also
  143. unaffected by the ``QUIET`` option.
  144. See also the :variable:`CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE`,
  145. :variable:`CTEST_CUSTOM_MAXIMUM_FAILED_TEST_OUTPUT_SIZE` and
  146. :variable:`CTEST_CUSTOM_TEST_OUTPUT_TRUNCATION` variables, along with their
  147. corresponding :manual:`ctest(1)` command line options
  148. :option:`--test-output-size-passed <ctest --test-output-size-passed>`,
  149. :option:`--test-output-size-failed <ctest --test-output-size-failed>`, and
  150. :option:`--test-output-truncation <ctest --test-output-truncation>`.
  151. .. _`Additional Test Measurements`:
  152. Additional Test Measurements
  153. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  154. CTest can parse the output of your tests for extra measurements to report
  155. to CDash.
  156. When run as a :ref:`Dashboard Client`, CTest will include these custom
  157. measurements in the ``Test.xml`` file that gets uploaded to CDash.
  158. Check the `CDash test measurement documentation
  159. <https://github.com/Kitware/CDash/blob/master/docs/test_measurements.md>`_
  160. for more information on the types of test measurements that CDash recognizes.
  161. .. versionadded: 3.22
  162. CTest can parse custom measurements from tags named
  163. ``<CTestMeasurement>`` or ``<CTestMeasurementFile>``. The older names
  164. ``<DartMeasurement>`` and ``<DartMeasurementFile>`` are still supported.
  165. The following example demonstrates how to output a variety of custom test
  166. measurements.
  167. .. code-block:: c++
  168. std::cout <<
  169. "<CTestMeasurement type=\"numeric/double\" name=\"score\">28.3</CTestMeasurement>"
  170. << std::endl;
  171. std::cout <<
  172. "<CTestMeasurement type=\"text/string\" name=\"color\">red</CTestMeasurement>"
  173. << std::endl;
  174. std::cout <<
  175. "<CTestMeasurement type=\"text/link\" name=\"CMake URL\">https://cmake.org</CTestMeasurement>"
  176. << std::endl;
  177. std::cout <<
  178. "<CTestMeasurement type=\"text/preformatted\" name=\"Console Output\">" <<
  179. "line 1.\n" <<
  180. " \033[31;1m line 2. Bold red, and indented!\033[0;0ml\n" <<
  181. "line 3. Not bold or indented...\n" <<
  182. "</CTestMeasurement>" << std::endl;
  183. Image Measurements
  184. """"""""""""""""""
  185. The following example demonstrates how to upload test images to CDash.
  186. .. code-block:: c++
  187. std::cout <<
  188. "<CTestMeasurementFile type=\"image/jpg\" name=\"TestImage\">" <<
  189. "/dir/to/test_img.jpg</CTestMeasurementFile>" << std::endl;
  190. std::cout <<
  191. "<CTestMeasurementFile type=\"image/gif\" name=\"ValidImage\">" <<
  192. "/dir/to/valid_img.gif</CTestMeasurementFile>" << std::endl;
  193. std::cout <<
  194. "<CTestMeasurementFile type=\"image/png\" name=\"AlgoResult\">" <<
  195. "/dir/to/img.png</CTestMeasurementFile>"
  196. << std::endl;
  197. Images will be displayed together in an interactive comparison mode on CDash
  198. if they are provided with two or more of the following names.
  199. * ``TestImage``
  200. * ``ValidImage``
  201. * ``BaselineImage``
  202. * ``DifferenceImage2``
  203. By convention, ``TestImage`` is the image generated by your test, and
  204. ``ValidImage`` (or ``BaselineImage``) is basis of comparison used to determine
  205. if the test passed or failed.
  206. If another image name is used it will be displayed by CDash as a static image
  207. separate from the interactive comparison UI.
  208. Attached Files
  209. """"""""""""""
  210. .. versionadded:: 3.21
  211. The following example demonstrates how to upload non-image files to CDash.
  212. .. code-block:: c++
  213. std::cout <<
  214. "<CTestMeasurementFile type=\"file\" name=\"TestInputData1\">" <<
  215. "/dir/to/data1.csv</CTestMeasurementFile>\n" <<
  216. "<CTestMeasurementFile type=\"file\" name=\"TestInputData2\">" <<
  217. "/dir/to/data2.csv</CTestMeasurementFile>" << std::endl;
  218. If the name of the file to upload is known at configure time, you can use the
  219. :prop_test:`ATTACHED_FILES` or :prop_test:`ATTACHED_FILES_ON_FAIL` test
  220. properties instead.
  221. Custom Details
  222. """"""""""""""
  223. .. versionadded:: 3.21
  224. The following example demonstrates how to specify a custom value for the
  225. ``Test Details`` field displayed on CDash.
  226. .. code-block:: c++
  227. std::cout <<
  228. "<CTestDetails>My Custom Details Value</CTestDetails>" << std::endl;
  229. .. _`Additional Labels`:
  230. Additional Labels
  231. """""""""""""""""
  232. .. versionadded:: 3.22
  233. The following example demonstrates how to add additional labels to a test
  234. at runtime.
  235. .. code-block:: c++
  236. std::cout <<
  237. "<CTestLabel>Custom Label 1</CTestLabel>\n" <<
  238. "<CTestLabel>Custom Label 2</CTestLabel>" << std::endl;
  239. Use the :prop_test:`LABELS` test property instead for labels that can be
  240. determined at configure time.