lit.rst 17 KB

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