From nobody Wed Nov 5 10:45:40 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1534157063136405.5584794990583; Mon, 13 Aug 2018 03:44:23 -0700 (PDT) Received: from localhost ([::1]:38764 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fpAKj-0000Xs-RS for importer@patchew.org; Mon, 13 Aug 2018 06:44:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44429) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fp9td-0007wz-5h for qemu-devel@nongnu.org; Mon, 13 Aug 2018 06:16:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fp9tb-00035X-JZ for qemu-devel@nongnu.org; Mon, 13 Aug 2018 06:16:21 -0400 Received: from mail-ed1-x542.google.com ([2a00:1450:4864:20::542]:36078) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fp9tb-00033m-8t; Mon, 13 Aug 2018 06:16:19 -0400 Received: by mail-ed1-x542.google.com with SMTP id k15-v6so7957937edr.3; Mon, 13 Aug 2018 03:16:19 -0700 (PDT) Received: from localhost.localdomain ([194.230.159.125]) by smtp.gmail.com with ESMTPSA id s27-v6sm11670006edb.73.2018.08.13.03.16.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Aug 2018 03:16:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sdwNeturm0GTdJSFOT4C1e9CuEkmGDs0zzhhO9L6oeU=; b=K20fK4LMtiQiEN0QplODJXtpCNmlavjwDPU5QM6JRcHKa7TchACZeq5VuXZK3OyEvP jph9vNpORhw4GueLrM8bgbQRakzCjVLrSEjd5ADvIV0yiMfGEUEzSFhKt2GinKpyblML P8AVyUgW3gmh+BfLC4opxMnS/xeorNOQux7Ynr6RO8s6IVXirRd4DfBqhEY1ruhEHPdd 5rXwgzaLAELoO+69Eb8tjfc5LgLE81UL2nGTcIZia7whDTUPkIbC5NPn62Cog7b1bzRe 7FliSvxMj7zJczGtgJD/NYzDFhpef5YH5bqtEZPCJMcRYioV6JG3ZDmunXRJ4CkXoJrE YwTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sdwNeturm0GTdJSFOT4C1e9CuEkmGDs0zzhhO9L6oeU=; b=n4rF12zp2ypaVFzHjksBvHHa8b3YoGURA567R99gl23GOOK6A1mQjffrIPDUiH7NbM 0tosNf4IAaUWu6gWOadx+XPtWzNaWs0hyyQkgefQlqL3HHXg20YC3SVvS9OsvPviFgMu QWrNBVgS44HeDLNslMNVySCfoAb/VNkwrgVHvarTRheTjbjLDNFhqdtpp3nswayfQ2pB jcieGiCDMSQExyiIYxF2Apck9U5+5bKAShFuL7a8diE42Huna8Mop4+pIiIVjjfxHRs7 fXCGkpZGnQeP/VDw4NIKdlpNKNou2cBhkZE3QTV6zOklu8xg9SlJKexlyZPxkypGfk2i 3Zxg== X-Gm-Message-State: AOUpUlEZzkPw4wdlFJbwwwcVy5Z/xReM/Xvf/u2N0P0h0FPFTUG/SGOo uZDIXVGmTJ1xEvaujvL4JDxzq2CgDxg= X-Google-Smtp-Source: AA+uWPz01iK8HGx50scrDu6rljkvwgfDKgGw9C9URUgcH9CN+rm2GyGSxLUytXqPqWar5xvM7/ZWgw== X-Received: by 2002:a50:99db:: with SMTP id n27-v6mr21391530edb.111.1534155377956; Mon, 13 Aug 2018 03:16:17 -0700 (PDT) From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Date: Mon, 13 Aug 2018 12:14:50 +0200 Message-Id: <20180813101453.10200-31-e.emanuelegiuseppe@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180813101453.10200-1-e.emanuelegiuseppe@gmail.com> References: <20180813101453.10200-1-e.emanuelegiuseppe@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::542 Subject: [Qemu-devel] [PATCH 30/33] tests/qgraph: virtio-net test node X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Fam Zheng , qemu-block@nongnu.org, "Michael S. Tsirkin" , Jason Wang , Amit Shah , Emanuele Giuseppe Esposito , Alexander Graf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Greg Kurz , qemu-ppc@nongnu.org, Gerd Hoffmann , Stefan Hajnoczi , Paolo Bonzini , John Snow , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- tests/Makefile.include | 3 +- tests/virtio-net-test.c | 161 ++++++++++++---------------------------- 2 files changed, 49 insertions(+), 115 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index c105c0902c..7a2b67c1ec 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -190,7 +190,6 @@ gcov-files-ipack-y +=3D hw/char/ipoctal232.c gcov-files-virtioserial-y +=3D hw/char/virtio-console.c =20 gcov-files-virtio-y +=3D i386-softmmu/hw/virtio/virtio.c -check-qtest-virtio-y +=3D tests/virtio-net-test$(EXESUF) gcov-files-virtio-y +=3D i386-softmmu/hw/net/virtio-net.c gcov-files-virtio-y +=3D i386-softmmu/hw/virtio/virtio-balloon.c gcov-files-virtio-y +=3D i386-softmmu/hw/block/virtio-blk.c @@ -785,6 +784,7 @@ libqgraph-tests-obj-y +=3D tests/virtio-9p-test.o libqgraph-tests-obj-y +=3D tests/virtio-balloon-test.o libqgraph-tests-obj-y +=3D tests/virtio-rng-test.o libqgraph-tests-obj-y +=3D tests/virtio-blk-test.o +libqgraph-tests-obj-y +=3D tests/virtio-net-test.o =20 check-unit-y +=3D 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 72728acf66..38daeda18c 100644 --- a/tests/virtio-net-test.c +++ b/tests/virtio-net-test.c @@ -9,18 +9,11 @@ =20 #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" =20 #define PCI_SLOT_HP 0x06 #define PCI_SLOT 0x04 @@ -29,59 +22,10 @@ #define QVIRTIO_NET_TIMEOUT_US (30 * 1000 * 1000) #define VNET_HDR_SIZE sizeof(struct virtio_net_hdr_mrg_rxbuf) =20 -static void test_end(void) -{ - qtest_end(); -} +static int sv[2]; =20 #ifndef _WIN32 =20 -static QVirtioPCIDevice *virtio_net_pci_init(QPCIBus *bus, int slot) -{ - QVirtioPCIDevice *dev; - - dev =3D qvirtio_pci_device_find(bus, VIRTIO_ID_NET); - g_assert(dev !=3D NULL); - g_assert_cmphex(dev->vdev.device_type, =3D=3D, 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 =3D qtest_get_arch(); - const char *cmd =3D "-netdev socket,fd=3D%d,id=3Dhs0 -device " - "virtio-net-pci,netdev=3Dhs0"; - - if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0) { - qs =3D qtest_pc_boot(cmd, socket); - } else if (strcmp(arch, "ppc64") =3D=3D 0) { - qs =3D qtest_spapr_boot(cmd, socket); - } else { - g_printerr("virtio-net tests are only available on x86 or ppc64\n"= ); - exit(EXIT_FAILURE); - } - global_qtest =3D qs->qts; - return qs; -} - -static void driver_init(QVirtioDevice *dev) -{ - uint32_t features; - - features =3D qvirtio_get_features(dev); - features =3D features & ~(QVIRTIO_F_BAD_FEATURE | - (1u << VIRTIO_RING_F_INDIRECT_DESC) | - (1u << VIRTIO_RING_F_EVENT_IDX)); - qvirtio_set_features(dev, features); - - qvirtio_set_driver_ok(dev); -} - static void rx_test(QVirtioDevice *dev, QGuestAllocator *alloc, QVirtQueue *vq, int socket) @@ -191,80 +135,71 @@ static void rx_stop_cont_test(QVirtioDevice *dev, guest_free(alloc, req_addr); } =20 -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 =3D obj; + QVirtioDevice *dev =3D net_if->vdev; + QVirtQueue *rx =3D net_if->rx; + QVirtQueue *tx =3D net_if->tx; + rx_test(dev, t_alloc, rx, sv[0]); + tx_test(dev, t_alloc, tx, sv[0]); } =20 -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 =3D obj; + QVirtioDevice *dev =3D net_if->vdev; + QVirtQueue *rx =3D net_if->rx; + rx_stop_cont_test(dev, t_alloc, rx, sv[0]); } =20 -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) =3D data; - int sv[2], ret; - - ret =3D socketpair(PF_UNIX, SOCK_STREAM, 0, sv); - g_assert_cmpint(ret, !=3D, -1); - - qs =3D pci_test_start(sv[1]); - dev =3D virtio_net_pci_init(qs->pcibus, PCI_SLOT); - - rx =3D (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0); - tx =3D (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 =20 -static void hotplug(void) +static void hotplug(void *obj, void *data, QGuestAllocator *t_alloc) { const char *arch =3D qtest_get_arch(); =20 - qtest_start("-device virtio-net-pci"); - qpci_plug_device_test("virtio-net-pci", "net1", PCI_SLOT_HP, NULL); =20 if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0) { qpci_unplug_acpi_device_test("net1", PCI_SLOT_HP); } =20 - test_end(); } =20 -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 =3D socketpair(PF_UNIX, SOCK_STREAM, 0, sv); + g_assert_cmpint(ret, !=3D, -1); + + new_cmdline =3D g_strdup_printf("%s -netdev socket,fd=3D%d,id=3Dhs0 ", + *cmd_line, sv[1]); + g_assert_nonnull(new_cmdline); + + g_free(*cmd_line); + *cmd_line =3D new_cmdline; +} + +static void virtio_net_test_cleanup(void) +{ + close(sv[0]); + close(sv[1]); +} +static void register_virtio_net_test(void) +{ + QOSGraphTestOptions opts =3D { + .before =3D virtio_net_test_setup, + .after =3D 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(register_virtio_net_test); --=20 2.17.1