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