lit.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. lit - LLVM Integrated Tester
  2. ============================
  3. SYNOPSIS
  4. --------
  5. :program:`lit` [*options*] [*tests*]
  6. DESCRIPTION
  7. -----------
  8. :program:`lit` is a portable tool for executing LLVM and Clang style test
  9. suites, summarizing their results, and providing indication of failures.
  10. :program:`lit` is designed to be a lightweight testing tool with as simple a
  11. user interface as possible.
  12. :program:`lit` should be run with one or more *tests* to run specified on the
  13. command line. Tests can be either individual test files or directories to
  14. search for tests (see :ref:`test-discovery`).
  15. Each specified test will be executed (potentially in parallel) and once all
  16. tests have been run :program:`lit` will print summary information on the number
  17. of tests which passed or failed (see :ref:`test-status-results`). The
  18. :program:`lit` program will execute with a non-zero exit code if any tests
  19. fail.
  20. By default :program:`lit` will use a succinct progress display and will only
  21. print summary information for test failures. See :ref:`output-options` for
  22. options controlling the :program:`lit` progress display and output.
  23. :program:`lit` also includes a number of options for controlling how tests are
  24. executed (specific features may depend on the particular test format). See
  25. :ref:`execution-options` for more information.
  26. Finally, :program:`lit` also supports additional options for only running a
  27. subset of the options specified on the command line, see
  28. :ref:`selection-options` for more information.
  29. Users interested in the :program:`lit` architecture or designing a
  30. :program:`lit` testing implementation should see :ref:`lit-infrastructure`.
  31. GENERAL OPTIONS
  32. ---------------
  33. .. option:: -h, --help
  34. Show the :program:`lit` help message.
  35. .. option:: -j N, --threads=N
  36. Run ``N`` tests in parallel. By default, this is automatically chosen to
  37. match the number of detected available CPUs.
  38. .. option:: --config-prefix=NAME
  39. Search for :file:`{NAME}.cfg` and :file:`{NAME}.site.cfg` when searching for
  40. test suites, instead of :file:`lit.cfg` and :file:`lit.site.cfg`.
  41. .. option:: -D NAME[=VALUE], --param NAME[=VALUE]
  42. Add a user defined parameter ``NAME`` with the given ``VALUE`` (or the empty
  43. string if not given). The meaning and use of these parameters is test suite
  44. dependent.
  45. .. _output-options:
  46. OUTPUT OPTIONS
  47. --------------
  48. .. option:: -q, --quiet
  49. Suppress any output except for test failures.
  50. .. option:: -s, --succinct
  51. Show less output, for example don't show information on tests that pass.
  52. .. option:: -v, --verbose
  53. Show more information on test failures, for example the entire test output
  54. instead of just the test result.
  55. .. option:: -vv, --echo-all-commands
  56. Echo all commands to stdout, as they are being executed.
  57. This can be valuable for debugging test failures, as the last echoed command
  58. will be the one which has failed.
  59. :program:`lit` normally inserts a no-op command (``:`` in the case of bash)
  60. with argument ``'RUN: at line N'`` before each command pipeline, and this
  61. option also causes those no-op commands to be echoed to stdout to help you
  62. locate the source line of the failed command.
  63. This option implies ``--verbose``.
  64. .. option:: -a, --show-all
  65. Show more information about all tests, for example the entire test
  66. commandline and output.
  67. .. option:: --no-progress-bar
  68. Do not use curses based progress bar.
  69. .. option:: --show-unsupported
  70. Show the names of unsupported tests.
  71. .. option:: --show-xfail
  72. Show the names of tests that were expected to fail.
  73. .. _execution-options:
  74. EXECUTION OPTIONS
  75. -----------------
  76. .. option:: --path=PATH
  77. Specify an additional ``PATH`` to use when searching for executables in tests.
  78. .. option:: --vg
  79. Run individual tests under valgrind (using the memcheck tool). The
  80. ``--error-exitcode`` argument for valgrind is used so that valgrind failures
  81. will cause the program to exit with a non-zero status.
  82. When this option is enabled, :program:`lit` will also automatically provide a
  83. "``valgrind``" feature that can be used to conditionally disable (or expect
  84. failure in) certain tests.
  85. .. option:: --vg-arg=ARG
  86. When :option:`--vg` is used, specify an additional argument to pass to
  87. :program:`valgrind` itself.
  88. .. option:: --vg-leak
  89. When :option:`--vg` is used, enable memory leak checks. When this option is
  90. enabled, :program:`lit` will also automatically provide a "``vg_leak``"
  91. feature that can be used to conditionally disable (or expect failure in)
  92. certain tests.
  93. .. option:: --time-tests
  94. Track the wall time individual tests take to execute and includes the results
  95. in the summary output. This is useful for determining which tests in a test
  96. suite take the most time to execute. Note that this option is most useful
  97. with ``-j 1``.
  98. .. _selection-options:
  99. SELECTION OPTIONS
  100. -----------------
  101. .. option:: --max-tests=N
  102. Run at most ``N`` tests and then terminate.
  103. .. option:: --max-time=N
  104. Spend at most ``N`` seconds (approximately) running tests and then terminate.
  105. .. option:: --shuffle
  106. Run the tests in a random order.
  107. .. option:: --num-shards=M
  108. Divide the set of selected tests into ``M`` equal-sized subsets or
  109. "shards", and run only one of them. Must be used with the
  110. ``--run-shard=N`` option, which selects the shard to run. The environment
  111. variable ``LIT_NUM_SHARDS`` can also be used in place of this
  112. option. These two options provide a coarse mechanism for paritioning large
  113. testsuites, for parallel execution on separate machines (say in a large
  114. testing farm).
  115. .. option:: --run-shard=N
  116. Select which shard to run, assuming the ``--num-shards=M`` option was
  117. provided. The two options must be used together, and the value of ``N``
  118. must be in the range ``1..M``. The environment variable
  119. ``LIT_RUN_SHARD`` can also be used in place of this option.
  120. .. option:: --filter=REGEXP
  121. Run only those tests whose name matches the regular expression specified in
  122. ``REGEXP``. The environment variable ``LIT_FILTER`` can be also used in place
  123. of this option, which is especially useful in environments where the call
  124. to ``lit`` is issued indirectly.
  125. ADDITIONAL OPTIONS
  126. ------------------
  127. .. option:: --debug
  128. Run :program:`lit` in debug mode, for debugging configuration issues and
  129. :program:`lit` itself.
  130. .. option:: --show-suites
  131. List the discovered test suites and exit.
  132. .. option:: --show-tests
  133. List all of the discovered tests and exit.
  134. EXIT STATUS
  135. -----------
  136. :program:`lit` will exit with an exit code of 1 if there are any FAIL or XPASS
  137. results. Otherwise, it will exit with the status 0. Other exit codes are used
  138. for non-test related failures (for example a user error or an internal program
  139. error).
  140. .. _test-discovery:
  141. TEST DISCOVERY
  142. --------------
  143. The inputs passed to :program:`lit` can be either individual tests, or entire
  144. directories or hierarchies of tests to run. When :program:`lit` starts up, the
  145. first thing it does is convert the inputs into a complete list of tests to run
  146. as part of *test discovery*.
  147. In the :program:`lit` model, every test must exist inside some *test suite*.
  148. :program:`lit` resolves the inputs specified on the command line to test suites
  149. by searching upwards from the input path until it finds a :file:`lit.cfg` or
  150. :file:`lit.site.cfg` file. These files serve as both a marker of test suites
  151. and as configuration files which :program:`lit` loads in order to understand
  152. how to find and run the tests inside the test suite.
  153. Once :program:`lit` has mapped the inputs into test suites it traverses the
  154. list of inputs adding tests for individual files and recursively searching for
  155. tests in directories.
  156. This behavior makes it easy to specify a subset of tests to run, while still
  157. allowing the test suite configuration to control exactly how tests are
  158. interpreted. In addition, :program:`lit` always identifies tests by the test
  159. suite they are in, and their relative path inside the test suite. For
  160. appropriately configured projects, this allows :program:`lit` to provide
  161. convenient and flexible support for out-of-tree builds.
  162. .. _test-status-results:
  163. TEST STATUS RESULTS
  164. -------------------
  165. Each test ultimately produces one of the following six results:
  166. **PASS**
  167. The test succeeded.
  168. **XFAIL**
  169. The test failed, but that is expected. This is used for test formats which allow
  170. specifying that a test does not currently work, but wish to leave it in the test
  171. suite.
  172. **XPASS**
  173. The test succeeded, but it was expected to fail. This is used for tests which
  174. were specified as expected to fail, but are now succeeding (generally because
  175. the feature they test was broken and has been fixed).
  176. **FAIL**
  177. The test failed.
  178. **UNRESOLVED**
  179. The test result could not be determined. For example, this occurs when the test
  180. could not be run, the test itself is invalid, or the test was interrupted.
  181. **UNSUPPORTED**
  182. The test is not supported in this environment. This is used by test formats
  183. which can report unsupported tests.
  184. Depending on the test format tests may produce additional information about
  185. their status (generally only for failures). See the :ref:`output-options`
  186. section for more information.
  187. .. _lit-infrastructure:
  188. LIT INFRASTRUCTURE
  189. ------------------
  190. This section describes the :program:`lit` testing architecture for users interested in
  191. creating a new :program:`lit` testing implementation, or extending an existing one.
  192. :program:`lit` proper is primarily an infrastructure for discovering and running
  193. arbitrary tests, and to expose a single convenient interface to these
  194. tests. :program:`lit` itself doesn't know how to run tests, rather this logic is
  195. defined by *test suites*.
  196. TEST SUITES
  197. ~~~~~~~~~~~
  198. As described in :ref:`test-discovery`, tests are always located inside a *test
  199. suite*. Test suites serve to define the format of the tests they contain, the
  200. logic for finding those tests, and any additional information to run the tests.
  201. :program:`lit` identifies test suites as directories containing ``lit.cfg`` or
  202. ``lit.site.cfg`` files (see also :option:`--config-prefix`). Test suites are
  203. initially discovered by recursively searching up the directory hierarchy for
  204. all the input files passed on the command line. You can use
  205. :option:`--show-suites` to display the discovered test suites at startup.
  206. Once a test suite is discovered, its config file is loaded. Config files
  207. themselves are Python modules which will be executed. When the config file is
  208. executed, two important global variables are predefined:
  209. **lit_config**
  210. The global **lit** configuration object (a *LitConfig* instance), which defines
  211. the builtin test formats, global configuration parameters, and other helper
  212. routines for implementing test configurations.
  213. **config**
  214. This is the config object (a *TestingConfig* instance) for the test suite,
  215. which the config file is expected to populate. The following variables are also
  216. available on the *config* object, some of which must be set by the config and
  217. others are optional or predefined:
  218. **name** *[required]* The name of the test suite, for use in reports and
  219. diagnostics.
  220. **test_format** *[required]* The test format object which will be used to
  221. discover and run tests in the test suite. Generally this will be a builtin test
  222. format available from the *lit.formats* module.
  223. **test_source_root** The filesystem path to the test suite root. For out-of-dir
  224. builds this is the directory that will be scanned for tests.
  225. **test_exec_root** For out-of-dir builds, the path to the test suite root inside
  226. the object directory. This is where tests will be run and temporary output files
  227. placed.
  228. **environment** A dictionary representing the environment to use when executing
  229. tests in the suite.
  230. **suffixes** For **lit** test formats which scan directories for tests, this
  231. variable is a list of suffixes to identify test files. Used by: *ShTest*.
  232. **substitutions** For **lit** test formats which substitute variables into a test
  233. script, the list of substitutions to perform. Used by: *ShTest*.
  234. **unsupported** Mark an unsupported directory, all tests within it will be
  235. reported as unsupported. Used by: *ShTest*.
  236. **parent** The parent configuration, this is the config object for the directory
  237. containing the test suite, or None.
  238. **root** The root configuration. This is the top-most :program:`lit` configuration in
  239. the project.
  240. **pipefail** Normally a test using a shell pipe fails if any of the commands
  241. on the pipe fail. If this is not desired, setting this variable to false
  242. makes the test fail only if the last command in the pipe fails.
  243. **available_features** A set of features that can be used in `XFAIL`,
  244. `REQUIRES`, and `UNSUPPORTED` directives.
  245. TEST DISCOVERY
  246. ~~~~~~~~~~~~~~
  247. Once test suites are located, :program:`lit` recursively traverses the source
  248. directory (following *test_source_root*) looking for tests. When :program:`lit`
  249. enters a sub-directory, it first checks to see if a nested test suite is
  250. defined in that directory. If so, it loads that test suite recursively,
  251. otherwise it instantiates a local test config for the directory (see
  252. :ref:`local-configuration-files`).
  253. Tests are identified by the test suite they are contained within, and the
  254. relative path inside that suite. Note that the relative path may not refer to
  255. an actual file on disk; some test formats (such as *GoogleTest*) define
  256. "virtual tests" which have a path that contains both the path to the actual
  257. test file and a subpath to identify the virtual test.
  258. .. _local-configuration-files:
  259. LOCAL CONFIGURATION FILES
  260. ~~~~~~~~~~~~~~~~~~~~~~~~~
  261. When :program:`lit` loads a subdirectory in a test suite, it instantiates a
  262. local test configuration by cloning the configuration for the parent directory
  263. --- the root of this configuration chain will always be a test suite. Once the
  264. test configuration is cloned :program:`lit` checks for a *lit.local.cfg* file
  265. in the subdirectory. If present, this file will be loaded and can be used to
  266. specialize the configuration for each individual directory. This facility can
  267. be used to define subdirectories of optional tests, or to change other
  268. configuration parameters --- for example, to change the test format, or the
  269. suffixes which identify test files.
  270. PRE-DEFINED SUBSTITUTIONS
  271. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  272. :program:`lit` provides various patterns that can be used with the RUN command.
  273. These are defined in TestRunner.py. The base set of substitutions are:
  274. ========== ==============
  275. Macro Substitution
  276. ========== ==============
  277. %s source path (path to the file currently being run)
  278. %S source dir (directory of the file currently being run)
  279. %p same as %S
  280. %{pathsep} path separator
  281. %t temporary file name unique to the test
  282. %T parent directory of %t (not unique, deprecated, do not use)
  283. %% %
  284. ========== ==============
  285. Other substitutions are provided that are variations on this base set and
  286. further substitution patterns can be defined by each test module. See the
  287. modules :ref:`local-configuration-files`.
  288. More detailed information on substitutions can be found in the
  289. :doc:`../TestingGuide`.
  290. TEST RUN OUTPUT FORMAT
  291. ~~~~~~~~~~~~~~~~~~~~~~
  292. The :program:`lit` output for a test run conforms to the following schema, in
  293. both short and verbose modes (although in short mode no PASS lines will be
  294. shown). This schema has been chosen to be relatively easy to reliably parse by
  295. a machine (for example in buildbot log scraping), and for other tools to
  296. generate.
  297. Each test result is expected to appear on a line that matches:
  298. .. code-block:: none
  299. <result code>: <test name> (<progress info>)
  300. where ``<result-code>`` is a standard test result such as PASS, FAIL, XFAIL,
  301. XPASS, UNRESOLVED, or UNSUPPORTED. The performance result codes of IMPROVED and
  302. REGRESSED are also allowed.
  303. The ``<test name>`` field can consist of an arbitrary string containing no
  304. newline.
  305. The ``<progress info>`` field can be used to report progress information such
  306. as (1/300) or can be empty, but even when empty the parentheses are required.
  307. Each test result may include additional (multiline) log information in the
  308. following format:
  309. .. code-block:: none
  310. <log delineator> TEST '(<test name>)' <trailing delineator>
  311. ... log message ...
  312. <log delineator>
  313. where ``<test name>`` should be the name of a preceding reported test, ``<log
  314. delineator>`` is a string of "*" characters *at least* four characters long
  315. (the recommended length is 20), and ``<trailing delineator>`` is an arbitrary
  316. (unparsed) string.
  317. The following is an example of a test run output which consists of four tests A,
  318. B, C, and D, and a log message for the failing test C:
  319. .. code-block:: none
  320. PASS: A (1 of 4)
  321. PASS: B (2 of 4)
  322. FAIL: C (3 of 4)
  323. ******************** TEST 'C' FAILED ********************
  324. Test 'C' failed as a result of exit code 1.
  325. ********************
  326. PASS: D (4 of 4)
  327. LIT EXAMPLE TESTS
  328. ~~~~~~~~~~~~~~~~~
  329. The :program:`lit` distribution contains several example implementations of
  330. test suites in the *ExampleTests* directory.
  331. SEE ALSO
  332. --------
  333. valgrind(1)