LIT(1)
π 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:litparses options from the environment variableLIT_OPTSafter parsing options from the command line.LIT_OPTSis primarily useful for supplementing or overriding the command-line options supplied tolitby 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 thelithelp message. Your lil onboarding moment. π-j N,--workers=Nβ RunNtests 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 forNAME.cfgandNAME.site.cfgwhen searching for test suites, instead oflit.cfgandlit.site.cfg. Renaming the whole vibe, periodt.-D NAME[=VALUE],--param NAME[=VALUE]β Add a user defined parameterNAMEwith the givenVALUE(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-baris 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 tostdout, 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.litnormally inserts a no-op command (:in the case ofbash) with argument'RUN: at line N'before each command pipeline, and this option also causes those no-op commands to be echoed tostdoutto 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 additionalPATHto use when searching for executables in tests. π--vgβ Run individual tests undervalgrind(using thememchecktool). The--error-exitcodeargument forvalgrindis used so thatvalgrindfailures 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--vgis used, specify an additional argument to pass tovalgrinditself.--vg-leakβ When--vgis used, enable memory leak checks. When this option is enabled,litwill 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--orderinstead. π--max-failures Nβ Stop execution after the given numberNof failures. An integer argument should be passed on the command line prior to execution. Enough is enough. π--max-tests=Nβ Run at mostNtests and then terminate.--max-time=Nβ Spend at mostNseconds (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 intoMequal-sized subsets or"shards", and run only one of them. Must be used with the--run-shard=Noption, which selects the shard to run. The environment variableLIT_NUM_SHARDScan 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=Moption was provided. The two options must be used together, and the value ofNmust be in the range1..M. The environment variableLIT_RUN_SHARDcan also be used in place of this option.--timeout=Nβ Spend at mostNseconds (approximately) running each individual test.0means no time limit, and0is 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 inREGEXP. The environment variableLIT_FILTERcan be also used in place of this option, which is especially useful in environments where the call tolitis issued indirectly. π£--filter-out=REGEXPβ Filter out those tests whose name matches the regular expression specified inREGEXP. The environment variableLIT_FILTER_OUTcan be also used in place of this option, which is especially useful in environments where the call tolitis issued indirectly.--xfail=LISTβ Treat those tests whose name is in the semicolon separated listLISTasXFAIL. This can be helpful when one does not want to modify the test suite. The environment variableLIT_XFAILcan be also used in place of this option, which is especially useful in environments where the call tolitis 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 asXFAIL. The environment variableLIT_XFAIL_NOTcan also be used in place of this option. The syntax is the same as for--xfailandLIT_XFAIL.--xfail-notandLIT_XFAIL_NOTalways override all otherXFAILspecifications, including an--xfailappearing later on the command line. The primary purpose is to suppress anXPASSresult without modifying a test case that uses theXFAILdirective. π«
π ADDITIONAL OPTIONS π
--debugβ Runlitin debug mode, for debugging configuration issues andlititself. π--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 anALLOW_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 globallitconfiguration object (aLitConfiginstance), which defines the builtin test formats, global configuration parameters, and other helper routines for implementing test configurations.configβ the config object (aTestingConfiginstance) 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 thelit.formatsmodule.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-checkis in effect.lit.suffixesandlit.excludesmust be empty when this variable is true. β οΈsuffixesβ forlittest formats which scan directories for tests, this variable is a list of suffixes to identify test files. Used by:ShTest.substitutionsβ forlittest 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, orNone.rootβ the root configuration. This is the top-mostlitconfiguration 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 inXFAIL,REQUIRES, andUNSUPPORTEDdirectives.
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%Sagain, 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.tmpextension stripped off%Tβ the parent directory of%t. NOT unique, deprecated, do NOT use π%%β just a literal%%/sβ%sbut every\is replaced by/%/Sβ%Sbut every\is replaced by/%/pβ%pbut every\is replaced by/%/tβ%tbut every\is replaced by/%/Tβ%Tbut every\is replaced by/%{/s:regex_replacement}β%/sbut escaped so you can use it in the replacement of as@@@command insedπΈ%{/S:regex_replacement}β%/Sbut escaped so you can use it in the replacement of as@@@command insed%{/p:regex_replacement}β%/pbut escaped so you can use it in the replacement of as@@@command insed%{/t:regex_replacement}β%/tbut escaped so you can use it in the replacement of as@@@command insed%{/T:regex_replacement}β%/Tbut escaped so you can use it in the replacement of as@@@command insed%:sβ on Windows, this is%/sbut a:gets removed if it's the second character. Otherwise, it's%sbut with a single leading/removed.%:Sβ on Windows, this is%/Sbut a:gets removed if it's the second character. Otherwise, it's%Sbut with a single leading/removed.%:pβ on Windows, this is%/pbut a:gets removed if it's the second character. Otherwise, it's%pbut with a single leading/removed.%:tβ on Windows, this is%/tbut a:gets removed if it's the second character. Otherwise, it's%tbut with a single leading/removed.%:Tβ on Windows, this is%/Tbut a:gets removed if it's the second character. Otherwise, it's%Tbut 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 π
π«Ά COPYRIGHT π«Ά
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
- ubuntu noble: llvm-16 1:16.0.6-23ubuntu4 Β· APACHE-2-LLVM-EXCEPTIONS
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms