How to improve the branch coverage using gcovr tool

2.1k views Asked by At

I have written a sample program using C++. I have written corresponding unit tests using GUNIT framework. I was successfully able to generate.gcda and .gcno files for every source file. I used (gcov -b -l -p -c *.gcno) command in the folder where the .gcno files were generated. I am using gcov 7.5.0 . When i ran this command i saw that it gave me a)Lines covergae in percentage b)Branches covered in percentage c)Taken atleast once . Next i ran (gcovr --html -o Filename.html -r /path_to_C_sourceFiles/ .) command to generate the html output for this data. In the html file i see that the branch covergae data is extracted from the taken atleast once data which was generated by the gcov. Why is the html not taking the branches covered percentage from the gcov data and displaying it as branch covergae. Taken atleast data given by the gcov tool is a reduced number when compared to branches percentage. What is this taken atleast once?

1

There are 1 answers

1
amon On

A branch is covered if it was taken at least once. If a branch is executed multiple times, it is not more covered. So gcovr primarily considers covered/uncovered status for lines and branches, whereas GCC's gcov tool shows execution counts and branch probabilities.

Having access to the branch probabilities can be useful. Not in the context of testing, but perhaps for low-level code optimization. If you need that data, you will likely want to look at the gcov files yourself.

However, the next version of gcovr (expected to be gcovr 4.3) will show branch counts (not percentages) in the HTML report:

For each line with branch coverage data, there will be a popup that shows full branch counts.

You can use this functionality right now if you install gcovr's development version:

pip install git+https://github.com/gcovr/gcovr.git