题
我做了一些改动的库与项目保持在线。我跑了测试,一切仍然通过,但覆盖范围不再是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
将有盖。有任何想法吗?除了man页我无法找到任何东西。
编辑:
从注释中,你可以看到,我并没有透露一切。我就这一问题取得了一些进展。一些其他测试等功能使机盖它们运行时消失。对于PreviouslyEncountered
仅运行测试,给出了该功能的100%的覆盖。运行其他测试重置该
解决方案
我能够重构导致问题的原因,所以我再次获得100%覆盖率的代码。我不知道问题出在哪里来的。也许我会再检查一遍。
不隶属于 StackOverflow