1 lit - LLVM Integrated Tester
2 ============================
9 :program:`lit` [*options*] [*tests*]
14 :program:`lit` is a portable tool for executing LLVM and Clang style test
15 suites, summarizing their results, and providing indication of failures.
16 :program:`lit` is designed to be a lightweight testing tool with as simple a
17 user interface as possible.
19 :program:`lit` should be run with one or more *tests* to run specified on the
20 command line. Tests can be either individual test files or directories to
21 search for tests (see :ref:`test-discovery`).
23 Each specified test will be executed (potentially in parallel) and once all
24 tests have been run :program:`lit` will print summary information on the number
25 of tests which passed or failed (see :ref:`test-status-results`). The
26 :program:`lit` program will execute with a non-zero exit code if any tests
29 By default :program:`lit` will use a succinct progress display and will only
30 print summary information for test failures. See :ref:`output-options` for
31 options controlling the :program:`lit` progress display and output.
33 :program:`lit` also includes a number of options for controlling how tests are
34 executed (specific features may depend on the particular test format). See
35 :ref:`execution-options` for more information.
37 Finally, :program:`lit` also supports additional options for only running a
38 subset of the options specified on the command line, see
39 :ref:`selection-options` for more information.
41 :program:`lit` parses options from the environment variable ``LIT_OPTS`` after
42 parsing options from the command line. ``LIT_OPTS`` is primarily useful for
43 supplementing or overriding the command-line options supplied to :program:`lit`
44 by ``check`` targets defined by a project's build system.
46 Users interested in the :program:`lit` architecture or designing a
47 :program:`lit` testing implementation should see :ref:`lit-infrastructure`.
52 .. option:: -h, --help
54 Show the :program:`lit` help message.
56 .. option:: -j N, --threads=N
58 Run ``N`` tests in parallel. By default, this is automatically chosen to
59 match the number of detected available CPUs.
61 .. option:: --config-prefix=NAME
63 Search for :file:`{NAME}.cfg` and :file:`{NAME}.site.cfg` when searching for
64 test suites, instead of :file:`lit.cfg` and :file:`lit.site.cfg`.
66 .. option:: -D NAME[=VALUE], --param NAME[=VALUE]
68 Add a user defined parameter ``NAME`` with the given ``VALUE`` (or the empty
69 string if not given). The meaning and use of these parameters is test suite
77 .. option:: -q, --quiet
79 Suppress any output except for test failures.
81 .. option:: -s, --succinct
83 Show less output, for example don't show information on tests that pass.
85 .. option:: -v, --verbose
87 Show more information on test failures, for example the entire test output
88 instead of just the test result.
90 .. option:: -vv, --echo-all-commands
92 Echo all commands to stdout, as they are being executed.
93 This can be valuable for debugging test failures, as the last echoed command
94 will be the one which has failed.
95 :program:`lit` normally inserts a no-op command (``:`` in the case of bash)
96 with argument ``'RUN: at line N'`` before each command pipeline, and this
97 option also causes those no-op commands to be echoed to stdout to help you
98 locate the source line of the failed command.
99 This option implies ``--verbose``.
101 .. option:: -a, --show-all
103 Show more information about all tests, for example the entire test
104 commandline and output.
106 .. option:: --no-progress-bar
108 Do not use curses based progress bar.
110 .. option:: --show-unsupported
112 Show the names of unsupported tests.
114 .. option:: --show-xfail
116 Show the names of tests that were expected to fail.
118 .. _execution-options:
123 .. option:: --path=PATH
125 Specify an additional ``PATH`` to use when searching for executables in tests.
129 Run individual tests under valgrind (using the memcheck tool). The
130 ``--error-exitcode`` argument for valgrind is used so that valgrind failures
131 will cause the program to exit with a non-zero status.
133 When this option is enabled, :program:`lit` will also automatically provide a
134 "``valgrind``" feature that can be used to conditionally disable (or expect
135 failure in) certain tests.
137 .. option:: --vg-arg=ARG
139 When :option:`--vg` is used, specify an additional argument to pass to
140 :program:`valgrind` itself.
142 .. option:: --vg-leak
144 When :option:`--vg` is used, enable memory leak checks. When this option is
145 enabled, :program:`lit` will also automatically provide a "``vg_leak``"
146 feature that can be used to conditionally disable (or expect failure in)
149 .. option:: --time-tests
151 Track the wall time individual tests take to execute and includes the results
152 in the summary output. This is useful for determining which tests in a test
153 suite take the most time to execute. Note that this option is most useful
156 .. _selection-options:
161 .. option:: --max-tests=N
163 Run at most ``N`` tests and then terminate.
165 .. option:: --max-time=N
167 Spend at most ``N`` seconds (approximately) running tests and then terminate.
169 .. option:: --shuffle
171 Run the tests in a random order.
173 .. option:: --num-shards=M
175 Divide the set of selected tests into ``M`` equal-sized subsets or
176 "shards", and run only one of them. Must be used with the
177 ``--run-shard=N`` option, which selects the shard to run. The environment
178 variable ``LIT_NUM_SHARDS`` can also be used in place of this
179 option. These two options provide a coarse mechanism for paritioning large
180 testsuites, for parallel execution on separate machines (say in a large
183 .. option:: --run-shard=N
185 Select which shard to run, assuming the ``--num-shards=M`` option was
186 provided. The two options must be used together, and the value of ``N``
187 must be in the range ``1..M``. The environment variable
188 ``LIT_RUN_SHARD`` can also be used in place of this option.
190 .. option:: --filter=REGEXP
192 Run only those tests whose name matches the regular expression specified in
193 ``REGEXP``. The environment variable ``LIT_FILTER`` can be also used in place
194 of this option, which is especially useful in environments where the call
195 to ``lit`` is issued indirectly.
202 Run :program:`lit` in debug mode, for debugging configuration issues and
203 :program:`lit` itself.
205 .. option:: --show-suites
207 List the discovered test suites and exit.
209 .. option:: --show-tests
211 List all of the discovered tests and exit.
216 :program:`lit` will exit with an exit code of 1 if there are any FAIL or XPASS
217 results. Otherwise, it will exit with the status 0. Other exit codes are used
218 for non-test related failures (for example a user error or an internal program
226 The inputs passed to :program:`lit` can be either individual tests, or entire
227 directories or hierarchies of tests to run. When :program:`lit` starts up, the
228 first thing it does is convert the inputs into a complete list of tests to run
229 as part of *test discovery*.
231 In the :program:`lit` model, every test must exist inside some *test suite*.
232 :program:`lit` resolves the inputs specified on the command line to test suites
233 by searching upwards from the input path until it finds a :file:`lit.cfg` or
234 :file:`lit.site.cfg` file. These files serve as both a marker of test suites
235 and as configuration files which :program:`lit` loads in order to understand
236 how to find and run the tests inside the test suite.
238 Once :program:`lit` has mapped the inputs into test suites it traverses the
239 list of inputs adding tests for individual files and recursively searching for
240 tests in directories.
242 This behavior makes it easy to specify a subset of tests to run, while still
243 allowing the test suite configuration to control exactly how tests are
244 interpreted. In addition, :program:`lit` always identifies tests by the test
245 suite they are in, and their relative path inside the test suite. For
246 appropriately configured projects, this allows :program:`lit` to provide
247 convenient and flexible support for out-of-tree builds.
249 .. _test-status-results:
254 Each test ultimately produces one of the following six results:
262 The test failed, but that is expected. This is used for test formats which allow
263 specifying that a test does not currently work, but wish to leave it in the test
268 The test succeeded, but it was expected to fail. This is used for tests which
269 were specified as expected to fail, but are now succeeding (generally because
270 the feature they test was broken and has been fixed).
278 The test result could not be determined. For example, this occurs when the test
279 could not be run, the test itself is invalid, or the test was interrupted.
283 The test is not supported in this environment. This is used by test formats
284 which can report unsupported tests.
286 Depending on the test format tests may produce additional information about
287 their status (generally only for failures). See the :ref:`output-options`
288 section for more information.
290 .. _lit-infrastructure:
295 This section describes the :program:`lit` testing architecture for users interested in
296 creating a new :program:`lit` testing implementation, or extending an existing one.
298 :program:`lit` proper is primarily an infrastructure for discovering and running
299 arbitrary tests, and to expose a single convenient interface to these
300 tests. :program:`lit` itself doesn't know how to run tests, rather this logic is
301 defined by *test suites*.
306 As described in :ref:`test-discovery`, tests are always located inside a *test
307 suite*. Test suites serve to define the format of the tests they contain, the
308 logic for finding those tests, and any additional information to run the tests.
310 :program:`lit` identifies test suites as directories containing ``lit.cfg`` or
311 ``lit.site.cfg`` files (see also :option:`--config-prefix`). Test suites are
312 initially discovered by recursively searching up the directory hierarchy for
313 all the input files passed on the command line. You can use
314 :option:`--show-suites` to display the discovered test suites at startup.
316 Once a test suite is discovered, its config file is loaded. Config files
317 themselves are Python modules which will be executed. When the config file is
318 executed, two important global variables are predefined:
322 The global **lit** configuration object (a *LitConfig* instance), which defines
323 the builtin test formats, global configuration parameters, and other helper
324 routines for implementing test configurations.
328 This is the config object (a *TestingConfig* instance) for the test suite,
329 which the config file is expected to populate. The following variables are also
330 available on the *config* object, some of which must be set by the config and
331 others are optional or predefined:
333 **name** *[required]* The name of the test suite, for use in reports and
336 **test_format** *[required]* The test format object which will be used to
337 discover and run tests in the test suite. Generally this will be a builtin test
338 format available from the *lit.formats* module.
340 **test_source_root** The filesystem path to the test suite root. For out-of-dir
341 builds this is the directory that will be scanned for tests.
343 **test_exec_root** For out-of-dir builds, the path to the test suite root inside
344 the object directory. This is where tests will be run and temporary output files
347 **environment** A dictionary representing the environment to use when executing
350 **suffixes** For **lit** test formats which scan directories for tests, this
351 variable is a list of suffixes to identify test files. Used by: *ShTest*.
353 **substitutions** For **lit** test formats which substitute variables into a test
354 script, the list of substitutions to perform. Used by: *ShTest*.
356 **unsupported** Mark an unsupported directory, all tests within it will be
357 reported as unsupported. Used by: *ShTest*.
359 **parent** The parent configuration, this is the config object for the directory
360 containing the test suite, or None.
362 **root** The root configuration. This is the top-most :program:`lit` configuration in
365 **pipefail** Normally a test using a shell pipe fails if any of the commands
366 on the pipe fail. If this is not desired, setting this variable to false
367 makes the test fail only if the last command in the pipe fails.
369 **available_features** A set of features that can be used in `XFAIL`,
370 `REQUIRES`, and `UNSUPPORTED` directives.
375 Once test suites are located, :program:`lit` recursively traverses the source
376 directory (following *test_source_root*) looking for tests. When :program:`lit`
377 enters a sub-directory, it first checks to see if a nested test suite is
378 defined in that directory. If so, it loads that test suite recursively,
379 otherwise it instantiates a local test config for the directory (see
380 :ref:`local-configuration-files`).
382 Tests are identified by the test suite they are contained within, and the
383 relative path inside that suite. Note that the relative path may not refer to
384 an actual file on disk; some test formats (such as *GoogleTest*) define
385 "virtual tests" which have a path that contains both the path to the actual
386 test file and a subpath to identify the virtual test.
388 .. _local-configuration-files:
390 LOCAL CONFIGURATION FILES
391 ~~~~~~~~~~~~~~~~~~~~~~~~~
393 When :program:`lit` loads a subdirectory in a test suite, it instantiates a
394 local test configuration by cloning the configuration for the parent directory
395 --- the root of this configuration chain will always be a test suite. Once the
396 test configuration is cloned :program:`lit` checks for a *lit.local.cfg* file
397 in the subdirectory. If present, this file will be loaded and can be used to
398 specialize the configuration for each individual directory. This facility can
399 be used to define subdirectories of optional tests, or to change other
400 configuration parameters --- for example, to change the test format, or the
401 suffixes which identify test files.
403 PRE-DEFINED SUBSTITUTIONS
404 ~~~~~~~~~~~~~~~~~~~~~~~~~~
406 :program:`lit` provides various patterns that can be used with the RUN command.
407 These are defined in TestRunner.py. The base set of substitutions are:
409 ========== ==============
411 ========== ==============
412 %s source path (path to the file currently being run)
413 %S source dir (directory of the file currently being run)
415 %{pathsep} path separator
416 %t temporary file name unique to the test
417 %T parent directory of %t (not unique, deprecated, do not use)
419 ========== ==============
421 Other substitutions are provided that are variations on this base set and
422 further substitution patterns can be defined by each test module. See the
423 modules :ref:`local-configuration-files`.
425 More detailed information on substitutions can be found in the
426 :doc:`../TestingGuide`.
428 TEST RUN OUTPUT FORMAT
429 ~~~~~~~~~~~~~~~~~~~~~~
431 The :program:`lit` output for a test run conforms to the following schema, in
432 both short and verbose modes (although in short mode no PASS lines will be
433 shown). This schema has been chosen to be relatively easy to reliably parse by
434 a machine (for example in buildbot log scraping), and for other tools to
437 Each test result is expected to appear on a line that matches:
441 <result code>: <test name> (<progress info>)
443 where ``<result-code>`` is a standard test result such as PASS, FAIL, XFAIL,
444 XPASS, UNRESOLVED, or UNSUPPORTED. The performance result codes of IMPROVED and
445 REGRESSED are also allowed.
447 The ``<test name>`` field can consist of an arbitrary string containing no
450 The ``<progress info>`` field can be used to report progress information such
451 as (1/300) or can be empty, but even when empty the parentheses are required.
453 Each test result may include additional (multiline) log information in the
458 <log delineator> TEST '(<test name>)' <trailing delineator>
462 where ``<test name>`` should be the name of a preceding reported test, ``<log
463 delineator>`` is a string of "*" characters *at least* four characters long
464 (the recommended length is 20), and ``<trailing delineator>`` is an arbitrary
467 The following is an example of a test run output which consists of four tests A,
468 B, C, and D, and a log message for the failing test C:
475 ******************** TEST 'C' FAILED ********************
476 Test 'C' failed as a result of exit code 1.
483 The :program:`lit` distribution contains several example implementations of
484 test suites in the *ExampleTests* directory.