From: Jason Wang <jasowang@redhat.com>
To: Fam Zheng <famz@redhat.com>
Cc: qemu-devel@nongnu.org, stefanha@redhat.com, mst@redhat.com
Subject: Re: [Qemu-devel] [PATCH 1/2] tests: introduce basic pci test for virtio-net
Date: Wed, 08 Jul 2015 17:41:44 +0800 [thread overview]
Message-ID: <559CF058.2060103@redhat.com> (raw)
In-Reply-To: <20150708054720.GB22926@ad.nay.redhat.com>
On 07/08/2015 01:47 PM, Fam Zheng wrote:
> On Wed, 07/08 13:02, Jason Wang wrote:
>> >
>> >
>> > On 07/08/2015 11:19 AM, Fam Zheng wrote:
>>> > > On Tue, 07/07 18:58, Jason Wang wrote:
>>>> > >> Signed-off-by: Jason Wang <jasowang@redhat.com>
>>>> > >> ---
>>>> > >> tests/Makefile | 2 +-
>>>> > >> tests/virtio-net-test.c | 184 ++++++++++++++++++++++++++++++++++++++++++++++--
>>>> > >> 2 files changed, 178 insertions(+), 8 deletions(-)
>>>> > >>
>>>> > >> diff --git a/tests/Makefile b/tests/Makefile
>>>> > >> index eff5e11..56179e5 100644
>>>> > >> --- a/tests/Makefile
>>>> > >> +++ b/tests/Makefile
>>>> > >> @@ -372,7 +372,7 @@ tests/ne2000-test$(EXESUF): tests/ne2000-test.o
>>>> > >> tests/wdt_ib700-test$(EXESUF): tests/wdt_ib700-test.o
>>>> > >> tests/virtio-balloon-test$(EXESUF): tests/virtio-balloon-test.o
>>>> > >> tests/virtio-blk-test$(EXESUF): tests/virtio-blk-test.o $(libqos-virtio-obj-y)
>>>> > >> -tests/virtio-net-test$(EXESUF): tests/virtio-net-test.o $(libqos-pc-obj-y)
>>>> > >> +tests/virtio-net-test$(EXESUF): tests/virtio-net-test.o $(libqos-pc-obj-y) $(libqos-virtio-obj-y)
>>>> > >> tests/virtio-rng-test$(EXESUF): tests/virtio-rng-test.o $(libqos-pc-obj-y)
>>>> > >> tests/virtio-scsi-test$(EXESUF): tests/virtio-scsi-test.o $(libqos-virtio-obj-y)
>>>> > >> tests/virtio-9p-test$(EXESUF): tests/virtio-9p-test.o
>>>> > >> diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c
>>>> > >> index ea7478c..97aa442 100644
>>>> > >> --- a/tests/virtio-net-test.c
>>>> > >> +++ b/tests/virtio-net-test.c
>>>> > >> @@ -10,20 +10,191 @@
>>>> > >> #include <glib.h>
>>>> > >> #include <string.h>
>>>> > >> #include "libqtest.h"
>>>> > >> +#include "qemu-common.h"
>>>> > >> +#include "qemu/sockets.h"
>>>> > >> #include "qemu/osdep.h"
>>>> > >> -#include "libqos/pci.h"
>>>> > >> +#include "qemu/iov.h"
>>>> > >> +#include "libqos/pci-pc.h"
>>>> > >> +#include "libqos/virtio.h"
>>>> > >> +#include "libqos/virtio-pci.h"
>>>> > >> +#include "libqos/malloc.h"
>>>> > >> +#include "libqos/malloc-pc.h"
>>>> > >> +#include "libqos/malloc-generic.h"
>>>> > >> +#include "qemu/bswap.h"
>>>> > >>
>>>> > >> #define PCI_SLOT_HP 0x06
>>>> > >> +#define PCI_SLOT 0x04
>>>> > >> +#define PCI_FN 0x00
>>>> > >>
>>>> > >> -/* Tests only initialization so far. TODO: Replace with functional tests */
>>>> > >> -static void pci_nop(void)
>>>> > >> +#define QVIRTIO_NET_TIMEOUT_US (30 * 1000 * 1000)
>>>> > >> +
>>>> > >> +static void test_end(void)
>>>> > >> +{
>>>> > >> + qtest_end();
>>>> > >> +}
>>>> > >> +
>>>> > >> +#ifndef _WIN32
>>>> > >> +
>>>> > >> +static QVirtioPCIDevice *virtio_net_pci_init(QPCIBus *bus, int slot)
>>>> > >> +{
>>>> > >> + QVirtioPCIDevice *dev;
>>>> > >> +
>>>> > >> + dev = qvirtio_pci_device_find(bus, QVIRTIO_NET_DEVICE_ID);
>>>> > >> + g_assert(dev != NULL);
>>>> > >> + g_assert_cmphex(dev->vdev.device_type, ==, QVIRTIO_NET_DEVICE_ID);
>>>> > >> +
>>>> > >> + qvirtio_pci_device_enable(dev);
>>>> > >> + qvirtio_reset(&qvirtio_pci, &dev->vdev);
>>>> > >> + qvirtio_set_acknowledge(&qvirtio_pci, &dev->vdev);
>>>> > >> + qvirtio_set_driver(&qvirtio_pci, &dev->vdev);
>>>> > >> +
>>>> > >> + return dev;
>>>> > >> +}
>>>> > >> +
>>>> > >> +static QPCIBus *pci_test_start(int socket)
>>>> > >> +{
>>>> > >> + char *cmdline;
>>>> > >> +
>>>> > >> + cmdline = g_strdup_printf("-netdev socket,fd=%d,id=hs0 -device "
>>>> > >> + "virtio-net-pci,netdev=hs0", socket);
>>>> > >> + qtest_start(cmdline);
>>>> > >> + g_free(cmdline);
>>>> > >> +
>>>> > >> + return qpci_init_pc();
>>>> > >> +}
>>>> > >> +
>>>> > >> +static void driver_init(const QVirtioBus *bus, QVirtioDevice *dev)
>>>> > >> +{
>>>> > >> + uint32_t features;
>>>> > >> +
>>>> > >> + features = qvirtio_get_features(bus, dev);
>>>> > >> + features = features & ~(QVIRTIO_F_BAD_FEATURE |
>>>> > >> + QVIRTIO_F_RING_INDIRECT_DESC |
>>>> > >> + QVIRTIO_F_RING_EVENT_IDX);
>>>> > >> + qvirtio_set_features(bus, dev, features);
>>>> > >> +
>>>> > >> + qvirtio_set_driver_ok(bus, dev);
>>>> > >> +}
>>>> > >> +
>>>> > >> +static void rx_test(const QVirtioBus *bus, QVirtioDevice *dev,
>>>> > >> + QGuestAllocator *alloc, QVirtQueue *vq,
>>>> > >> + int socket)
>>>> > >> {
>>>> > >> + uint64_t req_addr;
>>>> > >> + uint32_t free_head;
>>>> > >> + char test[] = "TEST";
>>>> > >> + char buffer[64];
>>>> > >> + int len = htonl(sizeof(test));
>>>> > >> + struct iovec iov[] = {
>>>> > >> + {
>>>> > >> + .iov_base = &len,
>>>> > >> + .iov_len = sizeof(len),
>>>> > >> + }, {
>>>> > >> + .iov_base = test,
>>>> > >> + .iov_len = sizeof(test),
>>>> > >> + },
>>>> > >> + };
>>>> > >> + int ret;
>>>> > >> +
>>>> > >> + req_addr = guest_alloc(alloc, 64);
>>>> > >> +
>>>> > >> + free_head = qvirtqueue_add(vq, req_addr, 64, true, false);
>>>> > >> + qvirtqueue_kick(bus, dev, vq, free_head);
>>>> > >> +
>>>> > >> + ret = iov_send(socket, iov, 2, 0, sizeof(len) + sizeof(test));
>>>> > >> + g_assert_cmpint(ret, ==, sizeof(test) + sizeof(len));
>>>> > >> +
>>>> > >> + qvirtio_wait_queue_isr(bus, dev, vq, QVIRTIO_NET_TIMEOUT_US);
>>>> > >> + memread(req_addr + 12, buffer, sizeof(test));
>>> > > What does 12 mean?
>> >
>> > It was the size of vnet header which needs to be put ahead of the real
>> > packet.
> Could you define a macro for this?
>
Will do this in v2.
prev parent reply other threads:[~2015-07-08 9:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-07 10:58 [Qemu-devel] [PATCH 1/2] tests: introduce basic pci test for virtio-net Jason Wang
2015-07-07 10:58 ` [Qemu-devel] [PATCH 2/2] tests: test rx recovery from cont Jason Wang
2015-07-08 3:22 ` Fam Zheng
2015-07-08 5:12 ` Jason Wang
2015-07-08 5:44 ` Fam Zheng
2015-07-08 5:48 ` Fam Zheng
2015-07-08 9:42 ` Jason Wang
2015-07-08 3:19 ` [Qemu-devel] [PATCH 1/2] tests: introduce basic pci test for virtio-net Fam Zheng
2015-07-08 5:02 ` Jason Wang
2015-07-08 5:47 ` Fam Zheng
2015-07-08 9:41 ` Jason Wang [this message]
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=559CF058.2060103@redhat.com \
--to=jasowang@redhat.com \
--cc=famz@redhat.com \
--cc=mst@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).