Postgres regress test
make check # parallel running the Tests Against a Temporary Installationmake installcheck # serial running the Tests Against an Existing Installationmake installcheck-paralle # parallel running the Tests Against an Existing Installation
Documentation concerning how to run these regression tests and interpret theresults can be found in the PostgreSQL manual, in the chapter "Regression Tests".
pg_regress
pg_regress --inputdir=. --bindir='tmp_basedir_polardb_pg_1100_bld/bin'--dlpath=. --max-concurrent-tests=20 --user=regress --schedule=./serial_schedule
./pg_regress -h####################################\PostgreSQL regression test driverUsage:pg_regress [OPTION]... [EXTRA-TEST]...Options:--bindir=BINPATH use BINPATH for programs that are run;if empty, use PATH from the environment--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-h, --help show this help, then exit--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 thetests; can appear multiple times--load-language=LANG load the named language before running thetests; can appear multiple times--max-connections=N maximum number of concurrent connections(default is 0, meaning unlimited)--max-concurrent-tests=N maximum number of concurrent tests in schedule(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-instance=DIR create a temporary instance in DIR--use-existing use an existing installation--no-restrict-auth disable restricted authentication settings-V, --version output version information, then exitOptions for "temp-instance" mode:--no-locale use C locale--port=PORT start postmaster on PORT--temp-config=FILE append contents of FILE to temporary config--temp-initdb-opts=OPTS additional flags passed to initdbOptions for using an existing installation:--host=HOST use postmaster running on HOST--port=PORT use postmaster running at PORT--user=USER connect as USERThe exit status is 0 if all tests passed, 1 if some tests failed, and 2if the tests could not be run for some reason.Report bugs to <support@enterprisedb.com>.
intmain(int argc, char *argv[]){return regression_main(argc, argv, psql_init, psql_start_test);}
1.参数解析 2.如果是在临时实例上运行,构建临时实例。 3.create 测试数据库和测试用户 4.读取schedule文件对于每一个schedule文件做: 4.1. 读取每一行,以test开头,获取后面的每一个case。 4.2. 每一个case启动一个进程 调用psql 执行case sql脚本。 4.3. 将执行sql脚本的输出重定向到./results目录下。 4.4. 将./results下的输出文件和./expected下的下相同文件名进行diff。 4.5. 如果没有差异ok,有差异falied。 5.如果是临时实例,关闭实例。 6.结束。
test: tablespacetest: booleantest: chartest: nametest: varchartest: text......
# ----------# 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......
如何添加新的 regress test case。
在regress/sql中添加新的sql文件,如test1.sql,test2.sql, test3.sql 使用psql执行添加的sql文件,psql -X -a -q -d databasename > regress/expected/test1.sql . 将其每个sql文件的执行结果放入expected目录下作为期望文件,用于下次回归进行比对。 可以在serial_schedule 和parallel_schedule 中添加自己新建的case ,也可以自己单独写一个schedule文件。 如果自己新建了schedule文件,在Makefile中添加对应的make 标签。serial_schedule 和parallel_schedule 中添加则不需要。
pg_isolation_regress
该目录包含一组针对并发行为的PostgreSQL的的测试。这些测试需要运行多个交互事务,这需要管理多个并发连接,因此无法使用正常的pg_regress程序进行测试。名字“隔离”来自这个事实,原来的动机是测试可序列化隔离级别;但测试其他类型的并发行为也被添加了。
setup { <SQL> }The given SQL block is executed once, in one session only, before runningthe test. Create any test tables or other required objects here. Thispart is optional. Multiple setup blocks are allowed if needed; each isrun separately, in the given order. (The reason for allowing multiplesetup blocks is that each block is run as a single PQexec submission,and some statements such as VACUUM cannot be combined with others in sucha block.)teardown { <SQL> }The teardown SQL block is executed once after the test is finished. Usethis to clean up in preparation for the next permutation, e.g droppingany test tables created by setup. This part is optional.session "<name>"There are normally several "session" parts in a spec file. Eachsession is executed in its own connection. A session part consistsof three parts: setup, teardown and one or more "steps". The per-sessionsetup and teardown parts have the same syntax as the per-test setup andteardown described above, but they are executed in each session. Thesetup part typically contains a "BEGIN" command to begin a transaction.Each step has the syntaxstep "<name>" { <SQL> }where <name> is a name identifying this step, and SQL is a SQL statement(or statements, separated by semicolons) that is executed in the step.Step names must be unique across the whole spec file.permutation "<step name>" ...A permutation line specifies a list of steps that are run in that order.Any number of permutation lines can appear. If no permutation lines aregiven, the test program automatically generates all possible orderingsof the steps from each session (running the steps of any one session inorder). Note that the list of steps in a manually specified"permutation" line doesn't actually have to be a permutation of theavailable steps; it could for instance repeat some steps more than once,or leave others out.
isolationtester
intmain(int argc, char *argv[]){return regression_main(argc, argv, isolation_init, isolation_start_test);}
1.参数解析 2.读取将要运行的case即 spec文件。 3.解析spec文件,初始化多个session和对应step。 4.检查step是否有重名。 5.使用libpq建立每一个session连接。 6.按步骤设置会话索引字段。 7.运行规范中指定的排列,如果没有明确指定,则运行所有排列。 8.将./results下的输出文件和./expected下的下相同文件名进行diff。 9.相同ok,有差异这failed 10.关闭所有连接,exit结束。
总结

文章转载自PostgreSQL中文社区,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




