LIT(1)

πŸ“¦
version 16.0.6 Β· 3 versions
, in ubuntu noble

πŸ’– NAME πŸ’–

lit β€” the LLVM Integrated Tester πŸ§ͺ✨ your ride-or-die bestie for running LLVM and Clang style test suites, no cap.


πŸ“œ SYNOPSIS πŸ“œ

lit [options] [tests]

🌸 DESCRIPTION 🌸

Okay so, lit is a portable tool for executing LLVM and Clang style test suites, summarizing their results, and giving you a lil indication of failures. πŸ’… It's designed to be a lightweight testing tool with as simple a user interface as possible β€” lowkey iconic behaviour honestly.

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

Each specified test gets executed (potentially concurrently, we love multitasking πŸ‘‘) and once all the tests have been run, lit prints summary info on the number of tests that passed or failed (see TEST STATUS RESULTS). And heads up: lit will exit with a non-zero exit code if any tests fail. Not me being dramatic, that's just the rules. 😀

By default, lit uses a succinct progress display and only prints summary info for test failures. Check OUTPUT OPTIONS for the options controlling the lit progress display and output.

lit also has a bunch of options for controlling how tests are executed β€” though specific features may depend on the particular test format. See EXECUTION OPTIONS for more.

And finally, lit supports additional options for only running a subset of the options specified on the command line. See SELECTION OPTIONS, go off. πŸŽ€

Real talk: 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. 🫢

lit can also read options from response files, which are specified as inputs using the @path/to/file.rsp syntax. Arguments read from a file must be one per line and are treated as if they were in the same place as the original file referencing argument on the command line. And yes bestie, a response file can reference other response files. πŸͺ†βœ¨

If you're interested in the lit architecture, or you're designing a lit testing implementation, you should see LIT INFRASTRUCTURE. πŸ’œ


βš™οΈ GENERAL OPTIONS βš™οΈ

  • -h, --help β€” Show the lit help message. Your lil onboarding moment. 🌈
  • -j N, --workers=N β€” Run N tests in parallel. By default, this is automatically chosen to match the number of detected available CPUs. Multitasking main character energy fr fr. πŸ’…
  • --config-prefix=NAME β€” Search for NAME.cfg and NAME.site.cfg when searching for test suites, instead of lit.cfg and lit.site.cfg. Renaming the whole vibe, periodt.
  • -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, not me. πŸ™ˆ

πŸ“Ί OUTPUT OPTIONS πŸ“Ί

  • -q, --quiet β€” Suppress any output except for test failures. Shhh. 🀫
  • -s, --succinct β€” Show less output, for example don't show information on tests that pass. Also show a progress bar, unless --no-progress-bar is specified.
  • -v, --verbose β€” Show more information on test failures, for example the entire test output instead of just the test result. Tell me everything. πŸ‘€
  • -vv, --echo-all-commands β€” Echo all commands to stdout, as they are being executed. This can be valuable for debugging test failures, since 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. Everything everywhere all at once. ✨
  • --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. ⏱️ Who's the slowest? We're about to find out.
  • --ignore-fail β€” Exit with status zero even if some tests fail. Gaslighting the exit code, honestly. 😌
  • --no-indirectly-run-check β€” Do not error if a test would not be run if the user had specified the containing directory instead of naming the test directly.

🎯 SELECTION OPTIONS 🎯

By default, lit will run failing tests first, then run tests in descending execution time order to optimize concurrency. The execution order can be changed using the --order option. πŸ”₯

The timing data is stored in the test_exec_root in a file named .lit_test_times.txt. If this file does not exist, then lit checks the test_source_root for the file to optionally accelerate clean builds. πŸ¦‹

  • --shuffle β€” Run the tests in a random order, not failing/slowest first. Deprecated, use --order instead. πŸ‘€
  • --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. Enough is enough. πŸ’€
  • --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. Don't get it twisted bestie. πŸ™ˆ
  • --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). 🚜
  • --order={lexical,random,smart} β€” Define the order in which tests are run. The supported values are:
    • lexical β€” tests will be run in lexical order according to the test file path. This option is useful when predictable test order is desired.
    • random β€” tests will be run in random order.
    • smart β€” tests that failed previously will be run first, then the remaining tests, all in descending execution time order. This is the default as it optimizes concurrency. 🧠✨
  • --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.
  • --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. 🎣
  • --filter-out=REGEXP β€” Filter out those tests whose name matches the regular expression specified in REGEXP. The environment variable LIT_FILTER_OUT can be also used in place of this option, which is especially useful in environments where the call to lit is issued indirectly.
  • --xfail=LIST β€” Treat those tests whose name is in the semicolon separated list LIST as XFAIL. This can be helpful when one does not want to modify the test suite. The environment variable LIT_XFAIL can be also used in place of this option, which is especially useful in environments where the call to lit is issued indirectly.

A test name can specified as a file name relative to the test suite directory. For example:

LIT_XFAIL="affinity/kmp-hw-subset.c;offloading/memory_manager.cpp"

In this case, all of the following tests are treated as XFAIL:

libomp :: affinity/kmp-hw-subset.c
libomptarget :: nvptx64-nvidia-cuda :: offloading/memory_manager.cpp
libomptarget :: x86_64-pc-linux-gnu :: offloading/memory_manager.cpp

Alternatively, a test name can be specified as the full test name reported in LIT output. For example, we can adjust the previous example not to treat the nvptx64-nvidia-cuda version of offloading/memory_manager.cpp as XFAIL:

LIT_XFAIL="affinity/kmp-hw-subset.c;libomptarget :: x86_64-pc-linux-gnu :: offloading/memory_manager.cpp"
  • --xfail-not=LIST β€” Do not treat the specified tests as XFAIL. The environment variable LIT_XFAIL_NOT can also be used in place of this option. The syntax is the same as for --xfail and LIT_XFAIL. --xfail-not and LIT_XFAIL_NOT always override all other XFAIL specifications, including an --xfail appearing later on the command line. The primary purpose is to suppress an XPASS result without modifying a test case that uses the XFAIL directive. 🚫

🌟 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). Those ones are giving "not the tests' fault" energy. 😭

πŸ” TEST DISCOVERY πŸ”

okay so bestie, here's the tea on how lit figures out what you even want to run πŸ’…

The inputs you hand to lit can be individual tests, or whole directories, or entire hierarchies of tests. When lit starts up, the very first thing it does is turn your inputs into one complete list of tests to run. That whole process? That's test discovery, and it's giving main character energy from second one ✨

In the lit model, every test has to live inside some test suite. No suite, no test, periodt. lit maps your command-line inputs onto test suites by searching upwards from the input path until it bumps into a lit.cfg or lit.site.cfg file. Those files are doing double duty, bestie β€” they're both the marker that says "a test suite lives here" and the config files lit loads to understand how to find and run the tests inside that suite πŸŽ€

Once lit has mapped the inputs onto test suites, it walks the list of inputs, adding tests for individual files and recursively searching directories for more tests πŸ¦‹

Why is this iconic? Because it makes it so easy to specify just a subset of tests to run, while the test suite configuration still gets to control exactly how tests are interpreted. And on top of that, lit always identifies tests by the test suite they're in plus their relative path inside that suite. For appropriately configured projects, that means convenient and flexible support for out-of-tree builds. slay πŸ’–


πŸ’– TEST STATUS RESULTS πŸ’–

Every test ends up producing one of these eight results. Eight! Count them, bestie πŸ”₯

  • PASS β€” the test succeeded. we love to see it πŸ‘‘
  • FLAKYPASS β€” the test succeeded, but only after being re-run more than once. This one only applies to tests containing an ALLOW_RETRIES: annotation. it took a few tries but she got there 😭
  • XFAIL β€” the test failed, and that's expected. This is for test formats that let you say "yeah this test doesn't currently work" while still wanting to leave it in the test suite. it's not broken, it's curated πŸ’…
  • XPASS β€” the test succeeded, but it was expected to fail. Used for tests marked as expected-to-fail that are now passing (generally because the feature they test was broken and has since been fixed). surprise! πŸŽ‰
  • FAIL β€” the test failed. that's it. that's the whole thing πŸ’€
  • UNRESOLVED β€” the test result could not be determined. For example, this happens when the test couldn't be run, when the test itself is invalid, or when the test got interrupted. it's giving mystery 🫠
  • UNSUPPORTED β€” the test is not supported in this environment. Used by test formats that can report unsupported tests.
  • TIMEOUT β€” the test ran, but it timed out before it could complete. And heads up: this one counts as a failure. no cap 🚨

Depending on the test format, tests may also produce extra info about their status (generally only for failures, because of course). Peep the OUTPUT OPTIONS section for more on that πŸ‘€


πŸ› οΈ LIT INFRASTRUCTURE πŸ› οΈ

This section is for the builders, the tinkerers, the "I want to make my own thing" girlies 🌈 It describes the lit testing architecture for users who are interested in creating a brand new lit testing implementation, or extending one that already exists.

Here's the vibe: lit proper is primarily an infrastructure for discovering and running arbitrary tests, and for exposing a single convenient interface to those tests. lit itself doesn't know how to run tests β€” that logic is defined by test suites. she's a platform, not a performer ✨

TEST SUITES

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

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. And if you want to see what got discovered, you can use --show-suites to display the discovered test suites at startup. very demure, very transparent πŸŽ€

Once a test suite is discovered, its config file gets loaded. And plot twist: config files are themselves Python modules which will be executed πŸ‘‘ When the config file is executed, two important global variables are predefined for you:

  • lit_config β€” the global lit configuration object (a LitConfig instance), which defines the builtin test formats, global configuration parameters, and other helper routines for implementing test configurations.
  • config β€” the config object (a TestingConfig instance) for the test suite, which the config file is expected to populate.

The following variables are also available on the config object. Some of them must be set by the config, and the others are optional or predefined. buckle up, it's a list πŸ’–

  • 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.
  • standalone_tests β€” when true, mark a directory with tests expected to be run standalone. Test discovery is disabled for that directory and --no-indirectly-run-check is in effect. lit.suffixes and lit.excludes must be empty when this variable is true. ⚠️
  • 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 that's not what you want, 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, the first thing it checks is whether a nested test suite is defined in that directory. If so, it loads that test suite recursively. If not, it instantiates a local test config for the directory (see LOCAL CONFIGURATION FILES below) πŸ¦‹

Tests are identified by the test suite they're contained within, plus the relative path inside that suite. And heads up, bestie: that relative path may not refer to an actual file on disk. Some test formats (like GoogleTest) define "virtual tests" whose path contains both the path to the actual test file and a subpath to identify the virtual test. sneaky but valid πŸ’…

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 β€” and the root of that configuration chain will always be a test suite, no exceptions. Once the test configuration is cloned, lit checks for a lit.local.cfg file in the subdirectory. If it's there, that file gets loaded and can be used to specialize the configuration for each individual directory 🌸

What's this facility good for? Defining subdirectories of optional tests, or changing other configuration parameters β€” for example, changing the test format, or changing the suffixes which identify test files. it's your little per-directory glow-up πŸ’–βœ¨

πŸ’– SUBSTITUTIONS πŸ’–

okay bestie, this is the good part. lit lets you substitute patterns right inside your RUN commands ✨ It also hands you this whole base set of substitutions for free, and they're all defined in TestRunner.py:

  • %s β€” the source path, aka the path to the file that's currently being run 🫢
  • %S β€” the source dir, aka the directory of the file that's currently being run
  • %p β€” literally just %S again, same thing πŸ’…
  • %{pathsep} β€” the path separator
  • %{fs-src-root} β€” the root component of file system paths that point to the LLVM checkout
  • %{fs-tmp-root} β€” the root component of file system paths that point to the test's temporary directory
  • %{fs-sep} β€” the file system 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. NOT unique, deprecated, do NOT use πŸ™ˆ
  • %% β€” just a literal %
  • %/s β€” %s but every \ is replaced by /
  • %/S β€” %S but every \ is replaced by /
  • %/p β€” %p but every \ is replaced by /
  • %/t β€” %t but every \ is replaced by /
  • %/T β€” %T but every \ is replaced by /
  • %{/s:regex_replacement} β€” %/s but escaped so you can use it in the replacement of a s@@@ command in sed 🌸
  • %{/S:regex_replacement} β€” %/S but escaped so you can use it in the replacement of a s@@@ command in sed
  • %{/p:regex_replacement} β€” %/p but escaped so you can use it in the replacement of a s@@@ command in sed
  • %{/t:regex_replacement} β€” %/t but escaped so you can use it in the replacement of a s@@@ command in sed
  • %{/T:regex_replacement} β€” %/T but escaped so you can use it in the replacement of a s@@@ command in sed
  • %:s β€” on Windows, this is %/s but a : gets removed if it's the second character. Otherwise, it's %s but with a single leading / removed.
  • %:S β€” on Windows, this is %/S but a : gets removed if it's the second character. Otherwise, it's %S but with a single leading / removed.
  • %:p β€” on Windows, this is %/p but a : gets removed if it's the second character. Otherwise, it's %p but with a single leading / removed.
  • %:t β€” on Windows, this is %/t but a : gets removed if it's the second character. Otherwise, it's %t but with a single leading / removed.
  • %:T β€” on Windows, this is %/T but a : gets removed if it's the second character. Otherwise, it's %T but with a single leading / removed.

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

wanna go deeper on substitutions? The LLVM Testing Infrastructure Guide has the full lore πŸ“š

🌈 TEST RUN OUTPUT FORMAT 🌈

The lit output for a test run follows this schema, in both short and verbose modes (tho in short mode you won't see any PASS lines at all, fyi). This schema was picked to be relatively easy for a machine to reliably parse β€” think buildbot log scraping β€” and easy for other tools to generate πŸ¦‹

Every test result is expected to show up 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 allowed too ⭐

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

The <progress info> field can report progress info like (1/300), or it can be empty β€” but even when it's empty, the parentheses are required, no cap πŸ’…

Each test result may also include extra (multiline) log information in this format:

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

Okay so the last three placeholders you're gonna see in those generated log headers are these little cuties:

  • <test name> β€” literally just the name of a test that got reported before this line. It has to have shown up already, no sneaking in new names πŸ’…
  • <log delineator> β€” a string made of * characters, and it has to be at least four characters long. The recommended length is 20. (Yes bestie, four asterisks is the bare minimum and it's giving "I woke up five minutes before class" energy β€” just use 20.) ✨
  • <trailing delineator> β€” an arbitrary string. Arbitrary! It is not parsed, so it can be whatever you want. Nobody's reading it. It's just vibes. πŸ¦‹

So here's what a test run output looks like when it's got four tests β€” A, B, C, and D β€” and test C fails and drops a log message:

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)

See how the delineators are exactly 20 * on each side? Iconic. Consistent. Obsessed. πŸ‘‘

🌸 LIT EXAMPLE TESTS 🌸

Not sure where to start with your own suite? Say less. The lit distribution ships with several example implementations of test suites, all hanging out in the ExampleTests directory. Go peek, copy the vibe, make it yours πŸŽ€


πŸ‘€ SEE ALSO πŸ‘€

(yeah, that's it. one friend. but a solid one.)


πŸ’– AUTHOR πŸ’–

Maintained by the LLVM Team (https://llvm.org/). They keep this thing alive fr fr πŸ™


2003-2024, LLVM Project


And that's a wrap on lit(1), bestie πŸ’…βœ¨ This page is from the LIT(1) manual, dated 2024-04-14. Now go write some tests, run some suites, and may all your failures come with a nice 20-asterisk delineator πŸŒˆπŸ’€

πŸ“¦ where this page comes from