GCOV type of coverage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

I?ve been searching the Internet to discover what type of coverage GCOV
produces and I do not agree with same statements that have been made. 
Of course, im not an expert in testing and am not claiming to be right, but
please look at the examples below and tell what you think.

See this example:

#include <stdio.h>

int functionToTest(int a , int b , int c)
{
   if(a || (b && c))
   {
     printf("executed\n");
    }
}

int main()
{
  functionToTest(0,1,0);
  functionToTest(0,0,1);
  functionToTest(1,0,1);
  /*functionToTest(0,1,1);*/   /* -> the missing test to have 100% modified
decision/condition coverage */
  return 1;
}

This is the GCOV output (gcov -abcfl xpto.gcda):

        -:    0:Source:xpto.c
        -:    0:Graph:xpto.gcno
        -:    0:Data:xpto.gcda
        -:    0:Runs:1
        -:    0:Programs:1
        -:    1:#include <stdio.h>
        -:    2:
        -:    3:
        -:    4:int functionToTest(int a , int b , int c)
function functionToTest called 3 returned 100% blocks executed 100%
        3:    5:{
        3:    6:   if(a || (b && c))
        3:    6-block  0
branch  0 taken 2 (fallthrough)
branch  1 taken 1
        2:    6-block  1
branch  2 taken 1 (fallthrough)
branch  3 taken 1
        1:    6-block  2
branch  4 taken 0 (fallthrough)
branch  5 taken 1
        -:    7:   {
        1:    8:     printf("executed\n");
        1:    8-block  0
call    0 returned 1
        -:    9:    }
        3:   10:}
        3:   10-block  0
        -:   11:
        -:   12:int main()
function main called 1 returned 100% blocks executed 100%
        1:   13:{
        1:   14:  functionToTest(0,1,0);
        1:   14-block  0
call    0 returned 1
        1:   15:  functionToTest(0,0,1);
call    0 returned 1
        1:   16:  functionToTest(1,0,1);
call    0 returned 1
        -:   17:  /*functionToTest(0,1,1);*/
        1:   18:  return 1;
        -:   19:}


The output printed is:

Function 'functionToTest'
Lines executed:100.00% of 4
No branches
No calls

Function 'main'
Lines executed:100.00% of 5
No branches
No calls

File 'xpto.c'
Lines executed:100.00% of 9
Branches executed:100.00% of 6
Taken at least once:83.33% of 6
No calls
xpto.c:creating 'xpto.gcda##xpto.c.gcov'

Think the statement coverage is more or less inline with the ?lines
executed?, so no problem here.

>From other examples I have been studying, the ?Branches executed? gives a
metric related to the number of branches that have been tested (with either
true or false). I don?t see a correlation between this metric and any other
normally found (statement coverage, decision coverage, condition coverage or
modified decision/condition coverage).

The ?Taken at least once? metric I believe it is a very powerful metric
since, from my understanding of the examples I have made, it gives MODIFIED
DECISION/CONDITION COVERAGE.

The ?Taken at least once? metric could give condition coverage if and only
if the expression only contains one condition. Since the above condition is
of the kind ? A or (B and C)? it does not give Condition Coverage.

I could elaborate more about how I think this is, in fact, modified
decision/condition, but would like to ear some feedback. Perhaps I?m making
a huge mistake somewhere?

Just to point out, these metrics (statement, condition and modified
condition/decision) are very important to systems following the DAL
specification and other important specifications.


Thank you very much!
Kind regards
Manuel Coutinho



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux