qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Marc Marí" <marc.mari.barcelo@gmail.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [RFC] Functions bus_foreach and device_find from libqos virtio API
Date: Tue, 24 Jun 2014 10:02:08 +0200	[thread overview]
Message-ID: <20140624100208.0f138f87@crunchbang> (raw)
In-Reply-To: <20140624044114.GC3147@stefanha-thinkpad.redhat.com>

Hello

> > +    for (slot = 0; slot < 32; slot++) {
> > +        for (fn = 0; fn < 8; fn++) {
> > +            dev = g_malloc0(sizeof(*dev));
> > +            dev->bus = bus;
> > +            dev->devfn = QPCI_DEVFN(slot, fn);
> > +
> > +            if (qpci_config_readw(dev, PCI_VENDOR_ID) == 0xFFFF) {
> > +                g_free(dev);
> > +                continue;
> > +            }
> > +
> > +            if (device_type != (uint16_t)-1 &&
> > +                qpci_config_readw(dev, PCI_SUBSYSTEM_ID) !=
> > device_type) {
> > +                continue;
> > +            }
> > +
> > +            func(qpcidevice_to_qvirtiodevice(dev), data);
> > +        }
> > +    }
> 
> 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í
> >   *
> >   * 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 @@
> >  
> >  #include <glib.h>
> >  #include <string.h>
> > +#include <stdlib.h>
> > +#include <unistd.h>
> > +#include <stdio.h>
> >  #include "libqtest.h"
> > -#include "qemu/osdep.h"
> > +#include "libqos/virtio.h"
> > +/*#include "qemu/osdep.h"*/
> >  
> > -/* 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[] = "/tmp/qtest.XXXXXX";
> > +extern QVirtioBus qvirtio_pci;
> > +
> > +static void pci_basic(void)
> >  {
> > +    QVirtioDevice *dev;
> > +    dev = qvirtio_pci.device_find(VIRTIO_BLK_DEVICE_ID);
> > +    fprintf(stderr, "Device: %x %x %x\n",
> > +                            dev->device_id, dev->location,
> > dev->device_type); }
> >  
> >  int main(int argc, char **argv)
> >  {
> >      int ret;
> > +    int fd;
> > +    char test_start[100];
> >  
> >      g_test_init(&argc, &argv, NULL);
> > -    qtest_add_func("/virtio/blk/pci/nop", pci_nop);
> > +    qtest_add_func("/virtio/blk/pci/basic", pci_basic);
> >  
> > -    qtest_start("-drive id=drv0,if=none,file=/dev/null "
> > -                "-device virtio-blk-pci,drive=drv0");
> > +    /* Create a temporary raw image */
> > +    fd = mkstemp(tmp_path);
> > +    g_assert_cmpint(fd, >=, 0);
> > +    ret = ftruncate(fd, TEST_IMAGE_SIZE);
> > +    g_assert_cmpint(ret, ==, 0);
> > +    close(fd);
> > +
> > +    sprintf(test_start, "-drive if=none,id=drive0,file=%s "
> > +                    "-device virtio-blk-pci,drive=drive0",
> > tmp_path);
> > +    qtest_start(test_start);
> 
> 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?

  reply	other threads:[~2014-06-24  8:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-23 14:55 [Qemu-devel] [RFC] Functions bus_foreach and device_find from libqos virtio API Marc Marí
2014-06-24  4:41 ` Stefan Hajnoczi
2014-06-24  8:02   ` Marc Marí [this message]
2014-06-24  6:05 ` Fam Zheng
2014-06-24  8:11   ` Marc Marí

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140624100208.0f138f87@crunchbang \
    --to=marc.mari.barcelo@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).