Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
I installed gcovr and it works very well, really easy to use(and fast in comparison with lcov !).
Now I have a question that I did not find in the documentation.
When I see an "if()" statement, it sometimes contains multiple X and V's but it is only a simple statement for example
Hi @deblauwetom, thanks for these ideas!
Gcov/gcovr/lcov use assembly code level coverage data, so they show the true branch coverage in the binary. This is neither good or bad, but this leads to many compiler-generated branches being included in the coverage calculation. For some use cases, it would be wrong to hide this information. But most of the time, these invisible branches are confusing.
I started typing a lengthy response explaining why post-processing of the source code should not be done, but the TL;DR is: parsing C/C++ is complex, especially considering macros, and how compiler optimizations might affect branches. Also note that there are many C operators that branch:
Gcov actually distinguishes normal code from code that is only reachable by exceptions. Currently, gcovr uses that to ignore uncovered lines that are only exception-reachable, but doesn't ignore branches that are only taken by exceptions. The problem is, this also applies to
While the branch to the catch-clause is uncovered (✗), the code in the catch clause itself is ignored (white background) because it is only exception-reachable. The corresponding gcov report is:
(Note that on the
I think I'll change this:
This will not be perfect, but the information for a perfect solution is unavailable in this case.
Thanks for the comment! Just so I understand correctly:
So currently it's almost impossible to show intuitive information with the output gcov gives you because you can't know if the branches are "exception generated" branches or "if-test" branches?
Your understanding is correct, gcov does not provide enough info to attribute a given branch to a specific operator.
I've written a FAQ entry that discusses C++ branch coverage, and added a new
You can test this option in the gcovr development version (see the installation guide) or wait for the 4.2 release which I'll probably do later this month.