有没有办法将两个 .gcda 文件合并为一个?
我对一个应用程序有几个单元测试,每个测试都能够生成 .gcda 文件。我希望能够生成统一的 .gcda 文件,它代表我的测试套件的整体覆盖范围。似乎没有一个简单的方法可以做到这一点,但我可能是错的,这就是我问的原因。
使用 gcov,是否可以合并到 .gcda 文件? 之前被问过,解决方案是转换为 lcov .info 文件并以这种方式合并。如果可能的话,我希望合并操作的输出仍然是单个 .gcda 文件,这样我就不会被迫使用 lcov。
I have several unit tests for an application, each of which is capable of generating .gcda files. I would like to be able to generate unified .gcda files which represent the coverage of my test suite as a whole. There doesn't appear to be an easy way to do this, but I could be wrong, and that's why I'm asking.
With gcov, is it possible to merge to .gcda files? was previously asked and the solution was to convert to lcov .info files and merge that way. If possible, I would like the output of the merge operation to still be a single .gcda file so that I'm not forced to use lcov.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有代码可以合并 .gcda 文件,但不幸的是它被隐藏在作为 gcc 的一部分构建的 libgcov.a 中。如果您退出(或以任何方式调用
__gcov_flush()
)一个使用覆盖率编译的程序,它实际上会检测预先存在的.gcda
文件,加载它们,聚合它们的数据正在运行的程序的数据,并将其保存回来。我不知道有任何工具可以在命令行提供该功能。即使使用 libgcov.a,您也可能没有有用的钩子来执行您想要的操作,并且必须从 gcc-core 发行版获取源代码并对其进行修改。我过去所做的只是将所有数据提取到带注释的源(
.gcov
)并在该级别进行聚合。.gcda
格式能够存储的不仅仅是行覆盖信息(例如分支计数),并且libgcov.a
聚合知道如何组合这些信息(对于某些人来说它不是就像求和一样简单)。There is code to merge
.gcda
files but unfortunately it's buried inlibgcov.a
which builds as part of gcc. If you exit (or in any way invoke__gcov_flush()
) a program compiled with coverage it will actually detect pre-existing.gcda
files, load them, aggregate their data with the running program's data, and save it back out. I don't know of any tool which provides that functionality at the command line. Even withlibgcov.a
you probably have no useful hooks to do what you want and would have to take the source from the gcc-core distribution and modify it.What I have done in the past is just extract all the data to annotated source (
.gcov
) and aggregate at that level. The.gcda
format is capable of storing a lot more than line coverage information (eg branch counts) and thelibgcov.a
aggregation knows how to combine those (for some it's not as simple as summation).我刚刚创建了一个测试项目,据我所知,当使用不同的参数连续运行单个测试应用程序时,gcda 文件会在运行和运行 gcov 之间更新一次(我使用 gcovr.py) 生成聚合覆盖信息。
I have just created a test project which shows, AFAIKT, that when a single test application is run successively with different parameters, then the gcda files are updated between runs and running gcov once (I use gcovr.py) produces aggregate coverage information.
Gcov 软件包附带了 gcov-tool 可执行文件,它能够合并 gcda 文件:
(dirN 中的 .gcda 文件的位置必须相同)。生成的 .gcda 将存储在
merged_profile
目录中(可以使用-o
标志覆盖)。Gcov-tool
主要用于与GCOV_PREFIX
或-fprofile-dir=XXX.%p
生成的一系列 .gcda 文件一起使用。Gcov-tool 一次只能合并两个配置文件,但您可以使用包装器 gcov-tool-many 来规避这个问题。
Gcov package comes with
gcov-tool
executable which is capable of merging gcda files:(position of .gcda files within dirN must be identical). Resulting .gcda will be stored in the
merged_profile
directory (can be overriden with-o
flag).Gcov-tool
is mainly meant to be used with series of .gcda files generated withGCOV_PREFIX
or-fprofile-dir=XXX.%p
.Gcov-tool can merge only two profiles at a time but you can use a wrapper gcov-tool-many to circumvent this.