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