This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: GCOV type of coverage


I have been looking into gcov and the type of coverage it calculates.

Based on your example and another simple example of my own gcov can
track statement, decision, and MC/DC statistics.
However, what it reports is not correct.

If you try the example in man gcov you wont get the results documented
in the manual.

$ cat tmp.c
#include <stdio.h>

int main (void)
{
  int i, total;

  total = 0;

  for (i = 0; i < 10; i++)
    total += i;

  if (total != 45)
    printf ("Failure\n");
  else
    printf ("Success\n");
  return 0;
}

$ gcov -b tmp.c
File `tmp.c'
Lines executed:88.89% of 9
Branches executed:100.00% of 4
Taken at least once:75.00% of 4
Calls executed:66.67% of 3
tmp.c:creating `tmp.c.gcov'

$ cat tmp.c.gcov
        -:    0:Source:tmp.c
        -:    0:Graph:tmp.gcno
        -:    0:Data:tmp.gcda
        -:    0:Runs:1
        -:    0:Programs:1
        -:    1:#include <stdio.h>
        -:    2:
        -:    3:int main (void)
function main called 1 returned 100% blocks executed 78%
        1:    4:{
call    0 returned 100%
        1:    5:  int i, total;
        -:    6:
        1:    7:  total = 0;
        -:    8:
       11:    9:  for (i = 0; i < 10; i++)
branch  0 taken 91% (fallthrough)
branch  1 taken 9%
       10:   10:    total += i;
        -:   11:
        1:   12:  if (total != 45)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:   13:    printf ("Failure\n");
call    0 never executed
        -:   14:  else
        1:   15:    printf ("Success\n");
call    0 returned 100%
        1:   16:  return 0;
        -:   17:}

You will notice that tmp.c.gcov is essentialy the same as the expected
output but the reported statistics is incorrect.  I have gone ahead
and reported it as a bug.

--
Frodak


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]