문제

프로젝트와 함께 인라인을 유지하기 위해 도서관을 변경했습니다. 나는 시험을 실행했고 모든 것이 여전히 통과되었지만 적용 범위는 더 이상 100%가 아닙니다. 나는 조사하고 코드가보고되지 않은 것을 보았다. 그러나 GCOV가 실행 중일 때 라인에 대한 보도를보고하지 않는 이유는 전혀 모릅니다.

이것은 코드입니다.

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;

} 

이것은 테스트입니다.

/* 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);
}

그리고 이것은 커버리지 결과입니다.

       -:   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:}

전에 인쇄를 추가합니다 return 1; 실행됩니다. 커버리지가 아니라 return 1 이제 덮개가있을 것입니다. 어떤 아이디어? 사람 페이지 외에는 아무것도 찾을 수 없습니다.

편집 : 의견에서 내가 모든 것을 공개하지 않았다는 것을 알 수 있습니다. 나는 문제를 약간 발전시켰다. 다른 기능 중 일부는 다른 기능을 통해 커버가 실행될 때 사라집니다. 테스트 만 실행합니다 PreviouslyEncountered 그 기능에 대해 100 % 커버를 제공합니다. 다른 테스트를 실행하면 이것을 재설정합니다.

도움이 되었습니까?

해결책

문제를 일으킨 코드를 리팩토링 할 수 있으므로 다시 100% 커버리지를 받고 있습니다. 문제가 어디에서 왔는지 모르겠습니다. 어쩌면 다시 확인하겠습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top