使用 gcov,是否可以合并到 .gcda 文件?
我有相同的源文件(C 和 Obj-C)被编译成两个目标:单元测试可执行文件和实际产品(然后进行集成测试)。这两个目标构建到不同的位置,因此目标文件、.gcno 和 .gcda 文件是分开的。并非所有源文件都会编译到单元测试中,因此并非所有对象都会存在于单元测试中。所有源文件都编译到产品版本中。
有没有办法组合两组 .gcda 文件以获得单元测试和集成测试的总覆盖率(因为它们在产品构建上运行)?
我用的是lcov。
Mac OS X 10.6、GCC 4.0
谢谢!
I have the same source files (C and Obj-C) being compiled into two targets: the unit test executable and the actual product (which then gets integration tested). The two targets build into different places, so the object files, .gcno and .gcda files are separate. Not all source files are compiled into the unit test, so not all objects will exist there. All source files are compiled into the product build.
Is there a way to combine the two sets of .gcda files to get the total coverage for unit tests and integration tests (as they are run on the product build)?
I'm using lcov.
Mac OS X 10.6, GCC 4.0
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
最后我设法通过 lcov 解决了我的问题。
基本上我所做的如下:
-fprofile-arcs -ftest-coverage --coverage
编译应用程序lcov --directory src/ --capture --output-filecoverage_reports/app.info
genhtml -ocoverage_reports/coverage_reports/app.info
我希望这对某人有帮助。
Finally I managed to solve my problem by means of lcov.
Basically what I did is the following:
-fprofile-arcs -ftest-coverage --coverage
lcov --directory src/ --capture --output-file coverage_reports/app.info
genhtml -o coverage_reports/ coverage_reports/app.info
I hope this can be of help to someone.
由于您使用的是 lcov,因此您应该能够将 gcov .gcda 文件转换为 lcov 文件并将它们与 lcov
--add-tracefile
合并。Since you're using lcov, you should be able to convert the gcov .gcda files into lcov files and merge them with lcov
--add-tracefile
.请参阅下面的更新。
我认为执行此操作的预期方法不是直接组合
.gcda
文件,而是使用每个覆盖数据代表一次“运行”来创建独立的覆盖数据文件。您当然可以创建单独的图表或 html 视图。但您也可以使用
--add-tracefile
组合数据,简称-a
从
total.coverage
您可以生成总报告,例如使用genhtml
。更新:我发现实际上可以使用
gcov-tool
直接合并.gcda
文件,不幸的是,这在 Mac 上不容易使用,因此此更新不会回答原来的问题。但是使用 gcov-tool,您甚至可以逐步将多个集合合并为一个集合:
尽管这没有记录在案,并且依赖它可能存在风险。
这确实很快,并且避免了 lcov 的迂回方式,在合并许多集合时,lcov 的速度要慢得多。在我的机器上,合并约 80 组 70 个文件只需不到 0.5 秒。您仍然可以在聚合集上执行 lcov,如果您需要的话,这也会快得多。我使用 Emacs
cov-mode
,它直接使用.gcov
文件。有关详细信息,请参阅此答案。
See UPDATE below.
I think the intended way to do this is not to combine the
.gcda
files directly but to create independent coverage data files usingEach coverage data then represents one "run". You can of course create separate graphs or html views. But you can also combine the data using
--add-tracefile
,-a
for shortFrom the
total.coverage
you can generate the total report, usinggenhtml
for example.UPDATE: I found that it is actually possible to merge
.gcda
files directly usinggcov-tool
, which unfortunately are not easily available on the Mac, so this update doesn't answer the original question.But with
gcov-tool
you can even incrementally merge many set together into one:Although that is not documented and might be risky to rely on.
This is really fast and avoids the round-about way over lcov, which is much slower when merging many sets. Merging some 80 sets of 70 files takes under .5 second on my machine. And you can still do an
lcov
on the aggregated set, which also is very much faster, should you need it. I use Emacscov-mode
which uses the.gcov
files directly.See this answer for details.
我通过 lcov multi -d 参数合并它,如下所示。有用。
I merge it by lcov multi -d parameters as below. It works.
一个更简单的替代方案是编译一次共享 C/ObjC 文件(生成
.o
文件,或者更好的是,生成单个.a
静态库),然后链接到每个测试中。在这种情况下,gcov 会自动将结果合并到单个.gcno
/.gcda
对中(请注意,测试必须连续运行,以避免访问 gcov 文件时出现竞争)。A simpler alternative would be to compile shared C/ObjC files once (generating
.o
files or better yet, single.a
static library) and later linked into each test. In that case gcov will automatically merge results into single.gcno
/.gcda
pair (beware that tests have to be run serially, to avoid races when accessing gcov files).