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 and exit.
64 Show :program:`lit`'s version number and exit.
66 .. option:: -j N, --workers=N
68 Run ``N`` tests in parallel. By default, this is automatically chosen to
69 match the number of detected available CPUs.
71 .. option:: --config-prefix=NAME
73 Search for :file:`{NAME}.cfg` and :file:`{NAME}.site.cfg` when searching for
74 test suites, instead of :file:`lit.cfg` and :file:`lit.site.cfg`.
76 .. option:: -D NAME[=VALUE], --param NAME[=VALUE]
78 Add a user defined parameter ``NAME`` with the given ``VALUE`` (or the empty
79 string if not given). The meaning and use of these parameters is test suite
87 .. option:: -q, --quiet
89 Suppress any output except for test failures.
91 .. option:: -s, --succinct
93 Show less output, for example don't show information on tests that pass.
94 Also show a progress bar, unless ``--no-progress-bar`` is specified.
96 .. option:: -v, --verbose
98 Show more information on test failures, for example the entire test output
99 instead of just the test result.
101 Each command is printed before it is executed. This can be valuable for
102 debugging test failures, as the last printed command is the one that failed.
103 Moreover, :program:`lit` inserts ``'RUN: at line N'`` before each
104 command pipeline in the output to help you locate the source line of
107 .. option:: -vv, --echo-all-commands
109 Deprecated alias for -v.
111 .. option:: -a, --show-all
113 Enable -v, but for all tests not just failed tests.
115 .. option:: -o PATH, --output PATH
117 Write test results to the provided path.
119 .. option:: --no-progress-bar
121 Do not use curses based progress bar.
123 .. option:: --show-excluded
127 .. option:: --show-skipped
131 .. option:: --show-unsupported
133 Show unsupported tests.
135 .. option:: --show-pass
139 .. option:: --show-flakypass
141 Show passed with retry tests.
143 .. option:: --show-xfail
145 Show expectedly failed tests.
147 .. _execution-options:
152 .. option:: --gtest-sharding
154 Enable sharding for GoogleTest format.
156 .. option:: --no-gtest-sharding
158 Disable sharding for GoogleTest format.
160 .. option:: --path=PATH
162 Specify an additional ``PATH`` to use when searching for executables in tests.
166 Run individual tests under valgrind (using the memcheck tool). The
167 ``--error-exitcode`` argument for valgrind is used so that valgrind failures
168 will cause the program to exit with a non-zero status.
170 When this option is enabled, :program:`lit` will also automatically provide a
171 "``valgrind``" feature that can be used to conditionally disable (or expect
172 failure in) certain tests.
174 .. option:: --vg-leak
176 When :option:`--vg` is used, enable memory leak checks. When this option is
177 enabled, :program:`lit` will also automatically provide a "``vg_leak``"
178 feature that can be used to conditionally disable (or expect failure in)
181 .. option:: --vg-arg=ARG
183 When :option:`--vg` is used, specify an additional argument to pass to
184 :program:`valgrind` itself.
186 .. option:: --no-execute
188 Don't execute any tests (assume that they pass).
190 .. option:: --xunit-xml-output XUNIT_XML_OUTPUT
192 Write XUnit-compatible XML test reports to the specified file.
194 .. option:: --report-failures-only
196 Only include unresolved, timed out, failed and unexpectedly passed tests in the report.
198 .. option:: --resultdb-output RESULTDB_OUTPUT
200 Write LuCI ResultDB compatible JSON to the specified file.
202 .. option:: --time-trace-output TIME_TRACE_OUTPUT
204 Write Chrome tracing compatible JSON to the specified file
206 .. option:: --timeout MAXINDIVIDUALTESTTIME
208 Maximum time to spend running a single test (in seconds). 0 means no time
211 .. option:: --timeout=N
213 Spend at most ``N`` seconds (approximately) running each individual test.
214 ``0`` means no time limit, and ``0`` is the default. Note that this is not an
215 alias for :option:`--max-time`; the two are different kinds of maximums.
217 .. option:: --max-failures MAX_FAILURES
219 Stop execution after the given number of failures.
221 .. option:: --allow-empty-runs
223 Do not fail the run if all tests are filtered out.
225 .. option:: --per-test-coverage
227 Emit the necessary test coverage data, divided per test case (involves
228 setting a unique value to LLVM_PROFILE_FILE for each RUN). The coverage
229 data files will be emitted in the directory specified by ``config.test_exec_root``.
231 .. option:: --ignore-fail
233 Exit with status zero even if some tests fail.
235 .. option:: --skip-test-time-recording
237 Do not track elapsed wall time for each test.
239 .. option:: --time-tests
241 Track the wall time individual tests take to execute and includes the results
242 in the summary output. This is useful for determining which tests in a test
243 suite take the most time to execute.
245 .. _selection-options:
250 By default, `lit` will run failing tests first, then run tests in descending
251 execution time order to optimize concurrency. The execution order can be
252 changed using the :option:`--order` option.
254 The timing data is stored in the `test_exec_root` in a file named
255 `.lit_test_times.txt`. If this file does not exist, then `lit` checks the
256 `test_source_root` for the file to optionally accelerate clean builds.
258 .. option:: --max-tests=N
260 Run at most ``N`` tests and then terminate.
262 .. option:: --max-time=N
264 Spend at most ``N`` seconds (approximately) running tests and then terminate.
265 Note that this is not an alias for :option:`--timeout`; the two are
266 different kinds of maximums.
268 .. option:: --order={lexical,random,smart}
270 Define the order in which tests are run. The supported values are:
272 - lexical - tests will be run in lexical order according to the test file
273 path. This option is useful when predictable test order is desired.
275 - random - tests will be run in random order.
277 - smart - tests that failed previously will be run first, then the remaining
278 tests, all in descending execution time order. This is the default as it
279 optimizes concurrency.
281 .. option:: --shuffle
283 Run the tests in a random order, not failing/slowest first. Deprecated,
284 use :option:`--order` instead.
286 .. option:: -i, --incremental
288 Run failed tests first (DEPRECATED: use ``--order=smart``).
290 .. option:: --filter=REGEXP
292 Run only those tests whose name matches the regular expression specified in
293 ``REGEXP``. The environment variable ``LIT_FILTER`` can be also used in place
294 of this option, which is especially useful in environments where the call
295 to ``lit`` is issued indirectly.
297 .. option:: --filter-out=REGEXP
299 Filter out those tests whose name matches the regular expression specified in
300 ``REGEXP``. The environment variable ``LIT_FILTER_OUT`` can be also used in
301 place of this option, which is especially useful in environments where the
302 call to ``lit`` is issued indirectly.
304 .. option:: --xfail=LIST
306 Treat those tests whose name is in the semicolon separated list ``LIST`` as
307 ``XFAIL``. This can be helpful when one does not want to modify the test
308 suite. The environment variable ``LIT_XFAIL`` can be also used in place of
309 this option, which is especially useful in environments where the call to
310 ``lit`` is issued indirectly.
312 A test name can specified as a file name relative to the test suite directory.
317 LIT_XFAIL="affinity/kmp-hw-subset.c;offloading/memory_manager.cpp"
319 In this case, all of the following tests are treated as ``XFAIL``:
323 libomp :: affinity/kmp-hw-subset.c
324 libomptarget :: nvptx64-nvidia-cuda :: offloading/memory_manager.cpp
325 libomptarget :: x86_64-pc-linux-gnu :: offloading/memory_manager.cpp
327 Alternatively, a test name can be specified as the full test name
328 reported in LIT output. For example, we can adjust the previous
329 example not to treat the ``nvptx64-nvidia-cuda`` version of
330 ``offloading/memory_manager.cpp`` as XFAIL:
334 LIT_XFAIL="affinity/kmp-hw-subset.c;libomptarget :: x86_64-pc-linux-gnu :: offloading/memory_manager.cpp"
336 .. option:: --xfail-not=LIST
338 Do not treat the specified tests as ``XFAIL``. The environment variable
339 ``LIT_XFAIL_NOT`` can also be used in place of this option. The syntax is the
340 same as for :option:`--xfail` and ``LIT_XFAIL``. :option:`--xfail-not` and
341 ``LIT_XFAIL_NOT`` always override all other ``XFAIL`` specifications,
342 including an :option:`--xfail` appearing later on the command line. The
343 primary purpose is to suppress an ``XPASS`` result without modifying a test
344 case that uses the ``XFAIL`` directive.
346 .. option:: --num-shards=M
348 Divide the set of selected tests into ``M`` equal-sized subsets or
349 "shards", and run only one of them. Must be used with the
350 ``--run-shard=N`` option, which selects the shard to run. The environment
351 variable ``LIT_NUM_SHARDS`` can also be used in place of this
352 option. These two options provide a coarse mechanism for partitioning large
353 testsuites, for parallel execution on separate machines (say in a large
356 .. option:: --run-shard=N
358 Select which shard to run, assuming the ``--num-shards=M`` option was
359 provided. The two options must be used together, and the value of ``N``
360 must be in the range ``1..M``. The environment variable
361 ``LIT_RUN_SHARD`` can also be used in place of this option.
368 Run :program:`lit` in debug mode, for debugging configuration issues and
369 :program:`lit` itself.
371 .. option:: --show-suites
373 List the discovered test suites and exit.
375 .. option:: --show-tests
377 List all of the discovered tests and exit.
379 .. option:: --show-used-features
381 Show all features used in the test suite (in ``XFAIL``, ``UNSUPPORTED`` and
382 ``REQUIRES``) and exit.
387 :program:`lit` will exit with an exit code of 1 if there are any FAIL or XPASS
388 results. Otherwise, it will exit with the status 0. Other exit codes are used
389 for non-test related failures (for example a user error or an internal program
397 The inputs passed to :program:`lit` can be either individual tests, or entire
398 directories or hierarchies of tests to run. When :program:`lit` starts up, the
399 first thing it does is convert the inputs into a complete list of tests to run
400 as part of *test discovery*.
402 In the :program:`lit` model, every test must exist inside some *test suite*.
403 :program:`lit` resolves the inputs specified on the command line to test suites
404 by searching upwards from the input path until it finds a :file:`lit.cfg` or
405 :file:`lit.site.cfg` file. These files serve as both a marker of test suites
406 and as configuration files which :program:`lit` loads in order to understand
407 how to find and run the tests inside the test suite.
409 Once :program:`lit` has mapped the inputs into test suites it traverses the
410 list of inputs adding tests for individual files and recursively searching for
411 tests in directories.
413 This behavior makes it easy to specify a subset of tests to run, while still
414 allowing the test suite configuration to control exactly how tests are
415 interpreted. In addition, :program:`lit` always identifies tests by the test
416 suite they are in, and their relative path inside the test suite. For
417 appropriately configured projects, this allows :program:`lit` to provide
418 convenient and flexible support for out-of-tree builds.
420 .. _test-status-results:
425 Each test ultimately produces one of the following eight results:
433 The test succeeded after being re-run more than once. This only applies to
434 tests containing an ``ALLOW_RETRIES:`` annotation.
438 The test failed, but that is expected. This is used for test formats which allow
439 specifying that a test does not currently work, but wish to leave it in the test
444 The test succeeded, but it was expected to fail. This is used for tests which
445 were specified as expected to fail, but are now succeeding (generally because
446 the feature they test was broken and has been fixed).
454 The test result could not be determined. For example, this occurs when the test
455 could not be run, the test itself is invalid, or the test was interrupted.
459 The test is not supported in this environment. This is used by test formats
460 which can report unsupported tests.
464 The test was run, but it timed out before it was able to complete. This is
465 considered a failure.
467 Depending on the test format tests may produce additional information about
468 their status (generally only for failures). See the :ref:`output-options`
469 section for more information.
471 .. _lit-infrastructure:
476 This section describes the :program:`lit` testing architecture for users interested in
477 creating a new :program:`lit` testing implementation, or extending an existing one.
479 :program:`lit` proper is primarily an infrastructure for discovering and running
480 arbitrary tests, and to expose a single convenient interface to these
481 tests. :program:`lit` itself doesn't know how to run tests, rather this logic is
482 defined by *test suites*.
487 As described in :ref:`test-discovery`, tests are always located inside a *test
488 suite*. Test suites serve to define the format of the tests they contain, the
489 logic for finding those tests, and any additional information to run the tests.
491 :program:`lit` identifies test suites as directories containing ``lit.cfg`` or
492 ``lit.site.cfg`` files (see also :option:`--config-prefix`). Test suites are
493 initially discovered by recursively searching up the directory hierarchy for
494 all the input files passed on the command line. You can use
495 :option:`--show-suites` to display the discovered test suites at startup.
497 Once a test suite is discovered, its config file is loaded. Config files
498 themselves are Python modules which will be executed. When the config file is
499 executed, two important global variables are predefined:
503 The global **lit** configuration object (a *LitConfig* instance), which defines
504 the builtin test formats, global configuration parameters, and other helper
505 routines for implementing test configurations.
509 This is the config object (a *TestingConfig* instance) for the test suite,
510 which the config file is expected to populate. The following variables are also
511 available on the *config* object, some of which must be set by the config and
512 others are optional or predefined:
514 **name** *[required]* The name of the test suite, for use in reports and
517 **test_format** *[required]* The test format object which will be used to
518 discover and run tests in the test suite. Generally this will be a builtin test
519 format available from the *lit.formats* module.
521 **test_source_root** The filesystem path to the test suite root. For out-of-dir
522 builds this is the directory that will be scanned for tests.
524 **test_exec_root** For out-of-dir builds, the path to the test suite root inside
525 the object directory. This is where tests will be run and temporary output files
528 **environment** A dictionary representing the environment to use when executing
531 **standalone_tests** When true, mark a directory with tests expected to be run
532 standalone. Test discovery is disabled for that directory. *lit.suffixes* and
533 *lit.excludes* must be empty when this variable is true.
535 **suffixes** For **lit** test formats which scan directories for tests, this
536 variable is a list of suffixes to identify test files. Used by: *ShTest*.
538 **substitutions** For **lit** test formats which substitute variables into a test
539 script, the list of substitutions to perform. Used by: *ShTest*.
541 **unsupported** Mark an unsupported directory, all tests within it will be
542 reported as unsupported. Used by: *ShTest*.
544 **parent** The parent configuration, this is the config object for the directory
545 containing the test suite, or None.
547 **root** The root configuration. This is the top-most :program:`lit` configuration in
550 **pipefail** Normally a test using a shell pipe fails if any of the commands
551 on the pipe fail. If this is not desired, setting this variable to false
552 makes the test fail only if the last command in the pipe fails.
554 **available_features** A set of features that can be used in `XFAIL`,
555 `REQUIRES`, and `UNSUPPORTED` directives.
560 Once test suites are located, :program:`lit` recursively traverses the source
561 directory (following *test_source_root*) looking for tests. When :program:`lit`
562 enters a sub-directory, it first checks to see if a nested test suite is
563 defined in that directory. If so, it loads that test suite recursively,
564 otherwise it instantiates a local test config for the directory (see
565 :ref:`local-configuration-files`).
567 Tests are identified by the test suite they are contained within, and the
568 relative path inside that suite. Note that the relative path may not refer to
569 an actual file on disk; some test formats (such as *GoogleTest*) define
570 "virtual tests" which have a path that contains both the path to the actual
571 test file and a subpath to identify the virtual test.
573 .. _local-configuration-files:
575 LOCAL CONFIGURATION FILES
576 ~~~~~~~~~~~~~~~~~~~~~~~~~
578 When :program:`lit` loads a subdirectory in a test suite, it instantiates a
579 local test configuration by cloning the configuration for the parent directory
580 --- the root of this configuration chain will always be a test suite. Once the
581 test configuration is cloned :program:`lit` checks for a *lit.local.cfg* file
582 in the subdirectory. If present, this file will be loaded and can be used to
583 specialize the configuration for each individual directory. This facility can
584 be used to define subdirectories of optional tests, or to change other
585 configuration parameters --- for example, to change the test format, or the
586 suffixes which identify test files.
591 :program:`lit` allows patterns to be substituted inside RUN commands. It also
592 provides the following base set of substitutions, which are defined in
595 ======================= ==============
597 ======================= ==============
598 %s source path (path to the file currently being run)
599 %S source dir (directory of the file currently being run)
601 %{pathsep} path separator
602 %{fs-src-root} root component of file system paths pointing to the LLVM checkout
603 %{fs-tmp-root} root component of file system paths pointing to the test's temporary directory
604 %{fs-sep} file system path separator
605 %t temporary file name unique to the test
606 %basename_t The last path component of %t but without the ``.tmp`` extension (deprecated, use ``%{t:stem}`` instead)
607 %T parent directory of %t (not unique, deprecated, do not use)
609 %/s %s but ``\`` is replaced by ``/``
610 %/S %S but ``\`` is replaced by ``/``
611 %/p %p but ``\`` is replaced by ``/``
612 %/t %t but ``\`` is replaced by ``/``
613 %/T %T but ``\`` is replaced by ``/``
614 %{s:basename} The last path component of %s
615 %{t:stem} The last path component of %t but without the ``.tmp`` extension (alias for %basename_t)
616 %{s:real} %s after expanding all symbolic links and substitute drives
617 %{S:real} %S after expanding all symbolic links and substitute drives
618 %{p:real} %p after expanding all symbolic links and substitute drives
619 %{t:real} %t after expanding all symbolic links and substitute drives
620 %{T:real} %T after expanding all symbolic links and substitute drives
621 %{/s:real} %/s after expanding all symbolic links and substitute drives
622 %{/S:real} %/S after expanding all symbolic links and substitute drives
623 %{/p:real} %/p after expanding all symbolic links and substitute drives
624 %{/t:real} %/t after expanding all symbolic links and substitute drives
625 %{/T:real} %/T after expanding all symbolic links and substitute drives
626 %{/s:regex_replacement} %/s but escaped for use in the replacement of a ``s@@@`` command in sed
627 %{/S:regex_replacement} %/S but escaped for use in the replacement of a ``s@@@`` command in sed
628 %{/p:regex_replacement} %/p but escaped for use in the replacement of a ``s@@@`` command in sed
629 %{/t:regex_replacement} %/t but escaped for use in the replacement of a ``s@@@`` command in sed
630 %{/T:regex_replacement} %/T but escaped for use in the replacement of a ``s@@@`` command in sed
631 %:s On Windows, %/s but a ``:`` is removed if its the second character.
632 Otherwise, %s but with a single leading ``/`` removed.
633 %:S On Windows, %/S but a ``:`` is removed if its the second character.
634 Otherwise, %S but with a single leading ``/`` removed.
635 %:p On Windows, %/p but a ``:`` is removed if its the second character.
636 Otherwise, %p but with a single leading ``/`` removed.
637 %:t On Windows, %/t but a ``:`` is removed if its the second character.
638 Otherwise, %t but with a single leading ``/`` removed.
639 %:T On Windows, %/T but a ``:`` is removed if its the second character.
640 Otherwise, %T but with a single leading ``/`` removed.
641 ======================= ==============
643 Other substitutions are provided that are variations on this base set and
644 further substitution patterns can be defined by each test module. See the
645 modules :ref:`local-configuration-files`.
647 More detailed information on substitutions can be found in the
648 :doc:`../TestingGuide`.
650 TEST RUN OUTPUT FORMAT
651 ~~~~~~~~~~~~~~~~~~~~~~
653 The :program:`lit` output for a test run conforms to the following schema, in
654 both short and verbose modes (although in short mode no PASS lines will be
655 shown). This schema has been chosen to be relatively easy to reliably parse by
656 a machine (for example in buildbot log scraping), and for other tools to
659 Each test result is expected to appear on a line that matches:
663 <result code>: <test name> (<progress info>)
665 where ``<result-code>`` is a standard test result such as PASS, FAIL, XFAIL,
666 XPASS, UNRESOLVED, or UNSUPPORTED. The performance result codes of IMPROVED and
667 REGRESSED are also allowed.
669 The ``<test name>`` field can consist of an arbitrary string containing no
672 The ``<progress info>`` field can be used to report progress information such
673 as (1/300) or can be empty, but even when empty the parentheses are required.
675 Each test result may include additional (multiline) log information in the
680 <log delineator> TEST '(<test name>)' <trailing delineator>
684 where ``<test name>`` should be the name of a preceding reported test, ``<log
685 delineator>`` is a string of "*" characters *at least* four characters long
686 (the recommended length is 20), and ``<trailing delineator>`` is an arbitrary
689 The following is an example of a test run output which consists of four tests A,
690 B, C, and D, and a log message for the failing test C:
697 ******************** TEST 'C' FAILED ********************
698 Test 'C' failed as a result of exit code 1.
705 For convenience :program:`lit` automatically adds **available_features** for
706 some common use cases.
708 :program:`lit` adds a feature based on the operating system being built on, for
709 example: `system-darwin`, `system-linux`, etc. :program:`lit` also
710 automatically adds a feature based on the current architecture, for example
711 `target-x86_64`, `target-aarch64`, etc.
713 When building with sanitizers enabled, :program:`lit` automatically adds the
714 short name of the sanitizer, for example: `asan`, `tsan`, etc.
716 To see the full list of features that can be added, see
717 *llvm/utils/lit/lit/llvm/config.py*.
722 The :program:`lit` distribution contains several example implementations of
723 test suites in the *ExampleTests* directory.