relatando gcov resultados inesperados cobertura
-
18-09-2019 - |
Pergunta
Eu fiz algumas mudanças para uma biblioteca para mantê-lo em linha com um projeto. Eu corri o teste e tudo ainda passou, mas a cobertura não é mais de 100%. I investigado e viu que o código é apenas Não executado relatou. Mas eu não tenho idéia porque gcov não está relatando a cobertura para a linha quando se está em execução.
Este é o código:
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;
}
Este é o teste:
/* 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);
}
E este é o resultado de cobertura:
-: 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:}
Adicionando uma impressão antes return 1;
seria executado. Não seria obter cobertura, mas o return 1
agora teria cobertura. Alguma ideia? diferente de páginas man Eu não posso encontrar nada.
Edit:
A partir dos comentários que você pode ver que eu não revelou tudo. I feito alguns progressos no problema. Alguns dos outros testes de outras funções causar a tampa para desaparecer quando eles correm. Correndo somente os testes para PreviouslyEncountered
dá 100 por cento de cobertura para essa função. A execução de outros testes redefine isso.
Solução
Eu era capaz de refatorar o código que causou o problema, então eu estou recebendo uma cobertura de 100% novamente. Eu não tenho nenhuma idéia de onde o problema veio. Talvez eu irá verificar-lo novamente.