4 <title id=
"regress-title">Regression Tests
</title>
6 <indexterm zone=
"regress">
7 <primary>regression tests
</primary>
10 <indexterm zone=
"regress">
11 <primary>test
</primary>
15 The regression tests are a comprehensive set of tests for the SQL
16 implementation in
<productname>PostgreSQL
</productname>. They test
17 standard SQL operations as well as the extended capabilities of
18 <productname>PostgreSQL
</productname>.
21 <sect1 id=
"regress-run">
22 <title>Running the Tests
</title>
25 The regression tests can be run against an already installed and
26 running server, or using a temporary installation within the build
27 tree. Furthermore, there is a
<quote>parallel
</quote> and a
28 <quote>sequential
</quote> mode for running the tests. The
29 sequential method runs each test script in turn, whereas the
30 parallel method starts up multiple server processes to run groups
31 of tests in parallel. Parallel testing gives confidence that
32 interprocess communication and locking are working correctly. For
33 historical reasons, the sequential test is usually run against an
34 existing installation and the parallel method against a temporary
35 installation, but there are no technical reasons for this.
39 To run the regression tests after building but before installation,
44 in the top-level directory. (Or you can change to
45 <filename>src/test/regress
</filename> and run the command there.)
46 This will first build several auxiliary files, such as
47 some sample user-defined trigger functions, and then run the test driver
48 script. At the end you should see something like
51 =======================
53 =======================
56 or otherwise a note about which tests failed. See
<xref
57 linkend=
"regress-evaluation"> below before assuming that a
58 <quote>failure<
/> represents a serious problem.
62 Because this test method runs a temporary server, it will not work
63 when you are the root user (since the server will not start as root).
64 If you already did the build as root, you do not have to start all
65 over. Instead, make the regression test directory writable by
66 some other user, log in as that user, and restart the tests.
69 <prompt>root#
</prompt><userinput>chmod -R a+w src/test/regress
</userinput>
70 <prompt>root#
</prompt><userinput>su - joeuser
</userinput>
71 <prompt>joeuser$
</prompt><userinput>cd
<replaceable>top-level build directory<
/></userinput>
72 <prompt>joeuser$
</prompt><userinput>gmake check
</userinput>
74 (The only possible
<quote>security risk
</quote> here is that other
75 users might be able to alter the regression test results behind
76 your back. Use common sense when managing user permissions.)
79 Alternatively, run the tests after installation.
83 If you have configured
<productname>PostgreSQL
</productname> to install
84 into a location where an older
<productname>PostgreSQL
</productname>
85 installation already exists, and you perform
<literal>gmake check<
/>
86 before installing the new version, you might find that the tests fail
87 because the new programs try to use the already-installed shared
88 libraries. (Typical symptoms are complaints about undefined symbols.)
89 If you wish to run the tests before overwriting the old installation,
90 you'll need to build with
<literal>configure --disable-rpath<
/>.
91 It is not recommended that you use this option for the final installation,
96 The parallel regression test starts quite a few processes under your
97 user ID. Presently, the maximum concurrency is twenty parallel test
98 scripts, which means forty processes: there's a server process and a
99 <application>psql<
/> process for each test script.
100 So if your system enforces a per-user limit on the number of processes,
101 make sure this limit is at least fifty or so, else you might get
102 random-seeming failures in the parallel test. If you are not in
103 a position to raise the limit, you can cut down the degree of parallelism
104 by setting the
<literal>MAX_CONNECTIONS<
/> parameter. For example,
106 gmake MAX_CONNECTIONS=
10 check
108 runs no more than ten tests concurrently.
112 To run the tests after installation<![%standalone-ignore;[ (see
<xref linkend=
"installation">)]]
>,
113 initialize a data area and start the
114 server, <![%standalone-ignore;[as explained in
<xref linkend=
"runtime">, ]]
> then type
118 or for a parallel test
120 gmake installcheck-parallel
122 The tests will expect to contact the server at the local host and the
123 default port number, unless directed otherwise by
<envar>PGHOST
</envar> and
124 <envar>PGPORT
</envar> environment variables.
128 The source distribution also contains regression tests for the optional
129 procedural languages and for some of the
<filename>contrib<
/> modules.
130 At present, these tests can be used only against an already-installed
131 server. To run the tests for all procedural languages that have been
132 built and installed, change to the
<filename>src/pl<
/> directory of the
137 You can also do this in any of the subdirectories of
<filename>src/pl<
/>
138 to run tests for just one procedural language. To run the tests for all
139 <filename>contrib<
/> modules that have them, change to the
140 <filename>contrib<
/> directory of the build tree and type
144 The
<filename>contrib<
/> modules must have been built and installed first.
145 You can also do this in a subdirectory of
<filename>contrib<
/> to run
146 the tests for just one module.
150 <sect1 id=
"regress-evaluation">
151 <title>Test Evaluation
</title>
154 Some properly installed and fully functional
155 <productname>PostgreSQL
</productname> installations can
156 <quote>fail
</quote> some of these regression tests due to
157 platform-specific artifacts such as varying floating-point representation
158 and message wording. The tests are currently evaluated using a simple
159 <command>diff
</command> comparison against the outputs
160 generated on a reference system, so the results are sensitive to
161 small system differences. When a test is reported as
162 <quote>failed
</quote>, always examine the differences between
163 expected and actual results; you might find that the
164 differences are not significant. Nonetheless, we still strive to
165 maintain accurate reference files across all supported platforms,
166 so it can be expected that all tests pass.
170 The actual outputs of the regression tests are in files in the
171 <filename>src/test/regress/results
</filename> directory. The test
172 script uses
<command>diff
</command> to compare each output
173 file against the reference outputs stored in the
174 <filename>src/test/regress/expected
</filename> directory. Any
175 differences are saved for your inspection in
176 <filename>src/test/regress/regression.diffs
</filename>. (Or you
177 can run
<command>diff
</command> yourself, if you prefer.)
181 If for some reason a particular platform generates a
<quote>failure<
/>
182 for a given test, but inspection of the output convinces you that
183 the result is valid, you can add a new comparison file to silence
184 the failure report in future test runs. See
185 <xref linkend=
"regress-variant"> for details.
189 <title>Error message differences
</title>
192 Some of the regression tests involve intentional invalid input
193 values. Error messages can come from either the
194 <productname>PostgreSQL
</productname> code or from the host
195 platform system routines. In the latter case, the messages can
196 vary between platforms, but should reflect similar
197 information. These differences in messages will result in a
198 <quote>failed
</quote> regression test that can be validated by
204 <title>Locale differences
</title>
207 If you run the tests against an already-installed server that was
208 initialized with a collation-order locale other than C, then
209 there might be differences due to sort order and follow-up
210 failures. The regression test suite is set up to handle this
211 problem by providing alternative result files that together are
212 known to handle a large number of locales.
217 <title>Date and time differences
</title>
220 Most of the date and time results are dependent on the time zone
221 environment. The reference files are generated for time zone
222 <literal>PST8PDT
</literal> (Berkeley, California), and there will be
223 apparent failures if the tests are not run with that time zone setting.
224 The regression test driver sets environment variable
225 <envar>PGTZ
</envar> to
<literal>PST8PDT
</literal>, which normally
226 ensures proper results.
231 <title>Floating-point differences
</title>
234 Some of the tests involve computing
64-bit floating-point numbers (
<type>double
235 precision
</type>) from table columns. Differences in
236 results involving mathematical functions of
<type>double
237 precision
</type> columns have been observed. The
<literal>float8<
/> and
238 <literal>geometry<
/> tests are particularly prone to small differences
239 across platforms, or even with different compiler optimization options.
240 Human eyeball comparison is needed to determine the real
241 significance of these differences which are usually
10 places to
242 the right of the decimal point.
246 Some systems display minus zero as
<literal>-
0<
/>, while others
247 just show
<literal>0<
/>.
251 Some systems signal errors from
<function>pow()
</function> and
252 <function>exp()
</function> differently from the mechanism
253 expected by the current
<productname>PostgreSQL
</productname>
259 <title>Row ordering differences
</title>
262 You might see differences in which the same rows are output in a
263 different order than what appears in the expected file. In most cases
264 this is not, strictly speaking, a bug. Most of the regression test
265 scripts are not so pedantic as to use an
<literal>ORDER BY<
/> for every single
266 <literal>SELECT<
/>, and so their result row orderings are not well-defined
267 according to the letter of the SQL specification. In practice, since we are
268 looking at the same queries being executed on the same data by the same
269 software, we usually get the same result ordering on all platforms, and
270 so the lack of
<literal>ORDER BY<
/> isn't a problem. Some queries do exhibit
271 cross-platform ordering differences, however. When testing against an
272 already-installed server, ordering differences can also be caused by
273 non-C locale settings or non-default parameter settings, such as custom values
274 of
<varname>work_mem<
/> or the planner cost parameters.
278 Therefore, if you see an ordering difference, it's not something to
279 worry about, unless the query does have an
<literal>ORDER BY<
/> that your
280 result is violating. But please report it anyway, so that we can add an
281 <literal>ORDER BY<
/> to that particular query and thereby eliminate the bogus
282 <quote>failure
</quote> in future releases.
286 You might wonder why we don't order all the regression test queries explicitly
287 to get rid of this issue once and for all. The reason is that that would
288 make the regression tests less useful, not more, since they'd tend
289 to exercise query plan types that produce ordered results to the
290 exclusion of those that don't.
295 <title>Insufficient stack depth
</title>
298 If the
<literal>errors
</literal> test results in a server crash
299 at the
<literal>select infinite_recurse()<
/> command, it means that
300 the platform's limit on process stack size is smaller than the
301 <![%standalone-ignore;[
<xref linkend=
"guc-max-stack-depth">]]
>
302 <![%standalone-include;[
<literal>max_stack_depth
</literal>]]
>
303 parameter indicates. This
304 can be fixed by running the server under a higher stack
305 size limit (
4MB is recommended with the default value of
306 <varname>max_stack_depth<
/>). If you are unable to do that, an
307 alternative is to reduce the value of
<varname>max_stack_depth<
/>.
312 <title>The
<quote>random
</quote> test
</title>
315 The
<literal>random
</literal> test script is intended to produce
316 random results. In rare cases, this causes the random regression
317 test to fail. Typing:
319 diff results/random.out expected/random.out
321 should produce only one or a few lines of differences. You need
322 not worry unless the random test fails repeatedly.
327 <!-- We might want to move the following section into the developer's guide. -->
328 <sect1 id=
"regress-variant">
329 <title>Variant Comparison Files
</title>
332 Since some of the tests inherently produce environment-dependent
333 results, we have provided ways to specify alternative
<quote>expected<
/>
334 result files. Each regression test can have several comparison files
335 showing possible results on different platforms. There are two
336 independent mechanisms for determining which comparison file is used
341 The first mechanism allows comparison files to be selected for
342 specific platforms. There is a mapping file,
343 <filename>src/test/regress/resultmap
</filename>, that defines
344 which comparison file to use for each platform.
345 To eliminate bogus test
<quote>failures
</quote> for a particular platform,
346 you first choose or make a variant result file, and then add a line to the
347 <filename>resultmap
</filename> file.
351 Each line in the mapping file is of the form
353 testname:output:platformpattern=comparisonfilename
355 The test name is just the name of the particular regression test
356 module. The output value indicates which output file to check. For the
357 standard regression tests, this is always
<literal>out
</literal>. The
358 value corresponds to the file extension of the output file.
359 The platform pattern is a pattern in the style of the Unix
360 tool
<command>expr<
/> (that is, a regular expression with an implicit
361 <literal>^
</literal> anchor at the start). It is matched against the
362 platform name as printed by
<command>config.guess
</command>.
363 The comparison file name is the base name of the substitute result
368 For example: some systems interpret very small floating-point values
369 as zero, rather than reporting an underflow error. This causes a
370 few differences in the
<filename>float8<
/> regression test.
371 Therefore, we provide a variant comparison file,
372 <filename>float8-small-is-zero.out
</filename>, which includes
373 the results to be expected on these systems. To silence the bogus
374 <quote>failure
</quote> message on
<systemitem>OpenBSD
</systemitem>
375 platforms,
<filename>resultmap
</filename> includes:
377 float8:out:i
.86-.*-openbsd=float8-small-is-zero.out
379 which will trigger on any machine for which the output of
380 <command>config.guess
</command> matches
<literal>i
.86-.*-openbsd
</literal>.
382 in
<filename>resultmap<
/> select the variant comparison file for other
383 platforms where it's appropriate.
387 The second selection mechanism for variant comparison files is
388 much more automatic: it simply uses the
<quote>best match<
/> among
389 several supplied comparison files. The regression test driver
390 script considers both the standard comparison file for a test,
391 <literal><replaceable>testname<
/>.out<
/>, and variant files named
392 <literal><replaceable>testname<
/>_
<replaceable>digit<
/>.out<
/>
393 (where the
<replaceable>digit<
/> is any single digit
394 <literal>0<
/>-
<literal>9<
/>). If any such file is an exact match,
395 the test is considered to pass; otherwise, the one that generates
396 the shortest diff is used to create the failure report. (If
397 <filename>resultmap
</filename> includes an entry for the particular
398 test, then the base
<replaceable>testname<
/> is the substitute
399 name given in
<filename>resultmap
</filename>.)
403 For example, for the
<literal>char
</literal> test, the comparison file
404 <filename>char.out
</filename> contains results that are expected
405 in the
<literal>C<
/> and
<literal>POSIX<
/> locales, while
406 the file
<filename>char_1.out
</filename> contains results sorted as
407 they appear in many other locales.
411 The best-match mechanism was devised to cope with locale-dependent
412 results, but it can be used in any situation where the test results
413 cannot be predicted easily from the platform name alone. A limitation of
414 this mechanism is that the test driver cannot tell which variant is
415 actually
<quote>correct<
/> for the current environment; it will just pick
416 the variant that seems to work best. Therefore it is safest to use this
417 mechanism only for variant results that you are willing to consider
418 equally valid in all contexts.
423 <sect1 id=
"regress-coverage">
424 <title>Test Coverage Examination
</title>
427 The PostgreSQL source code can be compiled with coverage testing
428 instrumentation, so that it becomes possible to examine which
429 parts of the code are covered by the regression tests or any other
430 test suite that is run with the code. This is currently supported
431 when compiling with GCC and requires the
<command>gcov
</command>
432 and
<command>lcov
</command> programs.
436 A typical workflow would look like this:
438 ./configure --enable-coverage ... OTHER OPTIONS ...
440 gmake check # or other test suite
443 Then point your HTML browser
444 to
<filename>coverage/index.html
</filename>.
448 To reset the execution counts between test runs, run