I use testing for some C program. To do this, I use GCC -Wl,--wrap=open
to mock the stdlib function open()
and verify that it was called with the correct parameters.
However, gcov has some problems writing the file .gcda
. I assume that the layout that I define is used not only by my tests, but also by gcov. Here is a small example of how to reproduce this:
#include <stdio.h>
int __wrap_open(const char *path, int flags, int mode)
{
printf("hello from __wrap_open\n");
return -1;
}
int main(void)
{
return 0;
}
And compile it with gcc main.c -Wl,--wrap=open -fprofile-arcs -ftest-coverage -lgcov
. To simplify a simple example, I removed the module testing part with CMocka to show the error I am encountering.
a.out
GCC gcov 6.3.0:
$ ./a.out
hello from __wrap_open
hello from __wrap_open
profiling:/home/romain/wrap-bug/main.gcda:Cannot open
open()
gcov ? , gcov __real_open()
?