1lit - LLVM Integrated Tester
2============================
3
4SYNOPSIS
5--------
6
7:program:`lit` [*options*] [*tests*]
8
9DESCRIPTION
10-----------
11
12:program:`lit` is a portable tool for executing LLVM and Clang style test
13suites, summarizing their results, and providing indication of failures.
14:program:`lit` is designed to be a lightweight testing tool with as simple a
15user interface as possible.
16
17:program:`lit` should be run with one or more *tests* to run specified on the
18command line.  Tests can be either individual test files or directories to
19search for tests (see :ref:`test-discovery`).
20
21Each specified test will be executed (potentially in parallel) and once all
22tests have been run :program:`lit` will print summary information on the number
23of tests which passed or failed (see :ref:`test-status-results`).  The
24:program:`lit` program will execute with a non-zero exit code if any tests
25fail.
26
27By default :program:`lit` will use a succinct progress display and will only
28print summary information for test failures.  See :ref:`output-options` for
29options controlling the :program:`lit` progress display and output.
30
31:program:`lit` also includes a number of options for controlling how tests are
32executed (specific features may depend on the particular test format).  See
33:ref:`execution-options` for more information.
34
35Finally, :program:`lit` also supports additional options for only running a
36subset of the options specified on the command line, see
37:ref:`selection-options` for more information.
38
39Users interested in the :program:`lit` architecture or designing a
40:program:`lit` testing implementation should see :ref:`lit-infrastructure`.
41
42GENERAL OPTIONS
43---------------
44
45.. option:: -h, --help
46
47 Show the :program:`lit` help message.
48
49.. option:: -j N, --threads=N
50
51 Run ``N`` tests in parallel.  By default, this is automatically chosen to
52 match the number of detected available CPUs.
53
54.. option:: --config-prefix=NAME
55
56 Search for :file:`{NAME}.cfg` and :file:`{NAME}.site.cfg` when searching for
57 test suites, instead of :file:`lit.cfg` and :file:`lit.site.cfg`.
58
59.. option:: -D NAME[=VALUE], --param NAME[=VALUE]
60
61 Add a user defined parameter ``NAME`` with the given ``VALUE`` (or the empty
62 string if not given).  The meaning and use of these parameters is test suite
63 dependent.
64
65.. _output-options:
66
67OUTPUT OPTIONS
68--------------
69
70.. option:: -q, --quiet
71
72 Suppress any output except for test failures.
73
74.. option:: -s, --succinct
75
76 Show less output, for example don't show information on tests that pass.
77
78.. option:: -v, --verbose
79
80 Show more information on test failures, for example the entire test output
81 instead of just the test result.
82
83.. option:: -vv, --echo-all-commands
84
85 Echo all commands to stdout, as they are being executed.
86 This can be valuable for debugging test failures, as the last echoed command
87 will be the one which has failed.
88 :program:`lit` normally inserts a no-op command (``:`` in the case of bash)
89 with argument ``'RUN: at line N'`` before each command pipeline, and this
90 option also causes those no-op commands to be echoed to stdout to help you
91 locate the source line of the failed command.
92 This option implies ``--verbose``.
93
94.. option:: -a, --show-all
95
96 Show more information about all tests, for example the entire test
97 commandline and output.
98
99.. option:: --no-progress-bar
100
101 Do not use curses based progress bar.
102
103.. option:: --show-unsupported
104
105 Show the names of unsupported tests.
106
107.. option:: --show-xfail
108
109 Show the names of tests that were expected to fail.
110
111.. _execution-options:
112
113EXECUTION OPTIONS
114-----------------
115
116.. option:: --path=PATH
117
118 Specify an additional ``PATH`` to use when searching for executables in tests.
119
120.. option:: --vg
121
122 Run individual tests under valgrind (using the memcheck tool).  The
123 ``--error-exitcode`` argument for valgrind is used so that valgrind failures
124 will cause the program to exit with a non-zero status.
125
126 When this option is enabled, :program:`lit` will also automatically provide a
127 "``valgrind``" feature that can be used to conditionally disable (or expect
128 failure in) certain tests.
129
130.. option:: --vg-arg=ARG
131
132 When :option:`--vg` is used, specify an additional argument to pass to
133 :program:`valgrind` itself.
134
135.. option:: --vg-leak
136
137 When :option:`--vg` is used, enable memory leak checks.  When this option is
138 enabled, :program:`lit` will also automatically provide a "``vg_leak``"
139 feature that can be used to conditionally disable (or expect failure in)
140 certain tests.
141
142.. option:: --time-tests
143
144 Track the wall time individual tests take to execute and includes the results
145 in the summary output.  This is useful for determining which tests in a test
146 suite take the most time to execute.  Note that this option is most useful
147 with ``-j 1``.
148
149.. _selection-options:
150
151SELECTION OPTIONS
152-----------------
153
154.. option:: --max-tests=N
155
156 Run at most ``N`` tests and then terminate.
157
158.. option:: --max-time=N
159
160 Spend at most ``N`` seconds (approximately) running tests and then terminate.
161
162.. option:: --shuffle
163
164 Run the tests in a random order.
165
166.. option:: --num-shards=M
167
168 Divide the set of selected tests into ``M`` equal-sized subsets or
169 "shards", and run only one of them.  Must be used with the
170 ``--run-shard=N`` option, which selects the shard to run. The environment
171 variable ``LIT_NUM_SHARDS`` can also be used in place of this
172 option. These two options provide a coarse mechanism for paritioning large
173 testsuites, for parallel execution on separate machines (say in a large
174 testing farm).
175
176.. option:: --run-shard=N
177
178 Select which shard to run, assuming the ``--num-shards=M`` option was
179 provided. The two options must be used together, and the value of ``N``
180 must be in the range ``1..M``. The environment variable
181 ``LIT_RUN_SHARD`` can also be used in place of this option.
182
183.. option:: --filter=REGEXP
184
185  Run only those tests whose name matches the regular expression specified in
186  ``REGEXP``. The environment variable ``LIT_FILTER`` can be also used in place
187  of this option, which is especially useful in environments where the call
188  to ``lit`` is issued indirectly.
189
190ADDITIONAL OPTIONS
191------------------
192
193.. option:: --debug
194
195 Run :program:`lit` in debug mode, for debugging configuration issues and
196 :program:`lit` itself.
197
198.. option:: --show-suites
199
200 List the discovered test suites and exit.
201
202.. option:: --show-tests
203
204 List all of the discovered tests and exit.
205
206EXIT STATUS
207-----------
208
209:program:`lit` will exit with an exit code of 1 if there are any FAIL or XPASS
210results.  Otherwise, it will exit with the status 0.  Other exit codes are used
211for non-test related failures (for example a user error or an internal program
212error).
213
214.. _test-discovery:
215
216TEST DISCOVERY
217--------------
218
219The inputs passed to :program:`lit` can be either individual tests, or entire
220directories or hierarchies of tests to run.  When :program:`lit` starts up, the
221first thing it does is convert the inputs into a complete list of tests to run
222as part of *test discovery*.
223
224In the :program:`lit` model, every test must exist inside some *test suite*.
225:program:`lit` resolves the inputs specified on the command line to test suites
226by searching upwards from the input path until it finds a :file:`lit.cfg` or
227:file:`lit.site.cfg` file.  These files serve as both a marker of test suites
228and as configuration files which :program:`lit` loads in order to understand
229how to find and run the tests inside the test suite.
230
231Once :program:`lit` has mapped the inputs into test suites it traverses the
232list of inputs adding tests for individual files and recursively searching for
233tests in directories.
234
235This behavior makes it easy to specify a subset of tests to run, while still
236allowing the test suite configuration to control exactly how tests are
237interpreted.  In addition, :program:`lit` always identifies tests by the test
238suite they are in, and their relative path inside the test suite.  For
239appropriately configured projects, this allows :program:`lit` to provide
240convenient and flexible support for out-of-tree builds.
241
242.. _test-status-results:
243
244TEST STATUS RESULTS
245-------------------
246
247Each test ultimately produces one of the following six results:
248
249**PASS**
250
251 The test succeeded.
252
253**XFAIL**
254
255 The test failed, but that is expected.  This is used for test formats which allow
256 specifying that a test does not currently work, but wish to leave it in the test
257 suite.
258
259**XPASS**
260
261 The test succeeded, but it was expected to fail.  This is used for tests which
262 were specified as expected to fail, but are now succeeding (generally because
263 the feature they test was broken and has been fixed).
264
265**FAIL**
266
267 The test failed.
268
269**UNRESOLVED**
270
271 The test result could not be determined.  For example, this occurs when the test
272 could not be run, the test itself is invalid, or the test was interrupted.
273
274**UNSUPPORTED**
275
276 The test is not supported in this environment.  This is used by test formats
277 which can report unsupported tests.
278
279Depending on the test format tests may produce additional information about
280their status (generally only for failures).  See the :ref:`output-options`
281section for more information.
282
283.. _lit-infrastructure:
284
285LIT INFRASTRUCTURE
286------------------
287
288This section describes the :program:`lit` testing architecture for users interested in
289creating a new :program:`lit` testing implementation, or extending an existing one.
290
291:program:`lit` proper is primarily an infrastructure for discovering and running
292arbitrary tests, and to expose a single convenient interface to these
293tests. :program:`lit` itself doesn't know how to run tests, rather this logic is
294defined by *test suites*.
295
296TEST SUITES
297~~~~~~~~~~~
298
299As described in :ref:`test-discovery`, tests are always located inside a *test
300suite*.  Test suites serve to define the format of the tests they contain, the
301logic for finding those tests, and any additional information to run the tests.
302
303:program:`lit` identifies test suites as directories containing ``lit.cfg`` or
304``lit.site.cfg`` files (see also :option:`--config-prefix`).  Test suites are
305initially discovered by recursively searching up the directory hierarchy for
306all the input files passed on the command line.  You can use
307:option:`--show-suites` to display the discovered test suites at startup.
308
309Once a test suite is discovered, its config file is loaded.  Config files
310themselves are Python modules which will be executed.  When the config file is
311executed, two important global variables are predefined:
312
313**lit_config**
314
315 The global **lit** configuration object (a *LitConfig* instance), which defines
316 the builtin test formats, global configuration parameters, and other helper
317 routines for implementing test configurations.
318
319**config**
320
321 This is the config object (a *TestingConfig* instance) for the test suite,
322 which the config file is expected to populate.  The following variables are also
323 available on the *config* object, some of which must be set by the config and
324 others are optional or predefined:
325
326 **name** *[required]* The name of the test suite, for use in reports and
327 diagnostics.
328
329 **test_format** *[required]* The test format object which will be used to
330 discover and run tests in the test suite.  Generally this will be a builtin test
331 format available from the *lit.formats* module.
332
333 **test_source_root** The filesystem path to the test suite root.  For out-of-dir
334 builds this is the directory that will be scanned for tests.
335
336 **test_exec_root** For out-of-dir builds, the path to the test suite root inside
337 the object directory.  This is where tests will be run and temporary output files
338 placed.
339
340 **environment** A dictionary representing the environment to use when executing
341 tests in the suite.
342
343 **suffixes** For **lit** test formats which scan directories for tests, this
344 variable is a list of suffixes to identify test files.  Used by: *ShTest*.
345
346 **substitutions** For **lit** test formats which substitute variables into a test
347 script, the list of substitutions to perform.  Used by: *ShTest*.
348
349 **unsupported** Mark an unsupported directory, all tests within it will be
350 reported as unsupported.  Used by: *ShTest*.
351
352 **parent** The parent configuration, this is the config object for the directory
353 containing the test suite, or None.
354
355 **root** The root configuration.  This is the top-most :program:`lit` configuration in
356 the project.
357
358 **pipefail** Normally a test using a shell pipe fails if any of the commands
359 on the pipe fail. If this is not desired, setting this variable to false
360 makes the test fail only if the last command in the pipe fails.
361
362 **available_features** A set of features that can be used in `XFAIL`,
363 `REQUIRES`, and `UNSUPPORTED` directives.
364
365TEST DISCOVERY
366~~~~~~~~~~~~~~
367
368Once test suites are located, :program:`lit` recursively traverses the source
369directory (following *test_source_root*) looking for tests.  When :program:`lit`
370enters a sub-directory, it first checks to see if a nested test suite is
371defined in that directory.  If so, it loads that test suite recursively,
372otherwise it instantiates a local test config for the directory (see
373:ref:`local-configuration-files`).
374
375Tests are identified by the test suite they are contained within, and the
376relative path inside that suite.  Note that the relative path may not refer to
377an actual file on disk; some test formats (such as *GoogleTest*) define
378"virtual tests" which have a path that contains both the path to the actual
379test file and a subpath to identify the virtual test.
380
381.. _local-configuration-files:
382
383LOCAL CONFIGURATION FILES
384~~~~~~~~~~~~~~~~~~~~~~~~~
385
386When :program:`lit` loads a subdirectory in a test suite, it instantiates a
387local test configuration by cloning the configuration for the parent directory
388--- the root of this configuration chain will always be a test suite.  Once the
389test configuration is cloned :program:`lit` checks for a *lit.local.cfg* file
390in the subdirectory.  If present, this file will be loaded and can be used to
391specialize the configuration for each individual directory.  This facility can
392be used to define subdirectories of optional tests, or to change other
393configuration parameters --- for example, to change the test format, or the
394suffixes which identify test files.
395
396PRE-DEFINED SUBSTITUTIONS
397~~~~~~~~~~~~~~~~~~~~~~~~~~
398
399:program:`lit` provides various patterns that can be used with the RUN command.
400These are defined in TestRunner.py. The base set of substitutions are:
401
402 ========== ==============
403  Macro      Substitution
404 ========== ==============
405 %s         source path (path to the file currently being run)
406 %S         source dir (directory of the file currently being run)
407 %p         same as %S
408 %{pathsep} path separator
409 %t         temporary file name unique to the test
410 %T         temporary directory unique to the test
411 %%         %
412 ========== ==============
413
414Other substitutions are provided that are variations on this base set and
415further substitution patterns can be defined by each test module. See the
416modules :ref:`local-configuration-files`.
417
418More detailed information on substitutions can be found in the
419:doc:`../TestingGuide`.
420
421TEST RUN OUTPUT FORMAT
422~~~~~~~~~~~~~~~~~~~~~~
423
424The :program:`lit` output for a test run conforms to the following schema, in
425both short and verbose modes (although in short mode no PASS lines will be
426shown).  This schema has been chosen to be relatively easy to reliably parse by
427a machine (for example in buildbot log scraping), and for other tools to
428generate.
429
430Each test result is expected to appear on a line that matches:
431
432.. code-block:: none
433
434  <result code>: <test name> (<progress info>)
435
436where ``<result-code>`` is a standard test result such as PASS, FAIL, XFAIL,
437XPASS, UNRESOLVED, or UNSUPPORTED.  The performance result codes of IMPROVED and
438REGRESSED are also allowed.
439
440The ``<test name>`` field can consist of an arbitrary string containing no
441newline.
442
443The ``<progress info>`` field can be used to report progress information such
444as (1/300) or can be empty, but even when empty the parentheses are required.
445
446Each test result may include additional (multiline) log information in the
447following format:
448
449.. code-block:: none
450
451  <log delineator> TEST '(<test name>)' <trailing delineator>
452  ... log message ...
453  <log delineator>
454
455where ``<test name>`` should be the name of a preceding reported test, ``<log
456delineator>`` is a string of "*" characters *at least* four characters long
457(the recommended length is 20), and ``<trailing delineator>`` is an arbitrary
458(unparsed) string.
459
460The following is an example of a test run output which consists of four tests A,
461B, C, and D, and a log message for the failing test C:
462
463.. code-block:: none
464
465  PASS: A (1 of 4)
466  PASS: B (2 of 4)
467  FAIL: C (3 of 4)
468  ******************** TEST 'C' FAILED ********************
469  Test 'C' failed as a result of exit code 1.
470  ********************
471  PASS: D (4 of 4)
472
473LIT EXAMPLE TESTS
474~~~~~~~~~~~~~~~~~
475
476The :program:`lit` distribution contains several example implementations of
477test suites in the *ExampleTests* directory.
478
479SEE ALSO
480--------
481
482valgrind(1)
483