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 thelithelp message. the classic "help me help you" moment π«Ά-j N,--workers=Nβ runNtests 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 forNAME.cfgandNAME.site.cfginstead of the usuallit.cfgandlit.site.cfg.-D NAME[=VALUE],--param NAME[=VALUE]β add a user-defined parameterNAMEwith the givenVALUE(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-baris 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 πlitnormally inserts a no-op command (:in the case of bash) with argumentRUN: at line Nbefore 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 additionalPATHto use when searching for executables in tests.--vgβ run individual tests undervalgrind(using thememchecktool). the--error-exitcodeargument forvalgrindis 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--vgis used, specify an additional argument to pass tovalgrinditself.--vg-leakβ when--vgis used, enable memory leak checks. When this option is enabled,litalso automatically provides avg_leakfeature 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--orderinstead. it's giving legacy vibes π--max-failures Nβ stop execution after the given numberNof failures. an integer argument should be passed on the command line prior to execution.--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, bestie, don't confuse them π«Ά--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 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=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, fr fr π«Ά--filter=REGEXPβ run only those tests whose name matches the regular expression specified inREGEXP. The environment variableLIT_FILTERcan also be used in place of this option, which is especially useful in environments where the call tolitis issued indirectly. sneaky filter queen π--filter-out=REGEXPβ filter out those tests whose name matches the regular expression specified inREGEXP. The environment variableLIT_FILTER_OUTcan also be 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 listLISTas XFAIL. this can be helpful when you don't wanna modify the test suite. The environment variableLIT_XFAILcan also be used in place of this option, which is especially useful in environments where the call tolitis 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 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 other XFAIL specifications, including an--xfailappearing 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β runlitin debug mode, for debugging configuration issues andlititself. 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 anALLOW_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 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. β οΈ like, the empty part is non-negotiable bestiesuffixesβ 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, orNone.rootβ The root configuration. This is the top-most lit configuration in the project. π³ the original, the blueprintpipefailβ 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 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, 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 theLLVMcheckout%{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%tbut without the.tmpextension%Tβ parent directory of%t(not unique, deprecated, do not use) π¨%%β%%/sβ%sbut\is replaced by/%/Sβ%Sbut\is replaced by/%/pβ%pbut\is replaced by/%/tβ%tbut\is replaced by/%/Tβ%Tbut\is replaced by/%{/s:regex_replacement}β%/sbut escaped for use in the replacement of as@@@command insed%{/S:regex_replacement}β%/Sbut escaped for use in the replacement of as@@@command insed%{/p:regex_replacement}β%/pbut escaped for use in the replacement of as@@@command insed%{/t:regex_replacement}β%/tbut escaped for use in the replacement of as@@@command insed%{/T:regex_replacement}β%/Tbut escaped for use in the replacement of as@@@command insed%:sβ on Windows,%/sbut a:is removed if it's the second character. Otherwise,%sbut with a single leading/removed.%:Sβ on Windows,%/Sbut a:is removed if it's the second character. Otherwise,%Sbut with a single leading/removed.%:pβ on Windows,%/pbut a:is removed if it's the second character. Otherwise,%pbut with a single leading/removed.%:tβ on Windows,%/tbut a:is removed if it's the second character. Otherwise,%tbut with a single leading/removed.%:Tβ on Windows,%/Tbut a:is removed if it's the second character. Otherwise,%Tbut 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/). π
Β©οΈ COPYRIGHT Β©οΈ
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
- ubuntu jammy: llvm-15 1:15.0.7-0ubuntu0.22.04.3 Β· APACHE-2-LLVM-EXCEPTIONS
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms