[libvirt] [PATCH 0/2] tests: Fix mock libraries linking

This patches make sure mock libraries do not link against either too many or too few libraries. Cheers. Andrea Bolognani (2): tests: Use plain close() in mock code tests: Link mock libraries against gnulib and gnulib only tests/Makefile.am | 21 +++++++++++++++------ tests/virportallocatortest.c | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) -- 2.5.0

The virportallocatortest.c file is compiled both as a test case and as a mock library; in the latter case, it can't use VIR_FORCE_CLOSE() because mock libraries are not linked against libvirt. Replace VIR_FORCE_CLOSE() with plain close() to solve the issue. --- tests/virportallocatortest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/virportallocatortest.c b/tests/virportallocatortest.c index 58b2155..077aad8 100644 --- a/tests/virportallocatortest.c +++ b/tests/virportallocatortest.c @@ -58,7 +58,7 @@ static void init_syms(void) return; host_has_ipv6 = true; - VIR_FORCE_CLOSE(fd); + close(fd); } int socket(int domain, -- 2.5.0

Mock libraries should not be linked against libvirt, but some of them did - fix that. On the other hand, not linking against gnulib can cause build failures on mingw, so define a new $(MOCKLIBS_LIBS) variable and use it everywhere. --- tests/Makefile.am | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index c5986f0..5f5a561 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -71,6 +71,9 @@ LDADDS = \ $(GNULIB_LIBS) \ ../src/libvirt.la +MOCKLIBS_LIBS = \ + $(GNULIB_LIBS) + EXTRA_DIST = \ .valgrind.supp \ bhyvexml2argvdata \ @@ -566,6 +569,7 @@ qemuxml2argvmock_la_SOURCES = \ qemuxml2argvmock.c qemuxml2argvmock_la_CFLAGS = $(AM_CFLAGS) qemuxml2argvmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +qemuxml2argvmock_la_LIBADD = $(MOCKLIBS_LIBS) qemuxml2xmltest_SOURCES = \ qemuxml2xmltest.c testutilsqemu.c testutilsqemu.h \ @@ -621,6 +625,7 @@ qemucaps2xmlmock_la_SOURCES = \ qemucaps2xmlmock.c qemucaps2xmlmock_la_CFLAGS = $(AM_CFLAGS) qemucaps2xmlmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +qemucaps2xmlmock_la_LIBADD = $(MOCKLIBS_LIBS) qemuagenttest_SOURCES = \ qemuagenttest.c \ @@ -728,6 +733,7 @@ bhyvexml2argvmock_la_SOURCES = \ bhyvexml2argvmock.c bhyvexml2argvmock_la_CFLAGS = $(AM_CFLAGS) bhyvexml2argvmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +bhyvexml2argvmock_la_LIBADD = $(MOCKLIBS_LIBS) bhyve_LDADDS = ../src/libvirt_driver_bhyve_impl.la if WITH_STORAGE @@ -946,7 +952,7 @@ virnetserverclientmock_la_SOURCES = \ virnetserverclientmock.c virnetserverclientmock_la_CFLAGS = $(AM_CFLAGS) virnetserverclientmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -virnetserverclientmock_la_LIBADD = $(GNULIB_LIBS) +virnetserverclientmock_la_LIBADD = $(MOCKLIBS_LIBS) if WITH_GNUTLS virnettlscontexttest_SOURCES = \ @@ -1025,7 +1031,7 @@ libvirportallocatormock_la_SOURCES = \ virportallocatortest.c libvirportallocatormock_la_CFLAGS = $(AM_CFLAGS) -DMOCK_HELPER=1 libvirportallocatormock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -libvirportallocatormock_la_LIBADD = ../src/libvirt.la +libvirportallocatormock_la_LIBADD = $(MOCKLIBS_LIBS) vircgrouptest_SOURCES = \ vircgrouptest.c testutils.h testutils.c @@ -1035,6 +1041,7 @@ vircgroupmock_la_SOURCES = \ vircgroupmock.c vircgroupmock_la_CFLAGS = $(AM_CFLAGS) vircgroupmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +vircgroupmock_la_LIBADD = $(MOCKLIBS_LIBS) vircryptotest_SOURCES = \ vircryptotest.c testutils.h testutils.c @@ -1051,14 +1058,14 @@ virpcitest_LDADD = $(LDADDS) virpcimock_la_SOURCES = \ virpcimock.c virpcimock_la_CFLAGS = $(AM_CFLAGS) -virpcimock_la_LIBADD = $(GNULIB_LIBS) \ - ../src/libvirt.la virpcimock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +virpcimock_la_LIBADD = $(MOCKLIBS_LIBS) nodeinfomock_la_SOURCES = \ nodeinfomock.c nodeinfomock_la_CFLAGS = $(AM_CFLAGS) nodeinfomock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +nodeinfomock_la_LIBADD = $(MOCKLIBS_LIBS) virnetdevtest_SOURCES = \ virnetdevtest.c testutils.h testutils.c @@ -1068,9 +1075,8 @@ virnetdevtest_LDADD = $(LDADDS) virnetdevmock_la_SOURCES = \ virnetdevmock.c virnetdevmock_la_CFLAGS = $(AM_CFLAGS) $(LIBNL_CFLAGS) -virnetdevmock_la_LIBADD = $(GNULIB_LIBS) \ - ../src/libvirt.la virnetdevmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +virnetdevmock_la_LIBADD = $(MOCKLIBS_LIBS) virrotatingfiletest_SOURCES = \ virrotatingfiletest.c testutils.h testutils.c @@ -1089,11 +1095,13 @@ virnetdevbandwidthtest_LDADD = $(LDADDS) $(LIBXML_LIBS) virusbmock_la_SOURCES = virusbmock.c virusbmock_la_CFLAGS = $(AM_CFLAGS) virusbmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +virusbmock_la_LIBADD = $(MOCKLIBS_LIBS) virnetdevbandwidthmock_la_SOURCES = \ virnetdevbandwidthmock.c virnetdevbandwidthmock_la_CFLAGS = $(AM_CFLAGS) virnetdevbandwidthmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +virnetdevbandwidthmock_la_LIBADD = $(MOCKLIBS_LIBS) else ! WITH_LINUX EXTRA_DIST += virusbtest.c virusbmock.c \ @@ -1110,6 +1118,7 @@ virmockdbus_la_SOURCES = \ virmockdbus.c virmockdbus_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS) virmockdbus_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +virmockdbus_la_LIBADD = $(MOCKLIBS_LIBS) virpolkittest_SOURCES = \ virpolkittest.c testutils.h testutils.c -- 2.5.0

On Thu, Feb 11, 2016 at 12:15:39PM +0100, Andrea Bolognani wrote:
This patches make sure mock libraries do not link against either too many or too few libraries.
Cheers.
Andrea Bolognani (2): tests: Use plain close() in mock code tests: Link mock libraries against gnulib and gnulib only
tests/Makefile.am | 21 +++++++++++++++------ tests/virportallocatortest.c | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Thu, 2016-02-11 at 11:17 +0000, Daniel P. Berrange wrote:
On Thu, Feb 11, 2016 at 12:15:39PM +0100, Andrea Bolognani wrote:
This patches make sure mock libraries do not link against either too many or too few libraries.
Cheers.
Andrea Bolognani (2): tests: Use plain close() in mock code tests: Link mock libraries against gnulib and gnulib only
tests/Makefile.am | 21 +++++++++++++++------ tests/virportallocatortest.c | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-)
ACK
Pushed, thanks. -- Andrea Bolognani Software Engineer - Virtualization Team

On Thu, 2016-02-11 at 12:34 +0100, Andrea Bolognani wrote:
On Thu, 2016-02-11 at 11:17 +0000, Daniel P. Berrange wrote:
On Thu, Feb 11, 2016 at 12:15:39PM +0100, Andrea Bolognani wrote:
This patches make sure mock libraries do not link against either too many or too few libraries. Cheers. Andrea Bolognani (2): tests: Use plain close() in mock code tests: Link mock libraries against gnulib and gnulib only tests/Makefile.am | 21 +++++++++++++++------ tests/virportallocatortest.c | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) ACK Pushed, thanks.
Aaaaand the mingw build is now broken again: .../gnulib/lib/.libs/libgnu.a(bind.o): In function `rpl_bind': .../gnulib/lib/bind.c:33: multiple definition of `rpl_bind' .../tests/virportallocatormock.c:79: first defined here .../gnulib/lib/.libs/libgnu.a(socket.o): In function `rpl_socket': .../gnulib/lib/socket.c:33: multiple definition of `rpl_socket' .../tests/virportallocatormock.c:65: first defined here collect2: error: ld returned 1 exit status Makefile:4130: recipe for target 'virportallocatormock.la' failed Note that this is the most recent failure[1] so it refers to the new filename, but it looks like it started failing[2] as soon as this snippet was introduced: @@ -1025,7 +1031,7 @@ libvirportallocatormock_la_SOURCES = \ virportallocatortest.c libvirportallocatormock_la_CFLAGS = $(AM_CFLAGS) -DMOCK_HELPER=1 libvirportallocatormock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) -libvirportallocatormock_la_LIBADD = ../src/libvirt.la +libvirportallocatormock_la_LIBADD = $(MOCKLIBS_LIBS) vircgrouptest_SOURCES = \ vircgrouptest.c testutils.h testutils.c IOW as soon as we started linking gnulib into virportallocatormock. Any ideas, Dan? Cheers. [1] https://ci.centos.org/view/libvirt-project/job/libvirt-mingw/1040/console [2] https://ci.centos.org/view/libvirt-project/job/libvirt-mingw/1038/console -- Andrea Bolognani Software Engineer - Virtualization Team
participants (2)
-
Andrea Bolognani
-
Daniel P. Berrange