1<!-- doc/src/sgml/regress.sgml -->
2
3 <chapter id="regress">
4  <title>Regression Tests</title>
5
6  <indexterm zone="regress">
7   <primary>regression tests</primary>
8  </indexterm>
9
10  <indexterm zone="regress">
11   <primary>test</primary>
12  </indexterm>
13
14  <para>
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>.
19  </para>
20
21  <sect1 id="regress-run">
22   <title>Running the Tests</title>
23
24  <para>
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 alone, while the
30   parallel method starts up multiple server processes to run groups
31   of tests in parallel.  Parallel testing adds confidence that
32   interprocess communication and locking are working correctly.
33  </para>
34
35  <sect2>
36   <title>Running the Tests Against a Temporary Installation</title>
37
38  <para>
39   To run the parallel regression tests after building but before installation,
40   type:
41<screen>
42make check
43</screen>
44   in the top-level directory.  (Or you can change to
45   <filename>src/test/regress</filename> and run the command there.)
46   At the end you should see something like:
47<screen>
48<computeroutput>
49=======================
50 All 193 tests passed.
51=======================
52</computeroutput>
53</screen>
54   or otherwise a note about which tests failed.  See <xref
55   linkend="regress-evaluation"/> below before assuming that a
56   <quote>failure</quote> represents a serious problem.
57  </para>
58
59   <para>
60    Because this test method runs a temporary server, it will not work
61    if you did the build as the root user, since the server will not start as
62    root.  Recommended procedure is not to do the build as root, or else to
63    perform testing after completing the installation.
64   </para>
65
66   <para>
67    If you have configured <productname>PostgreSQL</productname> to install
68    into a location where an older <productname>PostgreSQL</productname>
69    installation already exists, and you perform <literal>make check</literal>
70    before installing the new version, you might find that the tests fail
71    because the new programs try to use the already-installed shared
72    libraries.  (Typical symptoms are complaints about undefined symbols.)
73    If you wish to run the tests before overwriting the old installation,
74    you'll need to build with <literal>configure --disable-rpath</literal>.
75    It is not recommended that you use this option for the final installation,
76    however.
77   </para>
78
79   <para>
80    The parallel regression test starts quite a few processes under your
81    user ID.  Presently, the maximum concurrency is twenty parallel test
82    scripts, which means forty processes: there's a server process and a
83    <application>psql</application> process for each test script.
84    So if your system enforces a per-user limit on the number of processes,
85    make sure this limit is at least fifty or so, else you might get
86    random-seeming failures in the parallel test.  If you are not in
87    a position to raise the limit, you can cut down the degree of parallelism
88    by setting the <literal>MAX_CONNECTIONS</literal> parameter.  For example:
89<screen>
90make MAX_CONNECTIONS=10 check
91</screen>
92    runs no more than ten tests concurrently.
93   </para>
94  </sect2>
95
96  <sect2>
97   <title>Running the Tests Against an Existing Installation</title>
98
99  <para>
100   To run the tests after installation (see <xref linkend="installation"/>),
101   initialize a data directory and start the
102   server as explained in <xref linkend="runtime"/>, then type:
103<screen>
104make installcheck
105</screen>
106or for a parallel test:
107<screen>
108make installcheck-parallel
109</screen>
110   The tests will expect to contact the server at the local host and the
111   default port number, unless directed otherwise by <envar>PGHOST</envar> and
112   <envar>PGPORT</envar> environment variables.  The tests will be run in a
113   database named <literal>regression</literal>; any existing database by this name
114   will be dropped.
115  </para>
116
117  <para>
118   The tests will also transiently create some cluster-wide objects, such as
119   roles, tablespaces, and subscriptions.  These objects will have names
120   beginning with <literal>regress_</literal>.  Beware of
121   using <literal>installcheck</literal> mode with an installation that has
122   any actual global objects named that way.
123  </para>
124  </sect2>
125
126  <sect2>
127   <title>Additional Test Suites</title>
128
129  <para>
130   The <literal>make check</literal> and <literal>make installcheck</literal> commands
131   run only the <quote>core</quote> regression tests, which test built-in
132   functionality of the <productname>PostgreSQL</productname> server.  The source
133   distribution contains many additional test suites, most of them having
134   to do with add-on functionality such as optional procedural languages.
135  </para>
136
137  <para>
138   To run all test suites applicable to the modules that have been selected
139   to be built, including the core tests, type one of these commands at the
140   top of the build tree:
141<screen>
142make check-world
143make installcheck-world
144</screen>
145   These commands run the tests using temporary servers or an
146   already-installed server, respectively, just as previously explained
147   for <literal>make check</literal> and <literal>make installcheck</literal>.  Other
148   considerations are the same as previously explained for each method.
149   Note that <literal>make check-world</literal> builds a separate instance
150   (temporary data directory) for each tested module, so it requires more
151   time and disk space than <literal>make installcheck-world</literal>.
152  </para>
153
154  <para>
155   On a modern machine with multiple CPU cores and no tight operating-system
156   limits, you can make things go substantially faster with parallelism.
157   The recipe that most PostgreSQL developers actually use for running all
158   tests is something like
159<screen>
160make check-world -j8 >/dev/null
161</screen>
162   with a <option>-j</option> limit near to or a bit more than the number
163   of available cores.  Discarding <systemitem>stdout</systemitem>
164   eliminates chatter that's not interesting when you just want to verify
165   success.  (In case of failure, the <systemitem>stderr</systemitem>
166   messages are usually enough to determine where to look closer.)
167  </para>
168
169  <para>
170   Alternatively, you can run individual test suites by typing
171   <literal>make check</literal> or <literal>make installcheck</literal> in the appropriate
172   subdirectory of the build tree.  Keep in mind that <literal>make
173   installcheck</literal> assumes you've installed the relevant module(s), not
174   only the core server.
175  </para>
176
177  <para>
178   The additional tests that can be invoked this way include:
179  </para>
180
181  <itemizedlist>
182   <listitem>
183    <para>
184     Regression tests for optional procedural languages.
185     These are located under <filename>src/pl</filename>.
186    </para>
187   </listitem>
188   <listitem>
189    <para>
190     Regression tests for <filename>contrib</filename> modules,
191     located under <filename>contrib</filename>.
192     Not all <filename>contrib</filename> modules have tests.
193    </para>
194   </listitem>
195   <listitem>
196    <para>
197     Regression tests for the ECPG interface library,
198     located in <filename>src/interfaces/ecpg/test</filename>.
199    </para>
200   </listitem>
201   <listitem>
202    <para>
203     Tests for core-supported authentication methods,
204     located in <filename>src/test/authentication</filename>.
205     (See below for additional authentication-related tests.)
206    </para>
207   </listitem>
208   <listitem>
209    <para>
210     Tests stressing behavior of concurrent sessions,
211     located in <filename>src/test/isolation</filename>.
212    </para>
213   </listitem>
214   <listitem>
215    <para>
216     Tests for crash recovery and physical replication,
217     located in <filename>src/test/recovery</filename>.
218    </para>
219   </listitem>
220   <listitem>
221    <para>
222     Tests for logical replication,
223     located in <filename>src/test/subscription</filename>.
224    </para>
225   </listitem>
226   <listitem>
227    <para>
228     Tests of client programs, located under <filename>src/bin</filename>.
229    </para>
230   </listitem>
231  </itemizedlist>
232
233  <para>
234   When using <literal>installcheck</literal> mode, these tests will create
235   and destroy test databases whose names
236   include <literal>regression</literal>, for
237   example <literal>pl_regression</literal>
238   or <literal>contrib_regression</literal>.  Beware of
239   using <literal>installcheck</literal> mode with an installation that has
240   any non-test databases named that way.
241  </para>
242
243  <para>
244   Some of these auxiliary test suites use the TAP infrastructure explained
245   in <xref linkend="regress-tap"/>.
246   The TAP-based tests are run only when PostgreSQL was configured with the
247   option <option>--enable-tap-tests</option>.  This is recommended for
248   development, but can be omitted if there is no suitable Perl installation.
249  </para>
250
251  <para>
252   Some test suites are not run by default, either because they are not secure
253   to run on a multiuser system or because they require special software.  You
254   can decide which test suites to run additionally by setting the
255   <command>make</command> or environment variable
256   <varname>PG_TEST_EXTRA</varname> to a whitespace-separated list, for
257   example:
258<programlisting>
259make check-world PG_TEST_EXTRA='kerberos ldap ssl'
260</programlisting>
261   The following values are currently supported:
262   <variablelist>
263    <varlistentry>
264     <term><literal>kerberos</literal></term>
265     <listitem>
266      <para>
267       Runs the test suite under <filename>src/test/kerberos</filename>.  This
268       requires an MIT Kerberos installation and opens TCP/IP listen sockets.
269      </para>
270     </listitem>
271    </varlistentry>
272
273    <varlistentry>
274     <term><literal>ldap</literal></term>
275     <listitem>
276      <para>
277       Runs the test suite under <filename>src/test/ldap</filename>.  This
278       requires an <productname>OpenLDAP</productname> installation and opens
279       TCP/IP listen sockets.
280      </para>
281     </listitem>
282    </varlistentry>
283
284    <varlistentry>
285     <term><literal>ssl</literal></term>
286     <listitem>
287      <para>
288       Runs the test suite under <filename>src/test/ssl</filename>.  This opens TCP/IP listen sockets.
289      </para>
290     </listitem>
291    </varlistentry>
292   </variablelist>
293
294   Tests for features that are not supported by the current build
295   configuration are not run even if they are mentioned in
296   <varname>PG_TEST_EXTRA</varname>.
297  </para>
298
299  <para>
300   In addition, there are tests in <filename>src/test/modules</filename>
301   which will be run by <literal>make check-world</literal> but not
302   by <literal>make installcheck-world</literal>.  This is because they
303   install non-production extensions or have other side-effects that are
304   considered undesirable for a production installation.  You can
305   use <literal>make install</literal> and <literal>make
306   installcheck</literal> in one of those subdirectories if you wish,
307   but it's not recommended to do so with a non-test server.
308  </para>
309  </sect2>
310
311  <sect2>
312   <title>Locale and Encoding</title>
313
314   <para>
315    By default, tests using a temporary installation use the
316    locale defined in the current environment and the corresponding
317    database encoding as determined by <command>initdb</command>.  It
318    can be useful to test different locales by setting the appropriate
319    environment variables, for example:
320<screen>
321make check LANG=C
322make check LC_COLLATE=en_US.utf8 LC_CTYPE=fr_CA.utf8
323</screen>
324    For implementation reasons, setting <envar>LC_ALL</envar> does not
325    work for this purpose; all the other locale-related environment
326    variables do work.
327   </para>
328
329   <para>
330    When testing against an existing installation, the locale is
331    determined by the existing database cluster and cannot be set
332    separately for the test run.
333   </para>
334
335   <para>
336    You can also choose the database encoding explicitly by setting
337    the variable <envar>ENCODING</envar>, for example:
338<screen>
339make check LANG=C ENCODING=EUC_JP
340</screen>
341    Setting the database encoding this way typically only makes sense
342    if the locale is C; otherwise the encoding is chosen automatically
343    from the locale, and specifying an encoding that does not match
344    the locale will result in an error.
345   </para>
346
347   <para>
348    The database encoding can be set for tests against either a temporary or
349    an existing installation, though in the latter case it must be
350    compatible with the installation's locale.
351   </para>
352  </sect2>
353
354  <sect2>
355   <title>Extra Tests</title>
356
357   <para>
358    The core regression test suite contains a few test files that are not
359    run by default, because they might be platform-dependent or take a
360    very long time to run.  You can run these or other extra test
361    files by setting the variable <envar>EXTRA_TESTS</envar>.  For
362    example, to run the <literal>numeric_big</literal> test:
363<screen>
364make check EXTRA_TESTS=numeric_big
365</screen>
366    To run the collation tests:
367<screen>
368make check EXTRA_TESTS='collate.linux.utf8 collate.icu.utf8' LANG=en_US.utf8
369</screen>
370    The <literal>collate.linux.utf8</literal> test works only on Linux/glibc
371    platforms.  The <literal>collate.icu.utf8</literal> test only works when
372    support for ICU was built.  Both tests will only succeed when run in a
373    database that uses UTF-8 encoding.
374   </para>
375  </sect2>
376
377  <sect2>
378   <title>Testing Hot Standby</title>
379
380  <para>
381   The source distribution also contains regression tests for the static
382   behavior of Hot Standby. These tests require a running primary server
383   and a running standby server that is accepting new WAL changes from the
384   primary (using either file-based log shipping or streaming replication).
385   Those servers are not automatically created for you, nor is replication
386   setup documented here. Please check the various sections of the
387   documentation devoted to the required commands and related issues.
388  </para>
389
390  <para>
391   To run the Hot Standby tests, first create a database
392   called <literal>regression</literal> on the primary:
393<screen>
394psql -h primary -c "CREATE DATABASE regression"
395</screen>
396   Next, run the preparatory script
397   <filename>src/test/regress/sql/hs_primary_setup.sql</filename>
398   on the primary in the regression database, for example:
399<screen>
400psql -h primary -f src/test/regress/sql/hs_primary_setup.sql regression
401</screen>
402   Allow these changes to propagate to the standby.
403  </para>
404
405  <para>
406   Now arrange for the default database connection to be to the standby
407   server under test (for example, by setting the <envar>PGHOST</envar> and
408   <envar>PGPORT</envar> environment variables).
409   Finally, run <literal>make standbycheck</literal> in the regression directory:
410<screen>
411cd src/test/regress
412make standbycheck
413</screen>
414  </para>
415
416  <para>
417   Some extreme behaviors can also be generated on the primary using the
418   script <filename>src/test/regress/sql/hs_primary_extremes.sql</filename>
419   to allow the behavior of the standby to be tested.
420  </para>
421  </sect2>
422  </sect1>
423
424  <sect1 id="regress-evaluation">
425   <title>Test Evaluation</title>
426
427   <para>
428    Some properly installed and fully functional
429    <productname>PostgreSQL</productname> installations can
430    <quote>fail</quote> some of these regression tests due to
431    platform-specific artifacts such as varying floating-point representation
432    and message wording. The tests are currently evaluated using a simple
433    <command>diff</command> comparison against the outputs
434    generated on a reference system, so the results are sensitive to
435    small system differences.  When a test is reported as
436    <quote>failed</quote>, always examine the differences between
437    expected and actual results; you might find that the
438    differences are not significant.  Nonetheless, we still strive to
439    maintain accurate reference files across all supported platforms,
440    so it can be expected that all tests pass.
441   </para>
442
443   <para>
444    The actual outputs of the regression tests are in files in the
445    <filename>src/test/regress/results</filename> directory. The test
446    script uses <command>diff</command> to compare each output
447    file against the reference outputs stored in the
448    <filename>src/test/regress/expected</filename> directory.  Any
449    differences are saved for your inspection in
450    <filename>src/test/regress/regression.diffs</filename>.
451    (When running a test suite other than the core tests, these files
452    of course appear in the relevant subdirectory,
453    not <filename>src/test/regress</filename>.)
454   </para>
455
456   <para>
457    If you don't
458    like the <command>diff</command> options that are used by default, set the
459    environment variable <envar>PG_REGRESS_DIFF_OPTS</envar>, for
460    instance <literal>PG_REGRESS_DIFF_OPTS='-c'</literal>.  (Or you
461    can run <command>diff</command> yourself, if you prefer.)
462   </para>
463
464   <para>
465    If for some reason a particular platform generates a <quote>failure</quote>
466    for a given test, but inspection of the output convinces you that
467    the result is valid, you can add a new comparison file to silence
468    the failure report in future test runs.  See
469    <xref linkend="regress-variant"/> for details.
470   </para>
471
472   <sect2>
473    <title>Error Message Differences</title>
474
475    <para>
476     Some of the regression tests involve intentional invalid input
477     values.  Error messages can come from either the
478     <productname>PostgreSQL</productname> code or from the host
479     platform system routines. In the latter case, the messages can
480     vary between platforms, but should reflect similar
481     information. These differences in messages will result in a
482     <quote>failed</quote> regression test that can be validated by
483     inspection.
484    </para>
485   </sect2>
486
487   <sect2>
488    <title>Locale Differences</title>
489
490    <para>
491     If you run the tests against a server that was
492     initialized with a collation-order locale other than C, then
493     there might be differences due to sort order and subsequent
494     failures.  The regression test suite is set up to handle this
495     problem by providing alternate result files that together are
496     known to handle a large number of locales.
497    </para>
498
499    <para>
500     To run the tests in a different locale when using the
501     temporary-installation method, pass the appropriate
502     locale-related environment variables on
503     the <command>make</command> command line, for example:
504<programlisting>
505make check LANG=de_DE.utf8
506</programlisting>
507     (The regression test driver unsets <envar>LC_ALL</envar>, so it
508     does not work to choose the locale using that variable.)  To use
509     no locale, either unset all locale-related environment variables
510     (or set them to <literal>C</literal>) or use the following
511     special invocation:
512<programlisting>
513make check NO_LOCALE=1
514</programlisting>
515     When running the tests against an existing installation, the
516     locale setup is determined by the existing installation.  To
517     change it, initialize the database cluster with a different
518     locale by passing the appropriate options
519     to <command>initdb</command>.
520    </para>
521
522    <para>
523     In general, it is advisable to try to run the
524     regression tests in the locale setup that is wanted for
525     production use, as this will exercise the locale- and
526     encoding-related code portions that will actually be used in
527     production.  Depending on the operating system environment, you
528     might get failures, but then you will at least know what
529     locale-specific behaviors to expect when running real
530     applications.
531    </para>
532   </sect2>
533
534   <sect2>
535    <title>Date and Time Differences</title>
536
537    <para>
538     Most of the date and time results are dependent on the time zone
539     environment.  The reference files are generated for time zone
540     <literal>PST8PDT</literal> (Berkeley, California), and there will be
541     apparent failures if the tests are not run with that time zone setting.
542     The regression test driver sets environment variable
543     <envar>PGTZ</envar> to <literal>PST8PDT</literal>, which normally
544     ensures proper results.
545    </para>
546   </sect2>
547
548   <sect2>
549    <title>Floating-Point Differences</title>
550
551    <para>
552     Some of the tests involve computing 64-bit floating-point numbers (<type>double
553     precision</type>) from table columns. Differences in
554     results involving mathematical functions of <type>double
555     precision</type> columns have been observed.  The <literal>float8</literal> and
556     <literal>geometry</literal> tests are particularly prone to small differences
557     across platforms, or even with different compiler optimization settings.
558     Human eyeball comparison is needed to determine the real
559     significance of these differences which are usually 10 places to
560     the right of the decimal point.
561    </para>
562
563    <para>
564     Some systems display minus zero as <literal>-0</literal>, while others
565     just show <literal>0</literal>.
566    </para>
567
568    <para>
569     Some systems signal errors from <function>pow()</function> and
570     <function>exp()</function> differently from the mechanism
571     expected by the current <productname>PostgreSQL</productname>
572     code.
573    </para>
574   </sect2>
575
576   <sect2>
577    <title>Row Ordering Differences</title>
578
579    <para>
580You might see differences in which the same rows are output in a
581different order than what appears in the expected file.  In most cases
582this is not, strictly speaking, a bug.  Most of the regression test
583scripts are not so pedantic as to use an <literal>ORDER BY</literal> for every single
584<literal>SELECT</literal>, and so their result row orderings are not well-defined
585according to the SQL specification.  In practice, since we are
586looking at the same queries being executed on the same data by the same
587software, we usually get the same result ordering on all platforms,
588so the lack of <literal>ORDER BY</literal> is not a problem.  Some queries do exhibit
589cross-platform ordering differences, however.  When testing against an
590already-installed server, ordering differences can also be caused by
591non-C locale settings or non-default parameter settings, such as custom values
592of <varname>work_mem</varname> or the planner cost parameters.
593    </para>
594
595    <para>
596Therefore, if you see an ordering difference, it's not something to
597worry about, unless the query does have an <literal>ORDER BY</literal> that your
598result is violating.  However, please report it anyway, so that we can add an
599<literal>ORDER BY</literal> to that particular query to eliminate the bogus
600<quote>failure</quote> in future releases.
601    </para>
602
603    <para>
604You might wonder why we don't order all the regression test queries explicitly
605to get rid of this issue once and for all.  The reason is that that would
606make the regression tests less useful, not more, since they'd tend
607to exercise query plan types that produce ordered results to the
608exclusion of those that don't.
609    </para>
610   </sect2>
611
612   <sect2>
613    <title>Insufficient Stack Depth</title>
614
615    <para>
616     If the <literal>errors</literal> test results in a server crash
617     at the <literal>select infinite_recurse()</literal> command, it means that
618     the platform's limit on process stack size is smaller than the
619     <xref linkend="guc-max-stack-depth"/> parameter indicates.  This
620     can be fixed by running the server under a higher stack
621     size limit (4MB is recommended with the default value of
622     <varname>max_stack_depth</varname>).  If you are unable to do that, an
623     alternative is to reduce the value of <varname>max_stack_depth</varname>.
624    </para>
625
626    <para>
627     On platforms supporting <function>getrlimit()</function>, the server should
628     automatically choose a safe value of <varname>max_stack_depth</varname>;
629     so unless you've manually overridden this setting, a failure of this
630     kind is a reportable bug.
631    </para>
632   </sect2>
633
634   <sect2>
635    <title>The <quote>random</quote> Test</title>
636
637    <para>
638     The <literal>random</literal> test script is intended to produce
639     random results.   In very rare cases, this causes that regression
640     test to fail.  Typing:
641<programlisting>
642diff results/random.out expected/random.out
643</programlisting>
644     should produce only one or a few lines of differences.  You need
645     not worry unless the random test fails repeatedly.
646    </para>
647   </sect2>
648
649   <sect2>
650    <title>Configuration Parameters</title>
651
652    <para>
653     When running the tests against an existing installation, some non-default
654     parameter settings could cause the tests to fail.  For example, changing
655     parameters such as <varname>enable_seqscan</varname> or
656     <varname>enable_indexscan</varname> could cause plan changes that would
657     affect the results of tests that use <command>EXPLAIN</command>.
658    </para>
659   </sect2>
660  </sect1>
661
662<!-- We might want to move the following section into the developer's guide. -->
663  <sect1 id="regress-variant">
664   <title>Variant Comparison Files</title>
665
666   <para>
667    Since some of the tests inherently produce environment-dependent
668    results, we have provided ways to specify alternate <quote>expected</quote>
669    result files.  Each regression test can have several comparison files
670    showing possible results on different platforms.  There are two
671    independent mechanisms for determining which comparison file is used
672    for each test.
673   </para>
674
675   <para>
676    The first mechanism allows comparison files to be selected for
677    specific platforms.  There is a mapping file,
678    <filename>src/test/regress/resultmap</filename>, that defines
679    which comparison file to use for each platform.
680    To eliminate bogus test <quote>failures</quote> for a particular platform,
681    you first choose or make a variant result file, and then add a line to the
682    <filename>resultmap</filename> file.
683   </para>
684
685   <para>
686    Each line in the mapping file is of the form
687<synopsis>
688testname:output:platformpattern=comparisonfilename
689</synopsis>
690    The test name is just the name of the particular regression test
691    module. The output value indicates which output file to check. For the
692    standard regression tests, this is always <literal>out</literal>. The
693    value corresponds to the file extension of the output file.
694    The platform pattern is a pattern in the style of the Unix
695    tool <command>expr</command> (that is, a regular expression with an implicit
696    <literal>^</literal> anchor at the start).  It is matched against the
697    platform name as printed by <command>config.guess</command>.
698    The comparison file name is the base name of the substitute result
699    comparison file.
700   </para>
701
702   <para>
703    For example: some systems lack a working <literal>strtof</literal> function,
704    for which our workaround causes rounding errors in the
705    <filename>float4</filename> regression test.
706    Therefore, we provide a variant comparison file,
707    <filename>float4-misrounded-input.out</filename>, which includes
708    the results to be expected on these systems.  To silence the bogus
709    <quote>failure</quote> message on <systemitem>HP-UX 10</systemitem>
710    platforms, <filename>resultmap</filename> includes:
711<programlisting>
712float4:out:hppa.*-hp-hpux10.*=float4-misrounded-input.out
713</programlisting>
714    which will trigger on any machine where the output of
715    <command>config.guess</command> matches <literal>hppa.*-hp-hpux10.*</literal>.
716    Other lines in <filename>resultmap</filename> select the variant comparison
717    file for other platforms where it's appropriate.
718   </para>
719
720   <para>
721    The second selection mechanism for variant comparison files is
722    much more automatic: it simply uses the <quote>best match</quote> among
723    several supplied comparison files.  The regression test driver
724    script considers both the standard comparison file for a test,
725    <literal><replaceable>testname</replaceable>.out</literal>, and variant files named
726    <literal><replaceable>testname</replaceable>_<replaceable>digit</replaceable>.out</literal>
727    (where the <replaceable>digit</replaceable> is any single digit
728    <literal>0</literal>-<literal>9</literal>).  If any such file is an exact match,
729    the test is considered to pass; otherwise, the one that generates
730    the shortest diff is used to create the failure report.  (If
731    <filename>resultmap</filename> includes an entry for the particular
732    test, then the base <replaceable>testname</replaceable> is the substitute
733    name given in <filename>resultmap</filename>.)
734   </para>
735
736   <para>
737    For example, for the <literal>char</literal> test, the comparison file
738    <filename>char.out</filename> contains results that are expected
739    in the <literal>C</literal> and <literal>POSIX</literal> locales, while
740    the file <filename>char_1.out</filename> contains results sorted as
741    they appear in many other locales.
742   </para>
743
744   <para>
745    The best-match mechanism was devised to cope with locale-dependent
746    results, but it can be used in any situation where the test results
747    cannot be predicted easily from the platform name alone.  A limitation of
748    this mechanism is that the test driver cannot tell which variant is
749    actually <quote>correct</quote> for the current environment; it will just pick
750    the variant that seems to work best.  Therefore it is safest to use this
751    mechanism only for variant results that you are willing to consider
752    equally valid in all contexts.
753   </para>
754
755  </sect1>
756
757  <sect1 id="regress-tap">
758   <title>TAP Tests</title>
759
760   <para>
761    Various tests, particularly the client program tests
762    under <filename>src/bin</filename>, use the Perl TAP tools and are run
763    using the Perl testing program <command>prove</command>.  You can pass
764    command-line options to <command>prove</command> by setting
765    the <command>make</command> variable <varname>PROVE_FLAGS</varname>, for example:
766<programlisting>
767make -C src/bin check PROVE_FLAGS='--timer'
768</programlisting>
769    See the manual page of <command>prove</command> for more information.
770   </para>
771
772   <para>
773    The <command>make</command> variable <varname>PROVE_TESTS</varname>
774    can be used to define a whitespace-separated list of paths relative
775    to the <filename>Makefile</filename> invoking <command>prove</command>
776    to run the specified subset of tests instead of the default
777    <filename>t/*.pl</filename>.  For example:
778<programlisting>
779make check PROVE_TESTS='t/001_test1.pl t/003_test3.pl'
780</programlisting>
781   </para>
782
783   <para>
784    The TAP tests require the Perl module <literal>IPC::Run</literal>.
785    This module is available from CPAN or an operating system package.
786    They also require <productname>PostgreSQL</productname> to be
787    configured with the option <option>--enable-tap-tests</option>.
788   </para>
789
790   <para>
791    Generically speaking, the TAP tests will test the executables in a
792    previously-installed installation tree if you say <literal>make
793    installcheck</literal>, or will build a new local installation tree from
794    current sources if you say <literal>make check</literal>.  In either
795    case they will initialize a local instance (data directory) and
796    transiently run a server in it.  Some of these tests run more than one
797    server.  Thus, these tests can be fairly resource-intensive.
798   </para>
799
800   <para>
801    It's important to realize that the TAP tests will start test server(s)
802    even when you say <literal>make installcheck</literal>; this is unlike
803    the traditional non-TAP testing infrastructure, which expects to use an
804    already-running test server in that case.  Some PostgreSQL
805    subdirectories contain both traditional-style and TAP-style tests,
806    meaning that <literal>make installcheck</literal> will produce a mix of
807    results from temporary servers and the already-running test server.
808   </para>
809  </sect1>
810
811  <sect1 id="regress-coverage">
812   <title>Test Coverage Examination</title>
813
814   <para>
815    The PostgreSQL source code can be compiled with coverage testing
816    instrumentation, so that it becomes possible to examine which
817    parts of the code are covered by the regression tests or any other
818    test suite that is run with the code.  This is currently supported
819    when compiling with GCC and requires the <command>gcov</command>
820    and <command>lcov</command> programs.
821   </para>
822
823   <para>
824    A typical workflow would look like this:
825<screen>
826./configure --enable-coverage ... OTHER OPTIONS ...
827make
828make check # or other test suite
829make coverage-html
830</screen>
831    Then point your HTML browser
832    to <filename>coverage/index.html</filename>.
833    The <command>make</command> commands also work in subdirectories.
834   </para>
835
836   <para>
837    If you don't have <command>lcov</command> or prefer text output over an
838    HTML report, you can also run
839<screen>
840make coverage
841</screen>
842    instead of <literal>make coverage-html</literal>, which will
843    produce <filename>.gcov</filename> output files for each source file
844    relevant to the test.  (<literal>make coverage</literal> and <literal>make
845    coverage-html</literal> will overwrite each other's files, so mixing them
846    might be confusing.)
847   </para>
848
849   <para>
850    To reset the execution counts between test runs, run:
851<screen>
852make coverage-clean
853</screen>
854   </para>
855  </sect1>
856
857</chapter>
858