diff options
author | John Levon <john.levon@nutanix.com> | 2021-03-25 16:54:53 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-25 16:54:53 +0000 |
commit | 710a0081aa206b319161fac9bbafce14f5045ee8 (patch) | |
tree | fbf91231220be75cd05279c0492f90cf1d5ab669 /lib/common.h | |
parent | 4f4c378978f0e22ec5b803496e2971adca6a3f8f (diff) | |
download | libvfio-user-710a0081aa206b319161fac9bbafce14f5045ee8.zip libvfio-user-710a0081aa206b319161fac9bbafce14f5045ee8.tar.gz libvfio-user-710a0081aa206b319161fac9bbafce14f5045ee8.tar.bz2 |
re-work unit test mocking (#400)
Instead of trying to use the linker's --wrap, which just led to more problems
when we want to call the real function, we'll add two defines, MOCK_DEFINE() and
MOCK_DECLARE(), that behave differently when building the unit tests, such that
all wrapped functions are picked up from test/mocks.c instead, regardless of
compilation unit.
Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'lib/common.h')
-rw-r--r-- | lib/common.h | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/common.h b/lib/common.h index 7ac865e..d15017a 100644 --- a/lib/common.h +++ b/lib/common.h @@ -55,21 +55,22 @@ #define ROUND_DOWN(x, a) ((x) & ~((a)-1)) #define ROUND_UP(x,a) ROUND_DOWN((x)+(a)-1, a) -#define UNIT_TEST_SYMBOL(x) \ - typeof(x) __wrap_##x __attribute__((weak, alias(#x))) - #ifdef UNIT_TEST -#define MOCKED(r, f, ...) \ +#define MOCK_DEFINE(f) \ + (__real_ ## f) + +#define MOCK_DECLARE(r, f, ...) \ r f(__VA_ARGS__); \ r __real_ ## f(__VA_ARGS__); \ r __wrap_ ## f(__VA_ARGS__); #else /* UNIT_TEST */ -#define MOCKED(r, f, ...) \ - r f(__VA_ARGS__); \ - r __wrap_ ## f(__VA_ARGS__) +#define MOCK_DEFINE(f) (f) + +#define MOCK_DECLARE(r, f, ...) \ + r f(__VA_ARGS__); #endif /* UNIT_TEST */ |