linux-test-project / lcov

LCOV
GNU General Public License v2.0
866 stars 234 forks source link

inconsistent branch coverage summary #303

Closed icsfy closed 2 weeks ago

icsfy commented 2 weeks ago

lcov: LCOV version 2.1-1 test.cpp:

#include <stdio.h>
int func1(int n)
{
        if (n < 5)
                return n+10;
        return n+100;
}

int main(int argc, char *argv[])
{
        int a[100];

        a[argc] = func1(argc);
        if (a[argc])
                printf("111\n");
}

compile and run:

# g++ --coverage test.cpp
# ./a.out
111

use --rc no_exception_branch=1 and then use --summary to show the output .info:

[root@a6ee5ca3eff6 ~]# lcov -c -d . -o 1.info --branch --rc no_exception_branch=1
Capturing coverage data from .
geninfo cmd: '/usr/bin/geninfo . --output-filename 1.info --rc no_exception_branch=1 --branch-coverage'
Found gcov version: 14.1.1
Using intermediate gcov format
Recording 'internal' directories:
        /root
Writing temporary data to /tmp/geninfo_datNd7H
Scanning . for .gcda files ...
Found 1 data files in .
using: chunkSize: 1, nchunks:1, intervalLength:0
Finished processing 1 GCDA file
Apply filtering..
Finished filter file processing
Finished .info-file creation
Summary coverage rate:
  source files: 1
  lines.......: 88.9% (8 of 9 lines)
  functions...: 100.0% (2 of 2 functions)
  branches....: 60.0% (3 of 5 branches)
Message summary:
  no messages were reported
[root@a6ee5ca3eff6 ~]# lcov --summary 1.info --branch
Reading tracefile 1.info.
Summary coverage rate:
  source files: 1
  lines.......: 88.9% (8 of 9 lines)
  functions...: 100.0% (2 of 2 functions)
  branches....: 50.0% (2 of 4 branches)
Message summary:
  no messages were reported

The branch coverage summary first gives branches....: 60.0% (3 of 5 branches), but later is branches....: 50.0% (2 of 4 branches)

And man lcovrc tells:

The value no_exception_branch = 1 is equivalent to the --filter exception command line option.

but --filter does not recognize 'exception': geninfo: ERROR: unknown argument for --filter: 'exception'. And there is a exception argument which belongs to --ignore-errors option in man genhtml:

              exception:
                 Exclude  branches  related  to  C++  exception handling from branch coverage.  Whether C++ exception
                 branches are identified and removed is dependent on your compiler/toolchain correctly  marking  them
                 in the generated coverage data.  See the no_exception_branch section of man lcovrc(5).
henry2cox commented 2 weeks ago

The first issue was an accounting bug - fixed in eb5bd65591. (It also turns out that at least one of the lcov regression tests exposed the bug - but was not sensitive to the difference and did not notice. Sigh.)

The second appears to be a misunderstanding or an inconsistency in your environment/configuration.

In any event: please try your testcase again with this update - and close the issue if it appears fixed (or update the description to explain the new problem and how to see it).

Thanks

Henry