Postgresql 中文操作指南
33.5. Test Coverage Examination #
PostgreSQL 源代码可以用覆盖率测试工具编译,这样就可以检查代码的哪些部分被回归测试或与代码一起运行的任何其他测试套件覆盖。在使用 GCC 编译时当前支持此功能,并且它需要 gcov 和 lcov 软件包。
The PostgreSQL source code can be compiled with coverage testing instrumentation, so that it becomes possible to examine which parts of the code are covered by the regression tests or any other test suite that is run with the code. This is currently supported when compiling with GCC, and it requires the gcov and lcov packages.
33.5.1. Coverage with Autoconf and Make #
一个典型的流程如下:
A typical workflow looks like this:
./configure --enable-coverage ... OTHER OPTIONS ...
make
make check # or other test suite
make coverage-html
然后将您的 HTML 浏览器指向 coverage/index.html。
Then point your HTML browser to coverage/index.html.
如果您没有 lcov 或更喜欢文本输出而不是 HTML 报告,则可以运行
If you don’t have lcov or prefer text output over an HTML report, you can run
make coverage
而不是 make coverage-html,这将为与测试相关的所有源文件生成 .gcov 输出文件。(make coverage 和 make coverage-html 将覆盖彼此的文件,因此混合它们可能会令人困惑。)
instead of make coverage-html, which will produce .gcov output files for each source file relevant to the test. (make coverage and make coverage-html will overwrite each other’s files, so mixing them might be confusing.)
在制作覆盖报告之前,您可以运行几个不同的测试;执行计数将累积。如果您想在测试运行之间重置执行计数,请运行:
You can run several different tests before making the coverage report; the execution counts will accumulate. If you want to reset the execution counts between test runs, run:
make coverage-clean
如果您只需要代码树的一部分的覆盖报告,则可以在子目录中运行 make coverage-html 或 make coverage 命令。
You can run the make coverage-html or make coverage command in a subdirectory if you want a coverage report for only a portion of the code tree.
完成后使用 make distclean 清理。
Use make distclean to clean up when done.
33.5.2. Coverage with Meson #
一个典型的流程如下:
A typical workflow looks like this:
meson setup -Db_coverage=true ... OTHER OPTIONS ... builddir/
meson compile -C builddir/
meson test -C builddir/
cd builddir/
ninja coverage-html
然后将您的 HTML 浏览器指向 ./meson-logs/coveragereport/index.html。
Then point your HTML browser to ./meson-logs/coveragereport/index.html.
在制作覆盖报告之前,您可以运行几个不同的测试;执行计数将累积。
You can run several different tests before making the coverage report; the execution counts will accumulate.