I want to implement unit testing using the -Wl,--wrap
trick, however this doesn't work for functions within the same file. One solution is to rename the function (after it has been defined) to the wrapped one, as suggested here: https://stackoverflow.com/a/11758777/526568
I came up with the following macro to avoid having to manually define __wrap_foo
:
#define UNIT_TEST_SYMBOL(x) \
typeof(x) __wrap_##x __attribute__((weak, alias(#x)))
void foo(void) {
/* function body */
}
UNIT_TEST_SYMBOL(foo);
#define foo __wrap_foo
void bar(void) {
foo();
}
I then compile with -Wl,--wrap=foo
.
Is it possible to avoid having to manually define foo
to __wrap_foo
? Can this be somehow part of the UNIT_TEST_SYMBOL
?