Exclude Branch from coverage with Gcov / Gcovr

112 Views Asked by At

I'm trying to get some branches that I am not interested in testing removed from my test results, but I'm unable to get the "EXCL_BR" markers to work.

With this sample code

int32_t function(uint32_t a){
    if (a == 1) {
        a = a * 2;
    } else {
        /* GCOVR_EXCL_BR_START : these branch will never run */
        a = a * 3;
        /* GCOVR_EXCL_BR_STOP */
    }

    if (a < 25) {
        a = a + 2;
    }// GCOVR_EXCL_BR_START
    // GCOVR_EXCL_BR_STOP

    while (a > 123) {
        // GCOVR_EXCL_BR_START
    }// GCOV_EXCL_BR_STOP

    return a;
}

int32_t main (void) {

    uint32_t value = 1;

    function(value);

    return 0;
}

I compile and generate a GCOVR report with

gcc -Og --coverage -ftest-coverage -fprofile-arcs -o main.o main.c
./main.o
gcovr --html --html-details -r . --object-directory=. -o index.html

And this is the report I get

enter image description here

I was expecting to get 100% branch coverage with my code, by "excluding" the branches that can't be hit by calling function() with 1 as parameter.

Is my understanding of the EXCL_BR markers correct? Should those unreachable branches be tagged as hit and the report to show 100% in branches.

0

There are 0 best solutions below