| 1 | # Fortran Tests in the LLVM Test Suite |
| 2 | |
| 3 | ```{contents} |
| 4 | --- |
| 5 | local: |
| 6 | --- |
| 7 | ``` |
| 8 | |
| 9 | The [LLVM Test Suite](https://github.com/llvm/llvm-test-suite) is a |
| 10 | separate git repo from the main LLVM project. We recommend that |
| 11 | first-time users read through [LLVM Test Suite |
| 12 | Guide](https://llvm.org/docs/TestSuiteGuide.html) which describes the |
| 13 | organizational structure of the test suite and how to run it. |
| 14 | |
| 15 | ## Running the LLVM test-suite with Fortran |
| 16 | |
| 17 | Fortran support can be enabled by setting the following CMake variables: |
| 18 | ``` |
| 19 | cmake -G "Ninja" -DCMAKE_C_COMPILER=<path to C compiler> \ |
| 20 | -DCMAKE_CXX_COMPILER=<path to C++ compiler> \ |
| 21 | -DCMAKE_Fortran_COMPILER=<path to Fortran compiler> \ |
| 22 | -DTEST_SUITE_COLLECT_CODE_SIZE:STRING=OFF \ |
| 23 | -DTEST_SUITE_SUBDIRS:STRING="Fortran" \ |
| 24 | -DTEST_SUITE_FORTRAN:STRING=ON \ |
| 25 | -DTEST_SUITE_LIT=<path to llvm-lit> \ |
| 26 | <path to llvm-test-suite> |
| 27 | ``` |
| 28 | |
| 29 | This will configure the test-suite to run only the Fortran tests which |
| 30 | are found in the Fortran subdirectory. To run the C/C++ tests |
| 31 | alongside the Fortran tests omit the `-DTEST_SUITE_SUBDIRS` CMake |
| 32 | variable. |
| 33 | |
| 34 | If your Fortran compiler is Flang, there are a couple of other things you need |
| 35 | to do, which are explained |
| 36 | [here](https://github.com/llvm/llvm-test-suite/blob/main/Fortran/gfortran/README.md#usage). |
| 37 | |
| 38 | Then to build and run the tests: |
| 39 | ``` |
| 40 | ninja |
| 41 | ninja check |
| 42 | ``` |
| 43 | |
| 44 | ## Running the SPEC CPU 2017 |
| 45 | |
| 46 | We recently added CMake hooks into the LLVM Test Suite to support |
| 47 | Fortran tests from [SPEC CPU 2017](https://www.spec.org/cpu2017/). We |
| 48 | strongly encourage the use of the CMake Ninja (1.10 or later) generator |
| 49 | due to better support for Fortran module dependency detection. Some of |
| 50 | the SPEC CPU 2017 Fortran tests, those that are derived from climate |
| 51 | codes, require support for little-endian/big-endian byte swapping |
| 52 | capabilities which we automatically detect at CMake configuration |
| 53 | time. Note that a copy of SPEC CPU 2017 must be purchased by your |
| 54 | home institution and is not provided by LLVM. |
| 55 | |
| 56 | |
| 57 | Here is an example of how to build SPEC CPU 2017 with GCC |
| 58 | |
| 59 | ``` |
| 60 | cmake -G "Ninja" -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ \ |
| 61 | -DCMAKE_Fortran_COMPILER=gfortran \ |
| 62 | -DTEST_SUITE_COLLECT_CODE_SIZE:STRING=OFF \ |
| 63 | -DTEST_SUITE_SUBDIRS:STRING="External/SPEC" \ |
| 64 | -DTEST_SUITE_FORTRAN:STRING=ON \ |
| 65 | -DTEST_SUITE_SPEC2017_ROOT=<path to SPEC directory> .. |
| 66 | ``` |
| 67 | |
| 68 | ## Running the gfortran tests |
| 69 | |
| 70 | Tests from the gfortran test suite have been imported into the LLVM Test Suite. |
| 71 | The tests will be run automatically if the test suite is built following the |
| 72 | instructions described [above](#running-the-llvm-test-suite-with-fortran). |
| 73 | There are additional configure-time options that can be used with the gfortran |
| 74 | tests. More details about those options and their purpose can be found in |
| 75 | [`Fortran/gfortran/README.md`](https://github.com/llvm/llvm-test-suite/tree/main/Fortran/gfortran/README.md)`. |