0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

gcovをお試し実行する

Posted at

gcovはC言語のプログラムのカバレッジを測定するツールのようです

テストコード

test.c
# include <stdio.h>
 
int main() {
  int testnum = 1;
 
  if (testnum == 1) {
    printf("testnum No.1 \n");
  }
  else if (testnum == 2) {
    printf("testnum No.2 \n");
  } else {
    printf("nothing to do. %d\n", testnum);
  }
}

実行

$ gcc -fprofile-arcs -ftest-coverage test.c -o test.out
$ gcov-9 test.gcda 
File 'test.c'
Lines executed:57.14% of 7
Creating 'test.c.gcov'

test.c.gcovの中身

$ cat test.c.gcov 
        -:    0:Source:test.c
        -:    0:Graph:test.gcno
        -:    0:Data:test.gcda
        -:    0:Runs:1
        -:    1:#include <stdio.h>
        -:    2: 
        1:    3:int main() {
        1:    4:  int testnum = 1;
        -:    5: 
        1:    6:  if (testnum == 1) {
        1:    7:    printf("testnum No.1 \n");
        -:    8:  }
    #####:    9:  else if (testnum == 2) {
    #####:   10:    printf("testnum No.2 \n");
        -:   11:  } else {
    #####:   12:    printf("nothing to do. %d\n", testnum);
        -:   13:  }
        -:   14:}

lcovを実行

lcovはgcovの結果を可視化するツールのようです。

install

brew install lcov

実行

$ lcov -c -d . -o lcov.info
Capturing coverage data from .
Found LLVM gcov version 10.0.0, which emulates gcov version 4.2.0
Scanning . for .gcda files ...
Found 1 data files in .
Processing test.gcda
geninfo: WARNING: ./test.gcno: Overlong record at end of file!
Unexpected version: *39A.
Invalid .gcno File!
geninfo: WARNING: cannot find an entry for test.c.gcov in .gcno file, skipping file!
Finished .info-file creation

Unexpected version: *39A.のエラーが出る。。バージョン合ってないかも?

参考

gcovによるステートメントカバレッジ計測
gcovとlcov
gcovの使い方

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?