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 a 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.
216 To run the tests in a different locale when using the
217 temporary-installation method, pass the appropriate
218 locale-related environment variables on
219 the
<command>make
</command> command line, for example:
221 gmake check LANG=de_DE.utf8
223 (The regression test driver unsets
<envar>LC_ALL
</envar>, so it
224 does not work to choose the locale using that variable.) To use
225 no locale, either unset all locale-related environment variables
226 (or set them to
<literal>C
</literal>) or use the following
229 gmake check NO_LOCALE=
1
231 When running the tests against an existing installation, the
232 locale setup is determined by the existing installation. To
233 change it, initialize the database cluster with a different
234 locale by passing the appropriate options
235 to
<command>initdb
</command>.
239 In general, it is nevertheless advisable to try to run the
240 regression tests in the locale setup that is wanted for
241 production use, as this will exercise the locale- and
242 encoding-related code portions that will actually be used in
243 production. Depending on the operating system environment, you
244 might get failures, but then you will at least know what
245 locale-specific behaviors to expect when running real
251 <title>Date and time differences
</title>
254 Most of the date and time results are dependent on the time zone
255 environment. The reference files are generated for time zone
256 <literal>PST8PDT
</literal> (Berkeley, California), and there will be
257 apparent failures if the tests are not run with that time zone setting.
258 The regression test driver sets environment variable
259 <envar>PGTZ
</envar> to
<literal>PST8PDT
</literal>, which normally
260 ensures proper results.
265 <title>Floating-point differences
</title>
268 Some of the tests involve computing
64-bit floating-point numbers (
<type>double
269 precision
</type>) from table columns. Differences in
270 results involving mathematical functions of
<type>double
271 precision
</type> columns have been observed. The
<literal>float8<
/> and
272 <literal>geometry<
/> tests are particularly prone to small differences
273 across platforms, or even with different compiler optimization options.
274 Human eyeball comparison is needed to determine the real
275 significance of these differences which are usually
10 places to
276 the right of the decimal point.
280 Some systems display minus zero as
<literal>-
0<
/>, while others
281 just show
<literal>0<
/>.
285 Some systems signal errors from
<function>pow()
</function> and
286 <function>exp()
</function> differently from the mechanism
287 expected by the current
<productname>PostgreSQL
</productname>
293 <title>Row ordering differences
</title>
296 You might see differences in which the same rows are output in a
297 different order than what appears in the expected file. In most cases
298 this is not, strictly speaking, a bug. Most of the regression test
299 scripts are not so pedantic as to use an
<literal>ORDER BY<
/> for every single
300 <literal>SELECT<
/>, and so their result row orderings are not well-defined
301 according to the letter of the SQL specification. In practice, since we are
302 looking at the same queries being executed on the same data by the same
303 software, we usually get the same result ordering on all platforms, and
304 so the lack of
<literal>ORDER BY<
/> isn't a problem. Some queries do exhibit
305 cross-platform ordering differences, however. When testing against an
306 already-installed server, ordering differences can also be caused by
307 non-C locale settings or non-default parameter settings, such as custom values
308 of
<varname>work_mem<
/> or the planner cost parameters.
312 Therefore, if you see an ordering difference, it's not something to
313 worry about, unless the query does have an
<literal>ORDER BY<
/> that your
314 result is violating. But please report it anyway, so that we can add an
315 <literal>ORDER BY<
/> to that particular query and thereby eliminate the bogus
316 <quote>failure
</quote> in future releases.
320 You might wonder why we don't order all the regression test queries explicitly
321 to get rid of this issue once and for all. The reason is that that would
322 make the regression tests less useful, not more, since they'd tend
323 to exercise query plan types that produce ordered results to the
324 exclusion of those that don't.
329 <title>Insufficient stack depth
</title>
332 If the
<literal>errors
</literal> test results in a server crash
333 at the
<literal>select infinite_recurse()<
/> command, it means that
334 the platform's limit on process stack size is smaller than the
335 <![%standalone-ignore;[
<xref linkend=
"guc-max-stack-depth">]]
>
336 <![%standalone-include;[
<literal>max_stack_depth
</literal>]]
>
337 parameter indicates. This
338 can be fixed by running the server under a higher stack
339 size limit (
4MB is recommended with the default value of
340 <varname>max_stack_depth<
/>). If you are unable to do that, an
341 alternative is to reduce the value of
<varname>max_stack_depth<
/>.
346 <title>The
<quote>random
</quote> test
</title>
349 The
<literal>random
</literal> test script is intended to produce
350 random results. In rare cases, this causes the random regression
351 test to fail. Typing:
353 diff results/random.out expected/random.out
355 should produce only one or a few lines of differences. You need
356 not worry unless the random test fails repeatedly.
361 <!-- We might want to move the following section into the developer's guide. -->
362 <sect1 id=
"regress-variant">
363 <title>Variant Comparison Files
</title>
366 Since some of the tests inherently produce environment-dependent
367 results, we have provided ways to specify alternative
<quote>expected<
/>
368 result files. Each regression test can have several comparison files
369 showing possible results on different platforms. There are two
370 independent mechanisms for determining which comparison file is used
375 The first mechanism allows comparison files to be selected for
376 specific platforms. There is a mapping file,
377 <filename>src/test/regress/resultmap
</filename>, that defines
378 which comparison file to use for each platform.
379 To eliminate bogus test
<quote>failures
</quote> for a particular platform,
380 you first choose or make a variant result file, and then add a line to the
381 <filename>resultmap
</filename> file.
385 Each line in the mapping file is of the form
387 testname:output:platformpattern=comparisonfilename
389 The test name is just the name of the particular regression test
390 module. The output value indicates which output file to check. For the
391 standard regression tests, this is always
<literal>out
</literal>. The
392 value corresponds to the file extension of the output file.
393 The platform pattern is a pattern in the style of the Unix
394 tool
<command>expr<
/> (that is, a regular expression with an implicit
395 <literal>^
</literal> anchor at the start). It is matched against the
396 platform name as printed by
<command>config.guess
</command>.
397 The comparison file name is the base name of the substitute result
402 For example: some systems interpret very small floating-point values
403 as zero, rather than reporting an underflow error. This causes a
404 few differences in the
<filename>float8<
/> regression test.
405 Therefore, we provide a variant comparison file,
406 <filename>float8-small-is-zero.out
</filename>, which includes
407 the results to be expected on these systems. To silence the bogus
408 <quote>failure
</quote> message on
<systemitem>OpenBSD
</systemitem>
409 platforms,
<filename>resultmap
</filename> includes:
411 float8:out:i
.86-.*-openbsd=float8-small-is-zero.out
413 which will trigger on any machine for which the output of
414 <command>config.guess
</command> matches
<literal>i
.86-.*-openbsd
</literal>.
416 in
<filename>resultmap<
/> select the variant comparison file for other
417 platforms where it's appropriate.
421 The second selection mechanism for variant comparison files is
422 much more automatic: it simply uses the
<quote>best match<
/> among
423 several supplied comparison files. The regression test driver
424 script considers both the standard comparison file for a test,
425 <literal><replaceable>testname<
/>.out<
/>, and variant files named
426 <literal><replaceable>testname<
/>_
<replaceable>digit<
/>.out<
/>
427 (where the
<replaceable>digit<
/> is any single digit
428 <literal>0<
/>-
<literal>9<
/>). If any such file is an exact match,
429 the test is considered to pass; otherwise, the one that generates
430 the shortest diff is used to create the failure report. (If
431 <filename>resultmap
</filename> includes an entry for the particular
432 test, then the base
<replaceable>testname<
/> is the substitute
433 name given in
<filename>resultmap
</filename>.)
437 For example, for the
<literal>char
</literal> test, the comparison file
438 <filename>char.out
</filename> contains results that are expected
439 in the
<literal>C<
/> and
<literal>POSIX<
/> locales, while
440 the file
<filename>char_1.out
</filename> contains results sorted as
441 they appear in many other locales.
445 The best-match mechanism was devised to cope with locale-dependent
446 results, but it can be used in any situation where the test results
447 cannot be predicted easily from the platform name alone. A limitation of
448 this mechanism is that the test driver cannot tell which variant is
449 actually
<quote>correct<
/> for the current environment; it will just pick
450 the variant that seems to work best. Therefore it is safest to use this
451 mechanism only for variant results that you are willing to consider
452 equally valid in all contexts.
457 <sect1 id=
"regress-coverage">
458 <title>Test Coverage Examination
</title>
461 The PostgreSQL source code can be compiled with coverage testing
462 instrumentation, so that it becomes possible to examine which
463 parts of the code are covered by the regression tests or any other
464 test suite that is run with the code. This is currently supported
465 when compiling with GCC and requires the
<command>gcov
</command>
466 and
<command>lcov
</command> programs.
470 A typical workflow would look like this:
472 ./configure --enable-coverage ... OTHER OPTIONS ...
474 gmake check # or other test suite
477 Then point your HTML browser
478 to
<filename>coverage/index.html
</filename>.
482 To reset the execution counts between test runs, run: