1====================================== 2test-suite Makefile Guide (deprecated) 3====================================== 4 5.. contents:: 6 :local: 7 8Overview 9======== 10 11First, all tests are executed within the LLVM object directory tree. 12They *are not* executed inside of the LLVM source tree. This is because 13the test suite creates temporary files during execution. 14 15To run the test suite, you need to use the following steps: 16 17#. Check out the ``test-suite`` module with: 18 19 .. code-block:: bash 20 21 % git clone https://github.com/llvm/llvm-test-suite.git test-suite 22 23#. FIXME: these directions are outdated and won't work. Figure out 24 what the correct thing to do is, and write it down here. 25 26#. Configure and build ``llvm``. 27 28#. Configure and build ``llvm-gcc``. 29 30#. Install ``llvm-gcc`` somewhere. 31 32#. *Re-configure* ``llvm`` from the top level of each build tree (LLVM 33 object directory tree) in which you want to run the test suite, just 34 as you do before building LLVM. 35 36 During the *re-configuration*, you must either: (1) have ``llvm-gcc`` 37 you just built in your path, or (2) specify the directory where your 38 just-built ``llvm-gcc`` is installed using 39 ``--with-llvmgccdir=$LLVM_GCC_DIR``. 40 41 You must also tell the configure machinery that the test suite is 42 available so it can be configured for your build tree: 43 44 .. code-block:: bash 45 46 % cd $LLVM_OBJ_ROOT ; $LLVM_SRC_ROOT/configure [--with-llvmgccdir=$LLVM_GCC_DIR] 47 48 [Remember that ``$LLVM_GCC_DIR`` is the directory where you 49 *installed* llvm-gcc, not its src or obj directory.] 50 51#. You can now run the test suite from your build tree as follows: 52 53 .. code-block:: bash 54 55 % cd $LLVM_OBJ_ROOT/projects/test-suite 56 % make 57 58Note that the second and third steps only need to be done once. After 59you have the suite checked out and configured, you don't need to do it 60again (unless the test code or configure script changes). 61 62Configuring External Tests 63========================== 64 65In order to run the External tests in the ``test-suite`` module, you 66must specify *--with-externals*. This must be done during the 67*re-configuration* step (see above), and the ``llvm`` re-configuration 68must recognize the previously-built ``llvm-gcc``. If any of these is 69missing or neglected, the External tests won't work. 70 71* *--with-externals* 72 73* *--with-externals=<directory>* 74 75This tells LLVM where to find any external tests. They are expected to 76be in specifically named subdirectories of <``directory``>. If 77``directory`` is left unspecified, ``configure`` uses the default value 78``/home/vadve/shared/benchmarks/speccpu2000/benchspec``. Subdirectory 79names known to LLVM include: 80 81* spec95 82 83* speccpu2000 84 85* speccpu2006 86 87* povray31 88 89Others are added from time to time, and can be determined from 90``configure``. 91 92Running Different Tests 93======================= 94 95In addition to the regular "whole program" tests, the ``test-suite`` 96module also provides a mechanism for compiling the programs in different 97ways. If the variable TEST is defined on the ``gmake`` command line, the 98test system will include a Makefile named 99``TEST.<value of TEST variable>.Makefile``. This Makefile can modify 100build rules to yield different results. 101 102For example, the LLVM nightly tester uses ``TEST.nightly.Makefile`` to 103create the nightly test reports. To run the nightly tests, run 104``gmake TEST=nightly``. 105 106There are several TEST Makefiles available in the tree. Some of them are 107designed for internal LLVM research and will not work outside of the 108LLVM research group. They may still be valuable, however, as a guide to 109writing your own TEST Makefile for any optimization or analysis passes 110that you develop with LLVM. 111 112Generating Test Output 113====================== 114 115There are a number of ways to run the tests and generate output. The 116most simple one is simply running ``gmake`` with no arguments. This will 117compile and run all programs in the tree using a number of different 118methods and compare results. Any failures are reported in the output, 119but are likely drowned in the other output. Passes are not reported 120explicitly. 121 122Somewhat better is running ``gmake TEST=sometest test``, which runs the 123specified test and usually adds per-program summaries to the output 124(depending on which sometest you use). For example, the ``nightly`` test 125explicitly outputs TEST-PASS or TEST-FAIL for every test after each 126program. Though these lines are still drowned in the output, it's easy 127to grep the output logs in the Output directories. 128 129Even better are the ``report`` and ``report.format`` targets (where 130``format`` is one of ``html``, ``csv``, ``text`` or ``graphs``). The 131exact contents of the report are dependent on which ``TEST`` you are 132running, but the text results are always shown at the end of the run and 133the results are always stored in the ``report.<type>.format`` file (when 134running with ``TEST=<type>``). The ``report`` also generate a file 135called ``report.<type>.raw.out`` containing the output of the entire 136test run. 137 138Writing Custom Tests for the test-suite 139======================================= 140 141Assuming you can run the test suite, (e.g. 142"``gmake TEST=nightly report``" should work), it is really easy to run 143optimizations or code generator components against every program in the 144tree, collecting statistics or running custom checks for correctness. At 145base, this is how the nightly tester works, it's just one example of a 146general framework. 147 148Lets say that you have an LLVM optimization pass, and you want to see 149how many times it triggers. First thing you should do is add an LLVM 150`statistic <ProgrammersManual.html#Statistic>`_ to your pass, which will 151tally counts of things you care about. 152 153Following this, you can set up a test and a report that collects these 154and formats them for easy viewing. This consists of two files, a 155"``test-suite/TEST.XXX.Makefile``" fragment (where XXX is the name of 156your test) and a "``test-suite/TEST.XXX.report``" file that indicates 157how to format the output into a table. There are many example reports of 158various levels of sophistication included with the test suite, and the 159framework is very general. 160 161If you are interested in testing an optimization pass, check out the 162"libcalls" test as an example. It can be run like this: 163 164.. code-block:: bash 165 166 % cd llvm/projects/test-suite/MultiSource/Benchmarks # or some other level 167 % make TEST=libcalls report 168 169This will do a bunch of stuff, then eventually print a table like this: 170 171:: 172 173 Name | total | #exit | 174 ... 175 FreeBench/analyzer/analyzer | 51 | 6 | 176 FreeBench/fourinarow/fourinarow | 1 | 1 | 177 FreeBench/neural/neural | 19 | 9 | 178 FreeBench/pifft/pifft | 5 | 3 | 179 MallocBench/cfrac/cfrac | 1 | * | 180 MallocBench/espresso/espresso | 52 | 12 | 181 MallocBench/gs/gs | 4 | * | 182 Prolangs-C/TimberWolfMC/timberwolfmc | 302 | * | 183 Prolangs-C/agrep/agrep | 33 | 12 | 184 Prolangs-C/allroots/allroots | * | * | 185 Prolangs-C/assembler/assembler | 47 | * | 186 Prolangs-C/bison/mybison | 74 | * | 187 ... 188 189This basically is grepping the -stats output and displaying it in a 190table. You can also use the "TEST=libcalls report.html" target to get 191the table in HTML form, similarly for report.csv and report.tex. 192 193The source for this is in ``test-suite/TEST.libcalls.*``. The format is 194pretty simple: the Makefile indicates how to run the test (in this case, 195"``opt -simplify-libcalls -stats``"), and the report contains one line 196for each column of the output. The first value is the header for the 197column and the second is the regex to grep the output of the command 198for. There are lots of example reports that can do fancy stuff. 199