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.
のエラーが出る。。バージョン合ってないかも?