LIT(1)

πŸ“¦
version 13.0.1 Β· 5 versions
, in ubuntu jammy

πŸŽ€ NAME πŸŽ€

lit β€” from the LLVM fam, this is the LLVM Integrated Tester, aka lit(1). It’s a portable tool for executing LLVM and Clang style test suites, summarizing their results, and giving you a heads-up when things fail. It’s designed to be a lightweight testing tool with as simple a user interface as possible. Slay. ✨


✨ SYNOPSIS ✨

lit [options] [tests]

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so, you run lit with one or more tests to run specified on the command line. Those tests can be either individual test files or directories to search for tests β€” see TEST DISCOVERY.

Each specified test gets executed (potentially concurrently), and once all tests have been run, lit prints summary information on the number of tests which passed or failed β€” see TEST STATUS RESULTS. The lit program will execute with a non-zero exit code if any tests fail. No cap.

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

lit also includes a number 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 also supports additional options for only running a subset of the options specified on the command line β€” see SELECTION OPTIONS.

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. iykyk.

Users interested in the lit architecture or designing a lit testing implementation should see LIT INFRASTRUCTURE.


πŸ› οΈ GENERAL OPTIONS πŸ› οΈ

  • -h, --help β€” Show the lit help message. Bestie, start here if you’re lost. πŸ’…
  • -j N, --workers=N β€” Run N tests in parallel. By default, this is automatically chosen to match the number of detected available CPUs. parallelism is the vibe.
  • --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.

🌈 OUTPUT OPTIONS 🌈

  • -q, --quiet β€” Suppress any output except for test failures. quiet luxury.
  • -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.
  • -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.
  • --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.
  • --ignore-fail β€” Exit with status zero even if some tests fail. delulu but productive.
  • --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 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. chaotic good.
  • --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. important distinction, 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).
  • --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). know the difference, bestie.

πŸ” TEST DISCOVERY πŸ¦‹

Okay so bestie, here's the vibe: the inputs you pass to lit can be individual tests, or whole directories, or entire hierarchies of tests you want to run. And when lit boots up, the very first thing it does is turn those inputs into one complete list of tests to run. That whole process? That's test discovery. ✨

In the lit model, every test has to live inside some test suite β€” no strays, no orphans πŸ’…. So lit figures out which test suite your command-line inputs belong to by searching upwards from the input path until it finds a lit.cfg or lit.site.cfg file. Those files are double duty: they're the marker that says "yep, this is a test suite" AND they're config files that lit loads so it knows how to find and run the tests inside that suite.

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

This is what makes it so easy to say "just run this little subset" while the test suite config still gets to control exactly how tests are interpreted. And also β€” lit always identifies tests by the test suite they're in plus their relative path inside that suite. For projects configured the right way, that's what gives you convenient, flexible support for out-of-tree builds. Slay. πŸ”₯


🌸 TEST STATUS RESULTS 🌸

Every test ends up with one of these eight results, no cap:

  • PASS β€” the test succeeded πŸ’–
  • FLAKYPASS β€” the test succeeded after being re-run more than once. Heads up: this only applies to tests containing an ALLOW_RETRIES: annotation.
  • XFAIL β€” the test failed, but that's expected, so it's fine. This one's for test formats that let you say "yeah this doesn't work right now" while still keeping the test in the suite.
  • XPASS β€” the test succeeded but it was expected to fail. This is for tests marked as expected-to-fail that are now passing (usually because the feature they test was broken and got fixed). Surprise! πŸŽ‰
  • FAIL β€” the test failed 😭
  • UNRESOLVED β€” could not determine the test result. This happens, for example, when the test couldn't be run, when the test itself is invalid, or when the test got interrupted.
  • UNSUPPORTED β€” the test isn't supported in this environment. Used by test formats that can report unsupported tests.
  • TIMEOUT β€” the test ran, but it timed out before it could finish. And yeah, this counts as a failure. πŸ’€

Depending on the test format, tests may also produce extra info about their status (usually only for failures). Peep the OUTPUT OPTIONS section for more on that.


πŸ‘‘ LIT INFRASTRUCTURE πŸ‘‘

This section is for you if you're interested in creating a new lit testing implementation, or extending one that already exists. It's the whole architecture tour, bestie.

lit proper is primarily an infrastructure for discovering and running arbitrary tests, and for exposing one single convenient interface to all of them. lit itself doesn't actually know how to run tests β€” that logic is defined by test suites. 🧚

πŸ’œ TEST SUITES

Like we said in TEST DISCOVERY, tests are always located inside a test suite. A test suite defines the format of the tests it contains, the logic for finding those tests, and any additional info 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 found initially by recursively searching up the directory hierarchy for all the input files you passed on the command line. Wanna see them? Use --show-suites to display the discovered test suites at startup. 🌈

Once a test suite is discovered, its config file gets loaded. Config files are literally Python modules that will be executed. When the config file runs, two important global variables are predefined for it:

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

This is 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, others are optional or predefined:

  • name [required] β€” the name of the test suite, used in reports and diagnostics.
  • test_format [required] β€” the test format object that'll be used to discover and run tests in the test suite. Generally this is 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 get run and where temporary output files get 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. Also: lit.suffixes and lit.excludes must be empty when this variable is true.
  • suffixes β€” for lit test formats that scan directories for tests, this is a list of suffixes used to identify test files. Used by: ShTest.
  • substitutions β€” for lit test formats that substitute variables into a test script, the list of substitutions to perform. Used by: ShTest.
  • unsupported β€” mark a directory as unsupported; all tests within it will be reported as unsupported. Used by: ShTest.
  • parent β€” the parent configuration, i.e. 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, it first checks whether a nested test suite is defined in that directory. If it is, it loads that test suite recursively; if not, it instantiates a local test config for that directory (see LOCAL CONFIGURATION FILES).

Tests are identified by the test suite they're contained in and the relative path inside that suite. Quick note though: the relative path might 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 identifying the virtual test. πŸ¦‹

🫢 LOCAL CONFIGURATION FILES

When lit loads a subdirectory inside a test suite, it instantiates a local test configuration by cloning the configuration of the parent directory β€” and the root of that configuration chain is always a test suite. 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 specialize the configuration for each individual directory. πŸ’–

This is genuinely so handy: use it to define subdirectories of optional tests, or to change other configuration parameters β€” for example, to change the test format, or the suffixes that identify test files. iykyk. ✨

🌸 SUBSTITUTIONS 🌸

ok so lit literally lets you sub patterns inside RUN commands?? and it also ships with this whole base set of substitutions that are defined in TestRunner.py πŸ’… here's the entire lineup, no skips:

  • %s β€” source path, aka the path to the file that's currently being run 🫢
  • %S β€” source dir, aka the directory of the file that's 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 (not unique, deprecated, do not use β€” like bestie I'm begging you, don't) πŸ’€
  • %% β€” just %
  • %/s β€” %s but \ gets replaced by /
  • %/S β€” %S but \ gets replaced by /
  • %/p β€” %p but \ gets replaced by /
  • %/t β€” %t but \ gets replaced by /
  • %/T β€” %T but \ gets 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 it's %/s but a : is removed if it's the second character; otherwise it's %s but with a single leading / removed
  • %:S β€” on Windows it's %/S but a : is removed if it's the second character; otherwise it's %S but with a single leading / removed
  • %:p β€” on Windows it's %/p but a : is removed if it's the second character; otherwise it's %p but with a single leading / removed
  • %:t β€” on Windows it's %/t but a : is removed if it's the second character; otherwise it's %t but with a single leading / removed
  • %:T β€” on Windows it's %/T but a : is removed if it's the second character; otherwise it's %T but with a single leading / removed

There are other substitutions too β€” they're variations on this base set, and ngl each test module can define even more substitution patterns of its own πŸ’– see the modules LOCAL CONFIGURATION FILES.

By default, substitutions are expanded exactly once, so if like a substitution %build is defined on top of another substitution %cxx, then %build will expand to %cxx textually β€” not to whatever %cxx actually expands to. it's giving "one layer and that's it" πŸŽ€

BUT!! if the recursiveExpansionLimit property of the TestingConfig is set to a non-negative integer, substitutions get expanded recursively until that limit is hit. and listen β€” it is an error if the limit is reached and expanding substitutions again would yield a different result. no cap, that's a fail 🫠

More detailed info on substitutions lives in the ../TestingGuide ⭐


πŸ¦‹ TEST RUN OUTPUT FORMAT πŸ¦‹

k so the lit output for a test run conforms to the following schema, in both short and verbose modes (though in short mode no PASS lines will show up, bestie). this schema was chosen so it's relatively easy to reliably parse by a machine β€” like buildbot log scraping, iykyk β€” and so other tools can generate it too πŸ’…

Each test result is expected to appear on a line that matches:

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

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

The <test name> field can consist of an arbitrary string containing no newline.

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

Each test result may include additional (multiline) log info in the following format:

<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 that's at least four characters long (the recommended length is 20 ✨), and <trailing delineator> is an arbitrary string that doesn't get parsed.

Here's an 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 contains several example implementations of test suites in the ExampleTests directory πŸ‘‘ go look, they're iconic.


πŸ’œ SEE ALSO πŸ’œ


✨ AUTHOR ✨

Okay so this whole iconic thing is maintained by the LLVM Team β€” their whole vibe lives at https://llvm.org/. Go say hi, they're the ones keeping the lights on πŸ’–


2003-2023, LLVM Project β€” yes bestie, that's the copyright line, copy it exactly if you're citing it, don't come for me πŸ™ˆ

ngl, two decades of lit and it's still serving. The LLVM Project owns this one, periodt.

That's the whole page, bestie β€” you made it to the end, main character energy fr fr 🫢 This gem of a manpage is from the LIT(1) source and it's version 13, dated 2023-07-14. Go forth and run those tests, slay πŸ’…πŸŒΈ

πŸ“¦ where this page comes from