gpt4 book ai didi

c - Gcov报告意外的覆盖结果

转载 作者:行者123 更新时间:2023-11-30 18:14:42 24 4
gpt4 key购买 nike

我对库进行了一些更改,以使其与项目保持一致。我进行了测试,一切仍然通过,但覆盖率不再是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%的覆盖率。我不知道问题出在哪里。也许我会再检查一次。

关于c - Gcov报告意外的覆盖结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1294454/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com