有没有办法将两个 .gcda 文件合并为一个?

发布于 2024-11-17 17:48:57 字数 342 浏览 4 评论 0原文

我对一个应用程序有几个单元测试,每个测试都能够生成 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

咽泪装欢 2024-11-24 17:48:57

有代码可以合并 .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 in libgcov.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 with libgcov.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 the libgcov.a aggregation knows how to combine those (for some it's not as simple as summation).

她说她爱他 2024-11-24 17:48:57

我刚刚创建了一个测试项目,据我所知,当使用不同的参数连续运行单个测试应用程序时,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.

宁愿没拥抱 2024-11-24 17:48:57

Gcov 软件包附带了 gcov-tool 可执行文件,它能够合并 gcda 文件:

gcov-tool merge dir1 dir2

(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:

gcov-tool merge dir1 dir2

(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 with GCOV_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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文