$ cd src/test/regress $ src/test/regress/pg_regress --help PostgreSQL regression test driver
Usage: pg_regress [OPTION]... [EXTRA-TEST]...
Options: --config-auth=DATADIR update authentication settings for DATADIR --create-role=ROLE create the specified role before testing --dbname=DB use database DB (default "regression") --debug turn on debug mode in programs that are run --dlpath=DIR look for dynamic libraries in DIR --encoding=ENCODING use ENCODING as the encoding --inputdir=DIR take input files from DIR (default ".") --launcher=CMD use CMD as launcher of psql --load-extension=EXT load the named extension before running the tests; can appear multiple times --load-language=LANG load the named language before running the tests; can appear multiple times --max-connections=N maximum number of concurrent connections (default is 0, meaning unlimited) --outputdir=DIR place output files in DIR (default ".") --schedule=FILE use test ordering schedule from FILE (can be used multiple times to concatenate) --temp-install=DIR create a temporary installation in DIR --use-existing use an existing installation
Options for"temp-install" mode: --extra-install=DIR additional directory to install (e.g., contrib) --no-locale use C locale --port=PORT start postmaster on PORT --temp-config=FILE append contents of FILE to temporary config --top-builddir=DIR (relative) path to top level build directory
Options for using an existing installation: --host=HOST use postmaster running on HOST --port=PORT use postmaster running at PORT --user=USER connect as USER --psqldir=DIR use psql in DIR (default: configured bindir)
The exit status is 0 if all tests passed, 1 if some tests failed, and 2 if the tests could not be run for some reason.
Report bugs to <pgsql-bugs@postgresql.org>.
回归测试用法
在 PostgreSQL 源码根目录,或者源码的 regress 目录中执行如下:
1 2
make check # 测试时需要初始化数据库集群 make installcheck # 使用以及启动的数据库集群测试,不需要初始化数据库集群
make check EXTRA_TESTS=collate.linux.utf8 LANG=en_US.utf8 make check EXTRA_TESTS=numeric_big
接下来我们看看调度文件以及 sql 脚本目录:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
postgres@digoal-> pwd /opt/soft_bak/postgresql-9.4.4/src/test/regress postgres@digoal-> less serial_schedule # src/test/regress/serial_schedule # This should probably be in an order similar to parallel_schedule. test: tablespace test: boolean test: char test: name test: varchar test: text test: int2 test: int4 test: int8 ......
并行调度:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
postgres@digoal-> less parallel_schedule # ---------- # src/test/regress/parallel_schedule # # By convention, we put no more than twenty tests in any one parallel group; # this limits the number of connections needed to run the tests. # ---------- # run tablespace by itself, and first, because it forces a checkpoint; # we'd prefer not to have checkpoints later in the tests because that # interferes with crash-recovery testing. test: tablespace
# ---------- # The first group of parallel tests # ---------- test: boolean char name varchar text int2 int4 int8 oid float4 float8 bit numeric txid uuid enum money rangetypes pg_lsn regproc ......
调度文件的 test: 后面跟的就是 sql 目录下的文件名(不含 .sql 后缀)。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
postgres@digoal-> less sql/ total 1940 drwxrwxrwx 2 postgres postgres 4096 Sep 7 14:51 ./ drwxrwxrwx 10 postgres postgres 4096 Sep 7 22:34 ../ -rw-r--r-- 1 postgres postgres 2237 Jun 10 03:29 abstime.sql -rw-r--r-- 1 postgres postgres 4097 Jun 10 03:29 advisory_lock.sql -rw-r--r-- 1 postgres postgres 20295 Jun 10 03:29 aggregates.sql -rw-r--r-- 1 postgres postgres 24882 Jun 10 03:29 alter_generic.sql -rw-r--r-- 1 postgres postgres 54461 Jun 10 03:29 alter_table.sql -rw-r--r-- 1 postgres postgres 17244 Jun 10 03:29 arrays.sql -rw-r--r-- 1 postgres postgres 594 Jun 10 03:29 async.sql -rw-r--r-- 1 postgres postgres 1365 Jun 10 03:29 bitmapops.sql -rw-r--r-- 1 postgres postgres 6406 Jun 10 03:29 bit.sql -rw-r--r-- 1 postgres postgres 4164 Jun 10 03:29 boolean.sql ......
postgres@digoal-> pwd /opt/soft_bak/postgresql-9.4.4/src/test/regress postgres@digoal-> make installcheck-parallel //并行测试,使用已经开启的现有的数据库集群 make -C ../../../src/port all ...... ../../../src/test/regress/pg_regress --inputdir=. --psqldir='/opt/pgsql9.4.4/bin' --dlpath=. --schedule=./parallel_schedule (using postmaster on /data01/pg_root_1921, port 1921) ============== dropping database "regression" ============== DROP DATABASE ============== creating database "regression" ============== CREATE DATABASE ALTER DATABASE ============== running regression test queries ============== test tablespace ... ok ...... parallel group (19 tests): limit conversion sequence returning without_oid polymorphism copy2 xml prepare plancache rowtypes temp domain with truncate largeobject rangefuncs alter_table plpgsql plancache ... ok limit ... ok plpgsql ... ok copy2 ... ok temp ... ok domain ... ok rangefuncs ... FAILED prepare ... ok without_oid ... ok conversion ... ok truncate ... ok alter_table ... ok sequence ... ok polymorphism ... FAILED rowtypes ... ok returning ... ok largeobject ... ok with ... FAILED xml ... ok test stats ... ok ...... ========================= 22 of 145 tests failed. =========================
The differences that caused some tests to fail can be viewed in the file "/opt/soft_bak/postgresql-9.4.4/src/test/regress/regression.diffs". A copy of the test summary that you see above is saved in the file "/opt/soft_bak/postgresql-9.4.4/src/test/regress/regression.out".
postgres@digoal-> less regression.diffs *** /opt/soft_bak/postgresql-9.4.4/src/test/regress/expected/pg_lsn.out 2015-06-10 03:29:38.000000000 +0800 --- /opt/soft_bak/postgresql-9.4.4/src/test/regress/results/pg_lsn.out 2015-09-07 22:45:04.413922536 +0800 *************** *** 72,92 **** generate_series(1, 5) k WHERE i <= 10 AND j > 0 AND j <= 10 ORDER BY f; ! QUERY PLAN ! -------------------------------------------------------------------------- ! Sort ! Sort Key: (((((i.i)::text || '/'::text) || (j.j)::text))::pg_lsn) ! -> HashAggregate ! Group Key: ((((i.i)::text || '/'::text) || (j.j)::text))::pg_lsn -> Nested Loop -> Function Scan on generate_series k ! -> Materialize ! -> Nested Loop ! -> Function Scan on generate_series j ! Filter: ((j > 0) AND (j <= 10)) ! -> Function Scan on generate_series i ! Filter: (i <= 10) ! (12 rows)
SELECT DISTINCT (i || '/' || j)::pg_lsn f FROM generate_series(1, 10) i, --- 72,90 ---- generate_series(1, 5) k WHERE i <= 10 AND j > 0 AND j <= 10 ORDER BY f; ......
# Select database to use for running the tests ifneq ($(USE_MODULE_DB),) REGRESS_OPTS += --dbname=$(CONTRIB_TESTDB_MODULE) else REGRESS_OPTS += --dbname=$(CONTRIB_TESTDB) endif
# where to find psql for running the tests PSQLDIR = $(bindir)
# When doing a VPATH build, must copy over the data files so that the # driver script can find them. We have to use an absolute path for # the targets, because otherwise make will try to locate the missing # files using VPATH, and will find them in $(srcdir), but the point # here is that we want to copy them from $(srcdir) to the build # directory.