tests: fix mocking of large-file syscall versions 56/222956/1
authorMichal Bloch <m.bloch@partner.samsung.com>
Tue, 21 Jan 2020 12:19:49 +0000 (13:19 +0100)
committerMichal Bloch <m.bloch@partner.samsung.com>
Tue, 21 Jan 2020 12:36:57 +0000 (13:36 +0100)
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 <m.bloch@partner.samsung.com>
tests/CMakeLists.txt
tests/lowmem-mock.hpp
tests/lowmem-system-mock.cpp

index 954e272..75394f4 100644 (file)
@@ -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
index ffec288..4c418f2 100644 (file)
                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.
index 182ded0..1d4b437 100644 (file)
@@ -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))