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