Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 1 | ================================= |
| 2 | LLVM Testing Infrastructure Guide |
| 3 | ================================= |
| 4 | |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 5 | .. contents:: |
| 6 | :local: |
| 7 | |
Sean Silva | d5f4b4c | 2012-11-14 23:11:10 +0000 | [diff] [blame] | 8 | .. toctree:: |
| 9 | :hidden: |
| 10 | |
Matthias Braun | 64a07d9 | 2018-08-31 21:47:01 +0000 | [diff] [blame] | 11 | TestSuiteGuide |
Sean Silva | d5f4b4c | 2012-11-14 23:11:10 +0000 | [diff] [blame] | 12 | TestSuiteMakefileGuide |
| 13 | |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 14 | Overview |
| 15 | ======== |
| 16 | |
| 17 | This document is the reference manual for the LLVM testing |
| 18 | infrastructure. It documents the structure of the LLVM testing |
| 19 | infrastructure, the tools needed to use it, and how to add and run |
| 20 | tests. |
| 21 | |
| 22 | Requirements |
| 23 | ============ |
| 24 | |
Bill Wendling | 88429cf | 2013-10-27 04:02:21 +0000 | [diff] [blame] | 25 | In order to use the LLVM testing infrastructure, you will need all of the |
Rafael Espindola | 708bc15 | 2014-12-12 15:29:31 +0000 | [diff] [blame] | 26 | software required to build LLVM, as well as `Python <http://python.org>`_ 2.7 or |
Bill Wendling | 88429cf | 2013-10-27 04:02:21 +0000 | [diff] [blame] | 27 | later. |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 28 | |
Matthias Braun | 64a07d9 | 2018-08-31 21:47:01 +0000 | [diff] [blame] | 29 | LLVM Testing Infrastructure Organization |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 30 | ======================================== |
| 31 | |
| 32 | The LLVM testing infrastructure contains two major categories of tests: |
| 33 | regression tests and whole programs. The regression tests are contained |
| 34 | inside the LLVM repository itself under ``llvm/test`` and are expected |
| 35 | to always pass -- they should be run before every commit. |
| 36 | |
| 37 | The whole programs tests are referred to as the "LLVM test suite" (or |
| 38 | "test-suite") and are in the ``test-suite`` module in subversion. For |
| 39 | historical reasons, these tests are also referred to as the "nightly |
| 40 | tests" in places, which is less ambiguous than "test-suite" and remains |
| 41 | in use although we run them much more often than nightly. |
| 42 | |
| 43 | Regression tests |
| 44 | ---------------- |
| 45 | |
| 46 | The regression tests are small pieces of code that test a specific |
Eli Bendersky | 56537a5 | 2012-12-03 04:10:58 +0000 | [diff] [blame] | 47 | feature of LLVM or trigger a specific bug in LLVM. The language they are |
| 48 | written in depends on the part of LLVM being tested. These tests are driven by |
| 49 | the :doc:`Lit <CommandGuide/lit>` testing tool (which is part of LLVM), and |
| 50 | are located in the ``llvm/test`` directory. |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 51 | |
| 52 | Typically when a bug is found in LLVM, a regression test containing just |
| 53 | enough code to reproduce the problem should be written and placed |
Eli Bendersky | 56537a5 | 2012-12-03 04:10:58 +0000 | [diff] [blame] | 54 | somewhere underneath this directory. For example, it can be a small |
| 55 | piece of LLVM IR distilled from an actual application or benchmark. |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 56 | |
| 57 | ``test-suite`` |
| 58 | -------------- |
| 59 | |
| 60 | The test suite contains whole programs, which are pieces of code which |
| 61 | can be compiled and linked into a stand-alone program that can be |
| 62 | executed. These programs are generally written in high level languages |
| 63 | such as C or C++. |
| 64 | |
| 65 | These programs are compiled using a user specified compiler and set of |
| 66 | flags, and then executed to capture the program output and timing |
| 67 | information. The output of these programs is compared to a reference |
| 68 | output to ensure that the program is being compiled correctly. |
| 69 | |
| 70 | In addition to compiling and executing programs, whole program tests |
| 71 | serve as a way of benchmarking LLVM performance, both in terms of the |
| 72 | efficiency of the programs generated as well as the speed with which |
| 73 | LLVM compiles, optimizes, and generates code. |
| 74 | |
| 75 | The test-suite is located in the ``test-suite`` Subversion module. |
| 76 | |
Matthias Braun | 64a07d9 | 2018-08-31 21:47:01 +0000 | [diff] [blame] | 77 | See the :doc:`TestSuiteGuide` for details. |
| 78 | |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 79 | Debugging Information tests |
| 80 | --------------------------- |
| 81 | |
| 82 | The test suite contains tests to check quality of debugging information. |
| 83 | The test are written in C based languages or in LLVM assembly language. |
| 84 | |
| 85 | These tests are compiled and run under a debugger. The debugger output |
| 86 | is checked to validate of debugging information. See README.txt in the |
| 87 | test suite for more information . This test suite is located in the |
| 88 | ``debuginfo-tests`` Subversion module. |
| 89 | |
| 90 | Quick start |
| 91 | =========== |
| 92 | |
| 93 | The tests are located in two separate Subversion modules. The |
| 94 | regressions tests are in the main "llvm" module under the directory |
Eli Bendersky | 56537a5 | 2012-12-03 04:10:58 +0000 | [diff] [blame] | 95 | ``llvm/test`` (so you get these tests for free with the main LLVM tree). |
| 96 | Use ``make check-all`` to run the regression tests after building LLVM. |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 97 | |
Matthias Braun | 64a07d9 | 2018-08-31 21:47:01 +0000 | [diff] [blame] | 98 | The ``test-suite`` module contains more comprehensive tests including whole C |
| 99 | and C++ programs. See the :doc:`TestSuiteGuide` for details. |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 100 | |
| 101 | Regression tests |
| 102 | ---------------- |
| 103 | |
Chris Bieneman | 6ed3ca9 | 2016-01-26 22:53:12 +0000 | [diff] [blame] | 104 | To run all of the LLVM regression tests use the check-llvm target: |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 105 | |
| 106 | .. code-block:: bash |
| 107 | |
Chris Bieneman | 6ed3ca9 | 2016-01-26 22:53:12 +0000 | [diff] [blame] | 108 | % make check-llvm |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 109 | |
| 110 | If you have `Clang <http://clang.llvm.org/>`_ checked out and built, you |
| 111 | can run the LLVM and Clang tests simultaneously using: |
| 112 | |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 113 | .. code-block:: bash |
| 114 | |
Eli Bendersky | 56537a5 | 2012-12-03 04:10:58 +0000 | [diff] [blame] | 115 | % make check-all |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 116 | |
Daniel Dunbar | 22c6ccf | 2013-08-09 19:39:48 +0000 | [diff] [blame] | 117 | To run the tests with Valgrind (Memcheck by default), use the ``LIT_ARGS`` make |
| 118 | variable to pass the required options to lit. For example, you can use: |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 119 | |
| 120 | .. code-block:: bash |
| 121 | |
Daniel Dunbar | 22c6ccf | 2013-08-09 19:39:48 +0000 | [diff] [blame] | 122 | % make check LIT_ARGS="-v --vg --vg-leak" |
| 123 | |
| 124 | to enable testing with valgrind and with leak checking enabled. |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 125 | |
Eli Bendersky | 56537a5 | 2012-12-03 04:10:58 +0000 | [diff] [blame] | 126 | To run individual tests or subsets of tests, you can use the ``llvm-lit`` |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 127 | script which is built as part of LLVM. For example, to run the |
Eli Bendersky | 56537a5 | 2012-12-03 04:10:58 +0000 | [diff] [blame] | 128 | ``Integer/BitPacked.ll`` test by itself you can run: |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 129 | |
| 130 | .. code-block:: bash |
| 131 | |
| 132 | % llvm-lit ~/llvm/test/Integer/BitPacked.ll |
| 133 | |
| 134 | or to run all of the ARM CodeGen tests: |
| 135 | |
| 136 | .. code-block:: bash |
| 137 | |
| 138 | % llvm-lit ~/llvm/test/CodeGen/ARM |
| 139 | |
Eli Bendersky | 56537a5 | 2012-12-03 04:10:58 +0000 | [diff] [blame] | 140 | For more information on using the :program:`lit` tool, see ``llvm-lit --help`` |
| 141 | or the :doc:`lit man page <CommandGuide/lit>`. |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 142 | |
| 143 | Debugging Information tests |
| 144 | --------------------------- |
| 145 | |
| 146 | To run debugging information tests simply checkout the tests inside |
| 147 | clang/test directory. |
| 148 | |
| 149 | .. code-block:: bash |
| 150 | |
| 151 | % cd clang/test |
| 152 | % svn co http://llvm.org/svn/llvm-project/debuginfo-tests/trunk debuginfo-tests |
| 153 | |
| 154 | These tests are already set up to run as part of clang regression tests. |
| 155 | |
| 156 | Regression test structure |
| 157 | ========================= |
| 158 | |
Eli Bendersky | 56537a5 | 2012-12-03 04:10:58 +0000 | [diff] [blame] | 159 | The LLVM regression tests are driven by :program:`lit` and are located in the |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 160 | ``llvm/test`` directory. |
| 161 | |
| 162 | This directory contains a large array of small tests that exercise |
| 163 | various features of LLVM and to ensure that regressions do not occur. |
| 164 | The directory is broken into several sub-directories, each focused on a |
Eli Bendersky | 8b0eab4 | 2012-12-04 13:55:17 +0000 | [diff] [blame] | 165 | particular area of LLVM. |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 166 | |
| 167 | Writing new regression tests |
| 168 | ---------------------------- |
| 169 | |
| 170 | The regression test structure is very simple, but does require some |
| 171 | information to be set. This information is gathered via ``configure`` |
Eli Bendersky | 2cbe23f | 2012-12-04 14:34:00 +0000 | [diff] [blame] | 172 | and is written to a file, ``test/lit.site.cfg`` in the build directory. |
| 173 | The ``llvm/test`` Makefile does this work for you. |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 174 | |
| 175 | In order for the regression tests to work, each directory of tests must |
Eli Bendersky | 2cbe23f | 2012-12-04 14:34:00 +0000 | [diff] [blame] | 176 | have a ``lit.local.cfg`` file. :program:`lit` looks for this file to determine |
| 177 | how to run the tests. This file is just Python code and thus is very |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 178 | flexible, but we've standardized it for the LLVM regression tests. If |
| 179 | you're adding a directory of tests, just copy ``lit.local.cfg`` from |
| 180 | another directory to get running. The standard ``lit.local.cfg`` simply |
| 181 | specifies which files to look in for tests. Any directory that contains |
Dmitri Gribenko | 44da234 | 2012-11-18 10:35:18 +0000 | [diff] [blame] | 182 | only directories does not need the ``lit.local.cfg`` file. Read the :doc:`Lit |
| 183 | documentation <CommandGuide/lit>` for more information. |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 184 | |
Eli Bendersky | 2cbe23f | 2012-12-04 14:34:00 +0000 | [diff] [blame] | 185 | Each test file must contain lines starting with "RUN:" that tell :program:`lit` |
| 186 | how to run it. If there are no RUN lines, :program:`lit` will issue an error |
| 187 | while running a test. |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 188 | |
| 189 | RUN lines are specified in the comments of the test program using the |
| 190 | keyword ``RUN`` followed by a colon, and lastly the command (pipeline) |
Eli Bendersky | 2cbe23f | 2012-12-04 14:34:00 +0000 | [diff] [blame] | 191 | to execute. Together, these lines form the "script" that :program:`lit` |
| 192 | executes to run the test case. The syntax of the RUN lines is similar to a |
| 193 | shell's syntax for pipelines including I/O redirection and variable |
| 194 | substitution. However, even though these lines may *look* like a shell |
| 195 | script, they are not. RUN lines are interpreted by :program:`lit`. |
| 196 | Consequently, the syntax differs from shell in a few ways. You can specify |
| 197 | as many RUN lines as needed. |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 198 | |
Eli Bendersky | 2cbe23f | 2012-12-04 14:34:00 +0000 | [diff] [blame] | 199 | :program:`lit` performs substitution on each RUN line to replace LLVM tool names |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 200 | with the full paths to the executable built for each tool (in |
Eli Bendersky | 2cbe23f | 2012-12-04 14:34:00 +0000 | [diff] [blame] | 201 | ``$(LLVM_OBJ_ROOT)/$(BuildMode)/bin)``. This ensures that :program:`lit` does |
| 202 | not invoke any stray LLVM tools in the user's path during testing. |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 203 | |
| 204 | Each RUN line is executed on its own, distinct from other lines unless |
| 205 | its last character is ``\``. This continuation character causes the RUN |
| 206 | line to be concatenated with the next one. In this way you can build up |
| 207 | long pipelines of commands without making huge line lengths. The lines |
| 208 | ending in ``\`` are concatenated until a RUN line that doesn't end in |
| 209 | ``\`` is found. This concatenated set of RUN lines then constitutes one |
Eli Bendersky | 2cbe23f | 2012-12-04 14:34:00 +0000 | [diff] [blame] | 210 | execution. :program:`lit` will substitute variables and arrange for the pipeline |
| 211 | to be executed. If any process in the pipeline fails, the entire line (and |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 212 | test case) fails too. |
| 213 | |
| 214 | Below is an example of legal RUN lines in a ``.ll`` file: |
| 215 | |
| 216 | .. code-block:: llvm |
| 217 | |
| 218 | ; RUN: llvm-as < %s | llvm-dis > %t1 |
| 219 | ; RUN: llvm-dis < %s.bc-13 > %t2 |
| 220 | ; RUN: diff %t1 %t2 |
| 221 | |
Eli Bendersky | 2cbe23f | 2012-12-04 14:34:00 +0000 | [diff] [blame] | 222 | As with a Unix shell, the RUN lines permit pipelines and I/O |
Sean Silva | 037a4bc | 2013-03-19 15:22:02 +0000 | [diff] [blame] | 223 | redirection to be used. |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 224 | |
| 225 | There are some quoting rules that you must pay attention to when writing |
Eli Bendersky | 2cbe23f | 2012-12-04 14:34:00 +0000 | [diff] [blame] | 226 | your RUN lines. In general nothing needs to be quoted. :program:`lit` won't |
| 227 | strip off any quote characters so they will get passed to the invoked program. |
Eli Bendersky | 3177949 | 2013-01-18 19:01:34 +0000 | [diff] [blame] | 228 | To avoid this use curly braces to tell :program:`lit` that it should treat |
| 229 | everything enclosed as one value. |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 230 | |
Eli Bendersky | 2cbe23f | 2012-12-04 14:34:00 +0000 | [diff] [blame] | 231 | In general, you should strive to keep your RUN lines as simple as possible, |
Eli Bendersky | 3177949 | 2013-01-18 19:01:34 +0000 | [diff] [blame] | 232 | using them only to run tools that generate textual output you can then examine. |
Eli Bendersky | be67aa5 | 2013-03-22 16:09:06 +0000 | [diff] [blame] | 233 | The recommended way to examine output to figure out if the test passes is using |
Eli Bendersky | 3177949 | 2013-01-18 19:01:34 +0000 | [diff] [blame] | 234 | the :doc:`FileCheck tool <CommandGuide/FileCheck>`. *[The usage of grep in RUN |
| 235 | lines is deprecated - please do not send or commit patches that use it.]* |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 236 | |
Davide Italiano | 15d1960 | 2015-11-17 02:17:35 +0000 | [diff] [blame] | 237 | Put related tests into a single file rather than having a separate file per |
| 238 | test. Check if there are files already covering your feature and consider |
| 239 | adding your code there instead of creating a new file. |
| 240 | |
Sean Silva | 3911374 | 2014-11-05 22:17:18 +0000 | [diff] [blame] | 241 | Extra files |
| 242 | ----------- |
| 243 | |
| 244 | If your test requires extra files besides the file containing the ``RUN:`` |
| 245 | lines, the idiomatic place to put them is in a subdirectory ``Inputs``. |
| 246 | You can then refer to the extra files as ``%S/Inputs/foo.bar``. |
| 247 | |
| 248 | For example, consider ``test/Linker/ident.ll``. The directory structure is |
| 249 | as follows:: |
| 250 | |
| 251 | test/ |
| 252 | Linker/ |
| 253 | ident.ll |
| 254 | Inputs/ |
| 255 | ident.a.ll |
| 256 | ident.b.ll |
| 257 | |
| 258 | For convenience, these are the contents: |
| 259 | |
| 260 | .. code-block:: llvm |
| 261 | |
| 262 | ;;;;; ident.ll: |
| 263 | |
| 264 | ; RUN: llvm-link %S/Inputs/ident.a.ll %S/Inputs/ident.b.ll -S | FileCheck %s |
| 265 | |
| 266 | ; Verify that multiple input llvm.ident metadata are linked together. |
| 267 | |
| 268 | ; CHECK-DAG: !llvm.ident = !{!0, !1, !2} |
| 269 | ; CHECK-DAG: "Compiler V1" |
| 270 | ; CHECK-DAG: "Compiler V2" |
| 271 | ; CHECK-DAG: "Compiler V3" |
| 272 | |
| 273 | ;;;;; Inputs/ident.a.ll: |
| 274 | |
| 275 | !llvm.ident = !{!0, !1} |
| 276 | !0 = metadata !{metadata !"Compiler V1"} |
| 277 | !1 = metadata !{metadata !"Compiler V2"} |
| 278 | |
| 279 | ;;;;; Inputs/ident.b.ll: |
| 280 | |
| 281 | !llvm.ident = !{!0} |
| 282 | !0 = metadata !{metadata !"Compiler V3"} |
| 283 | |
| 284 | For symmetry reasons, ``ident.ll`` is just a dummy file that doesn't |
| 285 | actually participate in the test besides holding the ``RUN:`` lines. |
| 286 | |
| 287 | .. note:: |
| 288 | |
| 289 | Some existing tests use ``RUN: true`` in extra files instead of just |
| 290 | putting the extra files in an ``Inputs/`` directory. This pattern is |
| 291 | deprecated. |
| 292 | |
Dmitri Gribenko | 0d80c9c | 2012-12-30 14:51:03 +0000 | [diff] [blame] | 293 | Fragile tests |
| 294 | ------------- |
| 295 | |
| 296 | It is easy to write a fragile test that would fail spuriously if the tool being |
| 297 | tested outputs a full path to the input file. For example, :program:`opt` by |
| 298 | default outputs a ``ModuleID``: |
| 299 | |
| 300 | .. code-block:: console |
| 301 | |
| 302 | $ cat example.ll |
| 303 | define i32 @main() nounwind { |
| 304 | ret i32 0 |
| 305 | } |
| 306 | |
| 307 | $ opt -S /path/to/example.ll |
| 308 | ; ModuleID = '/path/to/example.ll' |
| 309 | |
| 310 | define i32 @main() nounwind { |
| 311 | ret i32 0 |
| 312 | } |
| 313 | |
Sylvestre Ledru | 1d6becb | 2017-01-14 11:37:01 +0000 | [diff] [blame] | 314 | ``ModuleID`` can unexpectedly match against ``CHECK`` lines. For example: |
Dmitri Gribenko | 0d80c9c | 2012-12-30 14:51:03 +0000 | [diff] [blame] | 315 | |
| 316 | .. code-block:: llvm |
| 317 | |
| 318 | ; RUN: opt -S %s | FileCheck |
| 319 | |
| 320 | define i32 @main() nounwind { |
| 321 | ; CHECK-NOT: load |
| 322 | ret i32 0 |
| 323 | } |
| 324 | |
| 325 | This test will fail if placed into a ``download`` directory. |
| 326 | |
| 327 | To make your tests robust, always use ``opt ... < %s`` in the RUN line. |
| 328 | :program:`opt` does not output a ``ModuleID`` when input comes from stdin. |
| 329 | |
Renato Golin | f0126ea | 2013-07-03 20:56:33 +0000 | [diff] [blame] | 330 | Platform-Specific Tests |
| 331 | ----------------------- |
| 332 | |
| 333 | Whenever adding tests that require the knowledge of a specific platform, |
| 334 | either related to code generated, specific output or back-end features, |
| 335 | you must make sure to isolate the features, so that buildbots that |
| 336 | run on different architectures (and don't even compile all back-ends), |
| 337 | don't fail. |
| 338 | |
| 339 | The first problem is to check for target-specific output, for example sizes |
| 340 | of structures, paths and architecture names, for example: |
| 341 | |
| 342 | * Tests containing Windows paths will fail on Linux and vice-versa. |
| 343 | * Tests that check for ``x86_64`` somewhere in the text will fail anywhere else. |
| 344 | * Tests where the debug information calculates the size of types and structures. |
| 345 | |
| 346 | Also, if the test rely on any behaviour that is coded in any back-end, it must |
| 347 | go in its own directory. So, for instance, code generator tests for ARM go |
| 348 | into ``test/CodeGen/ARM`` and so on. Those directories contain a special |
| 349 | ``lit`` configuration file that ensure all tests in that directory will |
| 350 | only run if a specific back-end is compiled and available. |
| 351 | |
| 352 | For instance, on ``test/CodeGen/ARM``, the ``lit.local.cfg`` is: |
| 353 | |
| 354 | .. code-block:: python |
| 355 | |
| 356 | config.suffixes = ['.ll', '.c', '.cpp', '.test'] |
Alp Toker | 8aeca44 | 2014-06-09 22:42:55 +0000 | [diff] [blame] | 357 | if not 'ARM' in config.root.targets: |
Renato Golin | f0126ea | 2013-07-03 20:56:33 +0000 | [diff] [blame] | 358 | config.unsupported = True |
| 359 | |
| 360 | Other platform-specific tests are those that depend on a specific feature |
| 361 | of a specific sub-architecture, for example only to Intel chips that support ``AVX2``. |
| 362 | |
| 363 | For instance, ``test/CodeGen/X86/psubus.ll`` tests three sub-architecture |
| 364 | variants: |
| 365 | |
| 366 | .. code-block:: llvm |
| 367 | |
| 368 | ; RUN: llc -mcpu=core2 < %s | FileCheck %s -check-prefix=SSE2 |
| 369 | ; RUN: llc -mcpu=corei7-avx < %s | FileCheck %s -check-prefix=AVX1 |
| 370 | ; RUN: llc -mcpu=core-avx2 < %s | FileCheck %s -check-prefix=AVX2 |
| 371 | |
| 372 | And the checks are different: |
| 373 | |
| 374 | .. code-block:: llvm |
| 375 | |
| 376 | ; SSE2: @test1 |
| 377 | ; SSE2: psubusw LCPI0_0(%rip), %xmm0 |
| 378 | ; AVX1: @test1 |
| 379 | ; AVX1: vpsubusw LCPI0_0(%rip), %xmm0, %xmm0 |
| 380 | ; AVX2: @test1 |
| 381 | ; AVX2: vpsubusw LCPI0_0(%rip), %xmm0, %xmm0 |
| 382 | |
| 383 | So, if you're testing for a behaviour that you know is platform-specific or |
| 384 | depends on special features of sub-architectures, you must add the specific |
| 385 | triple, test with the specific FileCheck and put it into the specific |
| 386 | directory that will filter out all other architectures. |
| 387 | |
Piotr Padlewski | eba0dbb | 2016-07-08 23:47:29 +0000 | [diff] [blame] | 388 | |
Greg Parker | 4a50c7f | 2017-01-25 02:26:03 +0000 | [diff] [blame] | 389 | Constraining test execution |
| 390 | --------------------------- |
| 391 | |
| 392 | Some tests can be run only in specific configurations, such as |
| 393 | with debug builds or on particular platforms. Use ``REQUIRES`` |
| 394 | and ``UNSUPPORTED`` to control when the test is enabled. |
| 395 | |
| 396 | Some tests are expected to fail. For example, there may be a known bug |
| 397 | that the test detect. Use ``XFAIL`` to mark a test as an expected failure. |
| 398 | An ``XFAIL`` test will be successful if its execution fails, and |
| 399 | will be a failure if its execution succeeds. |
Piotr Padlewski | eba0dbb | 2016-07-08 23:47:29 +0000 | [diff] [blame] | 400 | |
| 401 | .. code-block:: llvm |
| 402 | |
Greg Parker | 4a50c7f | 2017-01-25 02:26:03 +0000 | [diff] [blame] | 403 | ; This test will be only enabled in the build with asserts. |
Piotr Padlewski | eba0dbb | 2016-07-08 23:47:29 +0000 | [diff] [blame] | 404 | ; REQUIRES: asserts |
Greg Parker | 4a50c7f | 2017-01-25 02:26:03 +0000 | [diff] [blame] | 405 | ; This test is disabled on Linux. |
| 406 | ; UNSUPPORTED: -linux- |
| 407 | ; This test is expected to fail on PowerPC. |
| 408 | ; XFAIL: powerpc |
Piotr Padlewski | eba0dbb | 2016-07-08 23:47:29 +0000 | [diff] [blame] | 409 | |
Greg Parker | 4a50c7f | 2017-01-25 02:26:03 +0000 | [diff] [blame] | 410 | ``REQUIRES`` and ``UNSUPPORTED`` and ``XFAIL`` all accept a comma-separated |
| 411 | list of boolean expressions. The values in each expression may be: |
Piotr Padlewski | eba0dbb | 2016-07-08 23:47:29 +0000 | [diff] [blame] | 412 | |
Greg Parker | 4a50c7f | 2017-01-25 02:26:03 +0000 | [diff] [blame] | 413 | - Features added to ``config.available_features`` by |
| 414 | configuration files such as ``lit.cfg``. |
| 415 | - Substrings of the target triple (``UNSUPPORTED`` and ``XFAIL`` only). |
| 416 | |
| 417 | | ``REQUIRES`` enables the test if all expressions are true. |
| 418 | | ``UNSUPPORTED`` disables the test if any expression is true. |
| 419 | | ``XFAIL`` expects the test to fail if any expression is true. |
| 420 | |
| 421 | As a special case, ``XFAIL: *`` is expected to fail everywhere. |
| 422 | |
| 423 | .. code-block:: llvm |
| 424 | |
| 425 | ; This test is disabled on Windows, |
| 426 | ; and is disabled on Linux, except for Android Linux. |
| 427 | ; UNSUPPORTED: windows, linux && !android |
| 428 | ; This test is expected to fail on both PowerPC and ARM. |
| 429 | ; XFAIL: powerpc || arm |
| 430 | |
Renato Golin | f0126ea | 2013-07-03 20:56:33 +0000 | [diff] [blame] | 431 | |
Nico Rieck | 4b3ec17 | 2014-02-15 08:35:56 +0000 | [diff] [blame] | 432 | Substitutions |
| 433 | ------------- |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 434 | |
Nico Rieck | 4b3ec17 | 2014-02-15 08:35:56 +0000 | [diff] [blame] | 435 | Besides replacing LLVM tool names the following substitutions are performed in |
| 436 | RUN lines: |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 437 | |
Nico Rieck | 4b3ec17 | 2014-02-15 08:35:56 +0000 | [diff] [blame] | 438 | ``%%`` |
| 439 | Replaced by a single ``%``. This allows escaping other substitutions. |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 440 | |
Nico Rieck | 4b3ec17 | 2014-02-15 08:35:56 +0000 | [diff] [blame] | 441 | ``%s`` |
| 442 | File path to the test case's source. This is suitable for passing on the |
| 443 | command line as the input to an LLVM tool. |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 444 | |
Nico Rieck | 4b3ec17 | 2014-02-15 08:35:56 +0000 | [diff] [blame] | 445 | Example: ``/home/user/llvm/test/MC/ELF/foo_test.s`` |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 446 | |
Nico Rieck | 4b3ec17 | 2014-02-15 08:35:56 +0000 | [diff] [blame] | 447 | ``%S`` |
| 448 | Directory path to the test case's source. |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 449 | |
Nico Rieck | 4b3ec17 | 2014-02-15 08:35:56 +0000 | [diff] [blame] | 450 | Example: ``/home/user/llvm/test/MC/ELF`` |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 451 | |
Nico Rieck | 4b3ec17 | 2014-02-15 08:35:56 +0000 | [diff] [blame] | 452 | ``%t`` |
| 453 | File path to a temporary file name that could be used for this test case. |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 454 | The file name won't conflict with other test cases. You can append to it |
| 455 | if you need multiple temporaries. This is useful as the destination of |
| 456 | some redirected output. |
| 457 | |
Nico Rieck | 4b3ec17 | 2014-02-15 08:35:56 +0000 | [diff] [blame] | 458 | Example: ``/home/user/llvm.build/test/MC/ELF/Output/foo_test.s.tmp`` |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 459 | |
Nico Rieck | 4b3ec17 | 2014-02-15 08:35:56 +0000 | [diff] [blame] | 460 | ``%T`` |
Kuba Mracek | 9808fe2 | 2018-06-19 22:22:48 +0000 | [diff] [blame] | 461 | Directory of ``%t``. Deprecated. Shouldn't be used, because it can be easily |
| 462 | misused and cause race conditions between tests. |
| 463 | |
| 464 | Use ``rm -rf %t && mkdir %t`` instead if a temporary directory is necessary. |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 465 | |
Nico Rieck | 4b3ec17 | 2014-02-15 08:35:56 +0000 | [diff] [blame] | 466 | Example: ``/home/user/llvm.build/test/MC/ELF/Output`` |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 467 | |
Nico Rieck | 4b3ec17 | 2014-02-15 08:35:56 +0000 | [diff] [blame] | 468 | ``%{pathsep}`` |
| 469 | |
| 470 | Expands to the path separator, i.e. ``:`` (or ``;`` on Windows). |
| 471 | |
David Bozier | 56b920f | 2017-02-09 14:12:30 +0000 | [diff] [blame] | 472 | ``%/s, %/S, %/t, %/T:`` |
| 473 | |
| 474 | Act like the corresponding substitution above but replace any ``\`` |
| 475 | character with a ``/``. This is useful to normalize path separators. |
| 476 | |
| 477 | Example: ``%s: C:\Desktop Files/foo_test.s.tmp`` |
| 478 | |
| 479 | Example: ``%/s: C:/Desktop Files/foo_test.s.tmp`` |
| 480 | |
| 481 | ``%:s, %:S, %:t, %:T:`` |
| 482 | |
| 483 | Act like the corresponding substitution above but remove colons at |
| 484 | the beginning of Windows paths. This is useful to allow concatenation |
| 485 | of absolute paths on Windows to produce a legal path. |
| 486 | |
| 487 | Example: ``%s: C:\Desktop Files\foo_test.s.tmp`` |
| 488 | |
| 489 | Example: ``%:s: C\Desktop Files\foo_test.s.tmp`` |
| 490 | |
Nico Rieck | 4b3ec17 | 2014-02-15 08:35:56 +0000 | [diff] [blame] | 491 | |
| 492 | **LLVM-specific substitutions:** |
| 493 | |
| 494 | ``%shlibext`` |
| 495 | The suffix for the host platforms shared library files. This includes the |
| 496 | period as the first character. |
| 497 | |
| 498 | Example: ``.so`` (Linux), ``.dylib`` (OS X), ``.dll`` (Windows) |
| 499 | |
| 500 | ``%exeext`` |
| 501 | The suffix for the host platforms executable files. This includes the |
| 502 | period as the first character. |
| 503 | |
| 504 | Example: ``.exe`` (Windows), empty on Linux. |
| 505 | |
| 506 | ``%(line)``, ``%(line+<number>)``, ``%(line-<number>)`` |
| 507 | The number of the line where this substitution is used, with an optional |
| 508 | integer offset. This can be used in tests with multiple RUN lines, which |
| 509 | reference test file's line numbers. |
| 510 | |
| 511 | |
| 512 | **Clang-specific substitutions:** |
| 513 | |
| 514 | ``%clang`` |
| 515 | Invokes the Clang driver. |
| 516 | |
| 517 | ``%clang_cpp`` |
| 518 | Invokes the Clang driver for C++. |
| 519 | |
| 520 | ``%clang_cl`` |
| 521 | Invokes the CL-compatible Clang driver. |
| 522 | |
| 523 | ``%clangxx`` |
| 524 | Invokes the G++-compatible Clang driver. |
| 525 | |
| 526 | ``%clang_cc1`` |
| 527 | Invokes the Clang frontend. |
| 528 | |
| 529 | ``%itanium_abi_triple``, ``%ms_abi_triple`` |
| 530 | These substitutions can be used to get the current target triple adjusted to |
| 531 | the desired ABI. For example, if the test suite is running with the |
| 532 | ``i686-pc-win32`` target, ``%itanium_abi_triple`` will expand to |
| 533 | ``i686-pc-mingw32``. This allows a test to run with a specific ABI without |
| 534 | constraining it to a specific triple. |
| 535 | |
| 536 | To add more substituations, look at ``test/lit.cfg`` or ``lit.local.cfg``. |
| 537 | |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 538 | |
Matthias Braun | 458a265 | 2015-05-04 21:37:00 +0000 | [diff] [blame] | 539 | Options |
| 540 | ------- |
| 541 | |
| 542 | The llvm lit configuration allows to customize some things with user options: |
| 543 | |
| 544 | ``llc``, ``opt``, ... |
| 545 | Substitute the respective llvm tool name with a custom command line. This |
| 546 | allows to specify custom paths and default arguments for these tools. |
| 547 | Example: |
| 548 | |
| 549 | % llvm-lit "-Dllc=llc -verify-machineinstrs" |
| 550 | |
| 551 | ``run_long_tests`` |
| 552 | Enable the execution of long running tests. |
| 553 | |
| 554 | ``llvm_site_config`` |
| 555 | Load the specified lit configuration instead of the default one. |
| 556 | |
| 557 | |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 558 | Other Features |
| 559 | -------------- |
| 560 | |
Nico Rieck | 1139063 | 2014-01-08 16:30:03 +0000 | [diff] [blame] | 561 | To make RUN line writing easier, there are several helper programs. These |
| 562 | helpers are in the PATH when running tests, so you can just call them using |
| 563 | their name. For example: |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 564 | |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 565 | ``not`` |
Nico Rieck | 1139063 | 2014-01-08 16:30:03 +0000 | [diff] [blame] | 566 | This program runs its arguments and then inverts the result code from it. |
Eli Bendersky | 2cbe23f | 2012-12-04 14:34:00 +0000 | [diff] [blame] | 567 | Zero result codes become 1. Non-zero result codes become 0. |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 568 | |
Eli Bendersky | 2cbe23f | 2012-12-04 14:34:00 +0000 | [diff] [blame] | 569 | To make the output more useful, :program:`lit` will scan |
Sean Silva | ac99eed | 2012-11-14 21:09:30 +0000 | [diff] [blame] | 570 | the lines of the test case for ones that contain a pattern that matches |
| 571 | ``PR[0-9]+``. This is the syntax for specifying a PR (Problem Report) number |
| 572 | that is related to the test case. The number after "PR" specifies the |
| 573 | LLVM bugzilla number. When a PR number is specified, it will be used in |
| 574 | the pass/fail reporting. This is useful to quickly get some context when |
| 575 | a test fails. |
| 576 | |
| 577 | Finally, any line that contains "END." will cause the special |
| 578 | interpretation of lines to terminate. This is generally done right after |
| 579 | the last RUN: line. This has two side effects: |
| 580 | |
| 581 | (a) it prevents special interpretation of lines that are part of the test |
| 582 | program, not the instructions to the test case, and |
| 583 | |
| 584 | (b) it speeds things up for really big test cases by avoiding |
| 585 | interpretation of the remainder of the file. |