![3becb18a6afceeb5279a8bec6cc3851b.png](https://i-blog.csdnimg.cn/blog_migrate/54c7da81e80034a38dd880a90a34657d.jpeg)
作为PostgreSQL开发人员,首先我们需要知道如何在Linux下进行编译、测试。这里将会介绍环境准备,代码下载、配置、编译,回归测试,如何获得代码覆盖率。
环境准备
操作系统:
[postgres@localhost ~]$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[postgres@localhost ~]$ uname -a
Linux localhost.localdomain 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
环境准备(很贴心的只保留了命令):
sudo yum install -y git gcc lcov flex bison zlib-devel readline-devel libxml2-devel libxslt-devel openssl-devel vim lcov
sudo yum install -y epel-release
sudo yum install -y centos-release-scl
sudo yum install -y llvm-toolset-7 llvm-toolset-7-llvm-devel llvm5.0-devel llvm-toolset-7-clang-analyzer llvm-toolset-7-clang-tools-extra gcc-c++
scl enable llvm-toolset-7 bash //enable clang
sudo ln -s /opt/rh/llvm-toolset-7/root/usr/bin/clang /usr/bin/clang
补充:这里安装LLVM是为了启用PostgreSQL的JIT功能,详细安装过程,请参看:https://developers.redhat.com/blog/2018/07/07/yum-install-gcc7-clang/。
sudo yum install -y perl-core perl-IPC-Run
为了启用PostgreSQL的TAP测试套件,需要安装Perl相关组件。perl-core内容,请参看:https://www.perl.com/article/what-is-the-perl-core-/。更多TAP内容,请参看:http://testanything.org/。
源码下载
Git下载:
[postgres@localhost ~]$ git clone git://git.postgresql.org/git/postgresql.git pg13
Cloning into 'pg13'...
remote: Counting objects: 761424, done.
remote: Compressing objects: 100% (109491/109491), done.
remote: Total 761424 (delta 652269), reused 757277 (delta 649047)
Receiving objects: 100% (761424/761424), 229.17 MiB | 1.08 MiB/s, done.
Resolving deltas: 100% (652269/652269), done.
[postgres@localhost ~]$ cd pg13/
[postgres@localhost pg13]$ ls
aclocal.m4 configure contrib doc HISTORY README src
config configure.in COPYRIGHT GNUmakefile.in Makefile README.git
Git结构:
[postgres@localhost pg13]$ git tag | grep REL_12
REL_12_0
REL_12_1
REL_12_BETA1
REL_12_BETA2
REL_12_BETA3
REL_12_BETA4
REL_12_RC1
[postgres@localhost pg13]$ git branch -r | grep REL_12
origin/REL_12_STABLE
tag是PostgreSQL各个版本,branch是代码分支。
编译、测试:
[postgres@localhost pg13]$ ./configure --prefix=/home/postgres/pgdb13 --enable-debug --enable-coverage --enable-tap-tests --with-openssl --with-llvm LLVM_CONFIG=/usr/lib64/llvm5.0/bin/llvm-config --with-libxml --with-libxslt --enable-thread-safety
[postgres@localhost pg13]$ make world; make install-world; make check-world
[postgres@localhost pg13]$ make coverage-html
make coverage-html会代码覆盖率报告,如下:
![75cd99418feaf2e466d10eb88b6b9da6.png](https://i-blog.csdnimg.cn/blog_migrate/5ed6f042ba654eaecc29b8644e84b4bf.jpeg)
详细过程请参看:https://www.postgresql.org/docs/current/regress-coverage.html。
当准备开发PostgreSQL时,我们首先要对整个数据库进行回归测试,确认没有问题后,再进行开发。当完成功能开发后,同时要增加自己的测试用例,还需要再次进行回归测试。同时要进行代码覆盖率测试,确保开发代码覆盖率足够高。