0

我对库进行了一些更改,以使其与项目保持一致。我进行了测试,一切都通过了,但覆盖率不再是 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现在会有覆盖。有任何想法吗?除了手册页,我找不到任何东西。

编辑:从评论中你可以看到我没有透露所有内容。我在这个问题上取得了一些进展。其他一些测试其他功能会导致封面在运行时消失。仅运行测试可以PreviouslyEncountered100% 覆盖该功能。运行其他测试会重置它。

4

0 回答 0