Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gcov报告意外的封面结果_C_Gcc_Code Coverage_Gcov - Fatal编程技术网

Gcov报告意外的封面结果

Gcov报告意外的封面结果,c,gcc,code-coverage,gcov,C,Gcc,Code Coverage,Gcov,我对库做了一些更改,使其与项目保持一致。我进行了测试,所有测试都通过了,但覆盖率不再是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 =

我对库做了一些更改,使其与项目保持一致。我进行了测试,所有测试都通过了,但覆盖率不再是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:}
在返回1之前添加打印;将执行。它不会得到保险,但返回1现在有了保险。有什么想法吗?除了手册,我什么也找不到

编辑:
从评论中你可以看到,我没有透露一切。我在这个问题上取得了一些进展。其他一些测试和其他函数在运行时会导致盖子消失。只运行前面遇到的测试可以100%覆盖该函数。运行其他测试会重置此问题。

我能够重构导致问题的代码,因此我再次获得100%的覆盖率。我不知道问题出在哪里。也许我会再检查一遍。

哪个版本的gcov-和gcc-以及在哪个平台上?然而,只要你或多或少是最新的,这不太可能是一个主要因素。为什么当注释说numbertrackrmax是10000时,函数执行了201次?你把它改成100进行测试了吗?对函数的奇数调用从何而来?同样,如果调用函数100次以添加数字,然后100次以检查数字是否存在,为什么要添加数字200次?是否使用一些“-O”选项优化代码?您是否尝试过未经优化的覆盖范围?这更有意义吗?为了测试,我将NUMBERTRACKERMAX减少到100。我也怀疑优化,但GCC默认值为无。