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