summaryrefslogtreecommitdiff
path: root/test/README
blob: 4b1f93df3e86de03a882e72078a9abf34369f3b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
Regression test suite for cairo.

How to use cairo's test suite
=============================
Using this test should be as simple as running:

	make test

assuming that the cairo distribution in the directory above has been
configured and built. The test suite here goes through some effort to
run against the locally compiled library rather than any installed
version, but those efforts may fall short depending on the level of your
libtool madness.

The results of the test suite run are summarized in an index.html
file, which, when viewed in a web browser makes it quite easy to
visually see any failed renderings alongside the corresponding
reference image, (and a diff image as well).

The test suite needs to be run before any code is committed and before
any release. See below for hints and rules governing the use of the suite:

Tailoring tests running
-----------------------
There are some mechanisms to limit the tests run during "make test".
These come very handy when doing development, but should not be used
to circumvent the "pass" requirements listed below.

To limit the backends that the tests are run against, use the
TARGETS make variable, that can also be passed to make.
It should contain a (space-, comma-, etc-separated) list of backends to test.
To limit the tests run, use the TESTS make variable, which should be a
space-separated list of tests to run.  For example:

  make test TARGETS=image,ps TESTS="zero-alpha"

Another very handy mechanism when trying to fix bugs is:

  make retest

This will re-run the test suite, but only on tests that failed on the
last run. So this is a much faster way of checking if changes actually
fix bugs rather than running the entire test suite again.

The test suite first compares the output from the current run against the
previous in order to skip more expensive image comparisons . If you think
this is interfering with the results, you can clear the cached results using:

  make clean-caches

Running tests under modified enviroments or tools
-------------------------------------------------
To run tests under a tool like gdb, one can use the run target and
the TOOL variable.  For example:

  make run TOOL=gdb TARGETS=pdf TESTS=user-font

If you want to run under valgrind, there is a specific target for that
that also sets a bunch of useful valgrind options.  Try:

  make check-valgrind TESTS=user-font

You can run tests under a modified environment you can use the ENV
make variable.  However, that environment will also affect the libtool
wrapper of the tests.  To only affect the actual test binaries, pass
such environment as TOOL:

  make run TOOL="LD_PRELOAD=/path/to/something.so" TEST=user-font

Getting the elusive zero failures
---------------------------------
It's generally been very difficult to achieve a test run with zero
failures. The difficulties stem from the various versions of the many
libraries that the test suite depends on, (it depends on a lot more
than cairo itself), as well as fonts and other system-specific
settings. If your system differs significantly from the system on
which the reference images were generated, then you will likely see
the test suite reporting "failures", (even if cairo is working just
fine).

We are constantly working to reduce the number of variables that need
to be tweaked to get a clean run, (for example, by bundling fonts with
the test suite itself), and also working to more carefully document
the software configuration used to generate the reference images.

Here are some of the relevant details:

  * Your system must have a copy of the Bitstream Vera font. These are
      "Bitstream Vera Sans" (Vera.ttf);
      "Bitstream Vera Sans Mono" (VeraMono.ttf);
      "Bitstream Vera Serif" (VeraSe.ttf);
    and also
      "Nimbus Sans L" (n019003l.pfb).

  * Currently, you must be using a build of cairo using freetype
    (cairo-ft) as the default font backend. Otherwise all tests
    involving text are likely to fail.

  * To test the pdf backend, you will want the very latest version of
    poppler as made available via git:

	git clone git://anongit.freedesktop.org/git/poppler/poppler

    As of this writing, no released version of poppler contains all
    the fixes you will need to avoid false negatives from the test
    suite.

  * To test the ps backend, you will need ghostscript version 8.62.


What if I can't make my system match?
-------------------------------------
For one reason or another, you may be unable to get a clean run of the
test suite even if cairo is working properly, (for example, you might
be on a system without freetype). In this case, it's still useful to
be able to determine if code changes you make to cairo result in any
regressions to the test suite. But it's hard to notice regressions if
there are many failures both before and after your changes.

For this scenario, you can capture the output of a run of the test
suite before your changes, and then use the CAIRO_REF_DIR environment
variable to use that output as the reference images for a run after
your changes. The process looks like this:

        # Before code change there may be failures we don't care about
        make test

        # Let's save those output images
        mkdir /some/directory/
        cp test/*-out.png /some/directory/

        # hack, hack, hack

        # Now to see if nothing changed:
        CAIRO_REF_DIR=/some/directory/ make test

Best practices for cairo developers
===================================
If we all follow the guidelines below, then both the test suite and
cairo itself will stay much healthier, and we'll all have a lot more
fun hacking on cairo.

Before committing
-----------------
All tests should return a result of PASS or XFAIL. The XFAIL results
indicate known bugs. The final message should be one of the following:

	All XX tests behaved as expected (YY expected failures)
	All XX tests passed

If any tests have a status of FAIL, then the new code has caused a
regression error which should be fixed before the code is committed.

When a new bug is found
-----------------------
A new test case should be added by imitating the style of an existing
test. This means adding the following files:

	new-bug.c
	new-bug-ref.png

Where new-bug.c is a minimal program to demonstrate the bug, following
the style of existing tests. The new-bug-ref.png image should contain
the desired result of new-bug.c if the bug were fixed.

Makefile.am should be edited, adding new-bug.c to both the TESTS and
XFAIL_TESTS lists and new-bug-ref.png to EXTRA_DIST. Add new-bug to
.gitignore, and last but not least, don't forget to "git add" the new
files.

When a new feature is added
---------------------------
It's important for the regression suite to keep pace with development
of the library. So a new test should be added for each new feature.
The work involved is similar the work described above for new bugs.
The only distinction is that the test is expected to pass so it
should not be added to the XFAIL_TESTS list.

While working on a test
-----------------------
Before a bugfix or feature is ready, it may be useful to compare
output from different builds. For convenience, you can set
CAIRO_REF_DIR to point at a previous test directory, relative
to the current test directory, and any previous output will be
used by preference as reference images.

When a bug is fixed
-------------------
The fix should be verified by running the test suite which should
result in an "unexpected pass" for the test of interest. Rejoice as
appropriate, then remove the relevant file name from the XFAIL_TESTS
variable in Makefile.am.

Before releasing
----------------
All tests should return a result of PASS for all supported (those enabled by
default) backends,  meaning all known bugs are fixed, resulting in the happy
message:

	All XX tests passed

Some notes on limitations in poppler
====================================
One of the difficulties of our current test infrastructure is that we
rely on external tools to convert cairo's vector output (PDF,
PostScript, and SVG), into an image that can be used for the image
comparison. This means that any bugs in that conversion tool will
result in false negatives in the test suite.

We've identified several such bugs in the poppler library which is
used to convert PDF to an image. This is particularly discouraging
because 1) poppler is free software that will be used by *many* cairo
users, and 2) poppler calls into cairo for its rendering so it should
be able to do a 100% faithful conversion.

So we have an interest in ensuring that these poppler bugs get fixed
sooner rather than later. As such, we're trying to be good citizens by
reporting all such poppler bugs that we identify to the poppler
bugzilla. Here's a tracking bug explaining the situation:

	Poppler does not yet handle everything in the cairo test suite
	https://bugs.freedesktop.org/show_bug.cgi?id=12143

Here's the rule: If a cairo-pdf test reports a failure, but viewing
the resulting PDF file with acroread suggests that the PDF itself is
correct, then there's likely a bug in poppler. In this case, we can
simply report the poppler bug, (making it block 12143 above), post the
PDF result from the test suite, and list the bug in this file. Once
we've done this, we can capture poppler's buggy output as a
pdf-specific reference image so that the test suite will regard the
test as passing, (and we'll ensure there is no regression).

Once the poppler bug gets fixed, the test suite will start reporting a
false negative again, and this will be easy to fix by simply removing
the pdf-specific reference image.

Here are the reported poppler bugs and the tests they affect:

Poppler doesn't correctly handle gradients with transparency
https://bugs.freedesktop.org/show_bug.cgi?id=12144
--------------------------------------------------
fill-alpha-pattern
gradient-alpha
gradient-constant-alpha
linear-gradient
trap-clip
linear-gradient
linear-gradient-reflect
radial-gradient

Poppler renders patterned text as black
https://bugs.freedesktop.org/show_bug.cgi?id=14577
--------------------------------------------------
text-pattern
text-transform

Poppler should paint images with CAIRO_EXTEND_PAD
https://bugs.freedesktop.org/show_bug.cgi?id=14578
--------------------------------------------------
paint-source-alpha
paint-with-alpha
rotate-image-surface-paint
scale-source-surface-paint

Incorrect clipping of group object (regression?)
https://bugs.freedesktop.org/show_bug.cgi?id=14580
--------------------------------------------------
push-group

Ghostscript does not correctly render small miters
http://bugs.ghostscript.com/show_bug.cgi?id=690098
--------------------------------------------------
miter-precision