1lit - LLVM Integrated Tester
2============================
3
4.. program:: lit
5
6SYNOPSIS
7--------
8
9:program:`lit` [*options*] [*tests*]
10
11DESCRIPTION
12-----------
13
14:program:`lit` is a portable tool for executing LLVM and Clang style test
15suites, summarizing their results, and providing indication of failures.
16:program:`lit` is designed to be a lightweight testing tool with as simple a
17user interface as possible.
18
19:program:`lit` should be run with one or more *tests* to run specified on the
20command line.  Tests can be either individual test files or directories to
21search for tests (see :ref:`test-discovery`).
22
23Each specified test will be executed (potentially concurrently) and once all
24tests have been run :program:`lit` will print summary information on the number
25of tests which passed or failed (see :ref:`test-status-results`).  The
26:program:`lit` program will execute with a non-zero exit code if any tests
27fail.
28
29By default :program:`lit` will use a succinct progress display and will only
30print summary information for test failures.  See :ref:`output-options` for
31options controlling the :program:`lit` progress display and output.
32
33:program:`lit` also includes a number of options for controlling how tests are
34executed (specific features may depend on the particular test format).  See
35:ref:`execution-options` for more information.
36
37Finally, :program:`lit` also supports additional options for only running a
38subset of the options specified on the command line, see
39:ref:`selection-options` for more information.
40
41:program:`lit` parses options from the environment variable ``LIT_OPTS`` after
42parsing options from the command line.  ``LIT_OPTS`` is primarily useful for
43supplementing or overriding the command-line options supplied to :program:`lit`
44by ``check`` targets defined by a project's build system.
45
46Users interested in the :program:`lit` architecture or designing a
47:program:`lit` testing implementation should see :ref:`lit-infrastructure`.
48
49GENERAL OPTIONS
50---------------
51
52.. option:: -h, --help
53
54 Show the :program:`lit` help message.
55
56.. option:: -j N, --workers=N
57
58 Run ``N`` tests in parallel.  By default, this is automatically chosen to
59 match the number of detected available CPUs.
60
61.. option:: --config-prefix=NAME
62
63 Search for :file:`{NAME}.cfg` and :file:`{NAME}.site.cfg` when searching for
64 test suites, instead of :file:`lit.cfg` and :file:`lit.site.cfg`.
65
66.. option:: -D NAME[=VALUE], --param NAME[=VALUE]
67
68 Add a user defined parameter ``NAME`` with the given ``VALUE`` (or the empty
69 string if not given).  The meaning and use of these parameters is test suite
70 dependent.
71
72.. _output-options:
73
74OUTPUT OPTIONS
75--------------
76
77.. option:: -q, --quiet
78
79 Suppress any output except for test failures.
80
81.. option:: -s, --succinct
82
83 Show less output, for example don't show information on tests that pass.
84 Also show a progress bar, unless ``--no-progress-bar`` is specified.
85
86.. option:: -v, --verbose
87
88 Show more information on test failures, for example the entire test output
89 instead of just the test result.
90
91.. option:: -vv, --echo-all-commands
92
93 Echo all commands to stdout, as they are being executed.
94 This can be valuable for debugging test failures, as the last echoed command
95 will be the one which has failed.
96 :program:`lit` normally inserts a no-op command (``:`` in the case of bash)
97 with argument ``'RUN: at line N'`` before each command pipeline, and this
98 option also causes those no-op commands to be echoed to stdout to help you
99 locate the source line of the failed command.
100 This option implies ``--verbose``.
101
102.. option:: -a, --show-all
103
104 Show more information about all tests, for example the entire test
105 commandline and output.
106
107.. option:: --no-progress-bar
108
109 Do not use curses based progress bar.
110
111.. option:: --show-unsupported
112
113 Show the names of unsupported tests.
114
115.. option:: --show-xfail
116
117 Show the names of tests that were expected to fail.
118
119.. _execution-options:
120
121EXECUTION OPTIONS
122-----------------
123
124.. option:: --path=PATH
125
126 Specify an additional ``PATH`` to use when searching for executables in tests.
127
128.. option:: --vg
129
130 Run individual tests under valgrind (using the memcheck tool).  The
131 ``--error-exitcode`` argument for valgrind is used so that valgrind failures
132 will cause the program to exit with a non-zero status.
133
134 When this option is enabled, :program:`lit` will also automatically provide a
135 "``valgrind``" feature that can be used to conditionally disable (or expect
136 failure in) certain tests.
137
138.. option:: --vg-arg=ARG
139
140 When :option:`--vg` is used, specify an additional argument to pass to
141 :program:`valgrind` itself.
142
143.. option:: --vg-leak
144
145 When :option:`--vg` is used, enable memory leak checks.  When this option is
146 enabled, :program:`lit` will also automatically provide a "``vg_leak``"
147 feature that can be used to conditionally disable (or expect failure in)
148 certain tests.
149
150.. option:: --time-tests
151
152 Track the wall time individual tests take to execute and includes the results
153 in the summary output.  This is useful for determining which tests in a test
154 suite take the most time to execute.
155
156.. option:: --ignore-fail
157
158 Exit with status zero even if some tests fail.
159
160.. option:: --no-indirectly-run-check
161
162 Do not error if a test would not be run if the user had specified the
163 containing directory instead of naming the test directly.
164
165.. _selection-options:
166
167SELECTION OPTIONS
168-----------------
169
170By default, `lit` will run failing tests first, then run tests in descending
171execution time order to optimize concurrency.  The execution order can be
172changed using the :option:`--order` option.
173
174The timing data is stored in the `test_exec_root` in a file named
175`.lit_test_times.txt`. If this file does not exist, then `lit` checks the
176`test_source_root` for the file to optionally accelerate clean builds.
177
178.. option:: --shuffle
179
180 Run the tests in a random order, not failing/slowest first. Deprecated,
181 use :option:`--order` instead.
182
183.. option:: --max-failures N
184
185 Stop execution after the given number ``N`` of failures.
186 An integer argument should be passed on the command line
187 prior to execution.
188
189.. option:: --max-tests=N
190
191 Run at most ``N`` tests and then terminate.
192
193.. option:: --max-time=N
194
195 Spend at most ``N`` seconds (approximately) running tests and then terminate.
196 Note that this is not an alias for :option:`--timeout`; the two are
197 different kinds of maximums.
198
199.. option:: --num-shards=M
200
201 Divide the set of selected tests into ``M`` equal-sized subsets or
202 "shards", and run only one of them.  Must be used with the
203 ``--run-shard=N`` option, which selects the shard to run. The environment
204 variable ``LIT_NUM_SHARDS`` can also be used in place of this
205 option. These two options provide a coarse mechanism for partitioning large
206 testsuites, for parallel execution on separate machines (say in a large
207 testing farm).
208
209.. option:: --order={lexical,random,smart}
210
211 Define the order in which tests are run. The supported values are:
212
213 - lexical - tests will be run in lexical order according to the test file
214   path. This option is useful when predictable test order is desired.
215
216 - random - tests will be run in random order.
217
218 - smart - tests that failed previously will be run first, then the remaining
219   tests, all in descending execution time order. This is the default as it
220   optimizes concurrency.
221
222.. option:: --run-shard=N
223
224 Select which shard to run, assuming the ``--num-shards=M`` option was
225 provided. The two options must be used together, and the value of ``N``
226 must be in the range ``1..M``. The environment variable
227 ``LIT_RUN_SHARD`` can also be used in place of this option.
228
229.. option:: --timeout=N
230
231 Spend at most ``N`` seconds (approximately) running each individual test.
232 ``0`` means no time limit, and ``0`` is the default. Note that this is not an
233 alias for :option:`--max-time`; the two are different kinds of maximums.
234
235.. option:: --filter=REGEXP
236
237  Run only those tests whose name matches the regular expression specified in
238  ``REGEXP``. The environment variable ``LIT_FILTER`` can be also used in place
239  of this option, which is especially useful in environments where the call
240  to ``lit`` is issued indirectly.
241
242.. option:: --filter-out=REGEXP
243
244  Filter out those tests whose name matches the regular expression specified in
245  ``REGEXP``. The environment variable ``LIT_FILTER_OUT`` can be also used in
246  place of this option, which is especially useful in environments where the
247  call to ``lit`` is issued indirectly.
248
249.. option:: --xfail=LIST
250
251  Treat those tests whose name is in the semicolon separated list ``LIST`` as
252  ``XFAIL``. This can be helpful when one does not want to modify the test
253  suite. The environment variable ``LIT_XFAIL`` can be also used in place of
254  this option, which is especially useful in environments where the call to
255  ``lit`` is issued indirectly.
256
257  A test name can specified as a file name relative to the test suite directory.
258  For example:
259
260  .. code-block:: none
261
262    LIT_XFAIL="affinity/kmp-hw-subset.c;offloading/memory_manager.cpp"
263
264  In this case, all of the following tests are treated as ``XFAIL``:
265
266  .. code-block:: none
267
268    libomp :: affinity/kmp-hw-subset.c
269    libomptarget :: nvptx64-nvidia-cuda :: offloading/memory_manager.cpp
270    libomptarget :: x86_64-pc-linux-gnu :: offloading/memory_manager.cpp
271
272  Alternatively, a test name can be specified as the full test name
273  reported in LIT output.  For example, we can adjust the previous
274  example not to treat the ``nvptx64-nvidia-cuda`` version of
275  ``offloading/memory_manager.cpp`` as XFAIL:
276
277  .. code-block:: none
278
279    LIT_XFAIL="affinity/kmp-hw-subset.c;libomptarget :: x86_64-pc-linux-gnu :: offloading/memory_manager.cpp"
280
281.. option:: --xfail-not=LIST
282
283  Do not treat the specified tests as ``XFAIL``.  The environment variable
284  ``LIT_XFAIL_NOT`` can also be used in place of this option.  The syntax is the
285  same as for :option:`--xfail` and ``LIT_XFAIL``.  :option:`--xfail-not` and
286  ``LIT_XFAIL_NOT`` always override all other ``XFAIL`` specifications,
287  including an :option:`--xfail` appearing later on the command line.  The
288  primary purpose is to suppress an ``XPASS`` result without modifying a test
289  case that uses the ``XFAIL`` directive.
290
291ADDITIONAL OPTIONS
292------------------
293
294.. option:: --debug
295
296 Run :program:`lit` in debug mode, for debugging configuration issues and
297 :program:`lit` itself.
298
299.. option:: --show-suites
300
301 List the discovered test suites and exit.
302
303.. option:: --show-tests
304
305 List all of the discovered tests and exit.
306
307EXIT STATUS
308-----------
309
310:program:`lit` will exit with an exit code of 1 if there are any FAIL or XPASS
311results.  Otherwise, it will exit with the status 0.  Other exit codes are used
312for non-test related failures (for example a user error or an internal program
313error).
314
315.. _test-discovery:
316
317TEST DISCOVERY
318--------------
319
320The inputs passed to :program:`lit` can be either individual tests, or entire
321directories or hierarchies of tests to run.  When :program:`lit` starts up, the
322first thing it does is convert the inputs into a complete list of tests to run
323as part of *test discovery*.
324
325In the :program:`lit` model, every test must exist inside some *test suite*.
326:program:`lit` resolves the inputs specified on the command line to test suites
327by searching upwards from the input path until it finds a :file:`lit.cfg` or
328:file:`lit.site.cfg` file.  These files serve as both a marker of test suites
329and as configuration files which :program:`lit` loads in order to understand
330how to find and run the tests inside the test suite.
331
332Once :program:`lit` has mapped the inputs into test suites it traverses the
333list of inputs adding tests for individual files and recursively searching for
334tests in directories.
335
336This behavior makes it easy to specify a subset of tests to run, while still
337allowing the test suite configuration to control exactly how tests are
338interpreted.  In addition, :program:`lit` always identifies tests by the test
339suite they are in, and their relative path inside the test suite.  For
340appropriately configured projects, this allows :program:`lit` to provide
341convenient and flexible support for out-of-tree builds.
342
343.. _test-status-results:
344
345TEST STATUS RESULTS
346-------------------
347
348Each test ultimately produces one of the following eight results:
349
350**PASS**
351
352 The test succeeded.
353
354**FLAKYPASS**
355
356 The test succeeded after being re-run more than once. This only applies to
357 tests containing an ``ALLOW_RETRIES:`` annotation.
358
359**XFAIL**
360
361 The test failed, but that is expected.  This is used for test formats which allow
362 specifying that a test does not currently work, but wish to leave it in the test
363 suite.
364
365**XPASS**
366
367 The test succeeded, but it was expected to fail.  This is used for tests which
368 were specified as expected to fail, but are now succeeding (generally because
369 the feature they test was broken and has been fixed).
370
371**FAIL**
372
373 The test failed.
374
375**UNRESOLVED**
376
377 The test result could not be determined.  For example, this occurs when the test
378 could not be run, the test itself is invalid, or the test was interrupted.
379
380**UNSUPPORTED**
381
382 The test is not supported in this environment.  This is used by test formats
383 which can report unsupported tests.
384
385**TIMEOUT**
386
387 The test was run, but it timed out before it was able to complete. This is
388 considered a failure.
389
390Depending on the test format tests may produce additional information about
391their status (generally only for failures).  See the :ref:`output-options`
392section for more information.
393
394.. _lit-infrastructure:
395
396LIT INFRASTRUCTURE
397------------------
398
399This section describes the :program:`lit` testing architecture for users interested in
400creating a new :program:`lit` testing implementation, or extending an existing one.
401
402:program:`lit` proper is primarily an infrastructure for discovering and running
403arbitrary tests, and to expose a single convenient interface to these
404tests. :program:`lit` itself doesn't know how to run tests, rather this logic is
405defined by *test suites*.
406
407TEST SUITES
408~~~~~~~~~~~
409
410As described in :ref:`test-discovery`, tests are always located inside a *test
411suite*.  Test suites serve to define the format of the tests they contain, the
412logic for finding those tests, and any additional information to run the tests.
413
414:program:`lit` identifies test suites as directories containing ``lit.cfg`` or
415``lit.site.cfg`` files (see also :option:`--config-prefix`).  Test suites are
416initially discovered by recursively searching up the directory hierarchy for
417all the input files passed on the command line.  You can use
418:option:`--show-suites` to display the discovered test suites at startup.
419
420Once a test suite is discovered, its config file is loaded.  Config files
421themselves are Python modules which will be executed.  When the config file is
422executed, two important global variables are predefined:
423
424**lit_config**
425
426 The global **lit** configuration object (a *LitConfig* instance), which defines
427 the builtin test formats, global configuration parameters, and other helper
428 routines for implementing test configurations.
429
430**config**
431
432 This is the config object (a *TestingConfig* instance) for the test suite,
433 which the config file is expected to populate.  The following variables are also
434 available on the *config* object, some of which must be set by the config and
435 others are optional or predefined:
436
437 **name** *[required]* The name of the test suite, for use in reports and
438 diagnostics.
439
440 **test_format** *[required]* The test format object which will be used to
441 discover and run tests in the test suite.  Generally this will be a builtin test
442 format available from the *lit.formats* module.
443
444 **test_source_root** The filesystem path to the test suite root.  For out-of-dir
445 builds this is the directory that will be scanned for tests.
446
447 **test_exec_root** For out-of-dir builds, the path to the test suite root inside
448 the object directory.  This is where tests will be run and temporary output files
449 placed.
450
451 **environment** A dictionary representing the environment to use when executing
452 tests in the suite.
453
454 **standalone_tests** When true, mark a directory with tests expected to be run
455 standalone. Test discovery is disabled for that directory and
456 *--no-indirectly-run-check* is in effect. *lit.suffixes* and *lit.excludes*
457 must be empty when this variable is true.
458
459 **suffixes** For **lit** test formats which scan directories for tests, this
460 variable is a list of suffixes to identify test files.  Used by: *ShTest*.
461
462 **substitutions** For **lit** test formats which substitute variables into a test
463 script, the list of substitutions to perform.  Used by: *ShTest*.
464
465 **unsupported** Mark an unsupported directory, all tests within it will be
466 reported as unsupported.  Used by: *ShTest*.
467
468 **parent** The parent configuration, this is the config object for the directory
469 containing the test suite, or None.
470
471 **root** The root configuration.  This is the top-most :program:`lit` configuration in
472 the project.
473
474 **pipefail** Normally a test using a shell pipe fails if any of the commands
475 on the pipe fail. If this is not desired, setting this variable to false
476 makes the test fail only if the last command in the pipe fails.
477
478 **available_features** A set of features that can be used in `XFAIL`,
479 `REQUIRES`, and `UNSUPPORTED` directives.
480
481TEST DISCOVERY
482~~~~~~~~~~~~~~
483
484Once test suites are located, :program:`lit` recursively traverses the source
485directory (following *test_source_root*) looking for tests.  When :program:`lit`
486enters a sub-directory, it first checks to see if a nested test suite is
487defined in that directory.  If so, it loads that test suite recursively,
488otherwise it instantiates a local test config for the directory (see
489:ref:`local-configuration-files`).
490
491Tests are identified by the test suite they are contained within, and the
492relative path inside that suite.  Note that the relative path may not refer to
493an actual file on disk; some test formats (such as *GoogleTest*) define
494"virtual tests" which have a path that contains both the path to the actual
495test file and a subpath to identify the virtual test.
496
497.. _local-configuration-files:
498
499LOCAL CONFIGURATION FILES
500~~~~~~~~~~~~~~~~~~~~~~~~~
501
502When :program:`lit` loads a subdirectory in a test suite, it instantiates a
503local test configuration by cloning the configuration for the parent directory
504--- the root of this configuration chain will always be a test suite.  Once the
505test configuration is cloned :program:`lit` checks for a *lit.local.cfg* file
506in the subdirectory.  If present, this file will be loaded and can be used to
507specialize the configuration for each individual directory.  This facility can
508be used to define subdirectories of optional tests, or to change other
509configuration parameters --- for example, to change the test format, or the
510suffixes which identify test files.
511
512SUBSTITUTIONS
513~~~~~~~~~~~~~
514
515:program:`lit` allows patterns to be substituted inside RUN commands. It also
516provides the following base set of substitutions, which are defined in
517TestRunner.py:
518
519 ======================= ==============
520  Macro                   Substitution
521 ======================= ==============
522 %s                      source path (path to the file currently being run)
523 %S                      source dir (directory of the file currently being run)
524 %p                      same as %S
525 %{pathsep}              path separator
526 %{fs-src-root}          root component of file system paths pointing to the LLVM checkout
527 %{fs-tmp-root}          root component of file system paths pointing to the test's temporary directory
528 %{fs-sep}               file system path separator
529 %t                      temporary file name unique to the test
530 %basename_t             The last path component of %t but without the ``.tmp`` extension
531 %T                      parent directory of %t (not unique, deprecated, do not use)
532 %%                      %
533 %/s                     %s but ``\`` is replaced by ``/``
534 %/S                     %S but ``\`` is replaced by ``/``
535 %/p                     %p but ``\`` is replaced by ``/``
536 %/t                     %t but ``\`` is replaced by ``/``
537 %/T                     %T but ``\`` is replaced by ``/``
538 %{/s:regex_replacement} %/s but escaped for use in the replacement of a ``s@@@`` command in sed
539 %{/S:regex_replacement} %/S but escaped for use in the replacement of a ``s@@@`` command in sed
540 %{/p:regex_replacement} %/p but escaped for use in the replacement of a ``s@@@`` command in sed
541 %{/t:regex_replacement} %/t but escaped for use in the replacement of a ``s@@@`` command in sed
542 %{/T:regex_replacement} %/T but escaped for use in the replacement of a ``s@@@`` command in sed
543 %:s                     On Windows, %/s but a ``:`` is removed if its the second character.
544                         Otherwise, %s but with a single leading ``/`` removed.
545 %:S                     On Windows, %/S but a ``:`` is removed if its the second character.
546                         Otherwise, %S but with a single leading ``/`` removed.
547 %:p                     On Windows, %/p but a ``:`` is removed if its the second character.
548                         Otherwise, %p but with a single leading ``/`` removed.
549 %:t                     On Windows, %/t but a ``:`` is removed if its the second character.
550                         Otherwise, %t but with a single leading ``/`` removed.
551 %:T                     On Windows, %/T but a ``:`` is removed if its the second character.
552                         Otherwise, %T but with a single leading ``/`` removed.
553 ======================= ==============
554
555Other substitutions are provided that are variations on this base set and
556further substitution patterns can be defined by each test module. See the
557modules :ref:`local-configuration-files`.
558
559By default, substitutions are expanded exactly once, so that if e.g. a
560substitution ``%build`` is defined in top of another substitution ``%cxx``,
561``%build`` will expand to ``%cxx`` textually, not to what ``%cxx`` expands to.
562However, if the ``recursiveExpansionLimit`` property of the ``TestingConfig``
563is set to a non-negative integer, substitutions will be expanded recursively
564until that limit is reached. It is an error if the limit is reached and
565expanding substitutions again would yield a different result.
566
567More detailed information on substitutions can be found in the
568:doc:`../TestingGuide`.
569
570TEST RUN OUTPUT FORMAT
571~~~~~~~~~~~~~~~~~~~~~~
572
573The :program:`lit` output for a test run conforms to the following schema, in
574both short and verbose modes (although in short mode no PASS lines will be
575shown).  This schema has been chosen to be relatively easy to reliably parse by
576a machine (for example in buildbot log scraping), and for other tools to
577generate.
578
579Each test result is expected to appear on a line that matches:
580
581.. code-block:: none
582
583  <result code>: <test name> (<progress info>)
584
585where ``<result-code>`` is a standard test result such as PASS, FAIL, XFAIL,
586XPASS, UNRESOLVED, or UNSUPPORTED.  The performance result codes of IMPROVED and
587REGRESSED are also allowed.
588
589The ``<test name>`` field can consist of an arbitrary string containing no
590newline.
591
592The ``<progress info>`` field can be used to report progress information such
593as (1/300) or can be empty, but even when empty the parentheses are required.
594
595Each test result may include additional (multiline) log information in the
596following format:
597
598.. code-block:: none
599
600  <log delineator> TEST '(<test name>)' <trailing delineator>
601  ... log message ...
602  <log delineator>
603
604where ``<test name>`` should be the name of a preceding reported test, ``<log
605delineator>`` is a string of "*" characters *at least* four characters long
606(the recommended length is 20), and ``<trailing delineator>`` is an arbitrary
607(unparsed) string.
608
609The following is an example of a test run output which consists of four tests A,
610B, C, and D, and a log message for the failing test C:
611
612.. code-block:: none
613
614  PASS: A (1 of 4)
615  PASS: B (2 of 4)
616  FAIL: C (3 of 4)
617  ******************** TEST 'C' FAILED ********************
618  Test 'C' failed as a result of exit code 1.
619  ********************
620  PASS: D (4 of 4)
621
622LIT EXAMPLE TESTS
623~~~~~~~~~~~~~~~~~
624
625The :program:`lit` distribution contains several example implementations of
626test suites in the *ExampleTests* directory.
627
628SEE ALSO
629--------
630
631valgrind(1)
632