Appendix B. Regression Tests

The regression tests are a comprehensive set of tests for the SQL implementation in PostgreSQL. They test standard SQL operations as well as the extended capabilities of PostgreSQL. Typically, you run these tests at the end of the PostgreSQL installation process.

The regression test can be run against an already installed and running server, or using a temporary installation within the build tree. Furthermore, there is a "parallel" and a "sequential" mode for running the tests. The sequential mode runs each test script in turn, whereas the parallel mode starts up multiple server processes to run groups of tests in parallel. Parallel testing gives confidence that interprocess communication and locking are working correctly.

To run the regression tests after building but before installation, enter:
$ make check
in the top-level directory. (Or you can change to src/test/regress and run the command there.) This will first build several auxiliary files and some sample user-defined trigger functions, and then run the test driver script. At the end you should see something like
======================
 All 98 tests passed.
======================
or otherwise a note about what tests failed. See "Test Evaluation" for more.

Note

Because this test method runs a temporary server, it will not work when you are the root user (the server will not start as root). If you already did the build as root, you do not have to start all over. Instead, make the regression test directory writable by some other user, log in as that user, and restart the tests. For example:
root# chmod -R a+w src/test/regress
root# su - joeuser
joeuser$ make check
(The only possible "security risk" here is that other users might be able to alter the regression test results. Use common sense when managing user permissions.)

To run the tests, initialize a data area in the "C" locale, start the server (as explained in the Administrator and User's Guide), then enter:
$ make installcheck
The tests expect to contact the server at the local host and the default port number, unless directed otherwise by PGHOST and PGPORT environment variables.

Test Evaluation

The tests are currently evaluated using a simple diff comparison against the outputs generated on a reference system, so the results are sensitive to small system differences. When a test is reported as "failed", always examine the differences between expected and actual results; you may well find that the differences are not significant. Nonetheless, we still strive to maintain accurate reference files, so it can be expected that all tests pass.

The actual outputs of the regression tests are in files in the src/test/regress/results directory. The test script uses diff to compare each output file against the reference outputs stored in the src/test/regress/expected directory. Any differences are saved for your inspection in src/test/regress/regression.diffs. src/test/regress/regression.out. which lists which test cases pass and fail. (You can also run diff yourself, if you prefer.)

Error Message Differences

Some of the regression tests involve intentional invalid input values. Error messages can come from either the PostgreSQL code or from the Linux system routines.

Locale Differences

The tests expect to run in plain "C" locale (which is the default locale for PostgreSQL). This should not cause any problems when you run the tests against a temporary installation, since the regression test driver takes care to start the server in C locale. However, if you run the tests against an already-installed server that is using non-C locale settings, you may see differences caused by varying rules for string sort order, formatting of numeric and monetary values, and so forth.

In some locales the resulting differences are small and easily checked by inspection. However, in a locale that changes the rules for formatting of numeric values (typically by swapping the usage of commas and decimal points), entry of some data values will fail, resulting in extensive differences later in the tests where the missing data values are supposed to be used.

Date and Time Differences

Most of the date and time results are dependent on the time zone environment. The reference files are generated for time zone PST8PDT (Berkeley, California) and there will be apparent failures if the tests are not run with that time zone setting. The regression test driver sets environment variable PGTZ to PST8PDT to ensure proper results. However, your system must provide library support for the PST8PDT time zone, or the time zone-dependent tests will fail. To verify that your machine does have this support, type the following:
$ env TZ=PST8PDT date
The command above should have returned the current system time in the PST8PDT time zone. If the PST8PDT database is not available, then your system may have returned the time in GMT. If the PST8PDT time zone is not available, you can set the time zone rules explicitly:
PGTZ='PST8PDT7,M04.01.0,M10.05.03'; export PGTZ

The "Random" Test

There is at least one case in the "random" test script that is intended to produce random results. This causes random to fail the regression test once in a while (perhaps once in every five to ten trials). Typing
diff results/random.out expected/random.out
should produce only one or a few lines of differences. You need not worry unless the random test always fails in repeated attempts. (On the other hand, if the random test is never reported to fail even in many trials of the regress tests, you probably should worry.)