views:

127

answers:

1

I made some changes to a library to keep it inline with a project. I ran the test and everything still passed but the coverage is no longer 100%. I investigated and saw that the code is executed just not reported. But I have no idea why gcov is not reporting coverage for the line when it is executing.

This is the code:

int32_t PreviouslyEncountered(uint32_t n)
{
  uint32_t i;

  /* Search thru all the numbers encoountered so far see if there is a match */
  for(i = 0; i < xcount; i++)
  {
    if(n == collection[i])
    {
      return 1; /* This value has been seen before */
    }
  }

  /* Add the number to encountered values if there is space */
  if(xcount < NUMBERTRACKERMAX )
  {
    collection[xcount] = n;
    xcount++;
  }
  else
  {
    return NUMBERTRACKERMAX ;
  }

  return 0;

}

This is the test:

/* Fill with 10000 elements */
for(i = 0; i < NUMBERTRACKERMAX; i++)
{
  assert(PreviouslyEncountered(i) == 0);
}

/* Test that all 10000 elements are present */
for(i = 0; i < NUMBERTRACKERMAX; i++)
{
  assert(PreviouslyEncountered(i) == 1);
}

And this is the coverage results:

       -:   51:int32_t PreviouslyEncountered(uint32_t n)
function PreviouslyEncountered called 201 returned 100% blocks executed 90%
     201:   52:{
     201:   53:  uint32_t i;
       -:   54:
       -:   55:  /* Search thru all the numbers encoountered so far see if there is a match */
   20101:   56:  for(i = 0; i < xcount; i++)
       -:   57:  {
   19900:   58:    if(n == collection[i])
       -:   59:    {
   #####:   60:      return 1; /* This value has been seen before */
       -:   61:    }
       -:   62:  }
       -:   63:
       -:   64:  /* Add the number to encountered values if there is space */
     201:   65:  if(xcount < NUMBERTRACKERMAX )
       -:   66:  {
     200:   67:    collection[xcount] = n;
     200:   68:    xcount++;
       -:   69:  }
       -:   70:  else
       -:   71:  {
       1:   72:    return NUMBERTRACKERMAX ;
       -:   73:  }
       -:   74:
     200:   75:  return 0;
       -:   76:
       -:   77:}

Adding a print before return 1; would execute. It would not get coverage but the return 1 would now have cover. Any ideas? other than man pages I cant find anything.

Edit: From the comments you can see that I did not disclose everything. I made some progress on the problem. Some of the other tests other functions cause the cover to disappear when they run. Running only the tests for PreviouslyEncountered gives 100 percent cover for that function. Running other tests resets this.

A: 

I was able to refactor the code that cause the problem so I am get 100% again. I have no real idea where the problem came from. Maybe I will see it again?

Gerhard