Skip to content

Instantly share code, notes, and snippets.

@osamu0329nakamura
Created August 8, 2015 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osamu0329nakamura/a9fa216cba4f100b8e28 to your computer and use it in GitHub Desktop.
Save osamu0329nakamura/a9fa216cba4f100b8e28 to your computer and use it in GitHub Desktop.
kcovでラインカバレッジを収集する ref: http://qiita.com/osamu0329/items/7097fe0219675777c490
#include <stdio.h>
int fib(int n)
{
if (n <= 1) {
return 1;
}
return fib(n - 1) + fib(n - 2);
}
int main(int argc, char **argv)
{
int n;
if (argc == 1) {
fprintf(stderr, "Usage\nfib n\n");
exit(EXIT_FAILURE);
}
n = atoi(argv[1]);
printf("%d\n", fib(n));
exit(EXIT_SUCCESS);
}
# yum install cmake
# yum install elfutils-libelf-devel elfutils-libs elfutils-devel
# yum install libcurl-devel
# yum install binutils-devel
$ cd kcov-28
$ mkdir build
$ cd cmake ..
$ make
$ sudo make install
$ gcc -g fib.c
kcov out-dir in-file [args...]
out-dir: カバレッジデータを出力するディレクトリ
in-file: カバレッジデータを収集する実行可能ファイル
args: in-fileのプログラム引数
$ kcov fib.out fib 10
89
$ ls kcov.out/index.html
kcov.out/index.html
$ find . -name "*.xml"
./kcov.out/fib/cobertura.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment