问题
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.
回答1:
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).
回答2:
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.
来源:https://stackoverflow.com/questions/6513622/is-there-a-way-to-merge-two-gcda-files-into-one