PostgreSQL 获取regress回归测试代码覆盖率

PostgreSQL 源码提供了编译选项用来测试代码覆盖率,打开 –enable-coverage 选项,编译安装,然后执行回归测试或者其他的测试,最后生成代码覆盖率报告。

下面以 CentOS 7.9 环境为例,介绍整个操作流程。

0、依赖包安装

root 用户安装 lcov

git clone https://github.com/linux-test-project/lcov.git

cd lcov

make install

yum -y install perl-Digest-MD5

yum -y install perl-IO-Compress

yum -y install perl-Module-Load

yum -y install perl-Module-Load-Conditional

1、编译源码

./configure –prefix=/opt/app/pg13/ –enable-coverage –enable-debug –with-python –enable-cassert –enable-depend CFLAGS=-O0

make

make install

2、执行测试集或者执行自定义测试

make check

如果是自定义测试,初始化一个 PG 实例,执行各种自定义测试 SQL 即可。

3、生成覆盖率

make coverage-html

make coverage

coverage-html 生成 html 格式的覆盖率报告。执行完成后,在当前目录下生成 coverage 目录,该目录包含代码覆盖率报告。

4、清除覆盖率

make coverage-clean 

参考资料:

https://www.postgresql.org/docs/current/regress-coverage.html

上一篇 PostgreSQL空闲空间映射表FSM(Free Space Map)解析
下一篇 PostgreSQL Latch 实现逻辑