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現在はカバーを取得しています。何か案は?マニュアルページ以外は何も見つかりません。

編集:コメントから、私がすべてを開示していないことがわかります。私は問題についていくらか進歩しました。他の機能の一部のテストでは、実行時にカバーが消えます。のテストのみを実行するPreviouslyEncounteredと、その機能を 100% カバーできます。他のテストを実行すると、これがリセットされます。

4

0 に答える 0