Sean Silva | d5f4b4c | 2012-11-14 23:11:10 +0000 | [diff] [blame] | 1 | ============================== |
| 2 | LLVM test-suite Makefile Guide |
| 3 | ============================== |
| 4 | |
Sean Silva | d5f4b4c | 2012-11-14 23:11:10 +0000 | [diff] [blame] | 5 | .. contents:: |
| 6 | :local: |
| 7 | |
| 8 | Overview |
| 9 | ======== |
| 10 | |
| 11 | This document describes the features of the Makefile-based LLVM |
| 12 | test-suite. This way of interacting with the test-suite is deprecated in |
| 13 | favor of running the test-suite using LNT, but may continue to prove |
| 14 | useful for some users. See the Testing Guide's :ref:`test-suite Quickstart |
| 15 | <test-suite-quickstart>` section for more information. |
| 16 | |
| 17 | Test suite Structure |
| 18 | ==================== |
| 19 | |
| 20 | The ``test-suite`` module contains a number of programs that can be |
| 21 | compiled with LLVM and executed. These programs are compiled using the |
| 22 | native compiler and various LLVM backends. The output from the program |
| 23 | compiled with the native compiler is assumed correct; the results from |
| 24 | the other programs are compared to the native program output and pass if |
| 25 | they match. |
| 26 | |
| 27 | When executing tests, it is usually a good idea to start out with a |
| 28 | subset of the available tests or programs. This makes test run times |
| 29 | smaller at first and later on this is useful to investigate individual |
| 30 | test failures. To run some test only on a subset of programs, simply |
| 31 | change directory to the programs you want tested and run ``gmake`` |
| 32 | there. Alternatively, you can run a different test using the ``TEST`` |
| 33 | variable to change what tests or run on the selected programs (see below |
| 34 | for more info). |
| 35 | |
| 36 | In addition for testing correctness, the ``test-suite`` directory also |
| 37 | performs timing tests of various LLVM optimizations. It also records |
| 38 | compilation times for the compilers and the JIT. This information can be |
| 39 | used to compare the effectiveness of LLVM's optimizations and code |
| 40 | generation. |
| 41 | |
| 42 | ``test-suite`` tests are divided into three types of tests: MultiSource, |
| 43 | SingleSource, and External. |
| 44 | |
| 45 | - ``test-suite/SingleSource`` |
| 46 | |
| 47 | The SingleSource directory contains test programs that are only a |
| 48 | single source file in size. These are usually small benchmark |
| 49 | programs or small programs that calculate a particular value. Several |
| 50 | such programs are grouped together in each directory. |
| 51 | |
| 52 | - ``test-suite/MultiSource`` |
| 53 | |
| 54 | The MultiSource directory contains subdirectories which contain |
| 55 | entire programs with multiple source files. Large benchmarks and |
| 56 | whole applications go here. |
| 57 | |
| 58 | - ``test-suite/External`` |
| 59 | |
| 60 | The External directory contains Makefiles for building code that is |
| 61 | external to (i.e., not distributed with) LLVM. The most prominent |
| 62 | members of this directory are the SPEC 95 and SPEC 2000 benchmark |
| 63 | suites. The ``External`` directory does not contain these actual |
| 64 | tests, but only the Makefiles that know how to properly compile these |
| 65 | programs from somewhere else. The presence and location of these |
| 66 | external programs is configured by the test-suite ``configure`` |
| 67 | script. |
| 68 | |
| 69 | Each tree is then subdivided into several categories, including |
| 70 | applications, benchmarks, regression tests, code that is strange |
| 71 | grammatically, etc. These organizations should be relatively self |
| 72 | explanatory. |
| 73 | |
| 74 | Some tests are known to fail. Some are bugs that we have not fixed yet; |
| 75 | others are features that we haven't added yet (or may never add). In the |
| 76 | regression tests, the result for such tests will be XFAIL (eXpected |
| 77 | FAILure). In this way, you can tell the difference between an expected |
| 78 | and unexpected failure. |
| 79 | |
| 80 | The tests in the test suite have no such feature at this time. If the |
| 81 | test passes, only warnings and other miscellaneous output will be |
| 82 | generated. If a test fails, a large <program> FAILED message will be |
| 83 | displayed. This will help you separate benign warnings from actual test |
| 84 | failures. |
| 85 | |
| 86 | Running the test suite |
| 87 | ====================== |
| 88 | |
| 89 | First, all tests are executed within the LLVM object directory tree. |
| 90 | They *are not* executed inside of the LLVM source tree. This is because |
| 91 | the test suite creates temporary files during execution. |
| 92 | |
| 93 | To run the test suite, you need to use the following steps: |
| 94 | |
| 95 | #. ``cd`` into the ``llvm/projects`` directory in your source tree. |
| 96 | #. Check out the ``test-suite`` module with: |
| 97 | |
| 98 | .. code-block:: bash |
| 99 | |
| 100 | % svn co http://llvm.org/svn/llvm-project/test-suite/trunk test-suite |
| 101 | |
| 102 | This will get the test suite into ``llvm/projects/test-suite``. |
| 103 | |
| 104 | #. Configure and build ``llvm``. |
| 105 | |
| 106 | #. Configure and build ``llvm-gcc``. |
| 107 | |
| 108 | #. Install ``llvm-gcc`` somewhere. |
| 109 | |
| 110 | #. *Re-configure* ``llvm`` from the top level of each build tree (LLVM |
| 111 | object directory tree) in which you want to run the test suite, just |
| 112 | as you do before building LLVM. |
| 113 | |
| 114 | During the *re-configuration*, you must either: (1) have ``llvm-gcc`` |
| 115 | you just built in your path, or (2) specify the directory where your |
| 116 | just-built ``llvm-gcc`` is installed using |
| 117 | ``--with-llvmgccdir=$LLVM_GCC_DIR``. |
| 118 | |
| 119 | You must also tell the configure machinery that the test suite is |
| 120 | available so it can be configured for your build tree: |
| 121 | |
| 122 | .. code-block:: bash |
| 123 | |
| 124 | % cd $LLVM_OBJ_ROOT ; $LLVM_SRC_ROOT/configure [--with-llvmgccdir=$LLVM_GCC_DIR] |
| 125 | |
| 126 | [Remember that ``$LLVM_GCC_DIR`` is the directory where you |
| 127 | *installed* llvm-gcc, not its src or obj directory.] |
| 128 | |
| 129 | #. You can now run the test suite from your build tree as follows: |
| 130 | |
| 131 | .. code-block:: bash |
| 132 | |
| 133 | % cd $LLVM_OBJ_ROOT/projects/test-suite |
| 134 | % make |
| 135 | |
| 136 | Note that the second and third steps only need to be done once. After |
| 137 | you have the suite checked out and configured, you don't need to do it |
| 138 | again (unless the test code or configure script changes). |
| 139 | |
| 140 | Configuring External Tests |
| 141 | -------------------------- |
| 142 | |
| 143 | In order to run the External tests in the ``test-suite`` module, you |
| 144 | must specify *--with-externals*. This must be done during the |
| 145 | *re-configuration* step (see above), and the ``llvm`` re-configuration |
| 146 | must recognize the previously-built ``llvm-gcc``. If any of these is |
| 147 | missing or neglected, the External tests won't work. |
| 148 | |
| 149 | * *--with-externals* |
| 150 | |
| 151 | * *--with-externals=<directory>* |
| 152 | |
| 153 | This tells LLVM where to find any external tests. They are expected to |
| 154 | be in specifically named subdirectories of <``directory``>. If |
| 155 | ``directory`` is left unspecified, ``configure`` uses the default value |
| 156 | ``/home/vadve/shared/benchmarks/speccpu2000/benchspec``. Subdirectory |
| 157 | names known to LLVM include: |
| 158 | |
| 159 | * spec95 |
| 160 | |
| 161 | * speccpu2000 |
| 162 | |
| 163 | * speccpu2006 |
| 164 | |
| 165 | * povray31 |
| 166 | |
| 167 | Others are added from time to time, and can be determined from |
| 168 | ``configure``. |
| 169 | |
| 170 | Running different tests |
| 171 | ----------------------- |
| 172 | |
| 173 | In addition to the regular "whole program" tests, the ``test-suite`` |
| 174 | module also provides a mechanism for compiling the programs in different |
| 175 | ways. If the variable TEST is defined on the ``gmake`` command line, the |
| 176 | test system will include a Makefile named |
| 177 | ``TEST.<value of TEST variable>.Makefile``. This Makefile can modify |
| 178 | build rules to yield different results. |
| 179 | |
| 180 | For example, the LLVM nightly tester uses ``TEST.nightly.Makefile`` to |
| 181 | create the nightly test reports. To run the nightly tests, run |
| 182 | ``gmake TEST=nightly``. |
| 183 | |
| 184 | There are several TEST Makefiles available in the tree. Some of them are |
| 185 | designed for internal LLVM research and will not work outside of the |
| 186 | LLVM research group. They may still be valuable, however, as a guide to |
| 187 | writing your own TEST Makefile for any optimization or analysis passes |
| 188 | that you develop with LLVM. |
| 189 | |
| 190 | Generating test output |
| 191 | ---------------------- |
| 192 | |
| 193 | There are a number of ways to run the tests and generate output. The |
| 194 | most simple one is simply running ``gmake`` with no arguments. This will |
| 195 | compile and run all programs in the tree using a number of different |
| 196 | methods and compare results. Any failures are reported in the output, |
| 197 | but are likely drowned in the other output. Passes are not reported |
| 198 | explicitly. |
| 199 | |
| 200 | Somewhat better is running ``gmake TEST=sometest test``, which runs the |
| 201 | specified test and usually adds per-program summaries to the output |
| 202 | (depending on which sometest you use). For example, the ``nightly`` test |
| 203 | explicitly outputs TEST-PASS or TEST-FAIL for every test after each |
| 204 | program. Though these lines are still drowned in the output, it's easy |
| 205 | to grep the output logs in the Output directories. |
| 206 | |
| 207 | Even better are the ``report`` and ``report.format`` targets (where |
| 208 | ``format`` is one of ``html``, ``csv``, ``text`` or ``graphs``). The |
| 209 | exact contents of the report are dependent on which ``TEST`` you are |
| 210 | running, but the text results are always shown at the end of the run and |
| 211 | the results are always stored in the ``report.<type>.format`` file (when |
| 212 | running with ``TEST=<type>``). The ``report`` also generate a file |
| 213 | called ``report.<type>.raw.out`` containing the output of the entire |
| 214 | test run. |
| 215 | |
| 216 | Writing custom tests for the test suite |
| 217 | --------------------------------------- |
| 218 | |
| 219 | Assuming you can run the test suite, (e.g. |
| 220 | "``gmake TEST=nightly report``" should work), it is really easy to run |
| 221 | optimizations or code generator components against every program in the |
| 222 | tree, collecting statistics or running custom checks for correctness. At |
| 223 | base, this is how the nightly tester works, it's just one example of a |
| 224 | general framework. |
| 225 | |
| 226 | Lets say that you have an LLVM optimization pass, and you want to see |
| 227 | how many times it triggers. First thing you should do is add an LLVM |
| 228 | `statistic <ProgrammersManual.html#Statistic>`_ to your pass, which will |
| 229 | tally counts of things you care about. |
| 230 | |
| 231 | Following this, you can set up a test and a report that collects these |
| 232 | and formats them for easy viewing. This consists of two files, a |
| 233 | "``test-suite/TEST.XXX.Makefile``" fragment (where XXX is the name of |
| 234 | your test) and a "``test-suite/TEST.XXX.report``" file that indicates |
| 235 | how to format the output into a table. There are many example reports of |
| 236 | various levels of sophistication included with the test suite, and the |
| 237 | framework is very general. |
| 238 | |
| 239 | If you are interested in testing an optimization pass, check out the |
| 240 | "libcalls" test as an example. It can be run like this: |
| 241 | |
| 242 | .. code-block:: bash |
| 243 | |
| 244 | % cd llvm/projects/test-suite/MultiSource/Benchmarks # or some other level |
| 245 | % make TEST=libcalls report |
| 246 | |
| 247 | This will do a bunch of stuff, then eventually print a table like this: |
| 248 | |
| 249 | :: |
| 250 | |
| 251 | Name | total | #exit | |
| 252 | ... |
| 253 | FreeBench/analyzer/analyzer | 51 | 6 | |
| 254 | FreeBench/fourinarow/fourinarow | 1 | 1 | |
| 255 | FreeBench/neural/neural | 19 | 9 | |
| 256 | FreeBench/pifft/pifft | 5 | 3 | |
| 257 | MallocBench/cfrac/cfrac | 1 | * | |
| 258 | MallocBench/espresso/espresso | 52 | 12 | |
| 259 | MallocBench/gs/gs | 4 | * | |
| 260 | Prolangs-C/TimberWolfMC/timberwolfmc | 302 | * | |
| 261 | Prolangs-C/agrep/agrep | 33 | 12 | |
| 262 | Prolangs-C/allroots/allroots | * | * | |
| 263 | Prolangs-C/assembler/assembler | 47 | * | |
| 264 | Prolangs-C/bison/mybison | 74 | * | |
| 265 | ... |
| 266 | |
| 267 | This basically is grepping the -stats output and displaying it in a |
| 268 | table. You can also use the "TEST=libcalls report.html" target to get |
| 269 | the table in HTML form, similarly for report.csv and report.tex. |
| 270 | |
| 271 | The source for this is in ``test-suite/TEST.libcalls.*``. The format is |
| 272 | pretty simple: the Makefile indicates how to run the test (in this case, |
| 273 | "``opt -simplify-libcalls -stats``"), and the report contains one line |
| 274 | for each column of the output. The first value is the header for the |
| 275 | column and the second is the regex to grep the output of the command |
| 276 | for. There are lots of example reports that can do fancy stuff. |