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