为不同的绝对目录累积 lcov 输出

Cumulating lcov outputs for different absolute directories

我在不同的测试套件上使用代码覆盖,这些套件在不同的目录下启动。 假设我的 suite1 在目录 /path1/mysoft/src 中启动,而我的 suite2 在目录 /path2/mysoft/src/

中启动

我在 /path1/mysoft(分别使用 path2)中使用 lcov -d . -c -o suite1.info(分别使用 suite2)启动 lcov。

然后我想累加两个测试套件的覆盖率。我将 suite1.infosuite2.info 文件复制到另一个目录 /path3/mysoft 中,该目录还包含我程序的源代码。

我可以用 lcov -a suite1.info -a suite2.info -o tests.info 累加两者,但是给定文件 src/example.c 的覆盖率不会累加,因为 lcov 会考虑 /path1/mysoft/src/example.c/path2/mysoft/src/example.c 是两个不同的文件。所以累积是行不通的。

如何累计来自不同基本目录的相同源代码的代码覆盖率?

一些不令人满意的解决方案

一些上下文

为什么我要在不同的基本目录中启动我的测试套件?实际上,持续集成就是这样做的。所以 path1 类似于 /home/gitlab/builds/b8e873c2/0/。每个测试套件都在不同的作业中启动,并且覆盖率的累积也在另一个作业中完成。每个作业都在不同的基本目录中启动,.info 文件使用工件检索。

感谢您的帮助!

有一个答案,可能不是最优雅的。由于源文件名以纯文本形式存储,因此可以很容易地使用 sed 来更改它们。

因此所有启动的命令可能如下所示(提醒每个命令实际上是由不同的作业启动的):

lcov -d . -c --rc geninfo_adjust_src_path=/path1 -o suite1.info # in /path1/mysoft lcov -d . -c --rc geninfo_adjust_src_path=/path2 -o suite2.info # in /path2/mysoft # From /path3/mysoft, after retrieving suite1.info and suite2.info lcov -a suite1.info -a suite2.info | sed 's/^SF:/mysoft/SF:/path3/mysoft' > tests.info

前两行从 .info 文件中删除了对 /path1/path2 的任何引用。第三行在源文件路径前添加对 /path3 的引用,以便 genhtml 可以找到它们。