All of lore.kernel.org
 help / color / mirror / Atom feed
From: Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Laurent Vivier" <lvivier@redhat.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	qemu-devel@nongnu.org, "Stefan Hajnoczi" <stefanha@gmail.com>,
	"Emanuele Giuseppe Esposito" <e.emanuelegiuseppe@gmail.com>
Subject: [Qemu-devel] [PATCH v2 31/34] test/qgraph: virtio-net test node
Date: Mon,  6 Aug 2018 16:34:09 +0200	[thread overview]
Message-ID: <20180806143412.27722-32-e.emanuelegiuseppe@gmail.com> (raw)
In-Reply-To: <20180806143412.27722-1-e.emanuelegiuseppe@gmail.com>

Convert tests/virtio-net-test in qgraph test node,
virtio-net-test. This test consumes a virtio-net interface
and checks that its function return the expected values.

Some functions are implemented only for virtio-net-pci, so they
don't consume virtio-net, but virtio-net-pci

Note that this test does not allocate any virtio-net structure,
it's all done by the qtest walking graph mechanism

Signed-off-by: Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
---
 tests/Makefile.include  |   3 +-
 tests/virtio-net-test.c | 159 ++++++++++++----------------------------
 2 files changed, 49 insertions(+), 113 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index ecab26b7b2..4634fd8ef1 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -190,7 +190,6 @@ gcov-files-ipack-y += hw/char/ipoctal232.c
 gcov-files-virtioserial-y += hw/char/virtio-console.c
 
 gcov-files-virtio-y += i386-softmmu/hw/virtio/virtio.c
-check-qtest-virtio-y += tests/virtio-net-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/net/virtio-net.c
 gcov-files-virtio-y += i386-softmmu/hw/virtio/virtio-balloon.c
 gcov-files-virtio-y += i386-softmmu/hw/block/virtio-blk.c
@@ -785,6 +784,7 @@ libqgraph-tests-obj-y += tests/virtio-9p-test.o
 libqgraph-tests-obj-y += tests/virtio-balloon-test.o
 libqgraph-tests-obj-y += tests/virtio-rng-test.o
 libqgraph-tests-obj-y += tests/virtio-blk-test.o
+libqgraph-tests-obj-y += tests/virtio-net-test.o
 
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
@@ -828,7 +828,6 @@ tests/ne2000-test$(EXESUF): tests/ne2000-test.o
 tests/wdt_ib700-test$(EXESUF): tests/wdt_ib700-test.o
 tests/tco-test$(EXESUF): tests/tco-test.o $(libqos-pc-obj-y)
 tests/virtio-ccw-test$(EXESUF): tests/virtio-ccw-test.o
-tests/virtio-net-test$(EXESUF): tests/virtio-net-test.o $(libqos-pc-obj-y) $(libqos-virtio-obj-y)
 tests/virtio-scsi-test$(EXESUF): tests/virtio-scsi-test.o $(libqos-virtio-obj-y)
 tests/tpci200-test$(EXESUF): tests/tpci200-test.o
 tests/display-vga-test$(EXESUF): tests/display-vga-test.o
diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c
index b2a5f5a350..4f451395b9 100644
--- a/tests/virtio-net-test.c
+++ b/tests/virtio-net-test.c
@@ -9,18 +9,11 @@
 
 #include "qemu/osdep.h"
 #include "libqtest.h"
-#include "qemu-common.h"
-#include "qemu/sockets.h"
 #include "qemu/iov.h"
-#include "libqos/libqos-pc.h"
-#include "libqos/libqos-spapr.h"
-#include "libqos/virtio.h"
-#include "libqos/virtio-pci.h"
 #include "qapi/qmp/qdict.h"
-#include "qemu/bswap.h"
 #include "hw/virtio/virtio-net.h"
-#include "standard-headers/linux/virtio_ids.h"
-#include "standard-headers/linux/virtio_ring.h"
+#include "libqos/qgraph.h"
+#include "libqos/virtio-net.h"
 
 #define PCI_SLOT_HP             0x06
 #define PCI_SLOT                0x04
@@ -29,57 +22,10 @@
 #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();
-}
+static int sv[2];
 
 #ifndef _WIN32
 
-static QVirtioPCIDevice *virtio_net_pci_init(QPCIBus *bus, int slot)
-{
-    QVirtioPCIDevice *dev;
-
-    dev = qvirtio_pci_device_find(bus, VIRTIO_ID_NET);
-    g_assert(dev != NULL);
-    g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_NET);
-
-    qvirtio_pci_device_enable(dev);
-    qvirtio_start_device(&dev->vdev);
-
-    return dev;
-}
-
-static QOSState *pci_test_start(int socket)
-{
-    QOSState *qs;
-    const char *arch = qtest_get_arch();
-    const char *cmd = "-netdev socket,fd=%d,id=hs0 -device "
-                      "virtio-net-pci,netdev=hs0";
-
-    if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-        qs = qtest_pc_boot(cmd, socket);
-    } else if (strcmp(arch, "ppc64") == 0) {
-        qs = qtest_spapr_boot(cmd, socket);
-    } else {
-        g_printerr("virtio-net tests are only available on x86 or ppc64\n");
-        exit(EXIT_FAILURE);
-    }
-    global_qtest = qs->qts;
-    return qs;
-}
-
-static void driver_init(QVirtioDevice *dev)
-{
-    uint32_t features;
-
-    features = qvirtio_get_features(dev);
-    features = features & ~(QVIRTIO_F_BAD_FEATURE |
-                            (1u << VIRTIO_RING_F_INDIRECT_DESC) |
-                            (1u << VIRTIO_RING_F_EVENT_IDX));
-    qvirtio_set_features(dev, features);
-}
-
 static void rx_test(QVirtioDevice *dev,
                     QGuestAllocator *alloc, QVirtQueue *vq,
                     int socket)
@@ -189,80 +135,71 @@ static void rx_stop_cont_test(QVirtioDevice *dev,
     guest_free(alloc, req_addr);
 }
 
-static void send_recv_test(QVirtioDevice *dev,
-                           QGuestAllocator *alloc, QVirtQueue *rvq,
-                           QVirtQueue *tvq, int socket)
+static void send_recv_test(void *obj, void *data, QGuestAllocator *t_alloc)
 {
-    rx_test(dev, alloc, rvq, socket);
-    tx_test(dev, alloc, tvq, socket);
+    QVirtioNet *net_if = obj;
+    QVirtioDevice *dev = net_if->vdev;
+    QVirtQueue *rx = net_if->rx;
+    QVirtQueue *tx = net_if->tx;
+    rx_test(dev, t_alloc, rx, sv[0]);
+    tx_test(dev, t_alloc, tx, sv[0]);
 }
 
-static void stop_cont_test(QVirtioDevice *dev,
-                           QGuestAllocator *alloc, QVirtQueue *rvq,
-                           QVirtQueue *tvq, int socket)
+static void stop_cont_test(void *obj, void *data, QGuestAllocator *t_alloc)
 {
-    rx_stop_cont_test(dev, alloc, rvq, socket);
+    QVirtioNet *net_if = obj;
+    QVirtioDevice *dev = net_if->vdev;
+    QVirtQueue *rx = net_if->rx;
+    rx_stop_cont_test(dev, t_alloc, rx, sv[0]);
 }
 
-static void pci_basic(gconstpointer data)
-{
-    QVirtioPCIDevice *dev;
-    QOSState *qs;
-    QVirtQueuePCI *tx, *rx;
-    void (*func) (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);
-
-    qs = pci_test_start(sv[1]);
-    dev = virtio_net_pci_init(qs->pcibus, PCI_SLOT);
-
-    rx = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0);
-    tx = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 1);
-
-    driver_init(&dev->vdev);
-    func(&dev->vdev, qs->alloc, &rx->vq, &tx->vq, sv[0]);
-
-    /* End test */
-    close(sv[0]);
-    qvirtqueue_cleanup(dev->vdev.bus, &tx->vq, qs->alloc);
-    qvirtqueue_cleanup(dev->vdev.bus, &rx->vq, qs->alloc);
-    qvirtio_pci_device_disable(dev);
-    g_free(dev->pdev);
-    g_free(dev);
-    qtest_shutdown(qs);
-}
 #endif
 
-static void hotplug(void)
+static void hotplug(void *obj, void *data, QGuestAllocator *t_alloc)
 {
     const char *arch = qtest_get_arch();
 
-    qtest_start("-device virtio-net-pci");
-
     qpci_plug_device_test("virtio-net-pci", "net1", PCI_SLOT_HP, NULL);
 
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
         qpci_unplug_acpi_device_test("net1", PCI_SLOT_HP);
     }
 
-    test_end();
 }
 
-int main(int argc, char **argv)
+static void virtio_net_test_setup(char **cmd_line)
 {
-    g_test_init(&argc, &argv, NULL);
+    int ret;
+    char *new_cmdline;
+
+    ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sv);
+    g_assert_cmpint(ret, !=, -1);
+
+    new_cmdline = g_strdup_printf("%s -netdev socket,fd=%d,id=hs0 ",
+                                  *cmd_line, sv[1]);
+    g_assert_nonnull(new_cmdline);
+
+    g_free(*cmd_line);
+    *cmd_line = new_cmdline;
+}
+
+static void virtio_net_test_cleanup(void)
+{
+    close(sv[0]);
+    close(sv[1]);
+}
+static void virtio_net_test(void)
+{
+    QOSGraphTestOptions opts = {
+        .before = virtio_net_test_setup,
+        .after = virtio_net_test_cleanup,
+    };
+
 #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);
+    qos_add_test("net-basic", "virtio-net", send_recv_test, &opts);
+    qos_add_test("net-rx_stop_cont", "virtio-net", stop_cont_test, &opts);
 #endif
-    qtest_add_func("/virtio/net/pci/hotplug", hotplug);
-
-    return g_test_run();
+    qos_add_test("net-hotplug", "virtio-pci", hotplug, &opts);
 }
+
+libqos_init(virtio_net_test);
-- 
2.17.1

  parent reply	other threads:[~2018-08-06 14:35 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-06 14:33 [Qemu-devel] [PATCH v2 00/34] Qtest driver framework Emanuele Giuseppe Esposito
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 01/34] tests: qgraph API for the qtest " Emanuele Giuseppe Esposito
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 02/34] tests/qgraph: rename qpci_init_pc functions Emanuele Giuseppe Esposito
2018-08-06 15:04   ` Laurent Vivier
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 03/34] tests/qgraph: pci-pc driver and interface nodes Emanuele Giuseppe Esposito
2018-08-08 17:39   ` Laurent Vivier
2018-08-09 12:17     ` Emanuele
2018-08-09 12:29       ` Laurent Vivier
2018-08-09 12:33         ` Emanuele
2018-08-09 12:42           ` Laurent Vivier
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 04/34] tests/qgraph: x86_64/pc machine node Emanuele Giuseppe Esposito
2018-08-08 19:27   ` Laurent Vivier
2018-08-09 12:23     ` Emanuele
2018-08-09 12:32       ` Laurent Vivier
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 05/34] tests/qgraph: sdhci driver and interface nodes Emanuele Giuseppe Esposito
2018-08-09 10:10   ` Laurent Vivier
2018-08-09 10:15     ` Paolo Bonzini
2018-08-09 11:01       ` Laurent Vivier
2018-08-10 10:16         ` Paolo Bonzini
2018-08-09 13:27     ` Emanuele
2018-08-09 13:58       ` Laurent Vivier
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 06/34] tests/qgraph: sdhci test node Emanuele Giuseppe Esposito
2018-08-09 11:16   ` Laurent Vivier
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 07/34] tests/qgraph: arm/raspi2 machine node Emanuele Giuseppe Esposito
2018-08-09 12:35   ` Laurent Vivier
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 08/34] tests/qgraph: rename qpci_init_spapr functions Emanuele Giuseppe Esposito
2018-08-08 15:30   ` Laurent Vivier
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 09/34] tests/qgraph: pci-spapr driver and interface nodes Emanuele Giuseppe Esposito
2018-08-09 12:57   ` Laurent Vivier
2018-08-09 13:02   ` Laurent Vivier
2018-08-09 13:19     ` Emanuele
2018-08-10  7:14       ` Paolo Bonzini
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 10/34] tests/qgraph: ppc64/pseries machine node Emanuele Giuseppe Esposito
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 11/34] test/qgraph: e1000e driver and interface nodes Emanuele Giuseppe Esposito
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 12/34] test/qgraph: e1000e-test node Emanuele Giuseppe Esposito
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 13/34] test/qgraph: virtio_start_device function Emanuele Giuseppe Esposito
2018-08-09 13:39   ` Laurent Vivier
2018-08-09 15:00     ` Emanuele
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 14/34] test/qgraph: virtio-pci driver and interface nodes Emanuele Giuseppe Esposito
2018-08-09 14:08   ` Laurent Vivier
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 15/34] tests/qgraph: rename qvirtio_mmio_init_device functions Emanuele Giuseppe Esposito
2018-08-09 14:13   ` Laurent Vivier
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 16/34] test/qgraph: virtio-mmio driver and interface nodes Emanuele Giuseppe Esposito
2018-08-09 14:47   ` Laurent Vivier
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 17/34] test/qgraph: arm/virt machine node Emanuele Giuseppe Esposito
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 18/34] tests: virtio: separate ccw tests from libqos Emanuele Giuseppe Esposito
2018-08-08 19:34   ` Laurent Vivier
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 19/34] test/qgraph: virtio-serial driver and interface nodes Emanuele Giuseppe Esposito
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 20/34] test/qgraph: virtio-console test node Emanuele Giuseppe Esposito
2018-08-06 14:33 ` [Qemu-devel] [PATCH v2 21/34] test/qgraph: virtio-serial " Emanuele Giuseppe Esposito
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 22/34] test/qgraph: virtio-9p driver and interface nodes Emanuele Giuseppe Esposito
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 23/34] test/qgraph: virtio-9p test node Emanuele Giuseppe Esposito
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 24/34] test/qgraph: virtio-balloon driver and interface nodes Emanuele Giuseppe Esposito
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 25/34] test/qgraph: virtio-balloon test node Emanuele Giuseppe Esposito
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 26/34] test/qgraph: virtio-rng driver and interface nodes Emanuele Giuseppe Esposito
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 27/34] test/qgraph: virtio-rng test node Emanuele Giuseppe Esposito
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 28/34] test/qgraph: virtio-blk driver and interface nodes Emanuele Giuseppe Esposito
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 29/34] test/qgraph: virtio-blk test node Emanuele Giuseppe Esposito
2018-08-09 14:16   ` Laurent Vivier
2018-08-10  9:45     ` Emanuele
2018-08-10  9:52       ` Laurent Vivier
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 30/34] test/qgraph: virtio-net driver and interface nodes Emanuele Giuseppe Esposito
2018-08-06 14:34 ` Emanuele Giuseppe Esposito [this message]
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 32/34] test/qgraph: virtio-scsi " Emanuele Giuseppe Esposito
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 33/34] test/qgraph: virtio-scsi test node Emanuele Giuseppe Esposito
2018-08-06 14:34 ` [Qemu-devel] [PATCH v2 34/34] test/qgraph: temporarly commented vhost-user-test Emanuele Giuseppe Esposito
2018-08-09  8:57 ` [Qemu-devel] [PATCH v2 00/34] Qtest driver framework Paolo Bonzini
2018-08-09  9:20   ` Emanuele
2018-08-09  9:44     ` Paolo Bonzini
2018-08-09 10:27       ` Emanuele
2018-08-10 10:40       ` Emanuele

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=20180806143412.27722-32-e.emanuelegiuseppe@gmail.com \
    --to=e.emanuelegiuseppe@gmail.com \
    --cc=f4bug@amsat.org \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.