From nobody Wed May 14 23:49:54 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1525344987370962.1884965003065; Thu, 3 May 2018 03:56:27 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4F6A53185863; Thu, 3 May 2018 10:56:26 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1832726578; Thu, 3 May 2018 10:56:26 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B7079180BADA; Thu, 3 May 2018 10:56:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w43AsWZN018699 for ; Thu, 3 May 2018 06:54:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 20A06202345A; Thu, 3 May 2018 10:54:32 +0000 (UTC) Received: from inaba.usersys.redhat.com (unknown [10.43.2.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B85452023456 for ; Thu, 3 May 2018 10:54:31 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Thu, 3 May 2018 12:54:21 +0200 Message-Id: <20180503105423.24837-8-abologna@redhat.com> In-Reply-To: <20180503105423.24837-1-abologna@redhat.com> References: <20180503105423.24837-1-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 7/9] tests: Build virpcimock on non-Linux X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 03 May 2018 10:56:26 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" There are only a couple issues preventing it from working on other platform such as FreeBSD. Let's fix them. With the mocking in place, qemumemlocktest and qemuxml2xmltest can finally succeed on FreeBSD. This commit is best viewed with 'git show -w'. Signed-off-by: Andrea Bolognani Reviewed-by: Daniel P. Berrang=C3=A9 --- tests/virpcimock.c | 57 +++++++++++++++++++++++++++++++-------------------= ---- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/tests/virpcimock.c b/tests/virpcimock.c index 7e4ac191d0..09cb26567c 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -20,19 +20,18 @@ =20 #include =20 -#ifdef __linux__ -# include "virmock.h" -# include -# include -# include -# include -# include -# include -# include -# include "viralloc.h" -# include "virstring.h" -# include "virfile.h" -# include "dirname.h" +#include "virmock.h" +#include +#include +#include +#include +#include +#include +#include +#include "viralloc.h" +#include "virstring.h" +#include "virfile.h" +#include "dirname.h" =20 static int (*real_access)(const char *path, int mode); static int (*real_lstat)(const char *path, struct stat *sb); @@ -51,20 +50,20 @@ static char *(*real_virFileCanonicalizePath)(const char= *path); char *fakerootdir; char *fakesysfspcidir; =20 -# define SYSFS_PCI_PREFIX "/sys/bus/pci/" +#define SYSFS_PCI_PREFIX "/sys/bus/pci/" =20 -# define STDERR(...) \ +#define STDERR(...) \ fprintf(stderr, "%s %zu: ", __FUNCTION__, (size_t) __LINE__); \ fprintf(stderr, __VA_ARGS__); \ fprintf(stderr, "\n"); \ =20 -# define ABORT(...) \ +#define ABORT(...) \ do { \ STDERR(__VA_ARGS__); \ abort(); \ } while (0) =20 -# define ABORT_OOM() \ +#define ABORT_OOM() \ ABORT("Out of memory") /* * The plan: @@ -341,6 +340,7 @@ pci_device_new_from_stub(const struct pciDevice *data) char *configSrc; char tmp[256]; struct stat sb; + bool configSrcExists =3D false; =20 if (VIR_STRDUP_QUIET(id, data->id) < 0) ABORT_OOM(); @@ -368,10 +368,18 @@ pci_device_new_from_stub(const struct pciDevice *data) if (virFileMakePath(devpath) < 0) ABORT("Unable to create: %s", devpath); =20 + if (real_stat && real_stat(configSrc, &sb) =3D=3D 0) + configSrcExists =3D true; + +#ifdef HAVE___XSTAT + if (!configSrcExists && + real___xstat && real___xstat(_STAT_VER, configSrc, &sb) =3D=3D 0) + configSrcExists =3D true; +#endif + /* 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) =3D=3D 0) || - (real___xstat && real___xstat(_STAT_VER, configSrc, &sb) =3D=3D 0)= ) { + if (configSrcExists) { /* 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 @@ -834,7 +842,7 @@ init_env(void) =20 make_file(fakesysfspcidir, "drivers_probe", NULL, -1); =20 -# define MAKE_PCI_DRIVER(name, ...) \ +#define MAKE_PCI_DRIVER(name, ...) \ pci_driver_new(name, 0, __VA_ARGS__, -1, -1) =20 MAKE_PCI_DRIVER("iwlwifi", 0x8086, 0x0044); @@ -842,7 +850,7 @@ init_env(void) MAKE_PCI_DRIVER("pci-stub", -1, -1); pci_driver_new("vfio-pci", PCI_ACTION_BIND, -1, -1); =20 -# define MAKE_PCI_DEVICE(Id, Vendor, Device, ...) \ +#define MAKE_PCI_DEVICE(Id, Vendor, Device, ...) \ do { \ struct pciDevice dev =3D {.id =3D (char *)Id, .vendor =3D Vendor, \ .device =3D Device, __VA_ARGS__}; \ @@ -891,6 +899,7 @@ access(const char *path, int mode) return ret; } =20 +#ifdef HAVE___LXSTAT int __lxstat(int ver, const char *path, struct stat *sb) { @@ -909,6 +918,7 @@ __lxstat(int ver, const char *path, struct stat *sb) } return ret; } +#endif /* HAVE___LXSTAT */ =20 int lstat(const char *path, struct stat *sb) @@ -929,6 +939,7 @@ lstat(const char *path, struct stat *sb) return ret; } =20 +#ifdef HAVE___XSTAT int __xstat(int ver, const char *path, struct stat *sb) { @@ -947,6 +958,7 @@ __xstat(int ver, const char *path, struct stat *sb) } return ret; } +#endif /* HAVE___XSTAT */ =20 int stat(const char *path, struct stat *sb) @@ -1049,6 +1061,3 @@ virFileCanonicalizePath(const char *path) =20 return ret; } -#else -/* Nothing to override on non-__linux__ platforms */ -#endif --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list