tests: Fix mock chaining on macOS

Some tests in qemuxml2argvtest need opendir() from virpcimock, others
need opendir() from virfilewrapper.

But as of now, only opendir() from virpcimock has an effect.
real_opendir in virpcimock has a pointer to opendir$INODE64 in
libsystem_kernel.dylib instead of pointing to opendir$INODE64 in
qemuxml2argvtest (from virfilewrapper). And because the second one is
never used, tests that rely on prefixes added by virFileWrapperAddPrefix
fail.

That can be fixed if dlsym(3) is asked explicitly to search symbols in
main executable with RTLD_MAIN_ONLY before going to other dylibs.
Existing RTLD_NEXT handle results into libsystem_kernel.dylib being
searched before main executable.

Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Roman Bolshakov 2020-11-24 01:10:14 +03:00 committed by Michal Privoznik
parent c2745d009f
commit dbe922c945
2 changed files with 14 additions and 0 deletions

View File

@ -284,9 +284,21 @@
static void (*real_##name)(void); \
void wrap_##name(void)
#if defined(VIR_MOCK_LOOKUP_MAIN) && defined(__APPLE__)
# define VIR_MOCK_REAL_INIT_MAIN(name, alias) \
do { \
if (real_##name == NULL) { \
real_##name = dlsym(RTLD_MAIN_ONLY, alias); \
} \
} while (0)
#else
# define VIR_MOCK_REAL_INIT_MAIN(name, alias) \
do {} while (0)
#endif
#define VIR_MOCK_REAL_INIT(name) \
do { \
VIR_MOCK_REAL_INIT_MAIN(name, #name); \
if (real_##name == NULL && \
!(real_##name = dlsym(RTLD_NEXT, \
#name))) { \
@ -297,6 +309,7 @@
#define VIR_MOCK_REAL_INIT_ALIASED(name, alias) \
do { \
VIR_MOCK_REAL_INIT_MAIN(name, alias); \
if (real_##name == NULL && \
!(real_##name = dlsym(RTLD_NEXT, \
alias))) { \

View File

@ -19,6 +19,7 @@
#include <config.h>
#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
# define VIR_MOCK_LOOKUP_MAIN
# include "virmock.h"
# include <unistd.h>
# include <fcntl.h>