1test-suite Guide 2================ 3 4Quickstart 5---------- 6 71. The lit test runner is required to run the tests. You can either use one 8 from an LLVM build: 9 10 ```bash 11 % <path to llvm build>/bin/llvm-lit --version 12 lit 0.8.0dev 13 ``` 14 15 An alternative is installing it as a python package in a python virtual 16 environment: 17 18 ```bash 19 % mkdir venv 20 % virtualenv venv 21 % . venv/bin/activate 22 % pip install svn+https://llvm.org/svn/llvm-project/llvm/trunk/utils/lit 23 % lit --version 24 lit 0.8.0dev 25 ``` 26 272. Check out the `test-suite` module with: 28 29 ```bash 30 % git clone https://github.com/llvm/llvm-test-suite.git test-suite 31 ``` 32 333. Create a build directory and use CMake to configure the suite. Use the 34 `CMAKE_C_COMPILER` option to specify the compiler to test. Use a cache file 35 to choose a typical build configuration: 36 37 ```bash 38 % mkdir test-suite-build 39 % cd test-suite-build 40 % cmake -DCMAKE_C_COMPILER=<path to llvm build>/bin/clang \ 41 -C../test-suite/cmake/caches/O3.cmake \ 42 ../test-suite 43 ``` 44 45**NOTE!** if you are using your built clang, and you want to build and run the 46MicroBenchmarks/XRay microbenchmarks, you need to add `compiler-rt` to your 47`LLVM_ENABLE_RUNTIMES` cmake flag. 48 494. Build the benchmarks: 50 51 ```text 52 % make 53 Scanning dependencies of target timeit-target 54 [ 0%] Building C object tools/CMakeFiles/timeit-target.dir/timeit.c.o 55 [ 0%] Linking C executable timeit-target 56 ... 57 ``` 58 595. Run the tests with lit: 60 61 ```text 62 % llvm-lit -v -j 1 -o results.json . 63 -- Testing: 474 tests, 1 threads -- 64 PASS: test-suite :: MultiSource/Applications/ALAC/decode/alacconvert-decode.test (1 of 474) 65 ********** TEST 'test-suite :: MultiSource/Applications/ALAC/decode/alacconvert-decode.test' RESULTS ********** 66 compile_time: 0.2192 67 exec_time: 0.0462 68 hash: "59620e187c6ac38b36382685ccd2b63b" 69 size: 83348 70 ********** 71 PASS: test-suite :: MultiSource/Applications/ALAC/encode/alacconvert-encode.test (2 of 474) 72 ... 73 ``` 74 756. Show and compare result files (optional): 76 77 ```bash 78 # Make sure pandas and scipy are installed. Prepend `sudo` if necessary. 79 % pip install pandas scipy 80 # Show a single result file: 81 % test-suite/utils/compare.py results.json 82 # Compare two result files: 83 % test-suite/utils/compare.py results_a.json results_b.json 84 ``` 85 86 87Structure 88--------- 89 90The test-suite contains benchmark and test programs. The programs come with 91reference outputs so that their correctness can be checked. The suite comes 92with tools to collect metrics such as benchmark runtime, compilation time and 93code size. 94 95The test-suite is divided into several directories: 96 97- `SingleSource/` 98 99 Contains test programs that are only a single source file in size. A 100 subdirectory may contain several programs. 101 102- `MultiSource/` 103 104 Contains subdirectories which entire programs with multiple source files. 105 Large benchmarks and whole applications go here. 106 107- `MicroBenchmarks/` 108 109 Programs using the [google-benchmark](https://github.com/google/benchmark) 110 library. The programs define functions that are run multiple times until the 111 measurement results are statistically significant. 112 113- `External/` 114 115 Contains descriptions and test data for code that cannot be directly 116 distributed with the test-suite. The most prominent members of this 117 directory are the SPEC CPU benchmark suites. 118 See [External Suites](#external-suites). 119 120- `Bitcode/` 121 122 These tests are mostly written in LLVM bitcode. 123 124- `CTMark/` 125 126 Contains symbolic links to other benchmarks forming a representative sample 127 for compilation performance measurements. 128 129### Benchmarks 130 131Every program can work as a correctness test. Some programs are unsuitable for 132performance measurements. Setting the `TEST_SUITE_BENCHMARKING_ONLY` CMake 133option to `ON` will disable them. 134 135 136Configuration 137------------- 138 139The test-suite has configuration options to customize building and running the 140benchmarks. CMake can print a list of them: 141 142```bash 143% cd test-suite-build 144# Print basic options: 145% cmake -LH 146# Print all options: 147% cmake -LAH 148``` 149 150### Common Configuration Options 151 152- `CMAKE_C_FLAGS` 153 154 Specify extra flags to be passed to C compiler invocations. The flags are 155 also passed to the C++ compiler and linker invocations. See 156 [https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_FLAGS.html](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_FLAGS.html) 157 158- `CMAKE_C_COMPILER` 159 160 Select the C compiler executable to be used. Note that the C++ compiler is 161 inferred automatically i.e. when specifying `path/to/clang` CMake will 162 automatically use `path/to/clang++` as the C++ compiler. See 163 [https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER.html](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER.html) 164 165- `CMAKE_Fortran_COMPILER` 166 167 Select the Fortran compiler executable to be used. Not set by default and not 168 required unless running the Fortran Test Suite. 169 170- `CMAKE_BUILD_TYPE` 171 172 Select a build type like `OPTIMIZE` or `DEBUG` selecting a set of predefined 173 compiler flags. These flags are applied regardless of the `CMAKE_C_FLAGS` 174 option and may be changed by modifying `CMAKE_C_FLAGS_OPTIMIZE` etc. See 175 [https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html](https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html) 176 177- `TEST_SUITE_FORTRAN` 178 179 Activate that Fortran tests. This is a work in progress. More information can be 180 found in the [Flang documentation](https://flang.llvm.org/docs/html/FortranLLVMTestSuite.html) 181 182- `TEST_SUITE_RUN_UNDER` 183 184 Prefix test invocations with the given tool. This is typically used to run 185 cross-compiled tests within a simulator tool. 186 187- `TEST_SUITE_BENCHMARKING_ONLY` 188 189 Disable tests that are unsuitable for performance measurements. The disabled 190 tests either run for a very short time or are dominated by I/O performance 191 making them unsuitable as compiler performance tests. 192 193- `TEST_SUITE_SUBDIRS` 194 195 Semicolon-separated list of directories to include. This can be used to only 196 build parts of the test-suite or to include external suites. This option 197 does not work reliably with deeper subdirectories as it skips intermediate 198 `CMakeLists.txt` files which may be required. 199 200- `TEST_SUITE_COLLECT_STATS` 201 202 Collect internal LLVM statistics. Appends `-save-stats=obj` when invoking the 203 compiler and makes the lit runner collect and merge the statistic files. 204 205- `TEST_SUITE_RUN_BENCHMARKS` 206 207 If this is set to `OFF` then lit will not actually run the tests but just 208 collect build statistics like compile time and code size. 209 210- `TEST_SUITE_USE_PERF` 211 212 Use the `perf` tool for time measurement instead of the `timeit` tool that 213 comes with the test-suite. The `perf` is usually available on linux systems. 214 215- `TEST_SUITE_SPEC2000_ROOT`, `TEST_SUITE_SPEC2006_ROOT`, `TEST_SUITE_SPEC2017_ROOT`, ... 216 217 Specify installation directories of external benchmark suites. You can find 218 more information about expected versions or usage in the README files in the 219 `External` directory (such as `External/SPEC/README`) 220 221### Common CMake Flags 222 223- `-GNinja` 224 225 Generate build files for the ninja build tool. 226 227- `-Ctest-suite/cmake/caches/<cachefile.cmake>` 228 229 Use a CMake cache. The test-suite comes with several CMake caches which 230 predefine common or tricky build configurations. 231 232 233Displaying and Analyzing Results 234-------------------------------- 235 236The `compare.py` script displays and compares result files. A result file is 237produced when invoking lit with the `-o filename.json` flag. 238 239Example usage: 240 241- Basic Usage: 242 243 ```text 244 % test-suite/utils/compare.py baseline.json 245 Warning: 'test-suite :: External/SPEC/CINT2006/403.gcc/403.gcc.test' has No metrics! 246 Tests: 508 247 Metric: exec_time 248 249 Program baseline 250 251 INT2006/456.hmmer/456.hmmer 1222.90 252 INT2006/464.h264ref/464.h264ref 928.70 253 ... 254 baseline 255 count 506.000000 256 mean 20.563098 257 std 111.423325 258 min 0.003400 259 25% 0.011200 260 50% 0.339450 261 75% 4.067200 262 max 1222.896800 263 ``` 264 265- Show compile_time or text segment size metrics: 266 267 ```bash 268 % test-suite/utils/compare.py -m compile_time baseline.json 269 % test-suite/utils/compare.py -m size.__text baseline.json 270 ``` 271 272- Compare two result files and filter short running tests: 273 274 ```bash 275 % test-suite/utils/compare.py --filter-short baseline.json experiment.json 276 ... 277 Program baseline experiment diff 278 279 SingleSour.../Benchmarks/Linpack/linpack-pc 5.16 4.30 -16.5% 280 MultiSourc...erolling-dbl/LoopRerolling-dbl 7.01 7.86 12.2% 281 SingleSour...UnitTests/Vectorizer/gcc-loops 3.89 3.54 -9.0% 282 ... 283 ``` 284 285- Merge multiple baseline and experiment result files by taking the minimum 286 runtime each: 287 288 ```bash 289 % test-suite/utils/compare.py base0.json base1.json base2.json vs exp0.json exp1.json exp2.json 290 ``` 291 292### Continuous Tracking with LNT 293 294LNT is a set of client and server tools for continuously monitoring 295performance. You can find more information at 296[https://llvm.org/docs/lnt](https://llvm.org/docs/lnt). The official LNT instance 297of the LLVM project is hosted at [http://lnt.llvm.org](http://lnt.llvm.org). 298 299 300External Suites 301--------------- 302 303External suites such as SPEC can be enabled by either 304 305- placing (or linking) them into the `test-suite/test-suite-externals/xxx` directory (example: `test-suite/test-suite-externals/speccpu2000`) 306- using a configuration option such as `-D TEST_SUITE_SPEC2000_ROOT=path/to/speccpu2000` 307 308You can find further information in the respective README files such as 309`test-suite/External/SPEC/README`. 310 311For the SPEC benchmarks you can switch between the `test`, `train` and 312`ref` input datasets via the `TEST_SUITE_RUN_TYPE` configuration option. 313The `train` dataset is used by default. 314 315 316Custom Suites 317------------- 318 319You can build custom suites using the test-suite infrastructure. A custom suite 320has a `CMakeLists.txt` file at the top directory. The `CMakeLists.txt` will be 321picked up automatically if placed into a subdirectory of the test-suite or when 322setting the `TEST_SUITE_SUBDIRS` variable: 323 324```bash 325% cmake -DTEST_SUITE_SUBDIRS=path/to/my/benchmark-suite ../test-suite 326``` 327 328 329Profile Guided Optimization 330--------------------------- 331 332Profile guided optimization requires to compile and run twice. First the 333benchmark should be compiled with profile generation instrumentation enabled 334and setup for training data. The lit runner will merge the profile files 335using `llvm-profdata` so they can be used by the second compilation run. 336 337Example: 338```bash 339# Profile generation run: 340% cmake -DTEST_SUITE_PROFILE_GENERATE=ON \ 341 -DTEST_SUITE_RUN_TYPE=train \ 342 ../test-suite 343% make 344% llvm-lit . 345# Use the profile data for compilation and actual benchmark run: 346% cmake -DTEST_SUITE_PROFILE_GENERATE=OFF \ 347 -DTEST_SUITE_PROFILE_USE=ON \ 348 -DTEST_SUITE_RUN_TYPE=ref \ 349 . 350% make 351% llvm-lit -o result.json . 352``` 353 354The `TEST_SUITE_RUN_TYPE` setting only affects the SPEC benchmark suites. 355 356 357Cross Compilation and External Devices 358-------------------------------------- 359 360### Compilation 361 362CMake allows to cross compile to a different target via toolchain files. More 363information can be found here: 364 365- [https://llvm.org/docs/lnt/tests.html#cross-compiling](https://llvm.org/docs/lnt/tests.html#cross-compiling) 366 367- [https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html) 368 369Cross compilation from macOS to iOS is possible with the 370`test-suite/cmake/caches/target-target-*-iphoneos-internal.cmake` CMake cache 371files; this requires an internal iOS SDK. 372 373### Running 374 375There are two ways to run the tests in a cross compilation setting: 376 377- Via SSH connection to an external device: The `TEST_SUITE_REMOTE_HOST` option 378 should be set to the SSH hostname. The executables and data files need to be 379 transferred to the device after compilation. This is typically done via the 380 `rsync` make target. After this, the lit runner can be used on the host 381 machine. It will prefix the benchmark and verification command lines with an 382 `ssh` command. 383 384 Example: 385 386 ```bash 387 % cmake -G Ninja -D CMAKE_C_COMPILER=path/to/clang \ 388 -C ../test-suite/cmake/caches/target-arm64-iphoneos-internal.cmake \ 389 -D CMAKE_BUILD_TYPE=Release \ 390 -D TEST_SUITE_REMOTE_HOST=mydevice \ 391 ../test-suite 392 % ninja 393 % ninja rsync 394 % llvm-lit -j1 -o result.json . 395 ``` 396 397- You can specify a simulator for the target machine with the 398 `TEST_SUITE_RUN_UNDER` setting. The lit runner will prefix all benchmark 399 invocations with it. 400 401 402Running the test-suite via LNT 403------------------------------ 404 405The LNT tool can run the test-suite. Use this when submitting test results to 406an LNT instance. See 407[https://llvm.org/docs/lnt/tests.html#llvm-cmake-test-suite](https://llvm.org/docs/lnt/tests.html#llvm-cmake-test-suite) 408for details. 409 410Running the test-suite via Makefiles (deprecated) 411------------------------------------------------- 412 413**Note**: The test-suite comes with a set of Makefiles that are considered 414deprecated. They do not support newer testing modes like `Bitcode` or 415`Microbenchmarks` and are harder to use. 416 417Old documentation is available in the 418[test-suite Makefile Guide](TestSuiteMakefileGuide). 419