コード カバレッジの回帰テストを自動的に行う必要がある場合。これを試して:
https://www.osadl.org/Dumping-gcov-data-at-runtime-simple-ex.online-coverage-analysis.0.html
プログラムの「main.c」内に次のように記述します。
static unsigned long long i = 0;
void __gcov_flush(void); /* check in gcc sources gcc/gcov-io.h for the prototype */
void my_handler(int signum)
{
printf("received signal\n");
printf("%llu\n", i);
__gcov_flush(); /* dump coverage data on receiving SIGUSR1 */
}
int main(int argc, char **argv)
{
struct sigaction new_action, old_action;
int n;
/* setup signal hander */
new_action.sa_handler = my_handler;
sigemptyset(&new_action.sa_mask);
new_action.sa_flags = 0;
sigaction(SIGUSR1, NULL, &old_action);
if (old_action.sa_handler != SIG_IGN)
sigaction (SIGUSR1, &new_action, NULL);
//blah......
次に、プログラムを再構築して実行します。
$ ./hello &
$ killall -USR1 hello
received signal
2514147346
このようにして、引き続き .gcda ファイルを生成する必要があります
$ gcov hello
File 'hello.c'
Lines executed:100.00% of 14
hello.c:creating 'hello.c.gcov'