On Fri, 2018-04-27 at 16:35 +0100, Daniel P. Berrangé wrote:
> On Fri, Apr 27, 2018 at 05:21:21PM +0200, Andrea Bolognani wrote:
> > When hostdevs are involved, libvirt needs to poke into sysfs to
> > collect some information about them; since that pseudo-filesystem
> > doesn't exist on platforms other than Linux, the corresponding
> > tests would fail and need to be compiled out.
>
> Our test suite isn't supposed to touch /sysfs from the real
> host at all. Sounds like we either need to mock out the
> function that's doing that, or provide some fake sysfs data
> in a tests/ subdirectory to run against with a mock'd open()
> call. That would make it work even on non-Linux I hope.
Sorry, I should have provided some more context, but I was in a
bit of a hurry on Friday when I sent this.
We are already mocking (parts of) sysfs through virpcimock, but
the contents of that file are compiled out on non-Linux; after
removing the #ifdefs, it's fairly easy to solve most of the build
issues on FreeBSD (draft patch attached), but there's one I
couldn't quite get rid of.
Mocking canonicalize_file_name() causes a linking error:
../gnulib/lib/.libs/libgnu.a(canonicalize-lgpl.o): In function `canonicalize_file_name':
.../libvirt/gnulib/lib/canonicalize-lgpl.c:417: multiple definition of `canonicalize_file_name'
.libs/virpcimock.o:.../libvirt/tests/virpcimock.c:983: first defined here
This is not a problem on Linux, where canonicalize_file_name() is
provided by libc, but FreeBSD is using the gnulib implementation
instead, leading to the issue above.
Can you think of a way to make linking of virpcimock work despite
the above? That should get us to the point where at least
qemumemlocktest and qemuxml2xmltest are working; qemuxml2argvtest
will probably need more mocking because of NUMA information.
--
Andrea Bolognani / Red Hat / Virtualization
From ba477f6327c632d881c6dec0b07cfd2926027091 Mon Sep 17 00:00:00 2001
From: Andrea Bolognani <abologna@xxxxxxxxxx>
Date: Thu, 26 Apr 2018 12:52:47 +0000
Subject: [PATCH] virpcimock
---
tests/virpcimock.c | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/tests/virpcimock.c b/tests/virpcimock.c
index 176c64d65..934e4bc3c 100644
--- a/tests/virpcimock.c
+++ b/tests/virpcimock.c
@@ -20,7 +20,6 @@
#include <config.h>
-#ifdef __linux__
# include "virmock.h"
# include <stdio.h>
# include <stdlib.h>
@@ -341,6 +340,7 @@ pci_device_new_from_stub(const struct pciDevice *data)
char *configSrc;
char tmp[256];
struct stat sb;
+ bool succ = false;
if (VIR_STRDUP_QUIET(id, data->id) < 0)
ABORT_OOM();
@@ -370,8 +370,15 @@ pci_device_new_from_stub(const struct pciDevice *data)
/* If there is a config file for the device within virpcitestdata dir,
* symlink it. Otherwise create a dummy config file. */
- if ((real_stat && real_stat(configSrc, &sb) == 0) ||
- (real___xstat && real___xstat(_STAT_VER, configSrc, &sb) == 0)) {
+ if (real_stat && real_stat(configSrc, &sb) == 0)
+ succ = true;
+
+# ifdef HAVE___XSTAT
+ if (!succ && real___xstat && real___xstat(_STAT_VER, configSrc, &sb) == 0)
+ succ = true;
+# endif
+
+ if (succ) {
/* On success, copy @configSrc into the destination (a copy,
* rather than a symlink, is required since we write into the
* file, and parallel VPATH builds must not stomp on the
@@ -891,6 +898,7 @@ access(const char *path, int mode)
return ret;
}
+#ifdef HAVE___LXSTAT
int
__lxstat(int ver, const char *path, struct stat *sb)
{
@@ -909,6 +917,7 @@ __lxstat(int ver, const char *path, struct stat *sb)
}
return ret;
}
+#endif
int
lstat(const char *path, struct stat *sb)
@@ -929,6 +938,7 @@ lstat(const char *path, struct stat *sb)
return ret;
}
+#ifdef HAVE___XSTAT
int
__xstat(int ver, const char *path, struct stat *sb)
{
@@ -947,6 +957,7 @@ __xstat(int ver, const char *path, struct stat *sb)
}
return ret;
}
+#endif
int
stat(const char *path, struct stat *sb)
@@ -1000,11 +1011,11 @@ open(const char *path, int flags, ...)
if (flags & O_CREAT) {
va_list ap;
- mode_t mode;
+ int mode;
va_start(ap, flags);
- mode = va_arg(ap, mode_t);
+ mode = va_arg(ap, int);
va_end(ap);
- ret = real_open(newpath ? newpath : path, flags, mode);
+ ret = real_open(newpath ? newpath : path, flags, (mode_t) mode);
} else {
ret = real_open(newpath ? newpath : path, flags);
}
@@ -1046,6 +1057,3 @@ close(int fd)
return -1;
return real_close(fd);
}
-#else
-/* Nothing to override on non-__linux__ platforms */
-#endif
--
2.16.3
--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list