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:: --param NAME, --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:: --no-progress-bar
84
85 Do not use curses based progress bar.
86
87.. option:: --show-unsupported
88
89 Show the names of unsupported tests.
90
91.. option:: --show-xfail
92
93 Show the names of tests that were expected to fail.
94
95.. _execution-options:
96
97EXECUTION OPTIONS
98-----------------
99
100.. option:: --path=PATH
101
102 Specify an additional ``PATH`` to use when searching for executables in tests.
103
104.. option:: --vg
105
106 Run individual tests under valgrind (using the memcheck tool).  The
107 ``--error-exitcode`` argument for valgrind is used so that valgrind failures
108 will cause the program to exit with a non-zero status.
109
110 When this option is enabled, :program:`lit` will also automatically provide a
111 "``valgrind``" feature that can be used to conditionally disable (or expect
112 failure in) certain tests.
113
114.. option:: --vg-arg=ARG
115
116 When :option:`--vg` is used, specify an additional argument to pass to
117 :program:`valgrind` itself.
118
119.. option:: --vg-leak
120
121 When :option:`--vg` is used, enable memory leak checks.  When this option is
122 enabled, :program:`lit` will also automatically provide a "``vg_leak``"
123 feature that can be used to conditionally disable (or expect failure in)
124 certain tests.
125
126.. option:: --time-tests
127
128 Track the wall time individual tests take to execute and includes the results
129 in the summary output.  This is useful for determining which tests in a test
130 suite take the most time to execute.  Note that this option is most useful
131 with ``-j 1``.
132
133.. _selection-options:
134
135SELECTION OPTIONS
136-----------------
137
138.. option:: --max-tests=N
139
140 Run at most ``N`` tests and then terminate.
141
142.. option:: --max-time=N
143
144 Spend at most ``N`` seconds (approximately) running tests and then terminate.
145
146.. option:: --shuffle
147
148 Run the tests in a random order.
149
150ADDITIONAL OPTIONS
151------------------
152
153.. option:: --debug
154
155 Run :program:`lit` in debug mode, for debugging configuration issues and
156 :program:`lit` itself.
157
158.. option:: --show-suites
159
160 List the discovered test suites and exit.
161
162.. option:: --show-tests
163
164 List all of the the discovered tests and exit.
165
166EXIT STATUS
167-----------
168
169:program:`lit` will exit with an exit code of 1 if there are any FAIL or XPASS
170results.  Otherwise, it will exit with the status 0.  Other exit codes are used
171for non-test related failures (for example a user error or an internal program
172error).
173
174.. _test-discovery:
175
176TEST DISCOVERY
177--------------
178
179The inputs passed to :program:`lit` can be either individual tests, or entire
180directories or hierarchies of tests to run.  When :program:`lit` starts up, the
181first thing it does is convert the inputs into a complete list of tests to run
182as part of *test discovery*.
183
184In the :program:`lit` model, every test must exist inside some *test suite*.
185:program:`lit` resolves the inputs specified on the command line to test suites
186by searching upwards from the input path until it finds a :file:`lit.cfg` or
187:file:`lit.site.cfg` file.  These files serve as both a marker of test suites
188and as configuration files which :program:`lit` loads in order to understand
189how to find and run the tests inside the test suite.
190
191Once :program:`lit` has mapped the inputs into test suites it traverses the
192list of inputs adding tests for individual files and recursively searching for
193tests in directories.
194
195This behavior makes it easy to specify a subset of tests to run, while still
196allowing the test suite configuration to control exactly how tests are
197interpreted.  In addition, :program:`lit` always identifies tests by the test
198suite they are in, and their relative path inside the test suite.  For
199appropriately configured projects, this allows :program:`lit` to provide
200convenient and flexible support for out-of-tree builds.
201
202.. _test-status-results:
203
204TEST STATUS RESULTS
205-------------------
206
207Each test ultimately produces one of the following six results:
208
209**PASS**
210
211 The test succeeded.
212
213**XFAIL**
214
215 The test failed, but that is expected.  This is used for test formats which allow
216 specifying that a test does not currently work, but wish to leave it in the test
217 suite.
218
219**XPASS**
220
221 The test succeeded, but it was expected to fail.  This is used for tests which
222 were specified as expected to fail, but are now succeeding (generally because
223 the feature they test was broken and has been fixed).
224
225**FAIL**
226
227 The test failed.
228
229**UNRESOLVED**
230
231 The test result could not be determined.  For example, this occurs when the test
232 could not be run, the test itself is invalid, or the test was interrupted.
233
234**UNSUPPORTED**
235
236 The test is not supported in this environment.  This is used by test formats
237 which can report unsupported tests.
238
239Depending on the test format tests may produce additional information about
240their status (generally only for failures).  See the :ref:`output-options`
241section for more information.
242
243.. _lit-infrastructure:
244
245LIT INFRASTRUCTURE
246------------------
247
248This section describes the :program:`lit` testing architecture for users interested in
249creating a new :program:`lit` testing implementation, or extending an existing one.
250
251:program:`lit` proper is primarily an infrastructure for discovering and running
252arbitrary tests, and to expose a single convenient interface to these
253tests. :program:`lit` itself doesn't know how to run tests, rather this logic is
254defined by *test suites*.
255
256TEST SUITES
257~~~~~~~~~~~
258
259As described in :ref:`test-discovery`, tests are always located inside a *test
260suite*.  Test suites serve to define the format of the tests they contain, the
261logic for finding those tests, and any additional information to run the tests.
262
263:program:`lit` identifies test suites as directories containing ``lit.cfg`` or
264``lit.site.cfg`` files (see also :option:`--config-prefix`).  Test suites are
265initially discovered by recursively searching up the directory hierarchy for
266all the input files passed on the command line.  You can use
267:option:`--show-suites` to display the discovered test suites at startup.
268
269Once a test suite is discovered, its config file is loaded.  Config files
270themselves are Python modules which will be executed.  When the config file is
271executed, two important global variables are predefined:
272
273**lit_config**
274
275 The global **lit** configuration object (a *LitConfig* instance), which defines
276 the builtin test formats, global configuration parameters, and other helper
277 routines for implementing test configurations.
278
279**config**
280
281 This is the config object (a *TestingConfig* instance) for the test suite,
282 which the config file is expected to populate.  The following variables are also
283 available on the *config* object, some of which must be set by the config and
284 others are optional or predefined:
285
286 **name** *[required]* The name of the test suite, for use in reports and
287 diagnostics.
288
289 **test_format** *[required]* The test format object which will be used to
290 discover and run tests in the test suite.  Generally this will be a builtin test
291 format available from the *lit.formats* module.
292
293 **test_source_root** The filesystem path to the test suite root.  For out-of-dir
294 builds this is the directory that will be scanned for tests.
295
296 **test_exec_root** For out-of-dir builds, the path to the test suite root inside
297 the object directory.  This is where tests will be run and temporary output files
298 placed.
299
300 **environment** A dictionary representing the environment to use when executing
301 tests in the suite.
302
303 **suffixes** For **lit** test formats which scan directories for tests, this
304 variable is a list of suffixes to identify test files.  Used by: *ShTest*.
305
306 **substitutions** For **lit** test formats which substitute variables into a test
307 script, the list of substitutions to perform.  Used by: *ShTest*.
308
309 **unsupported** Mark an unsupported directory, all tests within it will be
310 reported as unsupported.  Used by: *ShTest*.
311
312 **parent** The parent configuration, this is the config object for the directory
313 containing the test suite, or None.
314
315 **root** The root configuration.  This is the top-most :program:`lit` configuration in
316 the project.
317
318 **pipefail** Normally a test using a shell pipe fails if any of the commands
319 on the pipe fail. If this is not desired, setting this variable to false
320 makes the test fail only if the last command in the pipe fails.
321
322TEST DISCOVERY
323~~~~~~~~~~~~~~
324
325Once test suites are located, :program:`lit` recursively traverses the source
326directory (following *test_source_root*) looking for tests.  When :program:`lit`
327enters a sub-directory, it first checks to see if a nested test suite is
328defined in that directory.  If so, it loads that test suite recursively,
329otherwise it instantiates a local test config for the directory (see
330:ref:`local-configuration-files`).
331
332Tests are identified by the test suite they are contained within, and the
333relative path inside that suite.  Note that the relative path may not refer to
334an actual file on disk; some test formats (such as *GoogleTest*) define
335"virtual tests" which have a path that contains both the path to the actual
336test file and a subpath to identify the virtual test.
337
338.. _local-configuration-files:
339
340LOCAL CONFIGURATION FILES
341~~~~~~~~~~~~~~~~~~~~~~~~~
342
343When :program:`lit` loads a subdirectory in a test suite, it instantiates a
344local test configuration by cloning the configuration for the parent direction
345--- the root of this configuration chain will always be a test suite.  Once the
346test configuration is cloned :program:`lit` checks for a *lit.local.cfg* file
347in the subdirectory.  If present, this file will be loaded and can be used to
348specialize the configuration for each individual directory.  This facility can
349be used to define subdirectories of optional tests, or to change other
350configuration parameters --- for example, to change the test format, or the
351suffixes which identify test files.
352
353TEST RUN OUTPUT FORMAT
354~~~~~~~~~~~~~~~~~~~~~~
355
356The :program:`lit` output for a test run conforms to the following schema, in
357both short and verbose modes (although in short mode no PASS lines will be
358shown).  This schema has been chosen to be relatively easy to reliably parse by
359a machine (for example in buildbot log scraping), and for other tools to
360generate.
361
362Each test result is expected to appear on a line that matches:
363
364.. code-block:: none
365
366  <result code>: <test name> (<progress info>)
367
368where ``<result-code>`` is a standard test result such as PASS, FAIL, XFAIL,
369XPASS, UNRESOLVED, or UNSUPPORTED.  The performance result codes of IMPROVED and
370REGRESSED are also allowed.
371
372The ``<test name>`` field can consist of an arbitrary string containing no
373newline.
374
375The ``<progress info>`` field can be used to report progress information such
376as (1/300) or can be empty, but even when empty the parentheses are required.
377
378Each test result may include additional (multiline) log information in the
379following format:
380
381.. code-block:: none
382
383  <log delineator> TEST '(<test name>)' <trailing delineator>
384  ... log message ...
385  <log delineator>
386
387where ``<test name>`` should be the name of a preceding reported test, ``<log
388delineator>`` is a string of "*" characters *at least* four characters long
389(the recommended length is 20), and ``<trailing delineator>`` is an arbitrary
390(unparsed) string.
391
392The following is an example of a test run output which consists of four tests A,
393B, C, and D, and a log message for the failing test C:
394
395.. code-block:: none
396
397  PASS: A (1 of 4)
398  PASS: B (2 of 4)
399  FAIL: C (3 of 4)
400  ******************** TEST 'C' FAILED ********************
401  Test 'C' failed as a result of exit code 1.
402  ********************
403  PASS: D (4 of 4)
404
405LIT EXAMPLE TESTS
406~~~~~~~~~~~~~~~~~
407
408The :program:`lit` distribution contains several example implementations of
409test suites in the *ExampleTests* directory.
410
411SEE ALSO
412--------
413
414valgrind(1)
415