lcov/genhtml 可以显示从未执行过的文件吗?

Can lcov/genhtml show files that were never executed?

如何让 lcovgenhtml 显示未链接/加载的文件?我用它来显示测试覆盖率,我希望看到每个源文件都出现在 HTML 报告中,即使它的覆盖率是零。这样我就可以使用 lcov 来识别缺少测试的源文件。缺少的源文件有一个为它们创建的 .gcno 文件,但没有 .gcda 文件。

如果您想查看所有文件,您必须使用 -i 选项创建基线覆盖率数据文件。 捕获数据后,您必须使用 -a 选项合并这两个文件。

lcov 手册页 (https://linux.die.net/man/1/lcov) 中有一个示例:

Capture initial zero coverage data.

Run lcov with -c and this option on the directories containing .bb, .bbg or .gcno files before running any test case. The result is a "baseline" coverage data file that contains zero coverage for every instrumented line. Combine this data file (using lcov -a) with coverage data files captured after a test run to ensure that the percentage of total lines covered is correct even when not all source code files were loaded during the test.

Recommended procedure when capturing data for a test case:

  1. create baseline coverage data file

    lcov -c -i -d appdir -o app_base.info

  2. perform test

    appdir/test

  3. create test coverage data file

    lcov -c -d appdir -o app_test.info

  4. combine baseline and test coverage data

    lcov -a app_base.info -a app_test.info -o app_total.info

然后您必须使用 app_total.info 作为 genhtml 的来源。