linux-test-project / lcov

LCOV
GNU General Public License v2.0
867 stars 235 forks source link

the branch coverage is strange. #240

Closed yangsee0 closed 9 months ago

yangsee0 commented 9 months ago

Test: gcc version 8.5.0 20210514 (Red Hat 8.5.0-15) (GCC)

I tested the gcov version differently on the same server, but the branch coverage is different. What's wrong with it? Please give your opinion. Thank you.

lcov 1.6.20230126 image

lcov 2.0 image

yangsee0 commented 9 months ago

g++ -o sol -fprofile-arcs -ftest-coverage main.cpp sol.cpp ./sol gcov -abcf main.cpp sol.cpp lcov --rc lcov_branch_coverage=1 --capture --directory ./ --output-file sol.info genhtml --branch-coverage ./sol.info --output-directory ./cov

henry2cox commented 9 months ago

Exception handlers. Did you happen to compile and run your lcov 1.6 test with gcc (C compiler) and the 2.0 test with g++ (C++ compiler)? If so: that would explain the difference. For lcov 2.0, you can use filtering to remove some of the bogus branches. $ man genhtml <- then search for "filter" "branch" and "exception"

yangsee0 commented 9 months ago

Confirmation is late. We have confirmed that it has been resolved by adding the --filter branch option you informed us. Thank you for your answer.

before : genhtml --branch-coverage ./sol.info --output-directory ./cov
after : genhtml --branch-coverage --filter branch ./sol.info --output-directory ./cov

GuWei007 commented 4 months ago

“--filter branch” works for me, thanks very much