ctest_test.rst 10 KB

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