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