LIT(1)

πŸ“¦
version 11.1.0 Β· 2 versions
, in fedora 43, fedora 44

lit(1) β€” LLVM Integrated Tester πŸ’…βœ¨

✨ NAME ✨

lit β€” the LLVM Integrated Tester. That's the name, bestie. Short, iconic, does exactly what it says on the tin. πŸ’–

πŸ“œ SYNOPSIS πŸ“œ

lit [options] [tests]

πŸ’– DESCRIPTION πŸ’–

Okay so lit is this portable tool for executing LLVM and Clang style test suites, summarizing their results, and giving you a lil indication of failures. The whole point? It's a lightweight testing tool with as simple a user interface as possible. Lowkey obsessed.

You run lit with one or more tests to run specified on the command line. Those tests can be individual test files, or directories to search for tests (peep TEST DISCOVERY for the deets).

Each test you specified gets executed (potentially in parallel, because multitasking is main character energy), and once all tests have run, lit prints summary info on how many tests passed or failed (see TEST STATUS RESULTS). And if any tests fail? The lit program will execute with a non-zero exit code. Not it being dramatic, it's just honest.

By default lit uses a succinct progress display and only prints summary info for test failures. See OUTPUT OPTIONS for the options that control the lit progress display and output.

lit also has a bunch of options for controlling how tests are executed (specific features may depend on the particular test format). See EXECUTION OPTIONS for more info.

Finally, lit supports extra options for only running a subset of the options specified on the command line. See SELECTION OPTIONS for more info.

lit parses options from the environment variable LIT_OPTS after parsing options from the command line. LIT_OPTS is primarily useful for supplementing or overriding the command-line options supplied to lit by check targets defined by a project's build system.

If you're interested in the lit architecture or designing a lit testing implementation, go look at LIT INFRASTRUCTURE. That's where the lore lives.


πŸŽ€ GENERAL OPTIONS πŸŽ€

  • -h, --help β€” Show the lit help message. Slay.
  • -j N, --workers=N β€” Run N tests in parallel. By default, this is automatically chosen to match the number of detected available CPUs. Let the machine cook.
  • --config-prefix=NAME β€” Search for NAME.cfg and NAME.site.cfg when searching for test suites, instead of lit.cfg and lit.site.cfg.
  • -D NAME[=VALUE], --param NAME[=VALUE] β€” Add a user defined parameter NAME with the given VALUE (or the empty string if not given). The meaning and use of these parameters is test suite dependent. So, like, ask your test suite.

🌸 OUTPUT OPTIONS 🌸

  • -q, --quiet β€” Suppress any output except for test failures. Peace and quiet, but make it failing tests only.
  • -s, --succinct β€” Show less output, for example don't show information on tests that pass. We love a minimalist moment.
  • -v, --verbose β€” Show more information on test failures, for example the entire test output instead of just the test result. Give me the whole story.
  • -vv, --echo-all-commands β€” Echo all commands to stdout, as they are being executed. This can be valuable for debugging test failures, as the last echoed command will be the one which has failed. lit normally inserts a no-op command (: in the case of bash) with argument 'RUN: at line N' before each command pipeline, and this option also causes those no-op commands to be echoed to stdout to help you locate the source line of the failed command. This option implies --verbose.
  • -a, --show-all β€” Show more information about all tests, for example the entire test commandline and output.
  • --no-progress-bar β€” Do not use curses based progress bar. Bye bye lil bar.
  • --show-unsupported β€” Show the names of unsupported tests.
  • --show-xfail β€” Show the names of tests that were expected to fail.

πŸ”₯ EXECUTION OPTIONS πŸ”₯

  • --path=PATH β€” Specify an additional PATH to use when searching for executables in tests.
  • --vg β€” Run individual tests under valgrind (using the memcheck tool). The --error-exitcode argument for valgrind is used so that valgrind failures will cause the program to exit with a non-zero status.

When this option is enabled, lit will also automatically provide a "valgrind" feature that can be used to conditionally disable (or expect failure in) certain tests.

  • --vg-arg=ARG β€” When --vg is used, specify an additional argument to pass to valgrind itself.
  • --vg-leak β€” When --vg is used, enable memory leak checks. When this option is enabled, lit will also automatically provide a "vg_leak" feature that can be used to conditionally disable (or expect failure in) certain tests.
  • --time-tests β€” Track the wall time individual tests take to execute and includes the results in the summary output. This is useful for determining which tests in a test suite take the most time to execute. Note that this option is most useful with -j 1.

πŸ‘‘ SELECTION OPTIONS πŸ‘‘

  • --max-failures N β€” Stop execution after the given number N of failures. An integer argument should be passed on the command line prior to execution.
  • --max-tests=N β€” Run at most N tests and then terminate.
  • --max-time=N β€” Spend at most N seconds (approximately) running tests and then terminate. Note that this is not an alias for --timeout; the two are different kinds of maximums.
  • --num-shards=M β€” Divide the set of selected tests into M equal-sized subsets or "shards", and run only one of them. Must be used with the --run-shard=N option, which selects the shard to run. The environment variable LIT_NUM_SHARDS can also be used in place of this option. These two options provide a coarse mechanism for partitioning large testsuites, for parallel execution on separate machines (say in a large testing farm).
  • --run-shard=N β€” Select which shard to run, assuming the --num-shards=M option was provided. The two options must be used together, and the value of N must be in the range 1..M. The environment variable LIT_RUN_SHARD can also be used in place of this option.
  • --shuffle β€” Run the tests in a random order. Chaos mode.
  • --timeout=N β€” Spend at most N seconds (approximately) running each individual test. 0 means no time limit, and 0 is the default. Note that this is not an alias for --max-time; the two are different kinds of maximums.
  • --filter=REGEXP β€” Run only those tests whose name matches the regular expression specified in REGEXP. The environment variable LIT_FILTER can be also used in place of this option, which is especially useful in environments where the call to lit is issued indirectly.

πŸ¦‹ ADDITIONAL OPTIONS πŸ¦‹

  • --debug β€” Run lit in debug mode, for debugging configuration issues and lit itself.
  • --show-suites β€” List the discovered test suites and exit.
  • --show-tests β€” List all of the discovered tests and exit.

πŸ’€ EXIT STATUS πŸ’€

lit will exit with an exit code of 1 if there are any FAIL or XPASS results. Otherwise, it will exit with the status 0. Other exit codes are used for non-test related failures (for example a user error or an internal program error). So 0 = good vibes, 1 = test tears, other numbers = something else entirely.


🧚 TEST DISCOVERY 🧚

The inputs passed to lit can be either individual tests, or entire directories or hierarchies of tests to run. When lit starts up, the first thing it does is convert the inputs into a complete list of tests to run as part of test discovery.

In the lit model, every test must exist inside some test suite. lit resolves the inputs specified on the command line to test suites by searching upwards from the input path until it finds a lit.cfg or lit.site.cfg file. These files serve as both a marker of test suites and as configuration files which lit loads in order to understand how to find and run the tests inside the test suite.

Once lit has mapped the inputs into test suites it traverses the list of inputs adding tests for individual files and recursively searching for tests in directories.

This behavior makes it easy to specify a subset of tests to run, while still allowing the test suite configuration to control exactly how tests are interpreted. In addition, lit always identifies tests by the test suite they are in, and their relative path inside the test suite. For appropriately configured projects, this allows lit to provide convenient and flexible support for out-of-tree builds.

🌈 TEST STATUS RESULTS 🌈

Each test ultimately produces one of the following eight results:

  • PASS β€” The test succeeded. We love a win.
  • FLAKYPASS β€” The test succeeded after being re-run more than once. This only applies to tests containing an ALLOW_RETRIES: annotation.
  • XFAIL β€” The test failed, but that is expected. This is used for test formats which allow specifying that a test does not currently work, but wish to leave it in the test suite.
  • XPASS β€” The test succeeded, but it was expected to fail. This is used for tests which were specified as expected to fail, but are now succeeding (generally because the feature they test was broken and has been fixed).
  • FAIL β€” The test failed. Sad.
  • UNRESOLVED β€” The test result could not be determined. For example, this occurs when the test could not be run, the test itself is invalid, or the test was interrupted.
  • UNSUPPORTED β€” The test is not supported in this environment. This is used by test formats which can report unsupported tests.
  • TIMEOUT β€” The test was run, but it timed out before it was able to complete. This is considered a failure.

Depending on the test format tests may produce additional information about their status (generally only for failures). See the OUTPUT OPTIONS section for more information.

πŸ’œ LIT INFRASTRUCTURE πŸ’œ

This section describes the lit testing architecture for users interested in creating a new lit testing implementation, or extending an existing one.

lit proper is primarily an infrastructure for discovering and running arbitrary tests, and to expose a single convenient interface to these tests. lit itself doesn't know how to run tests, rather this logic is defined by test suites. It's giving "platform, not personality."

🫢 TEST SUITES 🫢

As described in TEST DISCOVERY, tests are always located inside a test suite. Test suites serve to define the format of the tests they contain, the logic for finding those tests, and any additional information to run the tests.

lit identifies test suites as directories containing lit.cfg or lit.site.cfg files (see also --config-prefix). Test suites are initially discovered by recursively searching up the directory hierarchy for all the input files passed on the command line. You can use --show-suites to display the discovered test suites at startup.

okay so once a test suite gets discovered, its config file gets loaded, periodt. πŸ’– and bestie, config files are literally Python modules that get executed. when that config file runs, two super important global variables are already pre-defined for you:

  • lit_config β€” the global lit configuration object (a LitConfig instance). it defines the builtin test formats, global configuration parameters, and other helper routines for implementing test configurations. ✨
  • config β€” this is the config object (a TestingConfig instance) for the test suite, and the config file is expected to populate it. the following variables are also available on the config object, some of which must be set by the config and others are optional or predefined:
    • name [required] β€” the name of the test suite, for use in reports and diagnostics. πŸ‘‘
    • test_format [required] β€” the test format object which will be used to discover and run tests in the test suite. generally this will be a builtin test format available from the lit.formats module. 🧚
    • test_source_root β€” the filesystem path to the test suite root. for out-of-dir builds this is the directory that will be scanned for tests. πŸ“
    • test_exec_root β€” for out-of-dir builds, the path to the test suite root inside the object directory. this is where tests will be run and temporary output files placed. πŸ”₯
    • environment β€” a dictionary representing the environment to use when executing tests in the suite. 🌈
    • suffixes β€” for lit test formats which scan directories for tests, this variable is a list of suffixes to identify test files. used by: ShTest. πŸ’…
    • substitutions β€” for lit test formats which substitute variables into a test script, the list of substitutions to perform. used by: ShTest. πŸŽ€
    • unsupported β€” mark an unsupported directory, all tests within it will be reported as unsupported. used by: ShTest. 🚫
    • parent β€” the parent configuration, this is the config object for the directory containing the test suite, or None. πŸ‘ͺ
    • root β€” the root configuration. this is the top-most lit configuration in the project. 🌳
    • pipefail β€” normally a test using a shell pipe fails if any of the commands on the pipe fail. if this is not desired, setting this variable to false makes the test fail only if the last command in the pipe fails. πŸ’€
    • available_features β€” a set of features that can be used in XFAIL, REQUIRES, and UNSUPPORTED directives. ⭐

✨ TEST DISCOVERY ✨

once test suites are located, lit recursively traverses the source directory (following test_source_root) looking for tests. when lit enters a sub-directory, it first checks to see if a nested test suite is defined in that directory. if so, it loads that test suite recursively, otherwise it instantiates a local test config for the directory (see LOCAL CONFIGURATION FILES). πŸ¦‹

tests are identified by the test suite they are contained within, and the relative path inside that suite. note that the relative path may not refer to an actual file on disk; some test formats (such as GoogleTest) define "virtual tests" which have a path that contains both the path to the actual test file and a subpath to identify the virtual test. πŸ‘€


✨ LOCAL CONFIGURATION FILES ✨

when lit loads a subdirectory in a test suite, it instantiates a local test configuration by cloning the configuration for the parent directory --- the root of this configuration chain will always be a test suite. once the test configuration is cloned lit checks for a lit.local.cfg file in the subdirectory. if present, this file will be loaded and can be used to specialize the configuration for each individual directory. this facility can be used to define subdirectories of optional tests, or to change other configuration parameters --- for example, to change the test format, or the suffixes which identify test files. πŸ’–


πŸ¦‹ SUBSTITUTIONS πŸ¦‹

lit lets you swap patterns inside your RUN commands, bestie. And it comes with a whole base set of substitutions baked in, all defined in TestRunner.py. Here's the entire roster, no gatekeeping:

  • %s β€” source path, aka the path to the file that's currently being run πŸ’…
  • %S β€” source dir, aka the directory of the file currently being run
  • %p β€” literally the same thing as %S
  • %{pathsep} β€” the path separator
  • %t β€” a temporary file name that's unique to the test
  • %basename_t β€” the last path component of %t, but with the .tmp extension stripped off
  • %T β€” the parent directory of %t. It is not unique, it is deprecated, and honestly do not use it πŸ™ˆ
  • %% β€” just a %
  • %/s β€” %s but with \ replaced by /
  • %/S β€” %S but with \ replaced by /
  • %/p β€” %p but with \ replaced by /
  • %/t β€” %t but with \ replaced by /
  • %/T β€” %T but with \ replaced by /
  • %{/s:regex_replacement} β€” %/s but escaped so you can use it in the replacement of an s@@@ command in sed
  • %{/S:regex_replacement} β€” %/S but escaped so you can use it in the replacement of an s@@@ command in sed
  • %{/p:regex_replacement} β€” %/p but escaped so you can use it in the replacement of an s@@@ command in sed
  • %{/t:regex_replacement} β€” %/t but escaped so you can use it in the replacement of an s@@@ command in sed
  • %{/T:regex_replacement} β€” %/T but escaped so you can use it in the replacement of an s@@@ command in sed
  • %:s β€” on Windows, that's %/s but with a : removed if it's the second character. Otherwise it's %s but with a single leading / removed.
  • %:S β€” on Windows, that's %/S but with a : removed if it's the second character. Otherwise it's %S but with a single leading / removed.
  • %:p β€” on Windows, that's %/p but with a : removed if it's the second character. Otherwise it's %p but with a single leading / removed.
  • %:t β€” on Windows, that's %/t but with a : removed if it's the second character. Otherwise it's %t but with a single leading / removed.
  • %:T β€” on Windows, that's %/T but with a : removed if it's the second character. Otherwise it's %T but with a single leading / removed.

There are also other substitutions floating around that are just variations on this base set, and each test module can define even more of its own substitution patterns. Go peek at the modules LOCAL CONFIGURATION FILES for that πŸ‘‘


Now here's the tea on how expansion actually works. By default, substitutions get expanded exactly once. So if, say, a substitution %build is defined on top of another substitution %cxx, then %build expands to the literal text %cxx β€” not to whatever %cxx expands to. Textually, bestie, not recursively.

BUT. If the recursiveExpansionLimit property of the TestingConfig is set to a non-negative integer, substitutions will be expanded recursively until that limit is hit. And heads up: it's an error if the limit is reached and expanding the substitutions again would have given you a different result. So like, don't let it get weird 😭

Want the deep lore on substitutions? It lives in the LLVM Testing Infrastructure Guide.


✨ TEST RUN OUTPUT FORMAT ✨

The lit output for a test run follows this schema, in both short and verbose modes β€” though in short mode you won't see any PASS lines, periodt. This schema was deliberately chosen so a machine can reliably parse it (think buildbot log scraping πŸ‘€) and so other tools can generate it too.

Every test result should land on a line matching:

<result code>: <test name> (<progress info>)

where <result-code> is a standard test result like PASS, FAIL, XFAIL, XPASS, UNRESOLVED, or UNSUPPORTED. The performance result codes IMPROVED and REGRESSED are also allowed πŸ”₯

The <test name> field can be any arbitrary string, as long as there's no newline in it.

The <progress info> field is where you report progress info like (1/300), or you can leave it empty β€” but even when it's empty, the parentheses are required. No parentheses, no vibes πŸ’…

Every test result may also carry extra (multiline) log info, formatted like this:

<log delineator> TEST '(<test name>)' <trailing delineator>
... log message ...
<log delineator>

where <test name> should be the name of a preceding reported test, <log delineator> is a string of * characters at least four characters long (the recommended length is 20), and <trailing delineator> is an arbitrary (unparsed) string.

Here's a whole example test run output, consisting of four tests A, B, C, and D, plus a log message for the failing test C:

PASS: A (1 of 4)
PASS: B (2 of 4)
FAIL: C (3 of 4)
******************** TEST 'C' FAILED ********************
Test 'C' failed as a result of exit code 1.
********************
PASS: D (4 of 4)

πŸŽ€ LIT EXAMPLE TESTS πŸŽ€

The lit distribution ships with several example implementations of test suites, all chillin' in the ExampleTests directory. Go look, they're cute 🫢


🌈 SEE ALSO 🌈

valgrind(1)

✨ AUTHOR ✨

This absolute icon of a page is maintained by the LLVM Team β€” you can find them at https://llvm.org/. 🫢 Go say hi, they're doing the lord's work fr fr.


2003-2024, LLVM Project

That's the whole legal tea, bestie. Decades of collective slay. πŸ‘‘


and that's a wrap on lit(1)!! πŸŽ€ you made it all the way to the end, which is genuinely iconic behaviour. this was page 11 of the manuals, dated 2024-07-18 β€” so if you're reading this way in the future, hi, hope the tests are still passing. πŸ’…

go write some tests. go run lit. go be the main character of your own CI pipeline. periodt πŸŒˆβœ¨πŸ¦‹

πŸ“¦ where this page comes from