blob: 00b5c070d4ec9980e2858b68619f55eda8c79ab0 [file] [log] [blame]
Daniel Dunbar3b709d52012-05-08 16:50:35 +00001lit - LLVM Integrated Tester
2============================
3
Daniel Dunbar3b709d52012-05-08 16:50:35 +00004SYNOPSIS
5--------
6
Daniel Dunbar3b709d52012-05-08 16:50:35 +00007**lit** [*options*] [*tests*]
8
Daniel Dunbar3b709d52012-05-08 16:50:35 +00009DESCRIPTION
10-----------
11
Daniel Dunbar3b709d52012-05-08 16:50:35 +000012**lit** is a portable tool for executing LLVM and Clang style test suites,
13summarizing their results, and providing indication of failures. **lit** is
14designed to be a lightweight testing tool with as simple a user interface as
15possible.
16
17**lit** should be run with one or more *tests* to run specified on the command
18line. Tests can be either individual test files or directories to search for
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +000019tests (see :ref:`test-discovery`).
Daniel Dunbar3b709d52012-05-08 16:50:35 +000020
21Each specified test will be executed (potentially in parallel) and once all
22tests have been run **lit** will print summary information on the number of tests
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +000023which passed or failed (see :ref:`test-status-results`). The **lit** program will
Daniel Dunbar3b709d52012-05-08 16:50:35 +000024execute with a non-zero exit code if any tests fail.
25
26By default **lit** will use a succinct progress display and will only print
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +000027summary information for test failures. See :ref:`output-options` for options
Daniel Dunbar3b709d52012-05-08 16:50:35 +000028controlling the **lit** progress display and output.
29
30**lit** also includes a number of options for controlling how tests are executed
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +000031(specific features may depend on the particular test format). See
32:ref:`execution-options` for more information.
Daniel Dunbar3b709d52012-05-08 16:50:35 +000033
34Finally, **lit** also supports additional options for only running a subset of
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +000035the options specified on the command line, see :ref:`selection-options` for
Daniel Dunbar3b709d52012-05-08 16:50:35 +000036more information.
37
38Users interested in the **lit** architecture or designing a **lit** testing
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +000039implementation should see :ref:`lit-infrastructure`.
Daniel Dunbar3b709d52012-05-08 16:50:35 +000040
41GENERAL OPTIONS
42---------------
43
Daniel Dunbar3b709d52012-05-08 16:50:35 +000044**-h**, **--help**
45
46 Show the **lit** help message.
47
Daniel Dunbar3b709d52012-05-08 16:50:35 +000048**-j** *N*, **--threads**\ =\ *N*
49
50 Run *N* tests in parallel. By default, this is automatically chosen to match
51 the number of detected available CPUs.
52
Daniel Dunbar3b709d52012-05-08 16:50:35 +000053**--config-prefix**\ =\ *NAME*
54
55 Search for *NAME.cfg* and *NAME.site.cfg* when searching for test suites,
56 instead of *lit.cfg* and *lit.site.cfg*.
57
Daniel Dunbar3b709d52012-05-08 16:50:35 +000058**--param** *NAME*, **--param** *NAME*\ =\ *VALUE*
59
60 Add a user defined parameter *NAME* with the given *VALUE* (or the empty
61 string if not given). The meaning and use of these parameters is test suite
62 dependent.
63
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +000064.. _output-options:
Daniel Dunbar3b709d52012-05-08 16:50:35 +000065
66OUTPUT OPTIONS
67--------------
68
Daniel Dunbar3b709d52012-05-08 16:50:35 +000069**-q**, **--quiet**
70
71 Suppress any output except for test failures.
72
Daniel Dunbar3b709d52012-05-08 16:50:35 +000073**-s**, **--succinct**
74
75 Show less output, for example don't show information on tests that pass.
76
Daniel Dunbar3b709d52012-05-08 16:50:35 +000077**-v**, **--verbose**
78
79 Show more information on test failures, for example the entire test output
80 instead of just the test result.
81
Daniel Dunbar3b709d52012-05-08 16:50:35 +000082**--no-progress-bar**
83
84 Do not use curses based progress bar.
85
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +000086.. _execution-options:
Daniel Dunbar3b709d52012-05-08 16:50:35 +000087
88EXECUTION OPTIONS
89-----------------
90
Daniel Dunbar3b709d52012-05-08 16:50:35 +000091**--path**\ =\ *PATH*
92
93 Specify an addition *PATH* to use when searching for executables in tests.
94
Daniel Dunbar3b709d52012-05-08 16:50:35 +000095**--vg**
96
97 Run individual tests under valgrind (using the memcheck tool). The
98 *--error-exitcode* argument for valgrind is used so that valgrind failures will
99 cause the program to exit with a non-zero status.
100
Daniel Dunbarf8545972012-10-19 20:12:00 +0000101 When this option is enabled, **lit** will also automatically provide a
102 "valgrind" feature that can be used to conditionally disable (or expect failure
103 in) certain tests.
104
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000105**--vg-arg**\ =\ *ARG*
106
107 When *--vg* is used, specify an additional argument to pass to valgrind itself.
108
Daniel Dunbarf8545972012-10-19 20:12:00 +0000109**--vg-leak**
110
111 When *--vg* is used, enable memory leak checks. When this option is enabled,
Daniel Dunbar6b283ea2012-10-19 20:29:30 +0000112 **lit** will also automatically provide a "vg_leak" feature that can be
Daniel Dunbarf8545972012-10-19 20:12:00 +0000113 used to conditionally disable (or expect failure in) certain tests.
114
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000115**--time-tests**
116
117 Track the wall time individual tests take to execute and includes the results in
118 the summary output. This is useful for determining which tests in a test suite
119 take the most time to execute. Note that this option is most useful with *-j
120 1*.
121
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +0000122.. _selection-options:
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000123
124SELECTION OPTIONS
125-----------------
126
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000127**--max-tests**\ =\ *N*
128
129 Run at most *N* tests and then terminate.
130
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000131**--max-time**\ =\ *N*
132
133 Spend at most *N* seconds (approximately) running tests and then terminate.
134
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000135**--shuffle**
136
137 Run the tests in a random order.
138
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000139ADDITIONAL OPTIONS
140------------------
141
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000142**--debug**
143
144 Run **lit** in debug mode, for debugging configuration issues and **lit** itself.
145
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000146**--show-suites**
147
148 List the discovered test suites as part of the standard output.
149
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000150**--no-tcl-as-sh**
151
152 Run Tcl scripts internally (instead of converting to shell scripts).
153
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000154**--repeat**\ =\ *N*
155
156 Run each test *N* times. Currently this is primarily useful for timing tests,
157 other results are not collated in any reasonable fashion.
158
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000159EXIT STATUS
160-----------
161
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000162**lit** will exit with an exit code of 1 if there are any FAIL or XPASS
163results. Otherwise, it will exit with the status 0. Other exit codes are used
164for non-test related failures (for example a user error or an internal program
165error).
166
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +0000167.. _test-discovery:
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000168
169TEST DISCOVERY
170--------------
171
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000172The inputs passed to **lit** can be either individual tests, or entire
173directories or hierarchies of tests to run. When **lit** starts up, the first
174thing it does is convert the inputs into a complete list of tests to run as part
175of *test discovery*.
176
177In the **lit** model, every test must exist inside some *test suite*. **lit**
178resolves the inputs specified on the command line to test suites by searching
179upwards from the input path until it finds a *lit.cfg* or *lit.site.cfg*
180file. These files serve as both a marker of test suites and as configuration
181files which **lit** loads in order to understand how to find and run the tests
182inside the test suite.
183
184Once **lit** has mapped the inputs into test suites it traverses the list of
185inputs adding tests for individual files and recursively searching for tests in
186directories.
187
188This behavior makes it easy to specify a subset of tests to run, while still
189allowing the test suite configuration to control exactly how tests are
190interpreted. In addition, **lit** always identifies tests by the test suite they
191are in, and their relative path inside the test suite. For appropriately
192configured projects, this allows **lit** to provide convenient and flexible
193support for out-of-tree builds.
194
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +0000195.. _test-status-results:
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000196
197TEST STATUS RESULTS
198-------------------
199
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000200Each test ultimately produces one of the following six results:
201
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000202**PASS**
203
204 The test succeeded.
205
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000206**XFAIL**
207
208 The test failed, but that is expected. This is used for test formats which allow
209 specifying that a test does not currently work, but wish to leave it in the test
210 suite.
211
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000212**XPASS**
213
214 The test succeeded, but it was expected to fail. This is used for tests which
215 were specified as expected to fail, but are now succeeding (generally because
216 the feature they test was broken and has been fixed).
217
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000218**FAIL**
219
220 The test failed.
221
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000222**UNRESOLVED**
223
224 The test result could not be determined. For example, this occurs when the test
225 could not be run, the test itself is invalid, or the test was interrupted.
226
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000227**UNSUPPORTED**
228
229 The test is not supported in this environment. This is used by test formats
230 which can report unsupported tests.
231
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000232Depending on the test format tests may produce additional information about
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +0000233their status (generally only for failures). See the :ref:`output-options`
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000234section for more information.
235
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +0000236.. _lit-infrastructure:
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000237
238LIT INFRASTRUCTURE
239------------------
240
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000241This section describes the **lit** testing architecture for users interested in
242creating a new **lit** testing implementation, or extending an existing one.
243
244**lit** proper is primarily an infrastructure for discovering and running
245arbitrary tests, and to expose a single convenient interface to these
246tests. **lit** itself doesn't know how to run tests, rather this logic is
247defined by *test suites*.
248
249TEST SUITES
250~~~~~~~~~~~
251
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +0000252As described in :ref:`test-discovery`, tests are always located inside a *test
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000253suite*. Test suites serve to define the format of the tests they contain, the
254logic for finding those tests, and any additional information to run the tests.
255
256**lit** identifies test suites as directories containing *lit.cfg* or
257*lit.site.cfg* files (see also **--config-prefix**). Test suites are initially
258discovered by recursively searching up the directory hierarchy for all the input
259files passed on the command line. You can use **--show-suites** to display the
260discovered test suites at startup.
261
262Once a test suite is discovered, its config file is loaded. Config files
263themselves are Python modules which will be executed. When the config file is
264executed, two important global variables are predefined:
265
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000266**lit**
267
268 The global **lit** configuration object (a *LitConfig* instance), which defines
269 the builtin test formats, global configuration parameters, and other helper
270 routines for implementing test configurations.
271
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000272**config**
273
274 This is the config object (a *TestingConfig* instance) for the test suite,
275 which the config file is expected to populate. The following variables are also
276 available on the *config* object, some of which must be set by the config and
277 others are optional or predefined:
278
279 **name** *[required]* The name of the test suite, for use in reports and
280 diagnostics.
281
282 **test_format** *[required]* The test format object which will be used to
283 discover and run tests in the test suite. Generally this will be a builtin test
284 format available from the *lit.formats* module.
285
286 **test_src_root** The filesystem path to the test suite root. For out-of-dir
287 builds this is the directory that will be scanned for tests.
288
289 **test_exec_root** For out-of-dir builds, the path to the test suite root inside
290 the object directory. This is where tests will be run and temporary output files
291 placed.
292
293 **environment** A dictionary representing the environment to use when executing
294 tests in the suite.
295
296 **suffixes** For **lit** test formats which scan directories for tests, this
297 variable is a list of suffixes to identify test files. Used by: *ShTest*,
298 *TclTest*.
299
300 **substitutions** For **lit** test formats which substitute variables into a test
301 script, the list of substitutions to perform. Used by: *ShTest*, *TclTest*.
302
303 **unsupported** Mark an unsupported directory, all tests within it will be
304 reported as unsupported. Used by: *ShTest*, *TclTest*.
305
306 **parent** The parent configuration, this is the config object for the directory
307 containing the test suite, or None.
308
309 **root** The root configuration. This is the top-most **lit** configuration in
310 the project.
311
312 **on_clone** The config is actually cloned for every subdirectory inside a test
313 suite, to allow local configuration on a per-directory basis. The *on_clone*
314 variable can be set to a Python function which will be called whenever a
315 configuration is cloned (for a subdirectory). The function should takes three
316 arguments: (1) the parent configuration, (2) the new configuration (which the
317 *on_clone* function will generally modify), and (3) the test path to the new
318 directory being scanned.
319
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000320TEST DISCOVERY
321~~~~~~~~~~~~~~
322
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000323Once test suites are located, **lit** recursively traverses the source directory
324(following *test_src_root*) looking for tests. When **lit** enters a
325sub-directory, it first checks to see if a nested test suite is defined in that
326directory. If so, it loads that test suite recursively, otherwise it
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +0000327instantiates a local test config for the directory (see
328:ref:`local-configuration-files`).
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000329
330Tests are identified by the test suite they are contained within, and the
331relative path inside that suite. Note that the relative path may not refer to an
332actual file on disk; some test formats (such as *GoogleTest*) define "virtual
333tests" which have a path that contains both the path to the actual test file and
334a subpath to identify the virtual test.
335
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +0000336.. _local-configuration-files:
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000337
338LOCAL CONFIGURATION FILES
339~~~~~~~~~~~~~~~~~~~~~~~~~
340
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000341When **lit** loads a subdirectory in a test suite, it instantiates a local test
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +0000342configuration by cloning the configuration for the parent direction --- the root
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000343of this configuration chain will always be a test suite. Once the test
344configuration is cloned **lit** checks for a *lit.local.cfg* file in the
345subdirectory. If present, this file will be loaded and can be used to specialize
346the configuration for each individual directory. This facility can be used to
347define subdirectories of optional tests, or to change other configuration
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +0000348parameters --- for example, to change the test format, or the suffixes which
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000349identify test files.
350
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000351TEST RUN OUTPUT FORMAT
352~~~~~~~~~~~~~~~~~~~~~~
353
Eli Bendersky1f9f73a2012-11-20 00:26:08 +0000354The **lit** output for a test run conforms to the following schema, in both
355short and verbose modes (although in short mode no PASS lines will be shown).
356This schema has been chosen to be relatively easy to reliably parse by a machine
357(for example in buildbot log scraping), and for other tools to generate.
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000358
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +0000359Each test result is expected to appear on a line that matches:
360
361.. code-block:: none
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000362
Eli Bendersky1f9f73a2012-11-20 00:26:08 +0000363 <result code>: <test name> (<progress info>)
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000364
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +0000365where ``<result-code>`` is a standard test result such as PASS, FAIL, XFAIL,
366XPASS, UNRESOLVED, or UNSUPPORTED. The performance result codes of IMPROVED and
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000367REGRESSED are also allowed.
368
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +0000369The ``<test name>`` field can consist of an arbitrary string containing no
370newline.
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000371
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +0000372The ``<progress info>`` field can be used to report progress information such
373as (1/300) or can be empty, but even when empty the parentheses are required.
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000374
375Each test result may include additional (multiline) log information in the
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +0000376following format:
377
378.. code-block:: none
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000379
Eli Bendersky1f9f73a2012-11-20 00:26:08 +0000380 <log delineator> TEST '(<test name>)' <trailing delineator>
381 ... log message ...
382 <log delineator>
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000383
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +0000384where ``<test name>`` should be the name of a preceding reported test, ``<log
385delineator>`` is a string of "*" characters *at least* four characters long
386(the recommended length is 20), and ``<trailing delineator>`` is an arbitrary
387(unparsed) string.
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000388
389The following is an example of a test run output which consists of four tests A,
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +0000390B, C, and D, and a log message for the failing test C:
391
392.. code-block:: none
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000393
394 PASS: A (1 of 4)
395 PASS: B (2 of 4)
396 FAIL: C (3 of 4)
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +0000397 ******************** TEST 'C' FAILED ********************
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000398 Test 'C' failed as a result of exit code 1.
Dmitri Gribenkoe26b62c2012-11-29 17:05:34 +0000399 ********************
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000400 PASS: D (4 of 4)
401
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000402LIT EXAMPLE TESTS
403~~~~~~~~~~~~~~~~~
404
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000405The **lit** distribution contains several example implementations of test suites
406in the *ExampleTests* directory.
407
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000408SEE ALSO
409--------
410
Daniel Dunbar3b709d52012-05-08 16:50:35 +0000411valgrind(1)