LIT(1)

πŸŽ€ LIT(1) πŸŽ€

okay so bestie, meet lit β€” the LLVM Integrated Tester ✨ it's from the LLVM girlies, it's in section 1 of the manual, and it's genuinely one of my fave little tools. sit down, grab a strawberry πŸ“, and let's get into it.


✨ NAME ✨

lit β€” the LLVM Integrated Tester πŸ’…


✨ SYNOPSIS ✨

lit [options] [tests]

🌸 DESCRIPTION 🌸

lit is a portable tool for running LLVM- and Clang-style test suites, summarizing the results, and letting you know when stuff fails 😭 it's designed to be a lightweight testing tool with the simplest user interface possible β€” no cap, that's the whole vibe.

You should run lit with one or more tests specified on the command line. A test can be either a single individual test file, or a directory that lit will search for tests in (peep TEST DISCOVERY for that one).

Each test you specify gets executed β€” potentially concurrently, bestie, it's giving multitasking main character energy β€” and once they've all run, lit prints summary info on how many passed and how many failed (see TEST STATUS RESULTS). And yes: lit will exit with a non-zero exit code if any tests fail. it's strict like that πŸ’€

By default lit uses a succinct progress display and only prints summary info for failures. There are options for controlling the progress display and output β€” go look at OUTPUT OPTIONS 🫢

lit also has a bunch of options for controlling how tests get executed (specific features may depend on the particular test format, iykyk). That's the EXECUTION OPTIONS section ✨

And finally β€” because of course β€” lit supports extra options for running only 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 mostly useful for supplementing or overriding the command-line options that a project's build system hands to lit via its check targets. yes, it's the sneaky little override queen πŸ™ˆ

lit can also read options from response files, which you specify as inputs using the @path/to/file.rsp syntax.

If you're the type who cares about the lit architecture, or you're designing a lit testing implementation yourself (iconic of you), go read LIT INFRASTRUCTURE 🧚


πŸ’œ GENERAL OPTIONS πŸ’œ

  • -h, --help β€” shows you the lit help message. the classic "help me help you" moment 🫢
  • -j N, --workers=N β€” run N tests in parallel. by default this is automatically chosen to match the number of detected available CPUs, so it's already doing the smart thing ✨
  • --config-prefix=NAME β€” when searching for test suites, look for NAME.cfg and NAME.site.cfg instead of the usual 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 you don't give one). what these parameters actually mean and how they're used is test-suite dependent β€” so, like, ask your test suite, not me 😭

🌈 OUTPUT OPTIONS 🌈

  • -q, --quiet β€” suppress any output except for test failures. silence is golden and also kind of ominous πŸ’€
  • -s, --succinct β€” show less output, like, don't show info on tests that pass. it also shows a progress bar unless --no-progress-bar is specified.
  • -v, --verbose β€” show way more info on test failures, for example the entire test output instead of just the test result. the "tell me everything" setting πŸ”₯
  • -vv, --echo-all-commands β€” echo all commands to stdout as they're being executed. this is genuinely so valuable for debugging test failures, because the last echoed command will be the one that 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. full transparency, no secrets 🫢
  • --no-progress-bar β€” don't use the curses-based progress bar. bye bye little 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 make the program exit with a non-zero status 🚨

When this option is enabled, lit also automatically provides a valgrind feature that you can use to conditionally disable certain tests (or expect failure in them). iykyk ✨

  • --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 also automatically provides a vg_leak feature that you can use to conditionally disable certain tests (or expect failure in them). leaks found, wig snatched 😭
  • --time-tests β€” track the wall time that individual tests take to execute and include the results in the summary output. super useful for figuring out which tests in a suite are the slow little divas taking the most time ⏳
  • --ignore-fail β€” exit with status zero even if some tests fail. delusion? maybe. convenient? absolutely πŸ™ˆ
  • --no-indirectly-run-check β€” don't error if a test wouldn't have been run had you specified the containing directory instead of naming the test directly.

πŸ‘‘ SELECTION OPTIONS πŸ‘‘

By default, lit runs failing tests first, then runs tests in descending execution time order to optimize concurrency. the execution order can be changed with the --order option πŸ’…

The timing data is stored in the test_exec_root in a file named .lit_test_times.txt. If that file doesn't exist, then lit checks the test_source_root for the file to optionally accelerate clean builds. cute, right? πŸŽ€

  • --shuffle β€” run the tests in a random order, not failing/slowest first. Deprecated, use --order instead. it's giving legacy vibes πŸ’€
  • --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, bestie, don't confuse them 🫢
  • --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 are 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 one's useful when you want a predictable test order πŸŽ€
    • random β€” tests will be run in random order. chaos, but make it testing πŸŒ€
    • smart β€” tests that failed previously will be run first, then the remaining tests, all in descending execution time order. this is the default, because 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, fr fr 🫢
  • --filter=REGEXP β€” run only those tests whose name matches the regular expression specified in REGEXP. The environment variable LIT_FILTER can also be used in place of this option, which is especially useful in environments where the call to lit is issued indirectly. sneaky filter queen πŸ™ˆ
  • --filter-out=REGEXP β€” filter out those tests whose name matches the regular expression specified in REGEXP. The environment variable LIT_FILTER_OUT can also be 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 you don't wanna modify the test suite. The environment variable LIT_XFAIL can also be used in place of this option, which is especially useful in environments where the call to lit is issued indirectly.

A test name can be 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. for when you need to look inside the machine 🧚
  • --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 exits with status 0 πŸŽ‰ Other exit codes are used for non-test-related failures β€” for example a user error or an internal program error πŸ’€

πŸ” TEST DISCOVERY πŸ”

okay so bestie, here's the tea on how lit even finds stuff to run β˜•βœ¨

The inputs you pass to lit can be either individual tests, or entire directories or hierarchies of tests. 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. literally step one, no skipping πŸ’…

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. iconic double duty fr πŸŽ€

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. it just keeps going, like your group chat at 2am 😭

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 🌈 slay.


πŸ’– TEST STATUS RESULTS πŸ’–

Each test ultimately produces one of the following eight results β€” memorize these, they're the whole vibe check of your test run πŸ‘‘

  • PASS β€” the test succeeded. we love to see it 🫢
  • FLAKYPASS β€” the test succeeded after being re-run more than once. This only applies to tests containing an ALLOW_RETRIES: annotation. she's chaotic but she got there πŸ’€
  • 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. knowingly broken, respectfully πŸ™ˆ
  • 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). plot twist, the bug is dead πŸŽ‰
  • FAIL β€” the test failed. that's it, that's the tweet πŸ˜”
  • 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. we genuinely don't know what happened and that's lowkey worse πŸ”₯
  • 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. ⏰ not the clock doing us dirty

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. nerd mode: activated πŸ€“βœ¨

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 the main character that delegates, we stan a humble queen πŸ‘‘

πŸŽ€ 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. peek behind the curtain bestie πŸ¦‹

Once a test suite is discovered, its config file is loaded. Config files themselves are Python modules which will be executed. When the config file is executed, two important global variables are predefined:

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 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. gotta have a name, periodt πŸ‘‘
  • 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. ⚠️ like, the empty part is non-negotiable bestie
  • 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. 🌳 the original, the blueprint
  • 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). recursion, but make it fashion πŸ’…

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. spooky? a little. real? absolutely πŸ‘»

πŸ—‚οΈ 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. per-directory customization is genuinely such a moment πŸŽ€βœ¨

✨ SUBSTITUTIONS ✨

okay so lit lets patterns get substituted inside RUN commands, and it also hands you this base set of substitutions, all defined in TestRunner.py:

  • %s β€” source path, aka the path to the file currently being run πŸ’…
  • %S β€” source dir, aka the directory of the file currently being run
  • %p β€” same as %S
  • %{pathsep} β€” path separator
  • %{fs-src-root} β€” root component of file system paths pointing to the LLVM checkout
  • %{fs-tmp-root} β€” root component of file system paths pointing to the test's temporary directory
  • %{fs-sep} β€” file system path separator
  • %t β€” temporary file name unique to the test
  • %basename_t β€” the last path component of %t but without the .tmp extension
  • %T β€” parent directory of %t (not unique, deprecated, do not use) 🚨
  • %% β€” %
  • %/s β€” %s but \ is replaced by /
  • %/S β€” %S but \ is replaced by /
  • %/p β€” %p but \ is replaced by /
  • %/t β€” %t but \ is replaced by /
  • %/T β€” %T but \ is replaced by /
  • %{/s:regex_replacement} β€” %/s but escaped for use in the replacement of a s@@@ command in sed
  • %{/S:regex_replacement} β€” %/S but escaped for use in the replacement of a s@@@ command in sed
  • %{/p:regex_replacement} β€” %/p but escaped for use in the replacement of a s@@@ command in sed
  • %{/t:regex_replacement} β€” %/t but escaped for use in the replacement of a s@@@ command in sed
  • %{/T:regex_replacement} β€” %/T but escaped for use in the replacement of a s@@@ command in sed
  • %:s β€” on Windows, %/s but a : is removed if it's the second character. Otherwise, %s but with a single leading / removed.
  • %:S β€” on Windows, %/S but a : is removed if it's the second character. Otherwise, %S but with a single leading / removed.
  • %:p β€” on Windows, %/p but a : is removed if it's the second character. Otherwise, %p but with a single leading / removed.
  • %:t β€” on Windows, %/t but a : is removed if it's the second character. Otherwise, %t but with a single leading / removed.
  • %:T β€” on Windows, %/T but a : is removed if it's the second character. Otherwise, %T but with a single leading / removed.

There are other substitutions too β€” variations on this base set β€” and each test module can define even more substitution patterns. Peep the modules in LOCAL CONFIGURATION FILES for that πŸ‘€

By default, substitutions expand exactly once. So if a substitution like %build is defined on top of another substitution like %cxx, then %build expands to the literal text %cxx, not to whatever %cxx eventually expands to. iconic, but important ✨

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

More detailed info on substitutions lives in ../TestingGuide 🫢


πŸŽ€ TEST RUN OUTPUT FORMAT πŸŽ€

The lit output for a test run conforms to this schema, in both short and verbose modes β€” although in short mode no PASS lines will be shown. This schema was chosen so it's relatively easy to reliably parse by a machine (for example in buildbot log scraping), and for other tools to generate. iykyk πŸ’…

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.

okay so the <progress info> field is literally your little progress flex β€” it can report stuff like (1/300), or it can be totally empty. but even when it's empty, the parentheses are still required, no cap. 🫢

Each test result may also carry extra multiline log info, and it's giving this exact 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 at least four characters long (the recommended length is 20, slay), and <trailing delineator> is an arbitrary (unparsed) string β€” it's just decorative chaos. πŸ’…

Here's a whole example test run with four tests A, B, C, and D, plus a log message for the failing test C β€” it's giving failure, but make it organized:

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 peek if you want inspo. 🧚

πŸ‘€ SEE ALSO πŸ‘€

✍️ AUTHOR ✍️

Maintained by the LLVM Team (https://llvm.org/). 🌈

2003-2023, LLVM Project


okay that's the whole manual page, bestie πŸŽ€ β€” this is lit(1), version 15, dated 2023-07-14. go understand your test suite, you absolute icon πŸ’…βœ¨

πŸ“¦ where this page comes from