1 lit - LLVM Integrated Tester
2 ============================
9 :program:`lit` [*options*] [*tests*]
14 :program:`lit` is a portable tool for executing LLVM and Clang style test
15 suites, summarizing their results, and providing indication of failures.
16 :program:`lit` is designed to be a lightweight testing tool with as simple a
17 user interface as possible.
19 :program:`lit` should be run with one or more *tests* to run specified on the
20 command line. Tests can be either individual test files or directories to
21 search for tests (see :ref:`test-discovery`).
23 Each specified test will be executed (potentially concurrently) and once all
24 tests have been run :program:`lit` will print summary information on the number
25 of 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
29 By default :program:`lit` will use a succinct progress display and will only
30 print summary information for test failures. See :ref:`output-options` for
31 options controlling the :program:`lit` progress display and output.
33 :program:`lit` also includes a number of options for controlling how tests are
34 executed (specific features may depend on the particular test format). See
35 :ref:`execution-options` for more information.
37 Finally, :program:`lit` also supports additional options for only running a
38 subset of the options specified on the command line, see
39 :ref:`selection-options` for more information.
41 :program:`lit` parses options from the environment variable ``LIT_OPTS`` after
42 parsing options from the command line. ``LIT_OPTS`` is primarily useful for
43 supplementing or overriding the command-line options supplied to :program:`lit`
44 by ``check`` targets defined by a project's build system.
46 :program:`lit` can also read options from response files which are specified as
47 inputs using the ``@path/to/file.rsp`` syntax. Arguments read from a file must
48 be one per line and are treated as if they were in the same place as the
49 original file referencing argument on the command line. A response file can
50 reference other response files.
52 Users interested in the :program:`lit` architecture or designing a
53 :program:`lit` testing implementation should see :ref:`lit-infrastructure`.
58 .. option:: -h, --help
60 Show the :program:`lit` help message.
62 .. option:: -j N, --workers=N
64 Run ``N`` tests in parallel. By default, this is automatically chosen to
65 match the number of detected available CPUs.
67 .. option:: --config-prefix=NAME
69 Search for :file:`{NAME}.cfg` and :file:`{NAME}.site.cfg` when searching for
70 test suites, instead of :file:`lit.cfg` and :file:`lit.site.cfg`.
72 .. option:: -D NAME[=VALUE], --param NAME[=VALUE]
74 Add a user defined parameter ``NAME`` with the given ``VALUE`` (or the empty
75 string if not given). The meaning and use of these parameters is test suite
83 .. option:: -q, --quiet
85 Suppress any output except for test failures.
87 .. option:: -s, --succinct
89 Show less output, for example don't show information on tests that pass.
90 Also show a progress bar, unless ``--no-progress-bar`` is specified.
92 .. option:: -v, --verbose
94 Show more information on test failures, for example the entire test output
95 instead of just the test result.
97 Each command is printed before it is executed. This can be valuable for
98 debugging test failures, as the last printed command is the one that failed.
99 Moreover, :program:`lit` inserts ``'RUN: at line N'`` before each
100 command pipeline in the output to help you locate the source line of
103 .. option:: -vv, --echo-all-commands
105 Deprecated alias for -v.
107 .. option:: -a, --show-all
109 Enable -v, but for all tests not just failed tests.
111 .. option:: --no-progress-bar
113 Do not use curses based progress bar.
115 .. option:: --show-unsupported
117 Show the names of unsupported tests.
119 .. option:: --show-xfail
121 Show the names of tests that were expected to fail.
123 .. _execution-options:
128 .. option:: --path=PATH
130 Specify an additional ``PATH`` to use when searching for executables in tests.
134 Run individual tests under valgrind (using the memcheck tool). The
135 ``--error-exitcode`` argument for valgrind is used so that valgrind failures
136 will cause the program to exit with a non-zero status.
138 When this option is enabled, :program:`lit` will also automatically provide a
139 "``valgrind``" feature that can be used to conditionally disable (or expect
140 failure in) certain tests.
142 .. option:: --vg-arg=ARG
144 When :option:`--vg` is used, specify an additional argument to pass to
145 :program:`valgrind` itself.
147 .. option:: --vg-leak
149 When :option:`--vg` is used, enable memory leak checks. When this option is
150 enabled, :program:`lit` will also automatically provide a "``vg_leak``"
151 feature that can be used to conditionally disable (or expect failure in)
154 .. option:: --time-tests
156 Track the wall time individual tests take to execute and includes the results
157 in the summary output. This is useful for determining which tests in a test
158 suite take the most time to execute.
160 .. option:: --ignore-fail
162 Exit with status zero even if some tests fail.
164 .. _selection-options:
169 By default, `lit` will run failing tests first, then run tests in descending
170 execution time order to optimize concurrency. The execution order can be
171 changed using the :option:`--order` option.
173 The timing data is stored in the `test_exec_root` in a file named
174 `.lit_test_times.txt`. If this file does not exist, then `lit` checks the
175 `test_source_root` for the file to optionally accelerate clean builds.
177 .. option:: --shuffle
179 Run the tests in a random order, not failing/slowest first. Deprecated,
180 use :option:`--order` instead.
182 .. option:: --per-test-coverage
184 Emit the necessary test coverage data, divided per test case (involves
185 setting a unique value to LLVM_PROFILE_FILE for each RUN). The coverage
186 data files will be emitted in the directory specified by `config.test_exec_root`.
188 .. option:: --max-failures N
190 Stop execution after the given number ``N`` of failures.
191 An integer argument should be passed on the command line
194 .. option:: --max-tests=N
196 Run at most ``N`` tests and then terminate.
198 .. option:: --max-time=N
200 Spend at most ``N`` seconds (approximately) running tests and then terminate.
201 Note that this is not an alias for :option:`--timeout`; the two are
202 different kinds of maximums.
204 .. option:: --num-shards=M
206 Divide the set of selected tests into ``M`` equal-sized subsets or
207 "shards", and run only one of them. Must be used with the
208 ``--run-shard=N`` option, which selects the shard to run. The environment
209 variable ``LIT_NUM_SHARDS`` can also be used in place of this
210 option. These two options provide a coarse mechanism for partitioning large
211 testsuites, for parallel execution on separate machines (say in a large
214 .. option:: --order={lexical,random,smart}
216 Define the order in which tests are run. The supported values are:
218 - lexical - tests will be run in lexical order according to the test file
219 path. This option is useful when predictable test order is desired.
221 - random - tests will be run in random order.
223 - smart - tests that failed previously will be run first, then the remaining
224 tests, all in descending execution time order. This is the default as it
225 optimizes concurrency.
227 .. option:: --run-shard=N
229 Select which shard to run, assuming the ``--num-shards=M`` option was
230 provided. The two options must be used together, and the value of ``N``
231 must be in the range ``1..M``. The environment variable
232 ``LIT_RUN_SHARD`` can also be used in place of this option.
234 .. option:: --timeout=N
236 Spend at most ``N`` seconds (approximately) running each individual test.
237 ``0`` means no time limit, and ``0`` is the default. Note that this is not an
238 alias for :option:`--max-time`; the two are different kinds of maximums.
240 .. option:: --filter=REGEXP
242 Run only those tests whose name matches the regular expression specified in
243 ``REGEXP``. The environment variable ``LIT_FILTER`` can be also used in place
244 of this option, which is especially useful in environments where the call
245 to ``lit`` is issued indirectly.
247 .. option:: --filter-out=REGEXP
249 Filter out those tests whose name matches the regular expression specified in
250 ``REGEXP``. The environment variable ``LIT_FILTER_OUT`` can be also used in
251 place of this option, which is especially useful in environments where the
252 call to ``lit`` is issued indirectly.
254 .. option:: --xfail=LIST
256 Treat those tests whose name is in the semicolon separated list ``LIST`` as
257 ``XFAIL``. This can be helpful when one does not want to modify the test
258 suite. The environment variable ``LIT_XFAIL`` can be also used in place of
259 this option, which is especially useful in environments where the call to
260 ``lit`` is issued indirectly.
262 A test name can specified as a file name relative to the test suite directory.
267 LIT_XFAIL="affinity/kmp-hw-subset.c;offloading/memory_manager.cpp"
269 In this case, all of the following tests are treated as ``XFAIL``:
273 libomp :: affinity/kmp-hw-subset.c
274 libomptarget :: nvptx64-nvidia-cuda :: offloading/memory_manager.cpp
275 libomptarget :: x86_64-pc-linux-gnu :: offloading/memory_manager.cpp
277 Alternatively, a test name can be specified as the full test name
278 reported in LIT output. For example, we can adjust the previous
279 example not to treat the ``nvptx64-nvidia-cuda`` version of
280 ``offloading/memory_manager.cpp`` as XFAIL:
284 LIT_XFAIL="affinity/kmp-hw-subset.c;libomptarget :: x86_64-pc-linux-gnu :: offloading/memory_manager.cpp"
286 .. option:: --xfail-not=LIST
288 Do not treat the specified tests as ``XFAIL``. The environment variable
289 ``LIT_XFAIL_NOT`` can also be used in place of this option. The syntax is the
290 same as for :option:`--xfail` and ``LIT_XFAIL``. :option:`--xfail-not` and
291 ``LIT_XFAIL_NOT`` always override all other ``XFAIL`` specifications,
292 including an :option:`--xfail` appearing later on the command line. The
293 primary purpose is to suppress an ``XPASS`` result without modifying a test
294 case that uses the ``XFAIL`` directive.
301 Run :program:`lit` in debug mode, for debugging configuration issues and
302 :program:`lit` itself.
304 .. option:: --show-suites
306 List the discovered test suites and exit.
308 .. option:: --show-tests
310 List all of the discovered tests and exit.
315 :program:`lit` will exit with an exit code of 1 if there are any FAIL or XPASS
316 results. Otherwise, it will exit with the status 0. Other exit codes are used
317 for non-test related failures (for example a user error or an internal program
325 The inputs passed to :program:`lit` can be either individual tests, or entire
326 directories or hierarchies of tests to run. When :program:`lit` starts up, the
327 first thing it does is convert the inputs into a complete list of tests to run
328 as part of *test discovery*.
330 In the :program:`lit` model, every test must exist inside some *test suite*.
331 :program:`lit` resolves the inputs specified on the command line to test suites
332 by searching upwards from the input path until it finds a :file:`lit.cfg` or
333 :file:`lit.site.cfg` file. These files serve as both a marker of test suites
334 and as configuration files which :program:`lit` loads in order to understand
335 how to find and run the tests inside the test suite.
337 Once :program:`lit` has mapped the inputs into test suites it traverses the
338 list of inputs adding tests for individual files and recursively searching for
339 tests in directories.
341 This behavior makes it easy to specify a subset of tests to run, while still
342 allowing the test suite configuration to control exactly how tests are
343 interpreted. In addition, :program:`lit` always identifies tests by the test
344 suite they are in, and their relative path inside the test suite. For
345 appropriately configured projects, this allows :program:`lit` to provide
346 convenient and flexible support for out-of-tree builds.
348 .. _test-status-results:
353 Each test ultimately produces one of the following eight results:
361 The test succeeded after being re-run more than once. This only applies to
362 tests containing an ``ALLOW_RETRIES:`` annotation.
366 The test failed, but that is expected. This is used for test formats which allow
367 specifying that a test does not currently work, but wish to leave it in the test
372 The test succeeded, but it was expected to fail. This is used for tests which
373 were specified as expected to fail, but are now succeeding (generally because
374 the feature they test was broken and has been fixed).
382 The test result could not be determined. For example, this occurs when the test
383 could not be run, the test itself is invalid, or the test was interrupted.
387 The test is not supported in this environment. This is used by test formats
388 which can report unsupported tests.
392 The test was run, but it timed out before it was able to complete. This is
393 considered a failure.
395 Depending on the test format tests may produce additional information about
396 their status (generally only for failures). See the :ref:`output-options`
397 section for more information.
399 .. _lit-infrastructure:
404 This section describes the :program:`lit` testing architecture for users interested in
405 creating a new :program:`lit` testing implementation, or extending an existing one.
407 :program:`lit` proper is primarily an infrastructure for discovering and running
408 arbitrary tests, and to expose a single convenient interface to these
409 tests. :program:`lit` itself doesn't know how to run tests, rather this logic is
410 defined by *test suites*.
415 As described in :ref:`test-discovery`, tests are always located inside a *test
416 suite*. Test suites serve to define the format of the tests they contain, the
417 logic for finding those tests, and any additional information to run the tests.
419 :program:`lit` identifies test suites as directories containing ``lit.cfg`` or
420 ``lit.site.cfg`` files (see also :option:`--config-prefix`). Test suites are
421 initially discovered by recursively searching up the directory hierarchy for
422 all the input files passed on the command line. You can use
423 :option:`--show-suites` to display the discovered test suites at startup.
425 Once a test suite is discovered, its config file is loaded. Config files
426 themselves are Python modules which will be executed. When the config file is
427 executed, two important global variables are predefined:
431 The global **lit** configuration object (a *LitConfig* instance), which defines
432 the builtin test formats, global configuration parameters, and other helper
433 routines for implementing test configurations.
437 This is the config object (a *TestingConfig* instance) for the test suite,
438 which the config file is expected to populate. The following variables are also
439 available on the *config* object, some of which must be set by the config and
440 others are optional or predefined:
442 **name** *[required]* The name of the test suite, for use in reports and
445 **test_format** *[required]* The test format object which will be used to
446 discover and run tests in the test suite. Generally this will be a builtin test
447 format available from the *lit.formats* module.
449 **test_source_root** The filesystem path to the test suite root. For out-of-dir
450 builds this is the directory that will be scanned for tests.
452 **test_exec_root** For out-of-dir builds, the path to the test suite root inside
453 the object directory. This is where tests will be run and temporary output files
456 **environment** A dictionary representing the environment to use when executing
459 **standalone_tests** When true, mark a directory with tests expected to be run
460 standalone. Test discovery is disabled for that directory. *lit.suffixes* and
461 *lit.excludes* must be empty when this variable is true.
463 **suffixes** For **lit** test formats which scan directories for tests, this
464 variable is a list of suffixes to identify test files. Used by: *ShTest*.
466 **substitutions** For **lit** test formats which substitute variables into a test
467 script, the list of substitutions to perform. Used by: *ShTest*.
469 **unsupported** Mark an unsupported directory, all tests within it will be
470 reported as unsupported. Used by: *ShTest*.
472 **parent** The parent configuration, this is the config object for the directory
473 containing the test suite, or None.
475 **root** The root configuration. This is the top-most :program:`lit` configuration in
478 **pipefail** Normally a test using a shell pipe fails if any of the commands
479 on the pipe fail. If this is not desired, setting this variable to false
480 makes the test fail only if the last command in the pipe fails.
482 **available_features** A set of features that can be used in `XFAIL`,
483 `REQUIRES`, and `UNSUPPORTED` directives.
488 Once test suites are located, :program:`lit` recursively traverses the source
489 directory (following *test_source_root*) looking for tests. When :program:`lit`
490 enters a sub-directory, it first checks to see if a nested test suite is
491 defined in that directory. If so, it loads that test suite recursively,
492 otherwise it instantiates a local test config for the directory (see
493 :ref:`local-configuration-files`).
495 Tests are identified by the test suite they are contained within, and the
496 relative path inside that suite. Note that the relative path may not refer to
497 an actual file on disk; some test formats (such as *GoogleTest*) define
498 "virtual tests" which have a path that contains both the path to the actual
499 test file and a subpath to identify the virtual test.
501 .. _local-configuration-files:
503 LOCAL CONFIGURATION FILES
504 ~~~~~~~~~~~~~~~~~~~~~~~~~
506 When :program:`lit` loads a subdirectory in a test suite, it instantiates a
507 local test configuration by cloning the configuration for the parent directory
508 --- the root of this configuration chain will always be a test suite. Once the
509 test configuration is cloned :program:`lit` checks for a *lit.local.cfg* file
510 in the subdirectory. If present, this file will be loaded and can be used to
511 specialize the configuration for each individual directory. This facility can
512 be used to define subdirectories of optional tests, or to change other
513 configuration parameters --- for example, to change the test format, or the
514 suffixes which identify test files.
519 :program:`lit` allows patterns to be substituted inside RUN commands. It also
520 provides the following base set of substitutions, which are defined in
523 ======================= ==============
525 ======================= ==============
526 %s source path (path to the file currently being run)
527 %S source dir (directory of the file currently being run)
529 %{pathsep} path separator
530 %{fs-src-root} root component of file system paths pointing to the LLVM checkout
531 %{fs-tmp-root} root component of file system paths pointing to the test's temporary directory
532 %{fs-sep} file system path separator
533 %t temporary file name unique to the test
534 %basename_t The last path component of %t but without the ``.tmp`` extension
535 %T parent directory of %t (not unique, deprecated, do not use)
537 %/s %s but ``\`` is replaced by ``/``
538 %/S %S but ``\`` is replaced by ``/``
539 %/p %p but ``\`` is replaced by ``/``
540 %/t %t but ``\`` is replaced by ``/``
541 %/T %T but ``\`` is replaced by ``/``
542 %{s:real} %s after expanding all symbolic links and substitute drives
543 %{S:real} %S after expanding all symbolic links and substitute drives
544 %{p:real} %p after expanding all symbolic links and substitute drives
545 %{t:real} %t after expanding all symbolic links and substitute drives
546 %{T:real} %T after expanding all symbolic links and substitute drives
547 %{/s:real} %/s after expanding all symbolic links and substitute drives
548 %{/S:real} %/S after expanding all symbolic links and substitute drives
549 %{/p:real} %/p after expanding all symbolic links and substitute drives
550 %{/t:real} %/t after expanding all symbolic links and substitute drives
551 %{/T:real} %/T after expanding all symbolic links and substitute drives
552 %{/s:regex_replacement} %/s but escaped for use in the replacement of a ``s@@@`` command in sed
553 %{/S:regex_replacement} %/S but escaped for use in the replacement of a ``s@@@`` command in sed
554 %{/p:regex_replacement} %/p but escaped for use in the replacement of a ``s@@@`` command in sed
555 %{/t:regex_replacement} %/t but escaped for use in the replacement of a ``s@@@`` command in sed
556 %{/T:regex_replacement} %/T but escaped for use in the replacement of a ``s@@@`` command in sed
557 %:s On Windows, %/s but a ``:`` is removed if its the second character.
558 Otherwise, %s but with a single leading ``/`` removed.
559 %:S On Windows, %/S but a ``:`` is removed if its the second character.
560 Otherwise, %S but with a single leading ``/`` removed.
561 %:p On Windows, %/p but a ``:`` is removed if its the second character.
562 Otherwise, %p but with a single leading ``/`` removed.
563 %:t On Windows, %/t but a ``:`` is removed if its the second character.
564 Otherwise, %t but with a single leading ``/`` removed.
565 %:T On Windows, %/T but a ``:`` is removed if its the second character.
566 Otherwise, %T but with a single leading ``/`` removed.
567 ======================= ==============
569 Other substitutions are provided that are variations on this base set and
570 further substitution patterns can be defined by each test module. See the
571 modules :ref:`local-configuration-files`.
573 More detailed information on substitutions can be found in the
574 :doc:`../TestingGuide`.
576 TEST RUN OUTPUT FORMAT
577 ~~~~~~~~~~~~~~~~~~~~~~
579 The :program:`lit` output for a test run conforms to the following schema, in
580 both short and verbose modes (although in short mode no PASS lines will be
581 shown). This schema has been chosen to be relatively easy to reliably parse by
582 a machine (for example in buildbot log scraping), and for other tools to
585 Each test result is expected to appear on a line that matches:
589 <result code>: <test name> (<progress info>)
591 where ``<result-code>`` is a standard test result such as PASS, FAIL, XFAIL,
592 XPASS, UNRESOLVED, or UNSUPPORTED. The performance result codes of IMPROVED and
593 REGRESSED are also allowed.
595 The ``<test name>`` field can consist of an arbitrary string containing no
598 The ``<progress info>`` field can be used to report progress information such
599 as (1/300) or can be empty, but even when empty the parentheses are required.
601 Each test result may include additional (multiline) log information in the
606 <log delineator> TEST '(<test name>)' <trailing delineator>
610 where ``<test name>`` should be the name of a preceding reported test, ``<log
611 delineator>`` is a string of "*" characters *at least* four characters long
612 (the recommended length is 20), and ``<trailing delineator>`` is an arbitrary
615 The following is an example of a test run output which consists of four tests A,
616 B, C, and D, and a log message for the failing test C:
623 ******************** TEST 'C' FAILED ********************
624 Test 'C' failed as a result of exit code 1.
631 The :program:`lit` distribution contains several example implementations of
632 test suites in the *ExampleTests* directory.