lit.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. lit - LLVM Integrated Tester
  2. ============================
  3. SYNOPSIS
  4. --------
  5. :program:`lit` [*options*] [*tests*]
  6. DESCRIPTION
  7. -----------
  8. :program:`lit` is a portable tool for executing LLVM and Clang style test
  9. suites, summarizing their results, and providing indication of failures.
  10. :program:`lit` is designed to be a lightweight testing tool with as simple a
  11. user interface as possible.
  12. :program:`lit` should be run with one or more *tests* to run specified on the
  13. command line. Tests can be either individual test files or directories to
  14. search for tests (see :ref:`test-discovery`).
  15. Each specified test will be executed (potentially in parallel) and once all
  16. tests have been run :program:`lit` will print summary information on the number
  17. of tests which passed or failed (see :ref:`test-status-results`). The
  18. :program:`lit` program will execute with a non-zero exit code if any tests
  19. fail.
  20. By default :program:`lit` will use a succinct progress display and will only
  21. print summary information for test failures. See :ref:`output-options` for
  22. options controlling the :program:`lit` progress display and output.
  23. :program:`lit` also includes a number of options for controlling how tests are
  24. executed (specific features may depend on the particular test format). See
  25. :ref:`execution-options` for more information.
  26. Finally, :program:`lit` also supports additional options for only running a
  27. subset of the options specified on the command line, see
  28. :ref:`selection-options` for more information.
  29. Users interested in the :program:`lit` architecture or designing a
  30. :program:`lit` testing implementation should see :ref:`lit-infrastructure`.
  31. GENERAL OPTIONS
  32. ---------------
  33. .. option:: -h, --help
  34. Show the :program:`lit` help message.
  35. .. option:: -j N, --threads=N
  36. Run ``N`` tests in parallel. By default, this is automatically chosen to
  37. match the number of detected available CPUs.
  38. .. option:: --config-prefix=NAME
  39. Search for :file:`{NAME}.cfg` and :file:`{NAME}.site.cfg` when searching for
  40. test suites, instead of :file:`lit.cfg` and :file:`lit.site.cfg`.
  41. .. option:: -D NAME, -D NAME=VALUE, --param NAME, --param NAME=VALUE
  42. Add a user defined parameter ``NAME`` with the given ``VALUE`` (or the empty
  43. string if not given). The meaning and use of these parameters is test suite
  44. dependent.
  45. .. _output-options:
  46. OUTPUT OPTIONS
  47. --------------
  48. .. option:: -q, --quiet
  49. Suppress any output except for test failures.
  50. .. option:: -s, --succinct
  51. Show less output, for example don't show information on tests that pass.
  52. .. option:: -v, --verbose
  53. Show more information on test failures, for example the entire test output
  54. instead of just the test result.
  55. .. option:: --no-progress-bar
  56. Do not use curses based progress bar.
  57. .. option:: --show-unsupported
  58. Show the names of unsupported tests.
  59. .. option:: --show-xfail
  60. Show the names of tests that were expected to fail.
  61. .. _execution-options:
  62. EXECUTION OPTIONS
  63. -----------------
  64. .. option:: --path=PATH
  65. Specify an additional ``PATH`` to use when searching for executables in tests.
  66. .. option:: --vg
  67. Run individual tests under valgrind (using the memcheck tool). The
  68. ``--error-exitcode`` argument for valgrind is used so that valgrind failures
  69. will cause the program to exit with a non-zero status.
  70. When this option is enabled, :program:`lit` will also automatically provide a
  71. "``valgrind``" feature that can be used to conditionally disable (or expect
  72. failure in) certain tests.
  73. .. option:: --vg-arg=ARG
  74. When :option:`--vg` is used, specify an additional argument to pass to
  75. :program:`valgrind` itself.
  76. .. option:: --vg-leak
  77. When :option:`--vg` is used, enable memory leak checks. When this option is
  78. enabled, :program:`lit` will also automatically provide a "``vg_leak``"
  79. feature that can be used to conditionally disable (or expect failure in)
  80. certain tests.
  81. .. option:: --time-tests
  82. Track the wall time individual tests take to execute and includes the results
  83. in the summary output. This is useful for determining which tests in a test
  84. suite take the most time to execute. Note that this option is most useful
  85. with ``-j 1``.
  86. .. _selection-options:
  87. SELECTION OPTIONS
  88. -----------------
  89. .. option:: --max-tests=N
  90. Run at most ``N`` tests and then terminate.
  91. .. option:: --max-time=N
  92. Spend at most ``N`` seconds (approximately) running tests and then terminate.
  93. .. option:: --shuffle
  94. Run the tests in a random order.
  95. ADDITIONAL OPTIONS
  96. ------------------
  97. .. option:: --debug
  98. Run :program:`lit` in debug mode, for debugging configuration issues and
  99. :program:`lit` itself.
  100. .. option:: --show-suites
  101. List the discovered test suites and exit.
  102. .. option:: --show-tests
  103. List all of the discovered tests and exit.
  104. EXIT STATUS
  105. -----------
  106. :program:`lit` will exit with an exit code of 1 if there are any FAIL or XPASS
  107. results. Otherwise, it will exit with the status 0. Other exit codes are used
  108. for non-test related failures (for example a user error or an internal program
  109. error).
  110. .. _test-discovery:
  111. TEST DISCOVERY
  112. --------------
  113. The inputs passed to :program:`lit` can be either individual tests, or entire
  114. directories or hierarchies of tests to run. When :program:`lit` starts up, the
  115. first thing it does is convert the inputs into a complete list of tests to run
  116. as part of *test discovery*.
  117. In the :program:`lit` model, every test must exist inside some *test suite*.
  118. :program:`lit` resolves the inputs specified on the command line to test suites
  119. by searching upwards from the input path until it finds a :file:`lit.cfg` or
  120. :file:`lit.site.cfg` file. These files serve as both a marker of test suites
  121. and as configuration files which :program:`lit` loads in order to understand
  122. how to find and run the tests inside the test suite.
  123. Once :program:`lit` has mapped the inputs into test suites it traverses the
  124. list of inputs adding tests for individual files and recursively searching for
  125. tests in directories.
  126. This behavior makes it easy to specify a subset of tests to run, while still
  127. allowing the test suite configuration to control exactly how tests are
  128. interpreted. In addition, :program:`lit` always identifies tests by the test
  129. suite they are in, and their relative path inside the test suite. For
  130. appropriately configured projects, this allows :program:`lit` to provide
  131. convenient and flexible support for out-of-tree builds.
  132. .. _test-status-results:
  133. TEST STATUS RESULTS
  134. -------------------
  135. Each test ultimately produces one of the following six results:
  136. **PASS**
  137. The test succeeded.
  138. **XFAIL**
  139. The test failed, but that is expected. This is used for test formats which allow
  140. specifying that a test does not currently work, but wish to leave it in the test
  141. suite.
  142. **XPASS**
  143. The test succeeded, but it was expected to fail. This is used for tests which
  144. were specified as expected to fail, but are now succeeding (generally because
  145. the feature they test was broken and has been fixed).
  146. **FAIL**
  147. The test failed.
  148. **UNRESOLVED**
  149. The test result could not be determined. For example, this occurs when the test
  150. could not be run, the test itself is invalid, or the test was interrupted.
  151. **UNSUPPORTED**
  152. The test is not supported in this environment. This is used by test formats
  153. which can report unsupported tests.
  154. Depending on the test format tests may produce additional information about
  155. their status (generally only for failures). See the :ref:`output-options`
  156. section for more information.
  157. .. _lit-infrastructure:
  158. LIT INFRASTRUCTURE
  159. ------------------
  160. This section describes the :program:`lit` testing architecture for users interested in
  161. creating a new :program:`lit` testing implementation, or extending an existing one.
  162. :program:`lit` proper is primarily an infrastructure for discovering and running
  163. arbitrary tests, and to expose a single convenient interface to these
  164. tests. :program:`lit` itself doesn't know how to run tests, rather this logic is
  165. defined by *test suites*.
  166. TEST SUITES
  167. ~~~~~~~~~~~
  168. As described in :ref:`test-discovery`, tests are always located inside a *test
  169. suite*. Test suites serve to define the format of the tests they contain, the
  170. logic for finding those tests, and any additional information to run the tests.
  171. :program:`lit` identifies test suites as directories containing ``lit.cfg`` or
  172. ``lit.site.cfg`` files (see also :option:`--config-prefix`). Test suites are
  173. initially discovered by recursively searching up the directory hierarchy for
  174. all the input files passed on the command line. You can use
  175. :option:`--show-suites` to display the discovered test suites at startup.
  176. Once a test suite is discovered, its config file is loaded. Config files
  177. themselves are Python modules which will be executed. When the config file is
  178. executed, two important global variables are predefined:
  179. **lit_config**
  180. The global **lit** configuration object (a *LitConfig* instance), which defines
  181. the builtin test formats, global configuration parameters, and other helper
  182. routines for implementing test configurations.
  183. **config**
  184. This is the config object (a *TestingConfig* instance) for the test suite,
  185. which the config file is expected to populate. The following variables are also
  186. available on the *config* object, some of which must be set by the config and
  187. others are optional or predefined:
  188. **name** *[required]* The name of the test suite, for use in reports and
  189. diagnostics.
  190. **test_format** *[required]* The test format object which will be used to
  191. discover and run tests in the test suite. Generally this will be a builtin test
  192. format available from the *lit.formats* module.
  193. **test_source_root** The filesystem path to the test suite root. For out-of-dir
  194. builds this is the directory that will be scanned for tests.
  195. **test_exec_root** For out-of-dir builds, the path to the test suite root inside
  196. the object directory. This is where tests will be run and temporary output files
  197. placed.
  198. **environment** A dictionary representing the environment to use when executing
  199. tests in the suite.
  200. **suffixes** For **lit** test formats which scan directories for tests, this
  201. variable is a list of suffixes to identify test files. Used by: *ShTest*.
  202. **substitutions** For **lit** test formats which substitute variables into a test
  203. script, the list of substitutions to perform. Used by: *ShTest*.
  204. **unsupported** Mark an unsupported directory, all tests within it will be
  205. reported as unsupported. Used by: *ShTest*.
  206. **parent** The parent configuration, this is the config object for the directory
  207. containing the test suite, or None.
  208. **root** The root configuration. This is the top-most :program:`lit` configuration in
  209. the project.
  210. **pipefail** Normally a test using a shell pipe fails if any of the commands
  211. on the pipe fail. If this is not desired, setting this variable to false
  212. makes the test fail only if the last command in the pipe fails.
  213. TEST DISCOVERY
  214. ~~~~~~~~~~~~~~
  215. Once test suites are located, :program:`lit` recursively traverses the source
  216. directory (following *test_source_root*) looking for tests. When :program:`lit`
  217. enters a sub-directory, it first checks to see if a nested test suite is
  218. defined in that directory. If so, it loads that test suite recursively,
  219. otherwise it instantiates a local test config for the directory (see
  220. :ref:`local-configuration-files`).
  221. Tests are identified by the test suite they are contained within, and the
  222. relative path inside that suite. Note that the relative path may not refer to
  223. an actual file on disk; some test formats (such as *GoogleTest*) define
  224. "virtual tests" which have a path that contains both the path to the actual
  225. test file and a subpath to identify the virtual test.
  226. .. _local-configuration-files:
  227. LOCAL CONFIGURATION FILES
  228. ~~~~~~~~~~~~~~~~~~~~~~~~~
  229. When :program:`lit` loads a subdirectory in a test suite, it instantiates a
  230. local test configuration by cloning the configuration for the parent directory
  231. --- the root of this configuration chain will always be a test suite. Once the
  232. test configuration is cloned :program:`lit` checks for a *lit.local.cfg* file
  233. in the subdirectory. If present, this file will be loaded and can be used to
  234. specialize the configuration for each individual directory. This facility can
  235. be used to define subdirectories of optional tests, or to change other
  236. configuration parameters --- for example, to change the test format, or the
  237. suffixes which identify test files.
  238. TEST RUN OUTPUT FORMAT
  239. ~~~~~~~~~~~~~~~~~~~~~~
  240. The :program:`lit` output for a test run conforms to the following schema, in
  241. both short and verbose modes (although in short mode no PASS lines will be
  242. shown). This schema has been chosen to be relatively easy to reliably parse by
  243. a machine (for example in buildbot log scraping), and for other tools to
  244. generate.
  245. Each test result is expected to appear on a line that matches:
  246. .. code-block:: none
  247. <result code>: <test name> (<progress info>)
  248. where ``<result-code>`` is a standard test result such as PASS, FAIL, XFAIL,
  249. XPASS, UNRESOLVED, or UNSUPPORTED. The performance result codes of IMPROVED and
  250. REGRESSED are also allowed.
  251. The ``<test name>`` field can consist of an arbitrary string containing no
  252. newline.
  253. The ``<progress info>`` field can be used to report progress information such
  254. as (1/300) or can be empty, but even when empty the parentheses are required.
  255. Each test result may include additional (multiline) log information in the
  256. following format:
  257. .. code-block:: none
  258. <log delineator> TEST '(<test name>)' <trailing delineator>
  259. ... log message ...
  260. <log delineator>
  261. where ``<test name>`` should be the name of a preceding reported test, ``<log
  262. delineator>`` is a string of "*" characters *at least* four characters long
  263. (the recommended length is 20), and ``<trailing delineator>`` is an arbitrary
  264. (unparsed) string.
  265. The following is an example of a test run output which consists of four tests A,
  266. B, C, and D, and a log message for the failing test C:
  267. .. code-block:: none
  268. PASS: A (1 of 4)
  269. PASS: B (2 of 4)
  270. FAIL: C (3 of 4)
  271. ******************** TEST 'C' FAILED ********************
  272. Test 'C' failed as a result of exit code 1.
  273. ********************
  274. PASS: D (4 of 4)
  275. LIT EXAMPLE TESTS
  276. ~~~~~~~~~~~~~~~~~
  277. The :program:`lit` distribution contains several example implementations of
  278. test suites in the *ExampleTests* directory.
  279. SEE ALSO
  280. --------
  281. valgrind(1)