1lit - LLVM Integrated Tester
2============================
3
4.. program:: lit
5
6SYNOPSIS
7--------
8
9:program:`lit` [*options*] [*tests*]
10
11DESCRIPTION
12-----------
13
14:program:`lit` is a portable tool for executing LLVM and Clang style test
15suites, summarizing their results, and providing indication of failures.
16:program:`lit` is designed to be a lightweight testing tool with as simple a
17user interface as possible.
18
19:program:`lit` should be run with one or more *tests* to run specified on the
20command line.  Tests can be either individual test files or directories to
21search for tests (see :ref:`test-discovery`).
22
23Each specified test will be executed (potentially in parallel) and once all
24tests have been run :program:`lit` will print summary information on the number
25of tests which passed or failed (see :ref:`test-status-results`).  The
26:program:`lit` program will execute with a non-zero exit code if any tests
27fail.
28
29By default :program:`lit` will use a succinct progress display and will only
30print summary information for test failures.  See :ref:`output-options` for
31options controlling the :program:`lit` progress display and output.
32
33:program:`lit` also includes a number of options for controlling how tests are
34executed (specific features may depend on the particular test format).  See
35:ref:`execution-options` for more information.
36
37Finally, :program:`lit` also supports additional options for only running a
38subset of the options specified on the command line, see
39:ref:`selection-options` for more information.
40
41:program:`lit` parses options from the environment variable ``LIT_OPTS`` after
42parsing options from the command line.  ``LIT_OPTS`` is primarily useful for
43supplementing or overriding the command-line options supplied to :program:`lit`
44by ``check`` targets defined by a project's build system.
45
46Users interested in the :program:`lit` architecture or designing a
47:program:`lit` testing implementation should see :ref:`lit-infrastructure`.
48
49GENERAL OPTIONS
50---------------
51
52.. option:: -h, --help
53
54 Show the :program:`lit` help message.
55
56.. option:: -j N, --workers=N
57
58 Run ``N`` tests in parallel.  By default, this is automatically chosen to
59 match the number of detected available CPUs.
60
61.. option:: --config-prefix=NAME
62
63 Search for :file:`{NAME}.cfg` and :file:`{NAME}.site.cfg` when searching for
64 test suites, instead of :file:`lit.cfg` and :file:`lit.site.cfg`.
65
66.. option:: -D NAME[=VALUE], --param NAME[=VALUE]
67
68 Add a user defined parameter ``NAME`` with the given ``VALUE`` (or the empty
69 string if not given).  The meaning and use of these parameters is test suite
70 dependent.
71
72.. _output-options:
73
74OUTPUT OPTIONS
75--------------
76
77.. option:: -q, --quiet
78
79 Suppress any output except for test failures.
80
81.. option:: -s, --succinct
82
83 Show less output, for example don't show information on tests that pass.
84
85.. option:: -v, --verbose
86
87 Show more information on test failures, for example the entire test output
88 instead of just the test result.
89
90.. option:: -vv, --echo-all-commands
91
92 Echo all commands to stdout, as they are being executed.
93 This can be valuable for debugging test failures, as the last echoed command
94 will be the one which has failed.
95 :program:`lit` normally inserts a no-op command (``:`` in the case of bash)
96 with argument ``'RUN: at line N'`` before each command pipeline, and this
97 option also causes those no-op commands to be echoed to stdout to help you
98 locate the source line of the failed command.
99 This option implies ``--verbose``.
100
101.. option:: -a, --show-all
102
103 Show more information about all tests, for example the entire test
104 commandline and output.
105
106.. option:: --no-progress-bar
107
108 Do not use curses based progress bar.
109
110.. option:: --show-unsupported
111
112 Show the names of unsupported tests.
113
114.. option:: --show-xfail
115
116 Show the names of tests that were expected to fail.
117
118.. _execution-options:
119
120EXECUTION OPTIONS
121-----------------
122
123.. option:: --path=PATH
124
125 Specify an additional ``PATH`` to use when searching for executables in tests.
126
127.. option:: --vg
128
129 Run individual tests under valgrind (using the memcheck tool).  The
130 ``--error-exitcode`` argument for valgrind is used so that valgrind failures
131 will cause the program to exit with a non-zero status.
132
133 When this option is enabled, :program:`lit` will also automatically provide a
134 "``valgrind``" feature that can be used to conditionally disable (or expect
135 failure in) certain tests.
136
137.. option:: --vg-arg=ARG
138
139 When :option:`--vg` is used, specify an additional argument to pass to
140 :program:`valgrind` itself.
141
142.. option:: --vg-leak
143
144 When :option:`--vg` is used, enable memory leak checks.  When this option is
145 enabled, :program:`lit` will also automatically provide a "``vg_leak``"
146 feature that can be used to conditionally disable (or expect failure in)
147 certain tests.
148
149.. option:: --time-tests
150
151 Track the wall time individual tests take to execute and includes the results
152 in the summary output.  This is useful for determining which tests in a test
153 suite take the most time to execute.  Note that this option is most useful
154 with ``-j 1``.
155
156.. _selection-options:
157
158SELECTION OPTIONS
159-----------------
160
161.. option:: --max-tests=N
162
163 Run at most ``N`` tests and then terminate.
164
165.. option:: --max-time=N
166
167 Spend at most ``N`` seconds (approximately) running tests and then terminate.
168 Note that this is not an alias for :option:`--timeout`; the two are
169 different kinds of maximums.
170
171.. option:: --num-shards=M
172
173 Divide the set of selected tests into ``M`` equal-sized subsets or
174 "shards", and run only one of them.  Must be used with the
175 ``--run-shard=N`` option, which selects the shard to run. The environment
176 variable ``LIT_NUM_SHARDS`` can also be used in place of this
177 option. These two options provide a coarse mechanism for partitioning large
178 testsuites, for parallel execution on separate machines (say in a large
179 testing farm).
180
181.. option:: --run-shard=N
182
183 Select which shard to run, assuming the ``--num-shards=M`` option was
184 provided. The two options must be used together, and the value of ``N``
185 must be in the range ``1..M``. The environment variable
186 ``LIT_RUN_SHARD`` can also be used in place of this option.
187
188.. option:: --shuffle
189
190 Run the tests in a random order.
191
192.. option:: --timeout=N
193
194 Spend at most ``N`` seconds (approximately) running each individual test.
195 ``0`` means no time limit, and ``0`` is the default. Note that this is not an
196 alias for :option:`--max-time`; the two are different kinds of maximums.
197
198.. option:: --filter=REGEXP
199
200  Run only those tests whose name matches the regular expression specified in
201  ``REGEXP``. The environment variable ``LIT_FILTER`` can be also used in place
202  of this option, which is especially useful in environments where the call
203  to ``lit`` is issued indirectly.
204
205ADDITIONAL OPTIONS
206------------------
207
208.. option:: --debug
209
210 Run :program:`lit` in debug mode, for debugging configuration issues and
211 :program:`lit` itself.
212
213.. option:: --show-suites
214
215 List the discovered test suites and exit.
216
217.. option:: --show-tests
218
219 List all of the discovered tests and exit.
220
221EXIT STATUS
222-----------
223
224:program:`lit` will exit with an exit code of 1 if there are any FAIL or XPASS
225results.  Otherwise, it will exit with the status 0.  Other exit codes are used
226for non-test related failures (for example a user error or an internal program
227error).
228
229.. _test-discovery:
230
231TEST DISCOVERY
232--------------
233
234The inputs passed to :program:`lit` can be either individual tests, or entire
235directories or hierarchies of tests to run.  When :program:`lit` starts up, the
236first thing it does is convert the inputs into a complete list of tests to run
237as part of *test discovery*.
238
239In the :program:`lit` model, every test must exist inside some *test suite*.
240:program:`lit` resolves the inputs specified on the command line to test suites
241by searching upwards from the input path until it finds a :file:`lit.cfg` or
242:file:`lit.site.cfg` file.  These files serve as both a marker of test suites
243and as configuration files which :program:`lit` loads in order to understand
244how to find and run the tests inside the test suite.
245
246Once :program:`lit` has mapped the inputs into test suites it traverses the
247list of inputs adding tests for individual files and recursively searching for
248tests in directories.
249
250This behavior makes it easy to specify a subset of tests to run, while still
251allowing the test suite configuration to control exactly how tests are
252interpreted.  In addition, :program:`lit` always identifies tests by the test
253suite they are in, and their relative path inside the test suite.  For
254appropriately configured projects, this allows :program:`lit` to provide
255convenient and flexible support for out-of-tree builds.
256
257.. _test-status-results:
258
259TEST STATUS RESULTS
260-------------------
261
262Each test ultimately produces one of the following eight results:
263
264**PASS**
265
266 The test succeeded.
267
268**FLAKYPASS**
269
270 The test succeeded after being re-run more than once. This only applies to
271 tests containing an ``ALLOW_RETRIES:`` annotation.
272
273**XFAIL**
274
275 The test failed, but that is expected.  This is used for test formats which allow
276 specifying that a test does not currently work, but wish to leave it in the test
277 suite.
278
279**XPASS**
280
281 The test succeeded, but it was expected to fail.  This is used for tests which
282 were specified as expected to fail, but are now succeeding (generally because
283 the feature they test was broken and has been fixed).
284
285**FAIL**
286
287 The test failed.
288
289**UNRESOLVED**
290
291 The test result could not be determined.  For example, this occurs when the test
292 could not be run, the test itself is invalid, or the test was interrupted.
293
294**UNSUPPORTED**
295
296 The test is not supported in this environment.  This is used by test formats
297 which can report unsupported tests.
298
299**TIMEOUT**
300
301 The test was run, but it timed out before it was able to complete. This is
302 considered a failure.
303
304Depending on the test format tests may produce additional information about
305their status (generally only for failures).  See the :ref:`output-options`
306section for more information.
307
308.. _lit-infrastructure:
309
310LIT INFRASTRUCTURE
311------------------
312
313This section describes the :program:`lit` testing architecture for users interested in
314creating a new :program:`lit` testing implementation, or extending an existing one.
315
316:program:`lit` proper is primarily an infrastructure for discovering and running
317arbitrary tests, and to expose a single convenient interface to these
318tests. :program:`lit` itself doesn't know how to run tests, rather this logic is
319defined by *test suites*.
320
321TEST SUITES
322~~~~~~~~~~~
323
324As described in :ref:`test-discovery`, tests are always located inside a *test
325suite*.  Test suites serve to define the format of the tests they contain, the
326logic for finding those tests, and any additional information to run the tests.
327
328:program:`lit` identifies test suites as directories containing ``lit.cfg`` or
329``lit.site.cfg`` files (see also :option:`--config-prefix`).  Test suites are
330initially discovered by recursively searching up the directory hierarchy for
331all the input files passed on the command line.  You can use
332:option:`--show-suites` to display the discovered test suites at startup.
333
334Once a test suite is discovered, its config file is loaded.  Config files
335themselves are Python modules which will be executed.  When the config file is
336executed, two important global variables are predefined:
337
338**lit_config**
339
340 The global **lit** configuration object (a *LitConfig* instance), which defines
341 the builtin test formats, global configuration parameters, and other helper
342 routines for implementing test configurations.
343
344**config**
345
346 This is the config object (a *TestingConfig* instance) for the test suite,
347 which the config file is expected to populate.  The following variables are also
348 available on the *config* object, some of which must be set by the config and
349 others are optional or predefined:
350
351 **name** *[required]* The name of the test suite, for use in reports and
352 diagnostics.
353
354 **test_format** *[required]* The test format object which will be used to
355 discover and run tests in the test suite.  Generally this will be a builtin test
356 format available from the *lit.formats* module.
357
358 **test_source_root** The filesystem path to the test suite root.  For out-of-dir
359 builds this is the directory that will be scanned for tests.
360
361 **test_exec_root** For out-of-dir builds, the path to the test suite root inside
362 the object directory.  This is where tests will be run and temporary output files
363 placed.
364
365 **environment** A dictionary representing the environment to use when executing
366 tests in the suite.
367
368 **suffixes** For **lit** test formats which scan directories for tests, this
369 variable is a list of suffixes to identify test files.  Used by: *ShTest*.
370
371 **substitutions** For **lit** test formats which substitute variables into a test
372 script, the list of substitutions to perform.  Used by: *ShTest*.
373
374 **unsupported** Mark an unsupported directory, all tests within it will be
375 reported as unsupported.  Used by: *ShTest*.
376
377 **parent** The parent configuration, this is the config object for the directory
378 containing the test suite, or None.
379
380 **root** The root configuration.  This is the top-most :program:`lit` configuration in
381 the project.
382
383 **pipefail** Normally a test using a shell pipe fails if any of the commands
384 on the pipe fail. If this is not desired, setting this variable to false
385 makes the test fail only if the last command in the pipe fails.
386
387 **available_features** A set of features that can be used in `XFAIL`,
388 `REQUIRES`, and `UNSUPPORTED` directives.
389
390TEST DISCOVERY
391~~~~~~~~~~~~~~
392
393Once test suites are located, :program:`lit` recursively traverses the source
394directory (following *test_source_root*) looking for tests.  When :program:`lit`
395enters a sub-directory, it first checks to see if a nested test suite is
396defined in that directory.  If so, it loads that test suite recursively,
397otherwise it instantiates a local test config for the directory (see
398:ref:`local-configuration-files`).
399
400Tests are identified by the test suite they are contained within, and the
401relative path inside that suite.  Note that the relative path may not refer to
402an actual file on disk; some test formats (such as *GoogleTest*) define
403"virtual tests" which have a path that contains both the path to the actual
404test file and a subpath to identify the virtual test.
405
406.. _local-configuration-files:
407
408LOCAL CONFIGURATION FILES
409~~~~~~~~~~~~~~~~~~~~~~~~~
410
411When :program:`lit` loads a subdirectory in a test suite, it instantiates a
412local test configuration by cloning the configuration for the parent directory
413--- the root of this configuration chain will always be a test suite.  Once the
414test configuration is cloned :program:`lit` checks for a *lit.local.cfg* file
415in the subdirectory.  If present, this file will be loaded and can be used to
416specialize the configuration for each individual directory.  This facility can
417be used to define subdirectories of optional tests, or to change other
418configuration parameters --- for example, to change the test format, or the
419suffixes which identify test files.
420
421SUBSTITUTIONS
422~~~~~~~~~~~~~
423
424:program:`lit` allows patterns to be substituted inside RUN commands. It also
425provides the following base set of substitutions, which are defined in
426TestRunner.py:
427
428 ======================= ==============
429  Macro                   Substitution
430 ======================= ==============
431 %s                      source path (path to the file currently being run)
432 %S                      source dir (directory of the file currently being run)
433 %p                      same as %S
434 %{pathsep}              path separator
435 %t                      temporary file name unique to the test
436 %basename_t             The last path component of %t but without the ``.tmp`` extension
437 %T                      parent directory of %t (not unique, deprecated, do not use)
438 %%                      %
439 %/s                     %s but ``\`` is replaced by ``/``
440 %/S                     %S but ``\`` is replaced by ``/``
441 %/p                     %p but ``\`` is replaced by ``/``
442 %/t                     %t but ``\`` is replaced by ``/``
443 %/T                     %T but ``\`` is replaced by ``/``
444 %{/s:regex_replacement} %/s but escaped for use in the replacement of a ``s@@@`` command in sed
445 %{/S:regex_replacement} %/S but escaped for use in the replacement of a ``s@@@`` command in sed
446 %{/p:regex_replacement} %/p but escaped for use in the replacement of a ``s@@@`` command in sed
447 %{/t:regex_replacement} %/t but escaped for use in the replacement of a ``s@@@`` command in sed
448 %{/T:regex_replacement} %/T but escaped for use in the replacement of a ``s@@@`` command in sed
449 %:s                     On Windows, %/s but a ``:`` is removed if its the second character.
450                         Otherwise, %s but with a single leading ``/`` removed.
451 %:S                     On Windows, %/S but a ``:`` is removed if its the second character.
452                         Otherwise, %S but with a single leading ``/`` removed.
453 %:p                     On Windows, %/p but a ``:`` is removed if its the second character.
454                         Otherwise, %p but with a single leading ``/`` removed.
455 %:t                     On Windows, %/t but a ``:`` is removed if its the second character.
456                         Otherwise, %t but with a single leading ``/`` removed.
457 %:T                     On Windows, %/T but a ``:`` is removed if its the second character.
458                         Otherwise, %T but with a single leading ``/`` removed.
459 ======================= ==============
460
461Other substitutions are provided that are variations on this base set and
462further substitution patterns can be defined by each test module. See the
463modules :ref:`local-configuration-files`.
464
465By default, substitutions are expanded exactly once, so that if e.g. a
466substitution ``%build`` is defined in top of another substitution ``%cxx``,
467``%build`` will expand to ``%cxx`` textually, not to what ``%cxx`` expands to.
468However, if the ``recursiveExpansionLimit`` property of the ``TestingConfig``
469is set to a non-negative integer, substitutions will be expanded recursively
470until that limit is reached. It is an error if the limit is reached and
471expanding substitutions again would yield a different result.
472
473More detailed information on substitutions can be found in the
474:doc:`../TestingGuide`.
475
476TEST RUN OUTPUT FORMAT
477~~~~~~~~~~~~~~~~~~~~~~
478
479The :program:`lit` output for a test run conforms to the following schema, in
480both short and verbose modes (although in short mode no PASS lines will be
481shown).  This schema has been chosen to be relatively easy to reliably parse by
482a machine (for example in buildbot log scraping), and for other tools to
483generate.
484
485Each test result is expected to appear on a line that matches:
486
487.. code-block:: none
488
489  <result code>: <test name> (<progress info>)
490
491where ``<result-code>`` is a standard test result such as PASS, FAIL, XFAIL,
492XPASS, UNRESOLVED, or UNSUPPORTED.  The performance result codes of IMPROVED and
493REGRESSED are also allowed.
494
495The ``<test name>`` field can consist of an arbitrary string containing no
496newline.
497
498The ``<progress info>`` field can be used to report progress information such
499as (1/300) or can be empty, but even when empty the parentheses are required.
500
501Each test result may include additional (multiline) log information in the
502following format:
503
504.. code-block:: none
505
506  <log delineator> TEST '(<test name>)' <trailing delineator>
507  ... log message ...
508  <log delineator>
509
510where ``<test name>`` should be the name of a preceding reported test, ``<log
511delineator>`` is a string of "*" characters *at least* four characters long
512(the recommended length is 20), and ``<trailing delineator>`` is an arbitrary
513(unparsed) string.
514
515The following is an example of a test run output which consists of four tests A,
516B, C, and D, and a log message for the failing test C:
517
518.. code-block:: none
519
520  PASS: A (1 of 4)
521  PASS: B (2 of 4)
522  FAIL: C (3 of 4)
523  ******************** TEST 'C' FAILED ********************
524  Test 'C' failed as a result of exit code 1.
525  ********************
526  PASS: D (4 of 4)
527
528LIT EXAMPLE TESTS
529~~~~~~~~~~~~~~~~~
530
531The :program:`lit` distribution contains several example implementations of
532test suites in the *ExampleTests* directory.
533
534SEE ALSO
535--------
536
537valgrind(1)
538