From 1031dec2d9b5dfba214eb6bf16f13f5498ba2a54 Mon Sep 17 00:00:00 2001 From: Michal Bloch Date: Tue, 21 Jan 2020 13:19:49 +0100 Subject: [PATCH] tests: fix mocking of large-file syscall versions MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Some buildchains produce code that links to large-file versions of most syscalls (e.g. opendir → opendir64) which also need to be mocked. Change-Id: Ia1983069a15ded569172fc326e5f1de07f3cf2d4 Signed-off-by: Michal Bloch --- tests/CMakeLists.txt | 2 +- tests/lowmem-mock.hpp | 12 ++++++++++++ tests/lowmem-system-mock.cpp | 3 ++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 954e272..75394f4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -73,7 +73,7 @@ ADD_MEMORY_TESTS(lowmem-limit-test "${GLIB2_LDFLAGS}" ../src/memory/lowmem-limit.c) # lowmem-system unit test ADD_MEMORY_TESTS(lowmem-system-test "" - "-Wl,--wrap=opendir,--wrap=readdir,--wrap=closedir" + "-Wl,--wrap=opendir,--wrap=readdir,--wrap=closedir,--wrap=opendir64,--wrap=readdir64,--wrap=closedir64" lowmem-system-test.cpp lowmem-system-mock.cpp lowmem-system-env.cpp lowmem-env.cpp lowmem-env-mock.cpp ../src/memory/lowmem-system.c) # lowmem-dbus unit test diff --git a/tests/lowmem-mock.hpp b/tests/lowmem-mock.hpp index ffec288..4c418f2 100644 --- a/tests/lowmem-mock.hpp +++ b/tests/lowmem-mock.hpp @@ -38,6 +38,18 @@ return __real_##name call_args; \ } +/* Macro WRAP64 is used for wrapping the large-file versions of the base call. + * + * Its params are similar to WRAP (except global_object), but they call the base version of + * the call (so as to keep the queue of mocks intact, i.e. allow "__will_return(foo, x)" + * to return the value even inside foo64. + * + * Keep in mind this only really works when the base call is mocked as well. */ +#define WRAP64(rettype, name, def_args, call_args) \ + extern "C" rettype __wrap_##name##64 def_args { \ + return __wrap_##name call_args; \ + } + /* * Macro MOCK is used for redirecting function handlers for mocked functions from resourced * to global_test_lowmem_limit_env static object. diff --git a/tests/lowmem-system-mock.cpp b/tests/lowmem-system-mock.cpp index 182ded0..1d4b437 100644 --- a/tests/lowmem-system-mock.cpp +++ b/tests/lowmem-system-mock.cpp @@ -23,7 +23,8 @@ MOCK_SYSTEM(void, g_source_set_callback, MOCK_SYSTEM(guint, g_source_attach, (GSource *source, GMainContext *context), (source, context)) #define WRAP_SYSTEM(rettype, name, def_args, call_args) \ - WRAP(global_test_lowmem_system_env, rettype, name, def_args, call_args) + WRAP(global_test_lowmem_system_env, rettype, name, def_args, call_args) \ + WRAP64(rettype, name, def_args, call_args) WRAP_SYSTEM(DIR *, opendir, (const char *name), (name)) WRAP_SYSTEM(int, closedir, (DIR *dirp), (dirp)) -- 2.7.4