LIT(1)
β¨ 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 thelithelp message. literally the βwhat do I doβ button. π«Ά-j N,--workers=Nβ RunNtests in parallel. By default, this is automatically chosen to match the number of detected available CPUs. bestie said multitasking. β‘--config-prefix=NAMEβ Search forNAME.cfgandNAME.site.cfgwhen searching for test suites, instead oflit.cfgandlit.site.cfg. π-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. 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-baris 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 tostdout, 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.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. 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 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,litwill 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. Note that this option is most useful with-j 1. β±οΈ
π SELECTION OPTIONS π
--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. β³--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). π--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. π―--shuffleβ Run the tests in a random order. chaos mode, but make it productive. π²--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. π§΅
π¦ 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). π
π 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 anALLOW_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 (aLitConfiginstance, 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 (aTestingConfiginstance) 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 thelit.formatsmodule.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, orNone.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 inXFAIL,REQUIRES, andUNSUPPORTEDdirectives.
πΈ 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%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 its the second character. Otherwise,%sbut with a single leading/removed.%:Sβ on Windows,%/Sbut a:is removed if its the second character. Otherwise,%Sbut with a single leading/removed.%:pβ on Windows,%/pbut a:is removed if its the second character. Otherwise,%pbut with a single leading/removed.%:tβ on Windows,%/tbut a:is removed if its the second character. Otherwise,%tbut with a single leading/removed.%:Tβ on Windows,%/Tbut a:is removed if its the second character. Otherwise,%Tbut 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/>). β¨
π COPYRIGHT π
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
- fedora 43: llvm12 12.0.1-12.fc41 Β· NCSA
- fedora 43: llvm12 12.0.1-12.fc41 Β· NCSA
- fedora 44: llvm12 12.0.1-12.fc41 Β· NCSA
- fedora 44: llvm12 12.0.1-12.fc41 Β· NCSA
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms