* [Qemu-devel] [PATCH V2 1/2] tests: introduce basic pci test for virtio-net
@ 2015-07-13 6:04 Jason Wang
2015-07-13 6:04 ` [Qemu-devel] [PATCH V2 2/2] tests: test rx recovery from cont Jason Wang
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Jason Wang @ 2015-07-13 6:04 UTC (permalink / raw)
To: stefanha, qemu-devel; +Cc: Jason Wang, famz, mst
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
Changes from V1:
- replace the magic value 12 with a macro
---
tests/Makefile | 2 +-
tests/virtio-net-test.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 180 insertions(+), 8 deletions(-)
diff --git a/tests/Makefile b/tests/Makefile
index 2c4b8dc..5805326 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -381,7 +381,7 @@ tests/wdt_ib700-test$(EXESUF): tests/wdt_ib700-test.o
tests/tco-test$(EXESUF): tests/tco-test.o $(libqos-pc-obj-y)
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..b7d6f0b 100644
--- a/tests/virtio-net-test.c
+++ b/tests/virtio-net-test.c
@@ -10,20 +10,193 @@
#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"
+#include "hw/virtio/virtio-net.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)
+#define VNET_HDR_SIZE sizeof(struct virtio_net_hdr_mrg_rxbuf)
+
+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 + VNET_HDR_SIZE, buffer, sizeof(test));
+ g_assert_cmpstr(buffer, ==, "TEST");
+
+ guest_free(alloc, req_addr);
}
+static void tx_test(const QVirtioBus *bus, QVirtioDevice *dev,
+ QGuestAllocator *alloc, QVirtQueue *vq,
+ int socket)
+{
+ uint64_t req_addr;
+ uint32_t free_head;
+ uint32_t len;
+ char buffer[64];
+ int ret;
+
+ req_addr = guest_alloc(alloc, 64);
+ memwrite(req_addr + VNET_HDR_SIZE, "TEST", 4);
+
+ free_head = qvirtqueue_add(vq, req_addr, 64, false, false);
+ qvirtqueue_kick(bus, dev, vq, free_head);
+
+ qvirtio_wait_queue_isr(bus, dev, vq, QVIRTIO_NET_TIMEOUT_US);
+ guest_free(alloc, req_addr);
+
+ ret = qemu_recv(socket, &len, sizeof(len), 0);
+ g_assert_cmpint(ret, ==, sizeof(len));
+ len = ntohl(len);
+
+ ret = qemu_recv(socket, buffer, len, 0);
+ g_assert_cmpstr(buffer, ==, "TEST");
+}
+
+static void send_recv_test(const QVirtioBus *bus, QVirtioDevice *dev,
+ QGuestAllocator *alloc, QVirtQueue *rvq,
+ QVirtQueue *tvq, int socket)
+{
+ rx_test(bus, dev, alloc, rvq, socket);
+ tx_test(bus, dev, alloc, tvq, socket);
+}
+
+static void pci_basic(gconstpointer data)
+{
+ QVirtioPCIDevice *dev;
+ QPCIBus *bus;
+ QVirtQueuePCI *tx, *rx;
+ QGuestAllocator *alloc;
+ void (*func) (const QVirtioBus *bus,
+ QVirtioDevice *dev,
+ QGuestAllocator *alloc,
+ QVirtQueue *rvq,
+ QVirtQueue *tvq,
+ int socket) = data;
+ int sv[2], ret;
+
+ ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sv);
+ g_assert_cmpint(ret, !=, -1);
+
+ bus = pci_test_start(sv[1]);
+ dev = virtio_net_pci_init(bus, PCI_SLOT);
+
+ alloc = pc_alloc_init();
+ rx = (QVirtQueuePCI *)qvirtqueue_setup(&qvirtio_pci, &dev->vdev,
+ alloc, 0);
+ tx = (QVirtQueuePCI *)qvirtqueue_setup(&qvirtio_pci, &dev->vdev,
+ alloc, 1);
+
+ driver_init(&qvirtio_pci, &dev->vdev);
+ func(&qvirtio_pci, &dev->vdev, alloc, &rx->vq, &tx->vq, sv[0]);
+
+ /* End test */
+ close(sv[0]);
+ guest_free(alloc, tx->vq.desc);
+ pc_alloc_uninit(alloc);
+ qvirtio_pci_device_disable(dev);
+ g_free(dev);
+ qpci_free_pc(bus);
+ test_end();
+}
+#endif
+
static void hotplug(void)
{
+ qtest_start("-device virtio-net-pci");
+
qpci_plug_device_test("virtio-net-pci", "net1", PCI_SLOT_HP, NULL);
qpci_unplug_acpi_device_test("net1", PCI_SLOT_HP);
+ qtest_start("-device virtio-net-pci");
+
+ test_end();
}
int main(int argc, char **argv)
@@ -31,13 +204,12 @@ int main(int argc, char **argv)
int ret;
g_test_init(&argc, &argv, NULL);
- qtest_add_func("/virtio/net/pci/nop", pci_nop);
+#ifndef _WIN32
+ qtest_add_data_func("/virtio/net/pci/basic", send_recv_test, pci_basic);
+#endif
qtest_add_func("/virtio/net/pci/hotplug", hotplug);
- qtest_start("-device virtio-net-pci");
ret = g_test_run();
- qtest_end();
-
return ret;
}
--
2.1.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH V2 2/2] tests: test rx recovery from cont
2015-07-13 6:04 [Qemu-devel] [PATCH V2 1/2] tests: introduce basic pci test for virtio-net Jason Wang
@ 2015-07-13 6:04 ` Jason Wang
2015-07-13 8:52 ` Fam Zheng
2015-07-13 8:49 ` [Qemu-devel] [PATCH V2 1/2] tests: introduce basic pci test for virtio-net Fam Zheng
2015-07-16 10:41 ` Stefan Hajnoczi
2 siblings, 1 reply; 7+ messages in thread
From: Jason Wang @ 2015-07-13 6:04 UTC (permalink / raw)
To: stefanha, qemu-devel; +Cc: Jason Wang, famz, mst
Rx should be recovered after cont.
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
Changes from V1:
- query status before sending cont, this makes sure that the packet
were queued.
---
tests/virtio-net-test.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c
index b7d6f0b..3c412e2 100644
--- a/tests/virtio-net-test.c
+++ b/tests/virtio-net-test.c
@@ -140,6 +140,49 @@ static void tx_test(const QVirtioBus *bus, QVirtioDevice *dev,
g_assert_cmpstr(buffer, ==, "TEST");
}
+static void rx_stop_cont_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);
+
+ /* We could check the status, but this command is more importantly to
+ * ensure the packet data gets queued in QEMU, before we do 'cont'.
+ */
+ qmp("{ 'execute' : 'query-status'}");
+ qmp("{ 'execute' : 'stop'}");
+
+ ret = iov_send(socket, iov, 2, 0, sizeof(len) + sizeof(test));
+ g_assert_cmpint(ret, ==, sizeof(test) + sizeof(len));
+
+ qmp("{ 'execute' : 'cont'}");
+
+ qvirtio_wait_queue_isr(bus, dev, vq, QVIRTIO_NET_TIMEOUT_US);
+ memread(req_addr + VNET_HDR_SIZE, buffer, sizeof(test));
+ g_assert_cmpstr(buffer, ==, "TEST");
+
+ guest_free(alloc, req_addr);
+}
+
static void send_recv_test(const QVirtioBus *bus, QVirtioDevice *dev,
QGuestAllocator *alloc, QVirtQueue *rvq,
QVirtQueue *tvq, int socket)
@@ -148,6 +191,13 @@ static void send_recv_test(const QVirtioBus *bus, QVirtioDevice *dev,
tx_test(bus, dev, alloc, tvq, socket);
}
+static void stop_cont_test(const QVirtioBus *bus, QVirtioDevice *dev,
+ QGuestAllocator *alloc, QVirtQueue *rvq,
+ QVirtQueue *tvq, int socket)
+{
+ rx_stop_cont_test(bus, dev, alloc, rvq, socket);
+}
+
static void pci_basic(gconstpointer data)
{
QVirtioPCIDevice *dev;
@@ -206,6 +256,8 @@ int main(int argc, char **argv)
g_test_init(&argc, &argv, NULL);
#ifndef _WIN32
qtest_add_data_func("/virtio/net/pci/basic", send_recv_test, pci_basic);
+ qtest_add_data_func("/virtio/net/pci/rx_stop_cont",
+ stop_cont_test, pci_basic);
#endif
qtest_add_func("/virtio/net/pci/hotplug", hotplug);
--
2.1.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH V2 1/2] tests: introduce basic pci test for virtio-net
2015-07-13 6:04 [Qemu-devel] [PATCH V2 1/2] tests: introduce basic pci test for virtio-net Jason Wang
2015-07-13 6:04 ` [Qemu-devel] [PATCH V2 2/2] tests: test rx recovery from cont Jason Wang
@ 2015-07-13 8:49 ` Fam Zheng
2015-07-13 9:08 ` Jason Wang
2015-07-16 10:41 ` Stefan Hajnoczi
2 siblings, 1 reply; 7+ messages in thread
From: Fam Zheng @ 2015-07-13 8:49 UTC (permalink / raw)
To: Jason Wang; +Cc: qemu-devel, stefanha, mst
On Mon, 07/13 14:04, Jason Wang wrote:
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---
> Changes from V1:
> - replace the magic value 12 with a macro
> ---
> tests/Makefile | 2 +-
> tests/virtio-net-test.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++--
> 2 files changed, 180 insertions(+), 8 deletions(-)
>
> diff --git a/tests/Makefile b/tests/Makefile
> index 2c4b8dc..5805326 100644
> --- a/tests/Makefile
> +++ b/tests/Makefile
> @@ -381,7 +381,7 @@ tests/wdt_ib700-test$(EXESUF): tests/wdt_ib700-test.o
> tests/tco-test$(EXESUF): tests/tco-test.o $(libqos-pc-obj-y)
> 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..b7d6f0b 100644
> --- a/tests/virtio-net-test.c
> +++ b/tests/virtio-net-test.c
> @@ -10,20 +10,193 @@
> #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"
> +#include "hw/virtio/virtio-net.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)
> +#define VNET_HDR_SIZE sizeof(struct virtio_net_hdr_mrg_rxbuf)
> +
> +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 + VNET_HDR_SIZE, buffer, sizeof(test));
> + g_assert_cmpstr(buffer, ==, "TEST");
> +
> + guest_free(alloc, req_addr);
> }
>
> +static void tx_test(const QVirtioBus *bus, QVirtioDevice *dev,
> + QGuestAllocator *alloc, QVirtQueue *vq,
> + int socket)
> +{
> + uint64_t req_addr;
> + uint32_t free_head;
> + uint32_t len;
> + char buffer[64];
> + int ret;
> +
> + req_addr = guest_alloc(alloc, 64);
> + memwrite(req_addr + VNET_HDR_SIZE, "TEST", 4);
> +
> + free_head = qvirtqueue_add(vq, req_addr, 64, false, false);
> + qvirtqueue_kick(bus, dev, vq, free_head);
> +
> + qvirtio_wait_queue_isr(bus, dev, vq, QVIRTIO_NET_TIMEOUT_US);
> + guest_free(alloc, req_addr);
> +
> + ret = qemu_recv(socket, &len, sizeof(len), 0);
> + g_assert_cmpint(ret, ==, sizeof(len));
> + len = ntohl(len);
> +
> + ret = qemu_recv(socket, buffer, len, 0);
> + g_assert_cmpstr(buffer, ==, "TEST");
> +}
> +
> +static void send_recv_test(const QVirtioBus *bus, QVirtioDevice *dev,
> + QGuestAllocator *alloc, QVirtQueue *rvq,
> + QVirtQueue *tvq, int socket)
> +{
> + rx_test(bus, dev, alloc, rvq, socket);
> + tx_test(bus, dev, alloc, tvq, socket);
> +}
> +
> +static void pci_basic(gconstpointer data)
> +{
> + QVirtioPCIDevice *dev;
> + QPCIBus *bus;
> + QVirtQueuePCI *tx, *rx;
> + QGuestAllocator *alloc;
> + void (*func) (const QVirtioBus *bus,
> + QVirtioDevice *dev,
> + QGuestAllocator *alloc,
> + QVirtQueue *rvq,
> + QVirtQueue *tvq,
> + int socket) = data;
> + int sv[2], ret;
> +
> + ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sv);
> + g_assert_cmpint(ret, !=, -1);
> +
> + bus = pci_test_start(sv[1]);
> + dev = virtio_net_pci_init(bus, PCI_SLOT);
> +
> + alloc = pc_alloc_init();
> + rx = (QVirtQueuePCI *)qvirtqueue_setup(&qvirtio_pci, &dev->vdev,
> + alloc, 0);
> + tx = (QVirtQueuePCI *)qvirtqueue_setup(&qvirtio_pci, &dev->vdev,
> + alloc, 1);
> +
> + driver_init(&qvirtio_pci, &dev->vdev);
> + func(&qvirtio_pci, &dev->vdev, alloc, &rx->vq, &tx->vq, sv[0]);
> +
> + /* End test */
> + close(sv[0]);
> + guest_free(alloc, tx->vq.desc);
> + pc_alloc_uninit(alloc);
> + qvirtio_pci_device_disable(dev);
> + g_free(dev);
> + qpci_free_pc(bus);
> + test_end();
> +}
> +#endif
> +
> static void hotplug(void)
> {
> + qtest_start("-device virtio-net-pci");
> +
> qpci_plug_device_test("virtio-net-pci", "net1", PCI_SLOT_HP, NULL);
> qpci_unplug_acpi_device_test("net1", PCI_SLOT_HP);
> + qtest_start("-device virtio-net-pci");
What does this qtest_start do?
> +
> + test_end();
> }
>
> int main(int argc, char **argv)
> @@ -31,13 +204,12 @@ int main(int argc, char **argv)
> int ret;
>
> g_test_init(&argc, &argv, NULL);
> - qtest_add_func("/virtio/net/pci/nop", pci_nop);
> +#ifndef _WIN32
> + qtest_add_data_func("/virtio/net/pci/basic", send_recv_test, pci_basic);
> +#endif
> qtest_add_func("/virtio/net/pci/hotplug", hotplug);
>
> - qtest_start("-device virtio-net-pci");
> ret = g_test_run();
>
> - qtest_end();
> -
> return ret;
> }
> --
> 2.1.4
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH V2 2/2] tests: test rx recovery from cont
2015-07-13 6:04 ` [Qemu-devel] [PATCH V2 2/2] tests: test rx recovery from cont Jason Wang
@ 2015-07-13 8:52 ` Fam Zheng
2015-07-13 9:09 ` Jason Wang
0 siblings, 1 reply; 7+ messages in thread
From: Fam Zheng @ 2015-07-13 8:52 UTC (permalink / raw)
To: Jason Wang; +Cc: qemu-devel, stefanha, mst
On Mon, 07/13 14:04, Jason Wang wrote:
> Rx should be recovered after cont.
>
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---
> Changes from V1:
> - query status before sending cont, this makes sure that the packet
> were queued.
> ---
> tests/virtio-net-test.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 52 insertions(+)
>
> diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c
> index b7d6f0b..3c412e2 100644
> --- a/tests/virtio-net-test.c
> +++ b/tests/virtio-net-test.c
> @@ -140,6 +140,49 @@ static void tx_test(const QVirtioBus *bus, QVirtioDevice *dev,
> g_assert_cmpstr(buffer, ==, "TEST");
> }
>
> +static void rx_stop_cont_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);
> +
> + /* We could check the status, but this command is more importantly to
> + * ensure the packet data gets queued in QEMU, before we do 'cont'.
> + */
> + qmp("{ 'execute' : 'query-status'}");
> + qmp("{ 'execute' : 'stop'}");
> +
> + ret = iov_send(socket, iov, 2, 0, sizeof(len) + sizeof(test));
> + g_assert_cmpint(ret, ==, sizeof(test) + sizeof(len));
I meant QMP 'query-status' should be here, between the iov_send and 'cont'.
Fam
> +
> + qmp("{ 'execute' : 'cont'}");
> +
> + qvirtio_wait_queue_isr(bus, dev, vq, QVIRTIO_NET_TIMEOUT_US);
> + memread(req_addr + VNET_HDR_SIZE, buffer, sizeof(test));
> + g_assert_cmpstr(buffer, ==, "TEST");
> +
> + guest_free(alloc, req_addr);
> +}
> +
> static void send_recv_test(const QVirtioBus *bus, QVirtioDevice *dev,
> QGuestAllocator *alloc, QVirtQueue *rvq,
> QVirtQueue *tvq, int socket)
> @@ -148,6 +191,13 @@ static void send_recv_test(const QVirtioBus *bus, QVirtioDevice *dev,
> tx_test(bus, dev, alloc, tvq, socket);
> }
>
> +static void stop_cont_test(const QVirtioBus *bus, QVirtioDevice *dev,
> + QGuestAllocator *alloc, QVirtQueue *rvq,
> + QVirtQueue *tvq, int socket)
> +{
> + rx_stop_cont_test(bus, dev, alloc, rvq, socket);
> +}
> +
> static void pci_basic(gconstpointer data)
> {
> QVirtioPCIDevice *dev;
> @@ -206,6 +256,8 @@ int main(int argc, char **argv)
> g_test_init(&argc, &argv, NULL);
> #ifndef _WIN32
> qtest_add_data_func("/virtio/net/pci/basic", send_recv_test, pci_basic);
> + qtest_add_data_func("/virtio/net/pci/rx_stop_cont",
> + stop_cont_test, pci_basic);
> #endif
> qtest_add_func("/virtio/net/pci/hotplug", hotplug);
>
> --
> 2.1.4
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH V2 1/2] tests: introduce basic pci test for virtio-net
2015-07-13 8:49 ` [Qemu-devel] [PATCH V2 1/2] tests: introduce basic pci test for virtio-net Fam Zheng
@ 2015-07-13 9:08 ` Jason Wang
0 siblings, 0 replies; 7+ messages in thread
From: Jason Wang @ 2015-07-13 9:08 UTC (permalink / raw)
To: Fam Zheng; +Cc: qemu-devel, stefanha, mst
On 07/13/2015 04:49 PM, Fam Zheng wrote:
> On Mon, 07/13 14:04, Jason Wang wrote:
>> > Signed-off-by: Jason Wang <jasowang@redhat.com>
>> > ---
>> > Changes from V1:
>> > - replace the magic value 12 with a macro
>> > ---
>> > tests/Makefile | 2 +-
>> > tests/virtio-net-test.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++--
>> > 2 files changed, 180 insertions(+), 8 deletions(-)
>> >
>> > diff --git a/tests/Makefile b/tests/Makefile
>> > index 2c4b8dc..5805326 100644
>> > --- a/tests/Makefile
>> > +++ b/tests/Makefile
>> > @@ -381,7 +381,7 @@ tests/wdt_ib700-test$(EXESUF): tests/wdt_ib700-test.o
>> > tests/tco-test$(EXESUF): tests/tco-test.o $(libqos-pc-obj-y)
>> > 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..b7d6f0b 100644
>> > --- a/tests/virtio-net-test.c
>> > +++ b/tests/virtio-net-test.c
>> > @@ -10,20 +10,193 @@
>> > #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"
>> > +#include "hw/virtio/virtio-net.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)
>> > +#define VNET_HDR_SIZE sizeof(struct virtio_net_hdr_mrg_rxbuf)
>> > +
>> > +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 + VNET_HDR_SIZE, buffer, sizeof(test));
>> > + g_assert_cmpstr(buffer, ==, "TEST");
>> > +
>> > + guest_free(alloc, req_addr);
>> > }
>> >
>> > +static void tx_test(const QVirtioBus *bus, QVirtioDevice *dev,
>> > + QGuestAllocator *alloc, QVirtQueue *vq,
>> > + int socket)
>> > +{
>> > + uint64_t req_addr;
>> > + uint32_t free_head;
>> > + uint32_t len;
>> > + char buffer[64];
>> > + int ret;
>> > +
>> > + req_addr = guest_alloc(alloc, 64);
>> > + memwrite(req_addr + VNET_HDR_SIZE, "TEST", 4);
>> > +
>> > + free_head = qvirtqueue_add(vq, req_addr, 64, false, false);
>> > + qvirtqueue_kick(bus, dev, vq, free_head);
>> > +
>> > + qvirtio_wait_queue_isr(bus, dev, vq, QVIRTIO_NET_TIMEOUT_US);
>> > + guest_free(alloc, req_addr);
>> > +
>> > + ret = qemu_recv(socket, &len, sizeof(len), 0);
>> > + g_assert_cmpint(ret, ==, sizeof(len));
>> > + len = ntohl(len);
>> > +
>> > + ret = qemu_recv(socket, buffer, len, 0);
>> > + g_assert_cmpstr(buffer, ==, "TEST");
>> > +}
>> > +
>> > +static void send_recv_test(const QVirtioBus *bus, QVirtioDevice *dev,
>> > + QGuestAllocator *alloc, QVirtQueue *rvq,
>> > + QVirtQueue *tvq, int socket)
>> > +{
>> > + rx_test(bus, dev, alloc, rvq, socket);
>> > + tx_test(bus, dev, alloc, tvq, socket);
>> > +}
>> > +
>> > +static void pci_basic(gconstpointer data)
>> > +{
>> > + QVirtioPCIDevice *dev;
>> > + QPCIBus *bus;
>> > + QVirtQueuePCI *tx, *rx;
>> > + QGuestAllocator *alloc;
>> > + void (*func) (const QVirtioBus *bus,
>> > + QVirtioDevice *dev,
>> > + QGuestAllocator *alloc,
>> > + QVirtQueue *rvq,
>> > + QVirtQueue *tvq,
>> > + int socket) = data;
>> > + int sv[2], ret;
>> > +
>> > + ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sv);
>> > + g_assert_cmpint(ret, !=, -1);
>> > +
>> > + bus = pci_test_start(sv[1]);
>> > + dev = virtio_net_pci_init(bus, PCI_SLOT);
>> > +
>> > + alloc = pc_alloc_init();
>> > + rx = (QVirtQueuePCI *)qvirtqueue_setup(&qvirtio_pci, &dev->vdev,
>> > + alloc, 0);
>> > + tx = (QVirtQueuePCI *)qvirtqueue_setup(&qvirtio_pci, &dev->vdev,
>> > + alloc, 1);
>> > +
>> > + driver_init(&qvirtio_pci, &dev->vdev);
>> > + func(&qvirtio_pci, &dev->vdev, alloc, &rx->vq, &tx->vq, sv[0]);
>> > +
>> > + /* End test */
>> > + close(sv[0]);
>> > + guest_free(alloc, tx->vq.desc);
>> > + pc_alloc_uninit(alloc);
>> > + qvirtio_pci_device_disable(dev);
>> > + g_free(dev);
>> > + qpci_free_pc(bus);
>> > + test_end();
>> > +}
>> > +#endif
>> > +
>> > static void hotplug(void)
>> > {
>> > + qtest_start("-device virtio-net-pci");
>> > +
>> > qpci_plug_device_test("virtio-net-pci", "net1", PCI_SLOT_HP, NULL);
>> > qpci_unplug_acpi_device_test("net1", PCI_SLOT_HP);
>> > + qtest_start("-device virtio-net-pci");
> What does this qtest_start do?
>
Meaningless, will remove this.
Thanks
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH V2 2/2] tests: test rx recovery from cont
2015-07-13 8:52 ` Fam Zheng
@ 2015-07-13 9:09 ` Jason Wang
0 siblings, 0 replies; 7+ messages in thread
From: Jason Wang @ 2015-07-13 9:09 UTC (permalink / raw)
To: Fam Zheng; +Cc: qemu-devel, stefanha, mst
On 07/13/2015 04:52 PM, Fam Zheng wrote:
> On Mon, 07/13 14:04, Jason Wang wrote:
>> > Rx should be recovered after cont.
>> >
>> > Signed-off-by: Jason Wang <jasowang@redhat.com>
>> > ---
>> > Changes from V1:
>> > - query status before sending cont, this makes sure that the packet
>> > were queued.
>> > ---
>> > tests/virtio-net-test.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
>> > 1 file changed, 52 insertions(+)
>> >
>> > diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c
>> > index b7d6f0b..3c412e2 100644
>> > --- a/tests/virtio-net-test.c
>> > +++ b/tests/virtio-net-test.c
>> > @@ -140,6 +140,49 @@ static void tx_test(const QVirtioBus *bus, QVirtioDevice *dev,
>> > g_assert_cmpstr(buffer, ==, "TEST");
>> > }
>> >
>> > +static void rx_stop_cont_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);
>> > +
>> > + /* We could check the status, but this command is more importantly to
>> > + * ensure the packet data gets queued in QEMU, before we do 'cont'.
>> > + */
>> > + qmp("{ 'execute' : 'query-status'}");
>> > + qmp("{ 'execute' : 'stop'}");
>> > +
>> > + ret = iov_send(socket, iov, 2, 0, sizeof(len) + sizeof(test));
>> > + g_assert_cmpint(ret, ==, sizeof(test) + sizeof(len));
> I meant QMP 'query-status' should be here, between the iov_send and 'cont'.
>
> Fam
>
Sorry, an cut and paste error. Will fix this in next version.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH V2 1/2] tests: introduce basic pci test for virtio-net
2015-07-13 6:04 [Qemu-devel] [PATCH V2 1/2] tests: introduce basic pci test for virtio-net Jason Wang
2015-07-13 6:04 ` [Qemu-devel] [PATCH V2 2/2] tests: test rx recovery from cont Jason Wang
2015-07-13 8:49 ` [Qemu-devel] [PATCH V2 1/2] tests: introduce basic pci test for virtio-net Fam Zheng
@ 2015-07-16 10:41 ` Stefan Hajnoczi
2 siblings, 0 replies; 7+ messages in thread
From: Stefan Hajnoczi @ 2015-07-16 10:41 UTC (permalink / raw)
To: Jason Wang; +Cc: famz, qemu-devel, mst
[-- Attachment #1: Type: text/plain, Size: 447 bytes --]
On Mon, Jul 13, 2015 at 02:04:19PM +0800, Jason Wang wrote:
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---
> Changes from V1:
> - replace the magic value 12 with a macro
> ---
> tests/Makefile | 2 +-
> tests/virtio-net-test.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++--
> 2 files changed, 180 insertions(+), 8 deletions(-)
I haven't reviewed this series in detail but it's great that you are
doing this!
Stefan
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-07-16 10:41 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-13 6:04 [Qemu-devel] [PATCH V2 1/2] tests: introduce basic pci test for virtio-net Jason Wang
2015-07-13 6:04 ` [Qemu-devel] [PATCH V2 2/2] tests: test rx recovery from cont Jason Wang
2015-07-13 8:52 ` Fam Zheng
2015-07-13 9:09 ` Jason Wang
2015-07-13 8:49 ` [Qemu-devel] [PATCH V2 1/2] tests: introduce basic pci test for virtio-net Fam Zheng
2015-07-13 9:08 ` Jason Wang
2015-07-16 10:41 ` Stefan Hajnoczi
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).