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.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With