LIT(1)

πŸ“¦
version 12.0.1 Β· 4 versions
, in fedora 43, fedora 44

✨ NAME ✨

okay so bestie, meet lit β€” the LLVM Integrated Tester, aka LIT(1). She’s your portable little powerhouse for running LLVM and Clang style test suites, summarizing what happened, and pointing at failures. The whole vibe? A lightweight testing tool with the simplest possible user interface. periodt. πŸ’…


πŸ“œ SYNOPSIS πŸ“œ

lit [options] [tests]

🫢 DESCRIPTION 🫢

lit is a portable tool for executing LLVM and Clang style test suites, summarizing their results, and providing indication of failures. She’s designed to be a lightweight testing tool with as simple a user interface as possible. no cap. ✨

You should run lit with one or more tests to run specified on the command line. Tests can be either individual test files or directories to search for tests β€” see TEST DISCOVERY below. πŸ¦‹

Each specified test will be executed (potentially in parallel), and once all tests have been run lit will print 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. 😭

By default lit will use a succinct progress display and will only print 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 information. πŸ”₯

Finally, lit also supports additional options for only running a subset of the options specified on the command line β€” see SELECTION OPTIONS for more information. πŸ’–

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

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. literally the β€œwhat do I do” button. 🫢
  • -j N, --workers=N β€” Run N tests in parallel. By default, this is automatically chosen to match the number of detected available CPUs. bestie said multitasking. ⚑
  • --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. iykyk. ✨

🌸 OUTPUT OPTIONS 🌸

  • -q, --quiet β€” Suppress any output except for test failures. silent but deadly. 🀫
  • -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. cute and compact. πŸŽ€
  • -v, --verbose β€” Show more information on test failures, for example the entire test output instead of just the test result. spill the tea. β˜•
  • -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. all the receipts. 🧾
  • --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, but make it productive. 🎲
  • --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). πŸ’…


πŸ” 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. slay. βœ…
  • 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. πŸ’€
  • 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. πŸ’…


πŸ§ͺ 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. ✨

Once a test suite gets discovered, its config file gets loaded β€” and bestie, config files are Python modules, so they literally get executed. πŸ‘€ When the config file runs, two extremely important global variables are already sitting there waiting for you:

  • lit_config β€” the global lit configuration object (a LitConfig instance, no cap πŸ’…). This one defines the builtin test formats, the global configuration parameters, and all the other helper routines for implementing test configurations.
  • config β€” the config object (a TestingConfig instance) for the test suite, and this is the one your config file is expected to populate. It's giving main character energy fr fr.

The following variables are also available on the config object. Some of them you must set yourself, others are optional or already predefined, so read the tags carefully:

  • 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 gonna be a builtin test format you can grab 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 gets 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 run and where temporary output files get placed.
  • environment β€” a dictionary representing the environment to use when executing tests in the suite.
  • 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, this is the list of substitutions to perform. Used by: ShTest.
  • unsupported β€” marks a directory as unsupported, and every test inside 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 the vibe 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 the test suites are located, lit recursively traverses the source directory (following test_source_root, obviously πŸ’) looking for tests. When lit walks into a sub-directory, the very first thing it does is check whether a nested test suite is defined in that directory. If there is one, it loads that test suite recursively. If there isn't, it instantiates a local test config for the directory instead (peep LOCAL CONFIGURATION FILES for that whole situation).

Tests are identified by the test suite they're contained within, plus the relative path inside that suite. ⚠️ Important caveat bestie: that relative path might not refer to an actual file on disk. Some test formats (looking at you, GoogleTest) define "virtual tests", and those have a path that contains both the path to the actual test file and a subpath to identify the virtual test. Iconic, honestly.


✨ 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 this whole configuration chain will always be a test suite, periodt. 🫢

Once the test configuration is cloned, lit checks for a lit.local.cfg file in that subdirectory. If it's there, the file gets loaded, and you can use it to specialize the configuration for each individual directory. This is such a slay facility β€” use it to define subdirectories of optional tests, or to change other configuration parameters, like changing the test format, or changing the suffixes that identify test files. 🌈

✨ SUBSTITUTIONS ✨

okay so lit is literally out here letting you swap patterns into your RUN commands, and bestie, the base set is chef's kiss. These are all defined in TestRunner.py πŸ’–

  • %s β€” source path (path to the file currently being run)
  • %S β€” source dir (directory of the file currently being run)
  • %p β€” same as %S
  • %{pathsep} β€” 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 its the second character. Otherwise, %s but with a single leading / removed.
  • %:S β€” on Windows, %/S but a : is removed if its the second character. Otherwise, %S but with a single leading / removed.
  • %:p β€” on Windows, %/p but a : is removed if its the second character. Otherwise, %p but with a single leading / removed.
  • %:t β€” on Windows, %/t but a : is removed if its the second character. Otherwise, %t but with a single leading / removed.
  • %:T β€” on Windows, %/T but a : is removed if its the second character. Otherwise, %T but with a single leading / removed.

There's also a whole vibe of other substitutions that are just little variations on this base set, and ngl, each test module can define its own extra substitution patterns too πŸ¦‹ peek at the modules' LOCAL CONFIGURATION FILES.

Now, the tea on expansion β˜• by default, substitutions get expanded exactly once, okay? So like, if 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. No chain reaction, no drama.

But β€” plot twist β€” if the recursiveExpansionLimit property of the TestingConfig is set to a non-negative integer, then substitutions get expanded recursively until that limit is hit πŸ”. And it is an error if the limit is reached and expanding substitutions again would yield a different result. Like, you got greedy, the limit said no more, periodt.

Wanna go deeper? More detailed info on substitutions lives in the LLVM Testing Infrastructure Guide πŸ“š


πŸ’… TEST RUN OUTPUT FORMAT πŸ’…

The lit output for a test run conforms to the following schema, in both short and verbose modes (although in short mode no PASS lines will be shown, so don't @ me). This schema was chosen to be relatively easy to reliably parse by a machine (like, say, buildbot log scraping πŸ‘€) and for other tools to generate.

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 information such as (1/300) or can be empty, but even when empty the parentheses are required β€” them's the rules πŸ™

Each test result may include additional (multiline) log information 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 at least four characters long (the recommended length is 20), and <trailing delineator> is an arbitrary (unparsed) string.

Here's an example of a test run output which consists of four tests A, B, C, and D, and 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. cute little starter pack fr fr πŸŽ€


πŸ” SEE ALSO πŸ”

πŸ‘‘ AUTHOR πŸ‘‘

Maintained by the LLVM Team (<https://llvm.org/>). ✨


2003-2024, LLVM Project

okay so that's the whole thing bestie, no cap, every last flag and file path accounted for πŸ’…

and that's a wrap on LIT(1), page 12, dated 2024-07-18, straight outta the LLVM Project's very own docs πŸ’– go forth and run your tests, you absolute icon πŸ¦‹

πŸ“¦ where this page comes from