测试使用make check或make installcheck进行,它会通过pg_regress程序调用sql目录中的sql,并收集输出结果(通常放到results目录中),最后pg_regress会对expected目录和results目录中的文件使用diff进行一一比较。
但是这种测试方法实际上有一些需要注意的地方,例如我们使用不同的本地化设置,时区可能得到的结果和期望的结果就不一样。另外有些不可预知的结果,例如随机值,数据的顺序,执行计划和优化器相关参数有关。这些因素都可能导致测试结果和预期不一致,那么我们就需要人为去修复这种Failed。
这个目录的结构如下:
postgres@digoal-> ll -rttotal 1.2M2.3K serial_schedule 串行测试的调度配置rwxrxrx 4.4K regressplans.sh20K regressc159 README2.7K pg_regress_main1.6K pg_regressh69K3.6K parallel_schedule 并行测试的调度配置624Makefile5.6KGNUmakefiledrwxrwxrwx24.0K38 outputdrwxrwxrwx inputdata 一些测试数据drwxrwxr52 results 通过pg_regress调用目录中的脚本,得到的结果expected 执行目录中的文件对应的正确返回结果
上层目录结构如下,其中包含了一些其他的测试目标,例如隔离级别的测试,本地化测试,性能测试,线程安全测试。等。
cd /optsoft_bakpostgresql-9.4.4srctestll36Kexamples441 isolation6 locale389Makefilembperformanceperl1917 regressthread
$ cd srctestregress
$ srcregresspg_regress help
Postgresql regression test driver
Usage:
pg_regress [OPTION]...EXTRATEST]...
Optionsconfigauth=DATADIR update authentication settings for DATADIR
createroleROLE create the specified role before testing
dbnameDB use database DB (default "regression")
debug turn on debug mode in programs that are run
dlpathDIR look dynamic libraries DIR
encodingENCODING ENCODING as the encoding
inputdirDIR take input files from DIR "."launcherCMD CMD launcher of psql
loadextensionEXT load the named extension before running the
tests; can appear multiple times
languageLANG load the named language before running the
maxconnectionsN maximum number of concurrent connections
is0,0)"> meaning unlimitedoutputdirDIR place output files scheduleFILE test ordering schedule FILE
(can be used multiple times to concatenatetempinstallDIR create a temporary installation --useexisting an existing installation
Options"temp-install" modeextraDIR additional directory to install eg.,0)"> contribnolocale C locale
portPORT start postmaster on PORT
FILE append contents of FILE to temporary config
topbuilddirDIR relative) path to top level build directory
using an existing installationhostHOST postmaster running on HOST
PORT postmaster running at PORT
userUSER connect USER
Theexit status 0if all tests passed some tests Failedand2
if the tests could not be run some reason.