[libvirt] [PATCH 00/11] Fix 10 tests on macOS

Hi! This patch series attempts to reduce the number of failing tests on macOS. The fixes involve some funk with macOS dynamic and static linkers, dyld and ld64, respectively. As result, instead of 15 failing tests we get only 5. The tests have been fixed: qemublocktest qemumonitorjsontest viriscsitest virmacmaptest virnetserverclienttest vircryptotest qemufirmwaretest domaincapstest commandtest sockettest The tests are still failing: qemumemlocktest storagepoolxml2argvtest qemuxml2xmltest qemusecuritytest qemuxml2argvtest qemucapsprobe doesn't yet works but I started working on the fix. The failing tests depend on virpcimock that is guarded by ifdefs so no functions are injected and the mock is no-op on macOS. How can we fix the tests that rely on the mock? Should we select only specific tests to run on macOS or we should make virpci mock cross-platform? Skipping them entirely is not an option IMO as I think qemu driver can be used on macOS with qemu/hvf/haxm domains and the tests are helpful for the domains. And as soon as we get working tests and qemucapsprobe I'd want to resend hvf patchset. Best regards, Roman Roman Bolshakov (11): tests: Don't test octal localhost IP in sockettest on macOS tests: Avoid IPv4-translated IPv6 address in sockettest tests: Preload mocks with DYLD_INSERT_LIBRARIES on macOS tests: Add lib- prefix to all mocks tests: Remove -module flag for mocks tests: Drop /private CWD prefix in commandhelper build: Use flat namespace for libvirt on macOS tests: Lookup extended stat/lstat in mocks tests: Use flat namespace on macOS tests: Avoid gnulib replacements in mocks tests: Make references to global symbols indirect in test drivers configure.ac | 1 + src/Makefile.am | 9 +- tests/Makefile.am | 199 +++++++++++++++++---------------- tests/bhyveargv2xmltest.c | 2 +- tests/bhyvexml2argvtest.c | 2 +- tests/bhyvexml2xmltest.c | 2 +- tests/commandhelper.c | 9 ++ tests/domaincapstest.c | 6 +- tests/fchosttest.c | 2 +- tests/libxlxml2domconfigtest.c | 2 +- tests/nsstest.c | 2 +- tests/qemucaps2xmltest.c | 2 +- tests/qemucapsprobe.c | 2 +- tests/qemumemlocktest.c | 3 +- tests/qemumonitorjsontest.c | 2 +- tests/qemuxml2argvtest.c | 8 +- tests/qemuxml2xmltest.c | 6 +- tests/sockettest.c | 6 +- tests/testutils.c | 4 +- tests/testutils.h | 18 ++- tests/vircaps2xmltest.c | 2 +- tests/vircgrouptest.c | 2 +- tests/vircryptotest.c | 2 +- tests/virfilecachetest.c | 2 +- tests/virfiletest.c | 2 +- tests/virfilewrapper.c | 5 + tests/virfirewalltest.c | 2 +- tests/virhostcputest.c | 2 +- tests/virhostdevtest.c | 2 +- tests/viriscsitest.c | 3 +- tests/virmacmaptest.c | 2 +- tests/virmock.h | 10 ++ tests/virmockstathelpers.c | 18 +++ tests/virnetdaemontest.c | 2 +- tests/virnetdevbandwidthtest.c | 2 +- tests/virnetdevtest.c | 2 +- tests/virnetserverclienttest.c | 2 +- tests/virnettlscontexttest.c | 2 +- tests/virnettlssessiontest.c | 2 +- tests/virpcitest.c | 2 +- tests/virpolkittest.c | 2 +- tests/virportallocatortest.c | 2 +- tests/virsystemdtest.c | 2 +- tests/virusbtest.c | 2 +- 44 files changed, 214 insertions(+), 149 deletions(-) -- 2.22.0

getaddrinfo on macOS doesn't interpret octal IPv4 addresses. Only inet_aton can be used for that. Therefore, from macOS standpoint "0177.0.0.01" is not the same as "127.0.0.1". The issue was also discovered by python and dotnet core: https://bugs.python.org/issue27612 https://github.com/dotnet/corefx/issues/8362 Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- tests/sockettest.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/sockettest.c b/tests/sockettest.c index 859f02e51e..2b21352c13 100644 --- a/tests/sockettest.c +++ b/tests/sockettest.c @@ -465,7 +465,11 @@ mymain(void) DO_TEST_LOCALHOST("127.0.0.1", true); DO_TEST_LOCALHOST("2130706433", true); + + /* Octal IPv4 doesn't work in getaddrinfo on macOS */ +#ifndef __APPLE__ DO_TEST_LOCALHOST("0177.0.0.01", true); +#endif DO_TEST_LOCALHOST("::1", true); DO_TEST_LOCALHOST("0::1", true); DO_TEST_LOCALHOST("0:0:0::1", true); -- 2.22.0

On Wed, Aug 21, 2019 at 07:13:13PM +0300, Roman Bolshakov wrote:
getaddrinfo on macOS doesn't interpret octal IPv4 addresses. Only inet_aton can be used for that. Therefore, from macOS standpoint "0177.0.0.01" is not the same as "127.0.0.1".
The issue was also discovered by python and dotnet core: https://bugs.python.org/issue27612 https://github.com/dotnet/corefx/issues/8362
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- tests/sockettest.c | 4 ++++ 1 file changed, 4 insertions(+)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

getnameinfo on macOS formats certain IPv6 addresses as IPv4-translated addresses. The following pattern has been observed: ::ffff is formated as ::0.0.255.255 ::fffe is formated as ::0.0.255.254 ::ffff:0 is formated as ::255.255.0.0 ::fffe:0 is formated as ::255.254.0.0 ::ffff:0:0 is formated as ::ffff:0.0.0.0 ::fffe:0:0 is formated as ::fffe:0:0 ::ffff:0:0:0 is formated as ::ffff:0:0:0 The getnameinfo behavior causes a failure for: DO_TEST_PARSE_AND_FORMAT("::ffff", AF_UNSPEC, true); Use non-ambigious IPv6 for parse/format testing. Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- tests/sockettest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sockettest.c b/tests/sockettest.c index 2b21352c13..29a565de40 100644 --- a/tests/sockettest.c +++ b/tests/sockettest.c @@ -378,7 +378,7 @@ mymain(void) DO_TEST_PARSE_AND_FORMAT("::1", AF_INET, false); DO_TEST_PARSE_AND_FORMAT("::1", AF_INET6, true); DO_TEST_PARSE_AND_FORMAT("::1", AF_UNIX, false); - DO_TEST_PARSE_AND_FORMAT("::ffff", AF_UNSPEC, true); + DO_TEST_PARSE_AND_FORMAT("::fffe:0:0", AF_UNSPEC, true); /* tests that specify a network that should contain the range */ DO_TEST_RANGE("192.168.122.1", "192.168.122.1", "192.168.122.1", 24, 1, true); -- 2.22.0

On Wed, Aug 21, 2019 at 07:13:14PM +0300, Roman Bolshakov wrote:
getnameinfo on macOS formats certain IPv6 addresses as IPv4-translated addresses. The following pattern has been observed: ::ffff is formated as ::0.0.255.255 ::fffe is formated as ::0.0.255.254 ::ffff:0 is formated as ::255.255.0.0 ::fffe:0 is formated as ::255.254.0.0 ::ffff:0:0 is formated as ::ffff:0.0.0.0 ::fffe:0:0 is formated as ::fffe:0:0 ::ffff:0:0:0 is formated as ::ffff:0:0:0
The getnameinfo behavior causes a failure for: DO_TEST_PARSE_AND_FORMAT("::ffff", AF_UNSPEC, true);
Use non-ambigious IPv6 for parse/format testing.
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- tests/sockettest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

LD_PRELOAD has no effect on macOS. Instead, dyld(1) provides a way for symbol hooking via DYLD_INSERT_LIBRARIES. The variable should contain colon-separated paths to the dylibs to be inserted. Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- tests/testutils.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/testutils.h b/tests/testutils.h index 8c12fd7c12..07dda6e355 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -117,9 +117,15 @@ int virTestMain(int argc, return virTestMain(argc, argv, func, NULL); \ } +#ifdef __APPLE__ +# define PRELOAD_VAR "DYLD_INSERT_LIBRARIES" +#else +# define PRELOAD_VAR "LD_PRELOAD" +#endif + #define VIR_TEST_PRELOAD(lib) \ do { \ - const char *preload = getenv("LD_PRELOAD"); \ + const char *preload = getenv(PRELOAD_VAR); \ if (preload == NULL || strstr(preload, lib) == NULL) { \ char *newenv; \ if (!virFileIsExecutable(lib)) { \ @@ -132,7 +138,7 @@ int virTestMain(int argc, perror("virAsprintf"); \ return EXIT_FAILURE; \ } \ - setenv("LD_PRELOAD", newenv, 1); \ + setenv(PRELOAD_VAR, newenv, 1); \ execv(argv[0], argv); \ } \ } while (0) -- 2.22.0

On Wed, Aug 21, 2019 at 07:13:15PM +0300, Roman Bolshakov wrote:
LD_PRELOAD has no effect on macOS. Instead, dyld(1) provides a way for symbol hooking via DYLD_INSERT_LIBRARIES. The variable should contain colon-separated paths to the dylibs to be inserted.
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- tests/testutils.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

In preparation libtool "-module" flag removal, add lib prefix to all mock shared objects. While at it, introduce VIR_TEST_MOCK macros that makes path out of mock name to be used with VIR_TEST_PRELOAD or VIR_TEST_MAIN_PRELOAD. That, hopefully, improves readability, reduces line length and allows to tailor VIR_TEST_MOCK for specific platform if it has shared library suffix different from ".so". Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- tests/Makefile.am | 194 ++++++++++++++++----------------- tests/bhyveargv2xmltest.c | 2 +- tests/bhyvexml2argvtest.c | 2 +- tests/bhyvexml2xmltest.c | 2 +- tests/domaincapstest.c | 6 +- tests/fchosttest.c | 2 +- tests/libxlxml2domconfigtest.c | 2 +- tests/nsstest.c | 2 +- tests/qemucaps2xmltest.c | 2 +- tests/qemucapsprobe.c | 2 +- tests/qemumemlocktest.c | 3 +- tests/qemumonitorjsontest.c | 2 +- tests/qemuxml2argvtest.c | 8 +- tests/qemuxml2xmltest.c | 6 +- tests/testutils.c | 4 +- tests/testutils.h | 4 + tests/vircaps2xmltest.c | 2 +- tests/vircgrouptest.c | 2 +- tests/vircryptotest.c | 2 +- tests/virfilecachetest.c | 2 +- tests/virfiletest.c | 2 +- tests/virfirewalltest.c | 2 +- tests/virhostcputest.c | 2 +- tests/virhostdevtest.c | 2 +- tests/viriscsitest.c | 3 +- tests/virmacmaptest.c | 2 +- tests/virnetdaemontest.c | 2 +- tests/virnetdevbandwidthtest.c | 2 +- tests/virnetdevtest.c | 2 +- tests/virnetserverclienttest.c | 2 +- tests/virnettlscontexttest.c | 2 +- tests/virnettlssessiontest.c | 2 +- tests/virpcitest.c | 2 +- tests/virpolkittest.c | 2 +- tests/virportallocatortest.c | 2 +- tests/virsystemdtest.c | 2 +- tests/virusbtest.c | 2 +- 37 files changed, 143 insertions(+), 143 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 6b5d05bbed..713dc30de3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -206,16 +206,16 @@ test_programs = virshtest sockettest \ $(NULL) test_libraries = libshunload.la \ - virportallocatormock.la \ - virnetdaemonmock.la \ - virnetserverclientmock.la \ - vircgroupmock.la \ - virpcimock.la \ - virnetdevmock.la \ - virrandommock.la \ - virhostcpumock.la \ - domaincapsmock.la \ - virfilecachemock.la \ + libvirportallocatormock.la \ + libvirnetdaemonmock.la \ + libvirnetserverclientmock.la \ + libvircgroupmock.la \ + libvirpcimock.la \ + libvirnetdevmock.la \ + libvirrandommock.la \ + libvirhostcpumock.la \ + libdomaincapsmock.la \ + libvirfilecachemock.la \ $(NULL) if WITH_REMOTE @@ -234,11 +234,11 @@ test_programs += fchosttest test_programs += scsihosttest test_programs += vircaps2xmltest test_programs += virresctrltest -test_libraries += virusbmock.la \ - virnetdevbandwidthmock.la \ - virnumamock.la \ - virtestmock.la \ - virfilemock.la \ +test_libraries += libvirusbmock.la \ + libvirnetdevbandwidthmock.la \ + libvirnumamock.la \ + libvirtestmock.la \ + libvirfilemock.la \ $(NULL) endif WITH_LINUX @@ -250,7 +250,7 @@ if WITH_DBUS test_programs += virdbustest \ virsystemdtest \ $(NULL) -test_libraries += virdbusmock.la +test_libraries += libvirdbusmock.la if WITH_POLKIT test_programs += virpolkittest endif WITH_POLKIT @@ -291,10 +291,10 @@ test_programs += qemuxml2argvtest qemuxml2xmltest \ test_helpers += qemucapsprobe test_libraries += libqemumonitortestutils.la \ libqemutestdriver.la \ - qemuxml2argvmock.la \ - qemucaps2xmlmock.la \ - qemucapsprobemock.la \ - qemucpumock.la \ + libqemuxml2argvmock.la \ + libqemucaps2xmlmock.la \ + libqemucapsprobemock.la \ + libqemucpumock.la \ $(NULL) endif WITH_QEMU @@ -324,7 +324,7 @@ endif WITH_VMWARE if WITH_BHYVE test_programs += bhyvexml2argvtest bhyvexml2xmltest bhyveargv2xmltest -test_libraries += bhyvexml2argvmock.la bhyveargv2xmlmock.la +test_libraries += libbhyvexml2argvmock.la libbhyveargv2xmlmock.la endif WITH_BHYVE if WITH_CIL @@ -379,7 +379,7 @@ endif WITH_LINUX if WITH_NSS test_helpers += nsslinktest nssguestlinktest test_programs += nsstest nssguesttest -test_libraries += nssmock.la +test_libraries += libnssmock.la endif WITH_NSS test_programs += storagevolxml2xmltest @@ -555,10 +555,10 @@ libqemutestdriver_la_SOURCES = libqemutestdriver_la_LDFLAGS = $(DRIVERLIB_LDFLAGS) libqemutestdriver_la_LIBADD = $(qemu_LDADDS) -qemucpumock_la_SOURCES = \ +libqemucpumock_la_SOURCES = \ qemucpumock.c testutilshostcpus.h -qemucpumock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -qemucpumock_la_LIBADD = $(MOCKLIBS_LIBS) +libqemucpumock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libqemucpumock_la_LIBADD = $(MOCKLIBS_LIBS) qemuxml2argvtest_SOURCES = \ qemuxml2argvtest.c testutilsqemu.c testutilsqemu.h \ @@ -568,10 +568,10 @@ qemuxml2argvtest_SOURCES = \ qemuxml2argvtest_LDADD = libqemutestdriver.la \ $(LDADDS) $(LIBXML_LIBS) -qemuxml2argvmock_la_SOURCES = \ +libqemuxml2argvmock_la_SOURCES = \ qemuxml2argvmock.c -qemuxml2argvmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -qemuxml2argvmock_la_LIBADD = $(MOCKLIBS_LIBS) +libqemuxml2argvmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libqemuxml2argvmock_la_LIBADD = $(MOCKLIBS_LIBS) qemuxml2xmltest_SOURCES = \ qemuxml2xmltest.c testutilsqemu.c testutilsqemu.h \ @@ -600,10 +600,10 @@ qemucapsprobe_SOURCES = \ qemucapsprobe_LDADD = \ libqemutestdriver.la $(LDADDS) -qemucapsprobemock_la_SOURCES = \ +libqemucapsprobemock_la_SOURCES = \ qemucapsprobemock.c -qemucapsprobemock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -qemucapsprobemock_la_LIBADD = $(MOCKLIBS_LIBS) +libqemucapsprobemock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libqemucapsprobemock_la_LIBADD = $(MOCKLIBS_LIBS) qemucommandutiltest_SOURCES = \ qemucommandutiltest.c \ @@ -620,10 +620,10 @@ qemucaps2xmltest_SOURCES = \ $(NULL) qemucaps2xmltest_LDADD = $(qemu_LDADDS) -qemucaps2xmlmock_la_SOURCES = \ +libqemucaps2xmlmock_la_SOURCES = \ qemucaps2xmlmock.c -qemucaps2xmlmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -qemucaps2xmlmock_la_LIBADD = $(MOCKLIBS_LIBS) +libqemucaps2xmlmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libqemucaps2xmlmock_la_LIBADD = $(MOCKLIBS_LIBS) qemuagenttest_SOURCES = \ qemuagenttest.c \ @@ -780,15 +780,15 @@ EXTRA_DIST += vmwarevertest.c endif ! WITH_VMWARE if WITH_BHYVE -bhyvexml2argvmock_la_SOURCES = \ +libbhyvexml2argvmock_la_SOURCES = \ bhyvexml2argvmock.c -bhyvexml2argvmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -bhyvexml2argvmock_la_LIBADD = $(MOCKLIBS_LIBS) +libbhyvexml2argvmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libbhyvexml2argvmock_la_LIBADD = $(MOCKLIBS_LIBS) -bhyveargv2xmlmock_la_SOURCES = \ +libbhyveargv2xmlmock_la_SOURCES = \ bhyveargv2xmlmock.c -bhyveargv2xmlmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -bhyveargv2xmlmock_la_LIBADD = $(MOCKLIBS_LIBS) +libbhyveargv2xmlmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libbhyveargv2xmlmock_la_LIBADD = $(MOCKLIBS_LIBS) bhyve_LDADDS = ../src/libvirt_driver_bhyve_impl.la if WITH_STORAGE @@ -1035,9 +1035,9 @@ else ! WITH_QEMU vircapstest_LDADD = $(LDADDS) endif ! WITH_QEMU -domaincapsmock_la_SOURCES = domaincapsmock.c -domaincapsmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -domaincapsmock_la_LIBADD = $(MOCKLIBS_LIBS) +libdomaincapsmock_la_SOURCES = domaincapsmock.c +libdomaincapsmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libdomaincapsmock_la_LIBADD = $(MOCKLIBS_LIBS) domaincapstest_SOURCES = \ domaincapstest.c testutils.h testutils.c \ @@ -1072,20 +1072,20 @@ virnetdaemontest_SOURCES = \ testutils.h testutils.c virnetdaemontest_LDADD = $(LDADDS) -virnetdaemonmock_la_SOURCES = \ +libvirnetdaemonmock_la_SOURCES = \ virnetdaemonmock.c -virnetdaemonmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -virnetdaemonmock_la_LIBADD = $(MOCKLIBS_LIBS) +libvirnetdaemonmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libvirnetdaemonmock_la_LIBADD = $(MOCKLIBS_LIBS) virnetserverclienttest_SOURCES = \ virnetserverclienttest.c \ testutils.h testutils.c virnetserverclienttest_LDADD = $(LDADDS) -virnetserverclientmock_la_SOURCES = \ +libvirnetserverclientmock_la_SOURCES = \ virnetserverclientmock.c -virnetserverclientmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -virnetserverclientmock_la_LIBADD = $(MOCKLIBS_LIBS) +libvirnetserverclientmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libvirnetserverclientmock_la_LIBADD = $(MOCKLIBS_LIBS) virnettlscontexttest_SOURCES = \ virnettlscontexttest.c \ @@ -1157,19 +1157,19 @@ virportallocatortest_SOURCES = \ virportallocatortest.c testutils.h testutils.c virportallocatortest_LDADD = $(LDADDS) -virportallocatormock_la_SOURCES = \ +libvirportallocatormock_la_SOURCES = \ virportallocatormock.c -virportallocatormock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -virportallocatormock_la_LIBADD = $(MOCKLIBS_LIBS) +libvirportallocatormock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libvirportallocatormock_la_LIBADD = $(MOCKLIBS_LIBS) vircgrouptest_SOURCES = \ vircgrouptest.c testutils.h testutils.c vircgrouptest_LDADD = $(LDADDS) -vircgroupmock_la_SOURCES = \ +libvircgroupmock_la_SOURCES = \ vircgroupmock.c -vircgroupmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -vircgroupmock_la_LIBADD = $(MOCKLIBS_LIBS) +libvircgroupmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libvircgroupmock_la_LIBADD = $(MOCKLIBS_LIBS) vircryptotest_SOURCES = \ vircryptotest.c testutils.h testutils.c @@ -1183,44 +1183,44 @@ virpcitest_SOURCES = \ virpcitest.c testutils.h testutils.c virpcitest_LDADD = $(LDADDS) -virpcimock_la_SOURCES = \ +libvirpcimock_la_SOURCES = \ virpcimock.c -virpcimock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -virpcimock_la_LIBADD = $(MOCKLIBS_LIBS) +libvirpcimock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libvirpcimock_la_LIBADD = $(MOCKLIBS_LIBS) -virrandommock_la_SOURCES = \ +libvirrandommock_la_SOURCES = \ virrandommock.c -virrandommock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -virrandommock_la_LIBADD = $(MOCKLIBS_LIBS) +libvirrandommock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libvirrandommock_la_LIBADD = $(MOCKLIBS_LIBS) -virhostcpumock_la_SOURCES = \ +libvirhostcpumock_la_SOURCES = \ virhostcpumock.c -virhostcpumock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -virhostcpumock_la_LIBADD = $(MOCKLIBS_LIBS) +libvirhostcpumock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libvirhostcpumock_la_LIBADD = $(MOCKLIBS_LIBS) -virfilecachemock_la_SOURCES = \ +libvirfilecachemock_la_SOURCES = \ virfilecachemock.c -virfilecachemock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -virfilecachemock_la_LIBADD = $(MOCKLIBS_LIBS) +libvirfilecachemock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libvirfilecachemock_la_LIBADD = $(MOCKLIBS_LIBS) if WITH_LINUX vircaps2xmltest_SOURCES = \ vircaps2xmltest.c testutils.h testutils.c virfilewrapper.h virfilewrapper.c vircaps2xmltest_LDADD = $(LDADDS) -virnumamock_la_SOURCES = \ +libvirnumamock_la_SOURCES = \ virnumamock.c -virnumamock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -virnumamock_la_LIBADD = $(MOCKLIBS_LIBS) +libvirnumamock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libvirnumamock_la_LIBADD = $(MOCKLIBS_LIBS) virresctrltest_SOURCES = \ virresctrltest.c testutils.h testutils.c virfilewrapper.h virfilewrapper.c virresctrltest_LDADD = $(LDADDS) -virfilemock_la_SOURCES = \ +libvirfilemock_la_SOURCES = \ virfilemock.c -virfilemock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -virfilemock_la_LIBADD = $(MOCKLIBS_LIBS) +libvirfilemock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libvirfilemock_la_LIBADD = $(MOCKLIBS_LIBS) else ! WITH_LINUX EXTRA_DIST += vircaps2xmltest.c virnumamock.c virfilewrapper.c \ virfilewrapper.h virresctrltest.c virfilemock.c @@ -1246,10 +1246,10 @@ nssguesttest_LDADD = \ $(LDADDS) \ ../tools/nss/libnss_libvirt_guest_impl.la -nssmock_la_SOURCES = \ +libnssmock_la_SOURCES = \ nssmock.c -nssmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -nssmock_la_LIBADD = $(MOCKLIBS_LIBS) +libnssmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libnssmock_la_LIBADD = $(MOCKLIBS_LIBS) ## Intentionaly not linking with anything else. ## See the test source for more detailed explanation. @@ -1271,12 +1271,12 @@ else ! WITH_NSS EXTRA_DIST += nsstest.c nssmock.c nsslinktest.c endif ! WITH_NSS -virdeterministichashmock_la_SOURCES = \ +libvirdeterministichashmock_la_SOURCES = \ virdeterministichashmock.c -virdeterministichashmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -virdeterministichashmock_la_LIBADD = $(MOCKLIBS_LIBS) +libvirdeterministichashmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libvirdeterministichashmock_la_LIBADD = $(MOCKLIBS_LIBS) -test_libraries += virdeterministichashmock.la +test_libraries += libvirdeterministichashmock.la if WITH_YAJL virmacmaptest_SOURCES = \ @@ -1301,11 +1301,11 @@ virnetdevtest_SOURCES = \ virnetdevtest_CFLAGS = $(AM_CFLAGS) $(LIBNL_CFLAGS) virnetdevtest_LDADD = $(LDADDS) -virnetdevmock_la_SOURCES = \ +libvirnetdevmock_la_SOURCES = \ virnetdevmock.c -virnetdevmock_la_CFLAGS = $(AM_CFLAGS) $(LIBNL_CFLAGS) -virnetdevmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -virnetdevmock_la_LIBADD = $(MOCKLIBS_LIBS) +libvirnetdevmock_la_CFLAGS = $(AM_CFLAGS) $(LIBNL_CFLAGS) +libvirnetdevmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libvirnetdevmock_la_LIBADD = $(MOCKLIBS_LIBS) virrotatingfiletest_SOURCES = \ virrotatingfiletest.c testutils.h testutils.c @@ -1320,21 +1320,21 @@ virnetdevbandwidthtest_SOURCES = \ virnetdevbandwidthtest.c testutils.h testutils.c virnetdevbandwidthtest_LDADD = $(LDADDS) $(LIBXML_LIBS) -virusbmock_la_SOURCES = virusbmock.c -virusbmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -virusbmock_la_LIBADD = $(MOCKLIBS_LIBS) \ +libvirusbmock_la_SOURCES = virusbmock.c +libvirusbmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libvirusbmock_la_LIBADD = $(MOCKLIBS_LIBS) \ $(PROBES_O) \ ../src/libvirt_util.la -virnetdevbandwidthmock_la_SOURCES = \ +libvirnetdevbandwidthmock_la_SOURCES = \ virnetdevbandwidthmock.c -virnetdevbandwidthmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -virnetdevbandwidthmock_la_LIBADD = $(MOCKLIBS_LIBS) +libvirnetdevbandwidthmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libvirnetdevbandwidthmock_la_LIBADD = $(MOCKLIBS_LIBS) -virtestmock_la_SOURCES = \ +libvirtestmock_la_SOURCES = \ virtestmock.c -virtestmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -virtestmock_la_LIBADD = \ +libvirtestmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libvirtestmock_la_LIBADD = \ $(MOCKLIBS_LIBS) \ $(PROBES_O) \ ../src/libvirt_util.la @@ -1350,11 +1350,11 @@ virdbustest_SOURCES = \ virdbustest_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS) virdbustest_LDADD = $(LDADDS) $(DBUS_LIBS) -virdbusmock_la_SOURCES = \ +libvirdbusmock_la_SOURCES = \ virdbusmock.c -virdbusmock_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS) -virdbusmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -virdbusmock_la_LIBADD = $(MOCKLIBS_LIBS) +libvirdbusmock_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS) +libvirdbusmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +libvirdbusmock_la_LIBADD = $(MOCKLIBS_LIBS) virpolkittest_SOURCES = \ virpolkittest.c testutils.h testutils.c diff --git a/tests/bhyveargv2xmltest.c b/tests/bhyveargv2xmltest.c index d552364846..8e29225e31 100644 --- a/tests/bhyveargv2xmltest.c +++ b/tests/bhyveargv2xmltest.c @@ -205,7 +205,7 @@ mymain(void) return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/bhyveargv2xmlmock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("bhyveargv2xml")) #else diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c index c84925c57b..14ceac052e 100644 --- a/tests/bhyvexml2argvtest.c +++ b/tests/bhyvexml2argvtest.c @@ -258,7 +258,7 @@ mymain(void) return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/bhyvexml2argvmock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("bhyvexml2argv")) #else diff --git a/tests/bhyvexml2xmltest.c b/tests/bhyvexml2xmltest.c index e8a6867fcd..66394e2ae4 100644 --- a/tests/bhyvexml2xmltest.c +++ b/tests/bhyvexml2xmltest.c @@ -135,7 +135,7 @@ mymain(void) return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/bhyvexml2argvmock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("bhyvexml2argv")) #else diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c index 45ecfe61ac..c9cbf6ef8a 100644 --- a/tests/domaincapstest.c +++ b/tests/domaincapstest.c @@ -488,8 +488,8 @@ mymain(void) #if WITH_QEMU VIR_TEST_MAIN_PRELOAD(mymain, - abs_builddir "/.libs/domaincapsmock.so", - abs_builddir "/.libs/qemucpumock.so") + VIR_TEST_MOCK("domaincaps"), + VIR_TEST_MOCK("qemucpu")) #else -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/domaincapsmock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("domaincaps")) #endif diff --git a/tests/fchosttest.c b/tests/fchosttest.c index 3ee1912926..05272a2e9e 100644 --- a/tests/fchosttest.c +++ b/tests/fchosttest.c @@ -382,4 +382,4 @@ mymain(void) return ret; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virrandommock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virrandom")) diff --git a/tests/libxlxml2domconfigtest.c b/tests/libxlxml2domconfigtest.c index 048e6c0431..3b3f63403e 100644 --- a/tests/libxlxml2domconfigtest.c +++ b/tests/libxlxml2domconfigtest.c @@ -221,7 +221,7 @@ mymain(void) return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/libxlmock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("xl")) #else diff --git a/tests/nsstest.c b/tests/nsstest.c index 4118c31cef..734e4cbc07 100644 --- a/tests/nsstest.c +++ b/tests/nsstest.c @@ -190,7 +190,7 @@ mymain(void) return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/nssmock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("nss")) #else int main(void) diff --git a/tests/qemucaps2xmltest.c b/tests/qemucaps2xmltest.c index 08dc598541..3b381251a0 100644 --- a/tests/qemucaps2xmltest.c +++ b/tests/qemucaps2xmltest.c @@ -217,4 +217,4 @@ mymain(void) return (data.ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/qemucaps2xmlmock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("qemucaps2xml")) diff --git a/tests/qemucapsprobe.c b/tests/qemucapsprobe.c index 14c0ecad97..ae016c47c2 100644 --- a/tests/qemucapsprobe.c +++ b/tests/qemucapsprobe.c @@ -47,7 +47,7 @@ main(int argc, char **argv) virThread thread; virQEMUCapsPtr caps; - VIR_TEST_PRELOAD(abs_builddir "/.libs/qemucapsprobemock.so"); + VIR_TEST_PRELOAD(VIR_TEST_MOCK("qemucapsprobe")); if (argc != 2) { fprintf(stderr, "%s QEMU_binary\n", argv[0]); diff --git a/tests/qemumemlocktest.c b/tests/qemumemlocktest.c index 42a4643338..c9484ac9cb 100644 --- a/tests/qemumemlocktest.c +++ b/tests/qemumemlocktest.c @@ -155,8 +155,7 @@ mymain(void) return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN_PRELOAD(mymain, - abs_builddir "/.libs/virpcimock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virpci")) #else diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 522ff5a3d5..07832de3f1 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -3298,4 +3298,4 @@ mymain(void) return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virdeterministichashmock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virdeterministichash")) diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 2554d848cf..1799eb3387 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -2994,10 +2994,10 @@ mymain(void) } VIR_TEST_MAIN_PRELOAD(mymain, - abs_builddir "/.libs/qemuxml2argvmock.so", - abs_builddir "/.libs/virrandommock.so", - abs_builddir "/.libs/qemucpumock.so", - abs_builddir "/.libs/virpcimock.so") + VIR_TEST_MOCK("qemuxml2argv"), + VIR_TEST_MOCK("virrandom"), + VIR_TEST_MOCK("qemucpu"), + VIR_TEST_MOCK("virpci")) #else diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index d7850a89d3..cf46bb330f 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -1343,9 +1343,9 @@ mymain(void) } VIR_TEST_MAIN_PRELOAD(mymain, - abs_builddir "/.libs/virpcimock.so", - abs_builddir "/.libs/virrandommock.so", - abs_builddir "/.libs/virdeterministichashmock.so") + VIR_TEST_MOCK("virpci"), + VIR_TEST_MOCK("virrandom"), + VIR_TEST_MOCK("virdeterministichash")) #else diff --git a/tests/testutils.c b/tests/testutils.c index 245b1832f6..1fda3763f9 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -962,8 +962,6 @@ virTestSetEnvPath(void) return ret; } -#define TEST_MOCK (abs_builddir "/.libs/virtestmock.so") - int virTestMain(int argc, char **argv, int (*func)(void), @@ -981,7 +979,7 @@ int virTestMain(int argc, virLogOutputPtr *outputs = NULL; if (getenv("VIR_TEST_FILE_ACCESS")) - VIR_TEST_PRELOAD(TEST_MOCK); + VIR_TEST_PRELOAD(VIR_TEST_MOCK("virtest")); va_start(ap, func); while ((lib = va_arg(ap, const char *))) diff --git a/tests/testutils.h b/tests/testutils.h index 07dda6e355..e0fa2b2448 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -148,6 +148,10 @@ int virTestMain(int argc, return virTestMain(argc, argv, func, __VA_ARGS__, NULL); \ } +#define MOCK_EXT ".so" + +#define VIR_TEST_MOCK(mock) (abs_builddir "/.libs/lib" mock "mock" MOCK_EXT) + virCapsPtr virTestGenericCapsInit(void); int virTestCapsBuildNUMATopology(virCapsPtr caps, int seq); diff --git a/tests/vircaps2xmltest.c b/tests/vircaps2xmltest.c index fc112db0bc..41e84a3b25 100644 --- a/tests/vircaps2xmltest.c +++ b/tests/vircaps2xmltest.c @@ -116,4 +116,4 @@ mymain(void) return ret; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virnumamock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virnuma")) diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index 20f4c57b04..e862b132f0 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -1136,7 +1136,7 @@ mymain(void) return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/vircgroupmock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("vircgroup")) #else int diff --git a/tests/vircryptotest.c b/tests/vircryptotest.c index 6841d74901..42ef0b8900 100644 --- a/tests/vircryptotest.c +++ b/tests/vircryptotest.c @@ -179,4 +179,4 @@ mymain(void) } /* Forces usage of not so random virRandomBytes */ -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virrandommock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virrandom")) diff --git a/tests/virfilecachetest.c b/tests/virfilecachetest.c index 08062d66e3..a17086e004 100644 --- a/tests/virfilecachetest.c +++ b/tests/virfilecachetest.c @@ -233,4 +233,4 @@ mymain(void) return ret != 0 ? EXIT_FAILURE : EXIT_SUCCESS; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virfilecachemock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virfilecache")) diff --git a/tests/virfiletest.c b/tests/virfiletest.c index aa4c3435e5..14be2d9d60 100644 --- a/tests/virfiletest.c +++ b/tests/virfiletest.c @@ -464,7 +464,7 @@ mymain(void) } #ifdef __linux__ -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virfilemock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virfile")) #else VIR_TEST_MAIN(mymain) #endif diff --git a/tests/virfirewalltest.c b/tests/virfirewalltest.c index 7c586877d3..78685a3bf4 100644 --- a/tests/virfirewalltest.c +++ b/tests/virfirewalltest.c @@ -1198,7 +1198,7 @@ mymain(void) } # if WITH_DBUS -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virdbusmock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virdbus")) # else VIR_TEST_MAIN(mymain) # endif diff --git a/tests/virhostcputest.c b/tests/virhostcputest.c index bb60dd3ffc..9ee0d2f15b 100644 --- a/tests/virhostcputest.c +++ b/tests/virhostcputest.c @@ -276,6 +276,6 @@ mymain(void) return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virhostcpumock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virhostcpu")) #endif /* __linux__ */ diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c index f860426678..d0859a421c 100644 --- a/tests/virhostdevtest.c +++ b/tests/virhostdevtest.c @@ -597,7 +597,7 @@ mymain(void) return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virpcimock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virpci")) #else int main(void) diff --git a/tests/viriscsitest.c b/tests/viriscsitest.c index cc552a5cfe..1ce039425b 100644 --- a/tests/viriscsitest.c +++ b/tests/viriscsitest.c @@ -365,6 +365,5 @@ mymain(void) return EXIT_SUCCESS; } -VIR_TEST_MAIN_PRELOAD(mymain, - abs_builddir "/.libs/virrandommock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virrandom")) #endif /* WIN32 */ diff --git a/tests/virmacmaptest.c b/tests/virmacmaptest.c index 884dabab82..995aff1178 100644 --- a/tests/virmacmaptest.c +++ b/tests/virmacmaptest.c @@ -232,4 +232,4 @@ mymain(void) return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virdeterministichashmock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virdeterministichash")) diff --git a/tests/virnetdaemontest.c b/tests/virnetdaemontest.c index 816bfe05d4..0a75568902 100644 --- a/tests/virnetdaemontest.c +++ b/tests/virnetdaemontest.c @@ -416,7 +416,7 @@ mymain(void) return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virnetdaemonmock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virnetdaemon")) #else static int mymain(void) diff --git a/tests/virnetdevbandwidthtest.c b/tests/virnetdevbandwidthtest.c index 2c0b6a6713..59647173c3 100644 --- a/tests/virnetdevbandwidthtest.c +++ b/tests/virnetdevbandwidthtest.c @@ -166,4 +166,4 @@ mymain(void) return ret; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virnetdevbandwidthmock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virnetdevbandwidth")) diff --git a/tests/virnetdevtest.c b/tests/virnetdevtest.c index 24fb4d35e0..5d266a28ee 100644 --- a/tests/virnetdevtest.c +++ b/tests/virnetdevtest.c @@ -82,7 +82,7 @@ mymain(void) return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virnetdevmock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virnetdev")) #else int main(void) diff --git a/tests/virnetserverclienttest.c b/tests/virnetserverclienttest.c index cb5071b2d9..4d7c6555b9 100644 --- a/tests/virnetserverclienttest.c +++ b/tests/virnetserverclienttest.c @@ -170,7 +170,7 @@ mymain(void) return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virnetserverclientmock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virnetserverclient")) #else static int mymain(void) diff --git a/tests/virnettlscontexttest.c b/tests/virnettlscontexttest.c index 07910c2749..9a0d947c1b 100644 --- a/tests/virnettlscontexttest.c +++ b/tests/virnettlscontexttest.c @@ -630,7 +630,7 @@ mymain(void) return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virrandommock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virrandom")) #else diff --git a/tests/virnettlssessiontest.c b/tests/virnettlssessiontest.c index 41abbe7eaf..8d89b16814 100644 --- a/tests/virnettlssessiontest.c +++ b/tests/virnettlssessiontest.c @@ -484,7 +484,7 @@ mymain(void) return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virrandommock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virrandom")) #else diff --git a/tests/virpcitest.c b/tests/virpcitest.c index 0bd37268ef..12b142700a 100644 --- a/tests/virpcitest.c +++ b/tests/virpcitest.c @@ -420,7 +420,7 @@ mymain(void) return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virpcimock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virpci")) #else int main(void) diff --git a/tests/virpolkittest.c b/tests/virpolkittest.c index 94a6daae0c..ce1ff92bf2 100644 --- a/tests/virpolkittest.c +++ b/tests/virpolkittest.c @@ -347,7 +347,7 @@ mymain(void) return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virdbusmock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virdbus")) #else /* ! __ELF__ */ int diff --git a/tests/virportallocatortest.c b/tests/virportallocatortest.c index 211de705a4..c695b26859 100644 --- a/tests/virportallocatortest.c +++ b/tests/virportallocatortest.c @@ -182,7 +182,7 @@ mymain(void) return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virportallocatormock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virportallocator")) #else /* defined(__linux__) && defined(RTLD_NEXT) */ int main(void) diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index 2dafce2764..3add1ab56f 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -783,7 +783,7 @@ mymain(void) return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virdbusmock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virdbus")) #else /* ! (WITH_DBUS && __linux__) */ int diff --git a/tests/virusbtest.c b/tests/virusbtest.c index 564c4b44a4..1f04f283f5 100644 --- a/tests/virusbtest.c +++ b/tests/virusbtest.c @@ -288,4 +288,4 @@ mymain(void) return EXIT_SUCCESS; } -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virusbmock.so") +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virusb")) -- 2.22.0

On Wed, Aug 21, 2019 at 07:13:16PM +0300, Roman Bolshakov wrote:
In preparation libtool "-module" flag removal, add lib prefix to all mock shared objects.
While at it, introduce VIR_TEST_MOCK macros that makes path out of mock name to be used with VIR_TEST_PRELOAD or VIR_TEST_MAIN_PRELOAD. That, hopefully, improves readability, reduces line length and allows to tailor VIR_TEST_MOCK for specific platform if it has shared library suffix different from ".so".
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- tests/Makefile.am | 194 ++++++++++++++++----------------- tests/bhyveargv2xmltest.c | 2 +- tests/bhyvexml2argvtest.c | 2 +- tests/bhyvexml2xmltest.c | 2 +- tests/domaincapstest.c | 6 +- tests/fchosttest.c | 2 +- tests/libxlxml2domconfigtest.c | 2 +- tests/nsstest.c | 2 +- tests/qemucaps2xmltest.c | 2 +- tests/qemucapsprobe.c | 2 +- tests/qemumemlocktest.c | 3 +- tests/qemumonitorjsontest.c | 2 +- tests/qemuxml2argvtest.c | 8 +- tests/qemuxml2xmltest.c | 6 +- tests/testutils.c | 4 +- tests/testutils.h | 4 + tests/vircaps2xmltest.c | 2 +- tests/vircgrouptest.c | 2 +- tests/vircryptotest.c | 2 +- tests/virfilecachetest.c | 2 +- tests/virfiletest.c | 2 +- tests/virfirewalltest.c | 2 +- tests/virhostcputest.c | 2 +- tests/virhostdevtest.c | 2 +- tests/viriscsitest.c | 3 +- tests/virmacmaptest.c | 2 +- tests/virnetdaemontest.c | 2 +- tests/virnetdevbandwidthtest.c | 2 +- tests/virnetdevtest.c | 2 +- tests/virnetserverclienttest.c | 2 +- tests/virnettlscontexttest.c | 2 +- tests/virnettlssessiontest.c | 2 +- tests/virpcitest.c | 2 +- tests/virpolkittest.c | 2 +- tests/virportallocatortest.c | 2 +- tests/virsystemdtest.c | 2 +- tests/virusbtest.c | 2 +- 37 files changed, 143 insertions(+), 143 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

macOS has two kinds of loadable libraries: MH_BUNDLE, and MH_DYLIB. bundle is used for plugins that are loaded with dlopen/dlsym/dlclose. And there's no way to preload a bundle into an application. dynamic linker (dyld) will reject it when finds it in DYLD_INSERT_LIBRARIES. Unfortunately, a bundle is built if -module flag is provided to libtool. The flag has been removed to build dylibs with ".dylib" suffix. Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- tests/Makefile.am | 2 +- tests/testutils.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 713dc30de3..460efb6b7b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -48,7 +48,7 @@ AM_CFLAGS = \ AM_LDFLAGS = \ -export-dynamic -MOCKLIBS_LDFLAGS = -module -avoid-version \ +MOCKLIBS_LDFLAGS = -avoid-version \ -rpath /evil/libtool/hack/to/force/shared/lib/creation \ $(MINGW_EXTRA_LDFLAGS) diff --git a/tests/testutils.h b/tests/testutils.h index e0fa2b2448..7660101991 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -119,8 +119,10 @@ int virTestMain(int argc, #ifdef __APPLE__ # define PRELOAD_VAR "DYLD_INSERT_LIBRARIES" +# define MOCK_EXT ".dylib" #else # define PRELOAD_VAR "LD_PRELOAD" +# define MOCK_EXT ".so" #endif #define VIR_TEST_PRELOAD(lib) \ @@ -148,8 +150,6 @@ int virTestMain(int argc, return virTestMain(argc, argv, func, __VA_ARGS__, NULL); \ } -#define MOCK_EXT ".so" - #define VIR_TEST_MOCK(mock) (abs_builddir "/.libs/lib" mock "mock" MOCK_EXT) virCapsPtr virTestGenericCapsInit(void); -- 2.22.0

On Wed, Aug 21, 2019 at 07:13:17PM +0300, Roman Bolshakov wrote:
macOS has two kinds of loadable libraries: MH_BUNDLE, and MH_DYLIB. bundle is used for plugins that are loaded with dlopen/dlsym/dlclose. And there's no way to preload a bundle into an application. dynamic linker (dyld) will reject it when finds it in DYLD_INSERT_LIBRARIES.
Unfortunately, a bundle is built if -module flag is provided to libtool. The flag has been removed to build dylibs with ".dylib" suffix.
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- tests/Makefile.am | 2 +- tests/testutils.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

/tmp is a symbolic link to /private/tmp on macOS. That causes failures in commandtest, because getcwd returns /private/tmp and the expected output doesn't match to "CWD: /tmp". Rathern than making a copy of commanddata solely for macOS, the /private prefix is stripped. Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- tests/commandhelper.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 1312f3ee52..358c37e014 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -130,7 +130,16 @@ int main(int argc, char **argv) { if (strlen(cwd) > strlen(".../commanddata") && STREQ(cwd + strlen(cwd) - strlen("/commanddata"), "/commanddata")) strcpy(cwd, ".../commanddata"); +#ifdef __APPLE__ + char *noprivateprefix = NULL; + if (strstr(cwd, "/private")) + noprivateprefix = cwd + strlen("/private"); + else + noprivateprefix = cwd; + fprintf(log, "CWD:%s\n", noprivateprefix); +#else fprintf(log, "CWD:%s\n", cwd); +#endif free(cwd); fprintf(log, "UMASK:%04o\n", umask(0)); -- 2.22.0

On Wed, Aug 21, 2019 at 07:13:18PM +0300, Roman Bolshakov wrote:
/tmp is a symbolic link to /private/tmp on macOS. That causes failures in commandtest, because getcwd returns /private/tmp and the expected output doesn't match to "CWD: /tmp".
Rathern than making a copy of commanddata solely for macOS, the /private prefix is stripped.
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- tests/commandhelper.c | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 1312f3ee52..358c37e014 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -130,7 +130,16 @@ int main(int argc, char **argv) { if (strlen(cwd) > strlen(".../commanddata") && STREQ(cwd + strlen(cwd) - strlen("/commanddata"), "/commanddata")) strcpy(cwd, ".../commanddata"); +#ifdef __APPLE__ + char *noprivateprefix = NULL; + if (strstr(cwd, "/private"))
s/strstr/STRPREFIX/
+ noprivateprefix = cwd + strlen("/private"); + else + noprivateprefix = cwd; + fprintf(log, "CWD:%s\n", noprivateprefix); +#else fprintf(log, "CWD:%s\n", cwd); +#endif
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

From ld(1):
By default all references resolved to a dynamic library record the library to which they were resolved. At runtime, dyld uses that information to directly resolve symbols. The alternative is to use the -flat_namespace option. With flat namespace, the library is not recorded. At runtime, dyld will search each dynamic library in load order when resolving symbols. This is slower, but more like how other operating systems resolve symbols. That fixes the set of tests that preload a mock library to replace library symbols: qemublocktest qemumonitorjsontest viriscsitest virmacmaptest virnetserverclienttest Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- configure.ac | 1 + src/Makefile.am | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index f41c6d5d86..852b464e97 100644 --- a/configure.ac +++ b/configure.ac @@ -212,6 +212,7 @@ fi AM_CONDITIONAL([WITH_LINUX], [test "$with_linux" = "yes"]) AM_CONDITIONAL([WITH_FREEBSD], [test "$with_freebsd" = "yes"]) +AM_CONDITIONAL([WITH_MACOS], [test "$with_macos" = "yes"]) # We don't support the daemon yet if test "$with_win" = "yes" ; then diff --git a/src/Makefile.am b/src/Makefile.am index 817a7ecf34..adaf61350a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -579,8 +579,13 @@ libvirt_la_LDFLAGS = \ -version-info $(LIBVIRT_VERSION_INFO) \ $(LIBVIRT_NODELETE) \ $(NO_UNDEFINED_LDFLAGS) \ - $(AM_LDFLAGS) \ - $(NULL) + $(AM_LDFLAGS) +if WITH_MACOS +# macOS has two-level namespaces by default. +# Override it to allow symbol replacement with DYLD_INSERT_LIBRARIES +libvirt_la_LDFLAGS += -Wl,-flat_namespace +endif WITH_MACOS +libvirt_la_LDFLAGS += $(NULL) libvirt_la_BUILT_LIBADD += ../gnulib/lib/libgnu.la libvirt_la_LIBADD += \ $(DRIVER_MODULES_LIBS) \ -- 2.22.0

On Wed, Aug 21, 2019 at 07:13:19PM +0300, Roman Bolshakov wrote:
From ld(1):
By default all references resolved to a dynamic library record the library to which they were resolved. At runtime, dyld uses that information to directly resolve symbols. The alternative is to use the -flat_namespace option. With flat namespace, the library is not recorded. At runtime, dyld will search each dynamic library in load order when resolving symbols. This is slower, but more like how other operating systems resolve symbols.
That fixes the set of tests that preload a mock library to replace library symbols: qemublocktest qemumonitorjsontest viriscsitest virmacmaptest virnetserverclienttest
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- configure.ac | 1 + src/Makefile.am | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

macOS syscall interface (/usr/lib/system/libsystem_kernel.dylib) has three kinds of stat but only one of them can be used to fill "struct stat": stat$INODE64. virmockstathelpers looks up regular stat instead of stat$INODE64. That causes a failure in qemufirmwaretest because "struct stat" is laid out differently from the values returned by stat. Introduce VIR_MOCK_REAL_INIT_ALIASED that can be used to lookup stat$INODE64 and lstat$INODE64 and use it to setup real functions on macOS. Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- tests/virmock.h | 10 ++++++++++ tests/virmockstathelpers.c | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/tests/virmock.h b/tests/virmock.h index 74bb0d5b15..7520bb5d6e 100644 --- a/tests/virmock.h +++ b/tests/virmock.h @@ -288,3 +288,13 @@ abort(); \ } \ } while (0) + +#define VIR_MOCK_REAL_INIT_ALIASED(name, alias) \ + do { \ + if (real_##name == NULL && \ + !(real_##name = dlsym(RTLD_NEXT, \ + alias))) { \ + fprintf(stderr, "Missing symbol '" alias "'\n"); \ + abort(); \ + } \ + } while (0) diff --git a/tests/virmockstathelpers.c b/tests/virmockstathelpers.c index 0bbea4b437..1f6f831bed 100644 --- a/tests/virmockstathelpers.c +++ b/tests/virmockstathelpers.c @@ -138,7 +138,11 @@ static void virMockStatInit(void) debug = getenv("VIR_MOCK_STAT_DEBUG"); #ifdef MOCK_STAT +#ifdef __APPLE__ + VIR_MOCK_REAL_INIT_ALIASED(stat, "stat$INODE64"); +#else VIR_MOCK_REAL_INIT(stat); +#endif fdebug("real stat %p\n", real_stat); #endif #ifdef MOCK_STAT64 @@ -154,7 +158,11 @@ static void virMockStatInit(void) fdebug("real __xstat64 %p\n", real___xstat64); #endif #ifdef MOCK_LSTAT +#ifdef __APPLE__ + VIR_MOCK_REAL_INIT_ALIASED(stat, "lstat$INODE64"); +#else VIR_MOCK_REAL_INIT(lstat); +#endif fdebug("real lstat %p\n", real_lstat); #endif #ifdef MOCK_LSTAT64 -- 2.22.0

On Wed, Aug 21, 2019 at 07:13:20PM +0300, Roman Bolshakov wrote:
macOS syscall interface (/usr/lib/system/libsystem_kernel.dylib) has three kinds of stat but only one of them can be used to fill "struct stat": stat$INODE64.
virmockstathelpers looks up regular stat instead of stat$INODE64. That causes a failure in qemufirmwaretest because "struct stat" is laid out differently from the values returned by stat.
Introduce VIR_MOCK_REAL_INIT_ALIASED that can be used to lookup stat$INODE64 and lstat$INODE64 and use it to setup real functions on macOS.
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- tests/virmock.h | 10 ++++++++++ tests/virmockstathelpers.c | 8 ++++++++ 2 files changed, 18 insertions(+)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

Test executables and mocks have assumption that any symbol can be replaced with LD_PRELOAD. That's not a case for macOS unless flat namespace is used, because every external symbol reference records the library to be looked up. And the symbols cannot be replaced unless dyld interposing is used. Setting DYLD_FORCE_FLAT_NAMESPACE changes symbol lookup behaviour to be similar to Linux dynamic linker. It's more lightweight solution than explicitly decorating all mock symbols as interpositions and building libvirt as interposable dynamic library. This fixes vircryptotest and allows to proceed other tests that rely on mocks a little bit further. Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- tests/testutils.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/testutils.h b/tests/testutils.h index 7660101991..b46bc86d84 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -119,9 +119,12 @@ int virTestMain(int argc, #ifdef __APPLE__ # define PRELOAD_VAR "DYLD_INSERT_LIBRARIES" +# define FORCE_FLAT_NAMESPACE \ + setenv("DYLD_FORCE_FLAT_NAMESPACE", "1", 1); # define MOCK_EXT ".dylib" #else # define PRELOAD_VAR "LD_PRELOAD" +# define FORCE_FLAT_NAMESPACE # define MOCK_EXT ".so" #endif @@ -141,6 +144,7 @@ int virTestMain(int argc, return EXIT_FAILURE; \ } \ setenv(PRELOAD_VAR, newenv, 1); \ + FORCE_FLAT_NAMESPACE \ execv(argv[0], argv); \ } \ } while (0) -- 2.22.0

On Wed, Aug 21, 2019 at 07:13:21PM +0300, Roman Bolshakov wrote:
Test executables and mocks have assumption that any symbol can be replaced with LD_PRELOAD. That's not a case for macOS unless flat namespace is used, because every external symbol reference records the library to be looked up. And the symbols cannot be replaced unless dyld interposing is used.
Setting DYLD_FORCE_FLAT_NAMESPACE changes symbol lookup behaviour to be similar to Linux dynamic linker. It's more lightweight solution than explicitly decorating all mock symbols as interpositions and building libvirt as interposable dynamic library.
This fixes vircryptotest and allows to proceed other tests that rely on mocks a little bit further.
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- tests/testutils.h | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/tests/testutils.h b/tests/testutils.h index 7660101991..b46bc86d84 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -119,9 +119,12 @@ int virTestMain(int argc,
#ifdef __APPLE__ # define PRELOAD_VAR "DYLD_INSERT_LIBRARIES" +# define FORCE_FLAT_NAMESPACE \ + setenv("DYLD_FORCE_FLAT_NAMESPACE", "1", 1);
Remove the ';'
# define MOCK_EXT ".dylib" #else # define PRELOAD_VAR "LD_PRELOAD" +# define FORCE_FLAT_NAMESPACE
Make that 'do {} while (0)'
# define MOCK_EXT ".so" #endif
@@ -141,6 +144,7 @@ int virTestMain(int argc, return EXIT_FAILURE; \ } \ setenv(PRELOAD_VAR, newenv, 1); \ + FORCE_FLAT_NAMESPACE \
so that here you can have a trailing ';'
execv(argv[0], argv); \ } \ } while (0)
Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

gnulib headers change stat, lstat and open to replacement functions, even for function definitions. This effectively disables standard library overrides in virfilewrapper and virmockstathelpers since they are never reached. Rename the functions and provide a declartion that uses correct assembler name for the mocks. This fixes firmware lookup in domaincapstest on macOS. Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- tests/virfilewrapper.c | 5 +++++ tests/virmockstathelpers.c | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/tests/virfilewrapper.c b/tests/virfilewrapper.c index 067cb30657..20cb2f4464 100644 --- a/tests/virfilewrapper.c +++ b/tests/virfilewrapper.c @@ -157,7 +157,12 @@ int access(const char *path, int mode) return real_access(newpath ? newpath : path, mode); } +#ifdef __APPLE__ +int _open(const char *path, int flags, ...) __asm("_open"); +int _open(const char *path, int flags, ...) +#else int open(const char *path, int flags, ...) +#endif { VIR_AUTOFREE(char *) newpath = NULL; va_list ap; diff --git a/tests/virmockstathelpers.c b/tests/virmockstathelpers.c index 1f6f831bed..4ddb0dfec1 100644 --- a/tests/virmockstathelpers.c +++ b/tests/virmockstathelpers.c @@ -192,7 +192,12 @@ static int virMockStatRedirect(const char *path, char **newpath); #endif #ifdef MOCK_STAT +# ifdef __APPLE__ +int _stat(const char *path, struct stat *sb) __asm("_stat$INODE64"); +int _stat(const char *path, struct stat *sb) +# else int stat(const char *path, struct stat *sb) +# endif { VIR_AUTOFREE(char *) newpath = NULL; @@ -262,8 +267,13 @@ __xstat64(int ver, const char *path, struct stat64 *sb) #endif #ifdef MOCK_LSTAT +# ifdef __APPLE__ +int _lstat(const char *path, struct stat *sb) __asm("_lstat$INODE64"); +int _lstat(const char *path, struct stat *sb) +# else int lstat(const char *path, struct stat *sb) +# endif { VIR_AUTOFREE(char *) newpath = NULL; -- 2.22.0

On Wed, Aug 21, 2019 at 07:13:22PM +0300, Roman Bolshakov wrote:
gnulib headers change stat, lstat and open to replacement functions, even for function definitions. This effectively disables standard library overrides in virfilewrapper and virmockstathelpers since they are never reached.
Rename the functions and provide a declartion that uses correct assembler name for the mocks.
This fixes firmware lookup in domaincapstest on macOS.
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- tests/virfilewrapper.c | 5 +++++ tests/virmockstathelpers.c | 10 ++++++++++ 2 files changed, 15 insertions(+)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

A library has to be built with -flat_namespace to get all references to global symbols indirected. That can also be achieved with two-level namespace interposition but we're not using explicit symbol interposition since it's more verbose and requires massive changes to the mocks. This provides a way to interpose a mock for virQEMUCapsProbeHostCPU from qemucpumock and fixes domaincapstest on macOS. Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- tests/Makefile.am | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Makefile.am b/tests/Makefile.am index 460efb6b7b..f92710db43 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -56,6 +56,9 @@ DRIVERLIB_LDFLAGS = \ -avoid-version \ -rpath /evil/libtool/hack/to/force/shared/lib/creation \ $(MINGW_EXTRA_LDFLAGS) +if WITH_MACOS +DRIVERLIB_LDFLAGS += -Wl,-flat_namespace +endif WITH_MACOS PROBES_O = if WITH_DTRACE_PROBES -- 2.22.0

On Wed, Aug 21, 2019 at 07:13:23PM +0300, Roman Bolshakov wrote:
A library has to be built with -flat_namespace to get all references to global symbols indirected. That can also be achieved with two-level namespace interposition but we're not using explicit symbol interposition since it's more verbose and requires massive changes to the mocks.
This provides a way to interpose a mock for virQEMUCapsProbeHostCPU from qemucpumock and fixes domaincapstest on macOS.
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- tests/Makefile.am | 3 +++ 1 file changed, 3 insertions(+)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On Wed, Aug 21, 2019 at 07:13:12PM +0300, Roman Bolshakov wrote:
Hi!
This patch series attempts to reduce the number of failing tests on macOS.
The fixes involve some funk with macOS dynamic and static linkers, dyld and ld64, respectively.
As result, instead of 15 failing tests we get only 5. The tests have been fixed: qemublocktest qemumonitorjsontest viriscsitest virmacmaptest virnetserverclienttest vircryptotest qemufirmwaretest domaincapstest commandtest sockettest
The tests are still failing: qemumemlocktest storagepoolxml2argvtest qemuxml2xmltest qemusecuritytest qemuxml2argvtest
qemucapsprobe doesn't yet works but I started working on the fix.
The failing tests depend on virpcimock that is guarded by ifdefs so no functions are injected and the mock is no-op on macOS. How can we fix the tests that rely on the mock? Should we select only specific tests to run on macOS or we should make virpci mock cross-platform? Skipping them entirely is not an option IMO as I think qemu driver can be used on macOS with qemu/hvf/haxm domains and the tests are helpful for the domains.
Realistically the PCI code will only ever execute on Linux, since it uses VFIO linux kernel features, so if we don't test PCI bits on macOS that's fine. That said though, I'd be fine if you wanted to make the virpcimock cross-platform too. I'd pick whichever strategy results in the nicest code to maintain Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On Wed, Aug 21, 2019 at 06:18:11PM +0100, Daniel P. Berrangé wrote:
On Wed, Aug 21, 2019 at 07:13:12PM +0300, Roman Bolshakov wrote:
Hi!
This patch series attempts to reduce the number of failing tests on macOS.
The fixes involve some funk with macOS dynamic and static linkers, dyld and ld64, respectively.
As result, instead of 15 failing tests we get only 5. The tests have been fixed: qemublocktest qemumonitorjsontest viriscsitest virmacmaptest virnetserverclienttest vircryptotest qemufirmwaretest domaincapstest commandtest sockettest
The tests are still failing: qemumemlocktest storagepoolxml2argvtest qemuxml2xmltest qemusecuritytest qemuxml2argvtest
qemucapsprobe doesn't yet works but I started working on the fix.
The failing tests depend on virpcimock that is guarded by ifdefs so no functions are injected and the mock is no-op on macOS. How can we fix the tests that rely on the mock? Should we select only specific tests to run on macOS or we should make virpci mock cross-platform? Skipping them entirely is not an option IMO as I think qemu driver can be used on macOS with qemu/hvf/haxm domains and the tests are helpful for the domains.
Realistically the PCI code will only ever execute on Linux, since it uses VFIO linux kernel features, so if we don't test PCI bits on macOS that's fine.
That said though, I'd be fine if you wanted to make the virpcimock cross-platform too.
I'd pick whichever strategy results in the nicest code to maintain
BTW, I've acked all patches, but will give a little more time in case anyone else has comments, before pushing. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
participants (2)
-
Daniel P. Berrangé
-
Roman Bolshakov