ctest_test.rst 9.5 KB

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