From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45643) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzLgQ-0001Aw-UQ for qemu-devel@nongnu.org; Tue, 24 Jun 2014 04:02:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WzLgF-0001uD-OU for qemu-devel@nongnu.org; Tue, 24 Jun 2014 04:02:26 -0400 Received: from mail-wg0-x22f.google.com ([2a00:1450:400c:c00::22f]:40586) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzLgF-0001u4-F1 for qemu-devel@nongnu.org; Tue, 24 Jun 2014 04:02:15 -0400 Received: by mail-wg0-f47.google.com with SMTP id k14so7495829wgh.18 for ; Tue, 24 Jun 2014 01:02:14 -0700 (PDT) Date: Tue, 24 Jun 2014 10:02:08 +0200 From: Marc =?UTF-8?B?TWFyw60=?= Message-ID: <20140624100208.0f138f87@crunchbang> In-Reply-To: <20140624044114.GC3147@stefanha-thinkpad.redhat.com> References: <1403535322-3346-1-git-send-email-marc.mari.barcelo@gmail.com> <20140624044114.GC3147@stefanha-thinkpad.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [RFC] Functions bus_foreach and device_find from libqos virtio API List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: Paolo Bonzini , qemu-devel@nongnu.org Hello > > + for (slot =3D 0; slot < 32; slot++) { > > + for (fn =3D 0; fn < 8; fn++) { > > + dev =3D g_malloc0(sizeof(*dev)); > > + dev->bus =3D bus; > > + dev->devfn =3D QPCI_DEVFN(slot, fn); > > + > > + if (qpci_config_readw(dev, PCI_VENDOR_ID) =3D=3D 0xFFFF) { > > + g_free(dev); > > + continue; > > + } > > + > > + if (device_type !=3D (uint16_t)-1 && > > + qpci_config_readw(dev, PCI_SUBSYSTEM_ID) !=3D > > device_type) { > > + continue; > > + } > > + > > + func(qpcidevice_to_qvirtiodevice(dev), data); > > + } > > + } >=20 > Can you reuse qpci_device_foreach() instead of duplicating this code? I've been thinking and I don't know how to join this definition: void qvirtio_pci_foreach(uint16_t device_id, void (*func)(QVirtioDevice *d, void *data), void *data); With this definition: void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id, void (*func)(QPCIDevice *dev, int devfn, void *data), void *data) The function parameter lacks one parameter (which is PCI specific) Any idea? > > + > > +#endif > > diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c > > index d53f875..4f5b1e0 100644 > > --- a/tests/virtio-blk-test.c > > +++ b/tests/virtio-blk-test.c > > @@ -2,6 +2,7 @@ > > * QTest testcase for VirtIO Block Device > > * > > * Copyright (c) 2014 SUSE LINUX Products GmbH > > + * Copyright (c) 2014 Marc Mar=C3=AD > > * > > * This work is licensed under the terms of the GNU GPL, version 2 > > or later. > > * See the COPYING file in the top-level directory. > > @@ -9,26 +10,51 @@ > > =20 > > #include > > #include > > +#include > > +#include > > +#include > > #include "libqtest.h" > > -#include "qemu/osdep.h" > > +#include "libqos/virtio.h" > > +/*#include "qemu/osdep.h"*/ > > =20 > > -/* Tests only initialization so far. TODO: Replace with functional > > tests */ -static void pci_nop(void) > > +#define TEST_IMAGE_SIZE (64 * 1024 * 1024) > > + > > +static char tmp_path[] =3D "/tmp/qtest.XXXXXX"; > > +extern QVirtioBus qvirtio_pci; > > + > > +static void pci_basic(void) > > { > > + QVirtioDevice *dev; > > + dev =3D qvirtio_pci.device_find(VIRTIO_BLK_DEVICE_ID); > > + fprintf(stderr, "Device: %x %x %x\n", > > + dev->device_id, dev->location, > > dev->device_type); } > > =20 > > int main(int argc, char **argv) > > { > > int ret; > > + int fd; > > + char test_start[100]; > > =20 > > g_test_init(&argc, &argv, NULL); > > - qtest_add_func("/virtio/blk/pci/nop", pci_nop); > > + qtest_add_func("/virtio/blk/pci/basic", pci_basic); > > =20 > > - qtest_start("-drive id=3Ddrv0,if=3Dnone,file=3D/dev/null " > > - "-device virtio-blk-pci,drive=3Ddrv0"); > > + /* Create a temporary raw image */ > > + fd =3D mkstemp(tmp_path); > > + g_assert_cmpint(fd, >=3D, 0); > > + ret =3D ftruncate(fd, TEST_IMAGE_SIZE); > > + g_assert_cmpint(ret, =3D=3D, 0); > > + close(fd); > > + > > + sprintf(test_start, "-drive if=3Dnone,id=3Ddrive0,file=3D%s " > > + "-device virtio-blk-pci,drive=3Ddrive0", > > tmp_path); > > + qtest_start(test_start); >=20 > Every test case should probably start a fresh QEMU with a fresh disk > image. That way no device register state or disk image state can > affect later test cases. Is it better to create a new temporary file (and so, re-run qemu), or just truncate every time?