From nobody Sun Nov 9 22:34:28 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 155198328783684.5291957912674; Thu, 7 Mar 2019 10:28:07 -0800 (PST) Received: from localhost ([127.0.0.1]:56936 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xkR-0000ac-Dk for importer@patchew.org; Thu, 07 Mar 2019 13:28:03 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39788) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wr5-0003XC-52 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wr1-0008Jo-Hr for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:51 -0500 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]:35447) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wr1-0008Ib-4d for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:47 -0500 Received: by mail-wm1-x335.google.com with SMTP id y15so10119991wma.0 for ; Thu, 07 Mar 2019 09:30:47 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=i1Dt+JMG8477F9zKEkyymRnRh46/e7kRALE+q1f3QdM=; b=vQ85beYZWdl2f75SHwJvadYCiYI+0BJK4ow/MebhA/oIXNzB+yaPr1B/ZV6tXi40SO mLyiXep8BxIa8WaiCYSNNPpl/sOytPFSE2KjtnhcMu13vLed1oqIjhGNzAQIRZQUMxek yPNhU3acRawLVUszJO3aoICdwhZ/I35yEQ5Cj9Z+oI5Jxckx5W3hAj1MWeoHYCCGFRt2 OSpr/ttA6FB7J/bJlpfLy3HIdqjjjT7QgiYjX1YOHxqrglgHv6XfL1/1tSlZeeVcZPUn i4xQx3umf+ZQnqvPny5rjuF162n2+kRCRNZGbYaKJf6dGvLC+9RN1jfHogRJmzGwIzso 3jsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=i1Dt+JMG8477F9zKEkyymRnRh46/e7kRALE+q1f3QdM=; b=QehATIkVjCv9Se9C3WUdA9tN2FO0phT4+iAjboOif0gy20xzlMlNyvsyj8+njyRLqn wes4sbtHhZnqhaTfwYkEBAitmy3BGnzdKh1oXSJIqmD+GyQiIq7tQLBTMXNMj96TGYup x99SJl9dsv4JvKI1692rInk6z+g9Lae+6RJoQ3wLUJpDpw8RPM6AP6ruvAgUWMRZBM1i NrsuU/1a0seNZ+HADoMQo7OjocP+/vcPsmxW36vVbTECwjJ6ouIpCsTloFNlJSanxOeW +ADSOXSyxnJ6F2y8LphVbSO+rXiSEBKNsCekY5M8ULmjJid+aSyz+CxR+QD3h6TzUQK4 8Ibg== X-Gm-Message-State: APjAAAVzHvnYihbVc9gfxxnMrEFdI/LcI0OpTNnAs6F8gIsL8BRzByXH 4d7M0+YrtLndCutcdeaRPmYQIyVD X-Google-Smtp-Source: APXvYqzJeIYCHVbeB57y52b7xUfxOeymsV9WSgdNOV1a2fO8LmHqjaB15/1DNirvOtDbObjrfEx0qQ== X-Received: by 2002:a1c:80d6:: with SMTP id b205mr6709402wmd.109.1551979845344; Thu, 07 Mar 2019 09:30:45 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:42 +0100 Message-Id: <1551979804-6060-36-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::335 Subject: [Qemu-devel] [PULL 35/57] qos-test: virtio-blk 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Convert tests/virtio-blk-test in qgraph test node, virtio-blk-test. This test consumes a virtio-blk interface and checks that its function return the expected values. Some functions are implemented only for virtio-blk-pci, so they don't consume virtio-blk, but virtio-blk-pci Note that this test does not allocate any virtio-blk structure, it's all done by the qtest walking graph mechanism. The allocator is also provided by qgraph; remove malloc-generic.c and malloc-generic.h which are not used anymore. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 6 +- tests/libqos/malloc-generic.c | 24 --- tests/libqos/malloc-generic.h | 18 -- tests/libqtest.h | 3 + tests/virtio-blk-test.c | 474 ++++++++++++++++----------------------= ---- 5 files changed, 189 insertions(+), 336 deletions(-) delete mode 100644 tests/libqos/malloc-generic.c delete mode 100644 tests/libqos/malloc-generic.h diff --git a/tests/Makefile.include b/tests/Makefile.include index 5ef1b9b..1d3133e 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -154,7 +154,6 @@ check-qtest-generic-y +=3D tests/cdrom-test$(EXESUF) check-qtest-ipack-y +=3D tests/ipoctal232-test$(EXESUF) =20 check-qtest-virtio-y +=3D tests/virtio-net-test$(EXESUF) -check-qtest-virtio-y +=3D tests/virtio-blk-test$(EXESUF) check-qtest-virtio-y +=3D tests/virtio-scsi-test$(EXESUF) =20 check-qtest-pci-y +=3D tests/e1000-test$(EXESUF) @@ -285,7 +284,6 @@ check-qtest-arm-y +=3D tests/pca9552-test$(EXESUF) check-qtest-arm-y +=3D tests/ds1338-test$(EXESUF) check-qtest-arm-y +=3D tests/microbit-test$(EXESUF) check-qtest-arm-y +=3D tests/m25p80-test$(EXESUF) -check-qtest-arm-$(CONFIG_VIRTIO_BLK) +=3D tests/virtio-blk-test$(EXESUF) check-qtest-arm-y +=3D tests/test-arm-mptimer$(EXESUF) check-qtest-arm-y +=3D tests/boot-serial-test$(EXESUF) check-qtest-arm-y +=3D tests/hexloader-test$(EXESUF) @@ -722,7 +720,7 @@ tests/test-crypto-block$(EXESUF): tests/test-crypto-blo= ck.o $(test-crypto-obj-y) libqgraph-obj-y =3D tests/libqos/qgraph.o =20 libqos-obj-y =3D $(libqgraph-obj-y) tests/libqos/pci.o tests/libqos/fw_cfg= .o -libqos-obj-y +=3D tests/libqos/malloc.o tests/libqos/malloc-generic.o +libqos-obj-y +=3D tests/libqos/malloc.o libqos-obj-y +=3D tests/libqos/i2c.o tests/libqos/libqos.o libqos-spapr-obj-y =3D $(libqos-obj-y) tests/libqos/malloc-spapr.o libqos-spapr-obj-y +=3D tests/libqos/libqos-spapr.o @@ -764,6 +762,7 @@ qos-test-obj-y +=3D tests/pci-test.o qos-test-obj-y +=3D tests/sdhci-test.o qos-test-obj-y +=3D tests/virtio-test.o qos-test-obj-$(CONFIG_VIRTFS) +=3D tests/virtio-9p-test.o +qos-test-obj-y +=3D tests/virtio-blk-test.o qos-test-obj-y +=3D tests/virtio-rng-test.o qos-test-obj-y +=3D tests/virtio-serial-test.o =20 @@ -811,7 +810,6 @@ tests/vmxnet3-test$(EXESUF): tests/vmxnet3-test.o 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-blk-test$(EXESUF): tests/virtio-blk-test.o $(libqos-virtio-ob= j-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) diff --git a/tests/libqos/malloc-generic.c b/tests/libqos/malloc-generic.c deleted file mode 100644 index 766a308..0000000 --- a/tests/libqos/malloc-generic.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Basic libqos generic malloc support - * - * Copyright (c) 2014 Marc Mar=C3=AD - * - * This work is licensed under the terms of the GNU GPL, version 2 or late= r. - * See the COPYING file in the top-level directory. - */ - -#include "qemu/osdep.h" -#include "libqos/malloc-generic.h" -#include "libqos/malloc.h" - -/* - * Mostly for valgrind happiness, but it does offer - * a chokepoint for debugging guest memory leaks, too. - */ -void generic_alloc_init(QGuestAllocator *s, uint64_t base_addr, - uint64_t size, uint32_t page_size) -{ - uint64_t start =3D base_addr + (1 << 20); /* Start at 1MB */ - - alloc_init(s, 0, start, start + size, page_size); -} diff --git a/tests/libqos/malloc-generic.h b/tests/libqos/malloc-generic.h deleted file mode 100644 index 40ea058..0000000 --- a/tests/libqos/malloc-generic.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Basic libqos generic malloc support - * - * Copyright (c) 2014 Marc Mar=C3=AD - * - * This work is licensed under the terms of the GNU GPL, version 2 or late= r. - * See the COPYING file in the top-level directory. - */ - -#ifndef LIBQOS_MALLOC_GENERIC_H -#define LIBQOS_MALLOC_GENERIC_H - -#include "libqos/malloc.h" - -void generic_alloc_init(QGuestAllocator *s, uint64_t base_addr, uint64_t s= ize, - uint32_t page_size); - -#endif diff --git a/tests/libqtest.h b/tests/libqtest.h index 1a2f87e..a16acd5 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -17,6 +17,9 @@ #ifndef LIBQTEST_H #define LIBQTEST_H =20 +#include "qapi/qmp/qobject.h" +#include "qapi/qmp/qdict.h" + typedef struct QTestState QTestState; =20 extern QTestState *global_qtest; diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index 3a8126f..b02be02 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -10,20 +10,11 @@ =20 #include "qemu/osdep.h" #include "libqtest.h" -#include "libqos/libqos-pc.h" -#include "libqos/libqos-spapr.h" -#include "libqos/virtio.h" -#include "libqos/virtio-pci.h" -#include "libqos/virtio-mmio.h" -#include "libqos/malloc.h" -#include "libqos/malloc-generic.h" -#include "qapi/qmp/qdict.h" #include "qemu/bswap.h" -#include "standard-headers/linux/virtio_ids.h" -#include "standard-headers/linux/virtio_config.h" -#include "standard-headers/linux/virtio_ring.h" #include "standard-headers/linux/virtio_blk.h" #include "standard-headers/linux/virtio_pci.h" +#include "libqos/qgraph.h" +#include "libqos/virtio-blk.h" =20 /* TODO actually test the results and get rid of this */ #define qmp_discard_response(...) qobject_unref(qmp(__VA_ARGS__)) @@ -31,13 +22,6 @@ #define TEST_IMAGE_SIZE (64 * 1024 * 1024) #define QVIRTIO_BLK_TIMEOUT_US (30 * 1000 * 1000) #define PCI_SLOT_HP 0x06 -#define PCI_SLOT 0x04 -#define PCI_FN 0x00 - -#define MMIO_PAGE_SIZE 4096 -#define MMIO_DEV_BASE_ADDR 0x0A003E00 -#define MMIO_RAM_ADDR 0x40000000 -#define MMIO_RAM_SIZE 0x20000000 =20 typedef struct QVirtioBlkReq { uint32_t type; @@ -47,84 +31,34 @@ typedef struct QVirtioBlkReq { uint8_t status; } QVirtioBlkReq; =20 + #ifdef HOST_WORDS_BIGENDIAN const bool host_is_big_endian =3D true; #else const bool host_is_big_endian; /* false */ #endif =20 +static void drive_destroy(void *path) +{ + unlink(path); + g_free(path); + qos_invalidate_command_line(); +} + static char *drive_create(void) { int fd, ret; - char *tmp_path =3D g_strdup("/tmp/qtest.XXXXXX"); + char *t_path =3D g_strdup("/tmp/qtest.XXXXXX"); =20 /* Create a temporary raw image */ - fd =3D mkstemp(tmp_path); + fd =3D mkstemp(t_path); g_assert_cmpint(fd, >=3D, 0); ret =3D ftruncate(fd, TEST_IMAGE_SIZE); g_assert_cmpint(ret, =3D=3D, 0); close(fd); =20 - return tmp_path; -} - -static QOSState *pci_test_start(void) -{ - QOSState *qs; - const char *arch =3D qtest_get_arch(); - char *tmp_path; - const char *cmd =3D "-drive if=3Dnone,id=3Ddrive0,file=3D%s,format=3Dr= aw " - "-drive if=3Dnone,id=3Ddrive1,file=3Dnull-co://,form= at=3Draw " - "-device virtio-blk-pci,id=3Ddrv0,drive=3Ddrive0," - "addr=3D%x.%x"; - - tmp_path =3D drive_create(); - - if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0) { - qs =3D qtest_pc_boot(cmd, tmp_path, PCI_SLOT, PCI_FN); - } else if (strcmp(arch, "ppc64") =3D=3D 0) { - qs =3D qtest_spapr_boot(cmd, tmp_path, PCI_SLOT, PCI_FN); - } else { - g_printerr("virtio-blk tests are only available on x86 or ppc64\n"= ); - exit(EXIT_FAILURE); - } - global_qtest =3D qs->qts; - unlink(tmp_path); - g_free(tmp_path); - return qs; -} - -static void arm_test_start(void) -{ - char *tmp_path; - - tmp_path =3D drive_create(); - - global_qtest =3D qtest_initf("-machine virt " - "-drive if=3Dnone,id=3Ddrive0,file=3D%s,for= mat=3Draw " - "-device virtio-blk-device,drive=3Ddrive0", - tmp_path); - unlink(tmp_path); - g_free(tmp_path); -} - -static void test_end(void) -{ - qtest_end(); -} - -static QVirtioPCIDevice *virtio_blk_pci_init(QPCIBus *bus, int slot) -{ - QVirtioPCIDevice *dev; - - dev =3D qvirtio_pci_device_find_slot(bus, VIRTIO_ID_BLOCK, slot); - g_assert(dev !=3D NULL); - g_assert_cmphex(dev->vdev.device_type, =3D=3D, VIRTIO_ID_BLOCK); - g_assert_cmphex(dev->pdev->devfn, =3D=3D, ((slot << 3) | PCI_FN)); - - qvirtio_pci_device_enable(dev); - qvirtio_start_device(&dev->vdev); - return dev; + g_test_queue_destroy(drive_destroy, t_path); + return t_path; } =20 static inline void virtio_blk_fix_request(QVirtioDevice *d, QVirtioBlkReq = *req) @@ -395,32 +329,21 @@ static void test_basic(QVirtioDevice *dev, QGuestAllo= cator *alloc, } } =20 -static void pci_basic(void) +static void basic(void *obj, void *data, QGuestAllocator *t_alloc) { - QVirtioPCIDevice *dev; - QOSState *qs; - QVirtQueuePCI *vqpci; - - qs =3D pci_test_start(); - dev =3D virtio_blk_pci_init(qs->pcibus, PCI_SLOT); - - vqpci =3D (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, &qs->alloc, 0); - - test_basic(&dev->vdev, &qs->alloc, &vqpci->vq); + QVirtioBlk *blk_if =3D obj; + QVirtQueue *vq; + vq =3D qvirtqueue_setup(blk_if->vdev, t_alloc, 0); + test_basic(blk_if->vdev, t_alloc, vq); + qvirtqueue_cleanup(blk_if->vdev->bus, vq, t_alloc); =20 - /* End test */ - qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, &qs->alloc); - qvirtio_pci_device_disable(dev); - qvirtio_pci_device_free(dev); - g_free(dev); - qtest_shutdown(qs); } =20 -static void pci_indirect(void) +static void indirect(void *obj, void *u_data, QGuestAllocator *t_alloc) { - QVirtioPCIDevice *dev; - QVirtQueuePCI *vqpci; - QOSState *qs; + QVirtQueue *vq; + QVirtioBlk *blk_if =3D obj; + QVirtioDevice *dev =3D blk_if->vdev; QVirtioBlkReq req; QVRingIndirectDesc *indirect; uint64_t req_addr; @@ -430,22 +353,18 @@ static void pci_indirect(void) uint8_t status; char *data; =20 - qs =3D pci_test_start(); - - dev =3D virtio_blk_pci_init(qs->pcibus, PCI_SLOT); - - capacity =3D qvirtio_config_readq(&dev->vdev, 0); + capacity =3D qvirtio_config_readq(dev, 0); g_assert_cmpint(capacity, =3D=3D, TEST_IMAGE_SIZE / 512); =20 - features =3D qvirtio_get_features(&dev->vdev); + features =3D qvirtio_get_features(dev); g_assert_cmphex(features & (1u << VIRTIO_RING_F_INDIRECT_DESC), !=3D, = 0); features =3D features & ~(QVIRTIO_F_BAD_FEATURE | (1u << VIRTIO_RING_F_EVENT_IDX) | (1u << VIRTIO_BLK_F_SCSI)); - qvirtio_set_features(&dev->vdev, features); + qvirtio_set_features(dev, features); =20 - vqpci =3D (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, &qs->alloc, 0); - qvirtio_set_driver_ok(&dev->vdev); + vq =3D qvirtqueue_setup(dev, t_alloc, 0); + qvirtio_set_driver_ok(dev); =20 /* Write request */ req.type =3D VIRTIO_BLK_T_OUT; @@ -454,23 +373,23 @@ static void pci_indirect(void) req.data =3D g_malloc0(512); strcpy(req.data, "TEST"); =20 - req_addr =3D virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); + req_addr =3D virtio_blk_request(t_alloc, dev, &req, 512); =20 g_free(req.data); =20 - indirect =3D qvring_indirect_desc_setup(&dev->vdev, &qs->alloc, 2); + indirect =3D qvring_indirect_desc_setup(dev, t_alloc, 2); qvring_indirect_desc_add(indirect, req_addr, 528, false); qvring_indirect_desc_add(indirect, req_addr + 528, 1, true); - free_head =3D qvirtqueue_add_indirect(&vqpci->vq, indirect); - qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head); + free_head =3D qvirtqueue_add_indirect(vq, indirect); + qvirtqueue_kick(dev, vq, free_head); =20 - qvirtio_wait_used_elem(&dev->vdev, &vqpci->vq, free_head, NULL, + qvirtio_wait_used_elem(dev, vq, free_head, NULL, QVIRTIO_BLK_TIMEOUT_US); status =3D readb(req_addr + 528); g_assert_cmpint(status, =3D=3D, 0); =20 g_free(indirect); - guest_free(&qs->alloc, req_addr); + guest_free(t_alloc, req_addr); =20 /* Read request */ req.type =3D VIRTIO_BLK_T_IN; @@ -479,17 +398,17 @@ static void pci_indirect(void) req.data =3D g_malloc0(512); strcpy(req.data, "TEST"); =20 - req_addr =3D virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); + req_addr =3D virtio_blk_request(t_alloc, dev, &req, 512); =20 g_free(req.data); =20 - indirect =3D qvring_indirect_desc_setup(&dev->vdev, &qs->alloc, 2); + indirect =3D qvring_indirect_desc_setup(dev, t_alloc, 2); qvring_indirect_desc_add(indirect, req_addr, 16, false); qvring_indirect_desc_add(indirect, req_addr + 16, 513, true); - free_head =3D qvirtqueue_add_indirect(&vqpci->vq, indirect); - qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head); + free_head =3D qvirtqueue_add_indirect(vq, indirect); + qvirtqueue_kick(dev, vq, free_head); =20 - qvirtio_wait_used_elem(&dev->vdev, &vqpci->vq, free_head, NULL, + qvirtio_wait_used_elem(dev, vq, free_head, NULL, QVIRTIO_BLK_TIMEOUT_US); status =3D readb(req_addr + 528); g_assert_cmpint(status, =3D=3D, 0); @@ -500,52 +419,37 @@ static void pci_indirect(void) g_free(data); =20 g_free(indirect); - guest_free(&qs->alloc, req_addr); - - /* End test */ - qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, &qs->alloc); - qvirtio_pci_device_disable(dev); - qvirtio_pci_device_free(dev); - g_free(dev); - qtest_shutdown(qs); + guest_free(t_alloc, req_addr); + qvirtqueue_cleanup(dev->bus, vq, t_alloc); } =20 -static void pci_config(void) +static void config(void *obj, void *data, QGuestAllocator *t_alloc) { - QVirtioPCIDevice *dev; - QOSState *qs; + QVirtioBlk *blk_if =3D obj; + QVirtioDevice *dev =3D blk_if->vdev; int n_size =3D TEST_IMAGE_SIZE / 2; uint64_t capacity; =20 - qs =3D pci_test_start(); - - dev =3D virtio_blk_pci_init(qs->pcibus, PCI_SLOT); - - capacity =3D qvirtio_config_readq(&dev->vdev, 0); + capacity =3D qvirtio_config_readq(dev, 0); g_assert_cmpint(capacity, =3D=3D, TEST_IMAGE_SIZE / 512); =20 - qvirtio_set_driver_ok(&dev->vdev); + qvirtio_set_driver_ok(dev); =20 qmp_discard_response("{ 'execute': 'block_resize', " " 'arguments': { 'device': 'drive0', " " 'size': %d } }", n_size); - qvirtio_wait_config_isr(&dev->vdev, QVIRTIO_BLK_TIMEOUT_US); + qvirtio_wait_config_isr(dev, QVIRTIO_BLK_TIMEOUT_US); =20 - capacity =3D qvirtio_config_readq(&dev->vdev, 0); + capacity =3D qvirtio_config_readq(dev, 0); g_assert_cmpint(capacity, =3D=3D, n_size / 512); - - qvirtio_pci_device_disable(dev); - qvirtio_pci_device_free(dev); - g_free(dev); - - qtest_shutdown(qs); } =20 -static void pci_msix(void) +static void msix(void *obj, void *u_data, QGuestAllocator *t_alloc) { - QVirtioPCIDevice *dev; - QOSState *qs; - QVirtQueuePCI *vqpci; + QVirtQueue *vq; + QVirtioBlkPCI *blk =3D obj; + QVirtioPCIDevice *pdev =3D &blk->pci_vdev; + QVirtioDevice *dev =3D &pdev->vdev; QVirtioBlkReq req; int n_size =3D TEST_IMAGE_SIZE / 2; uint64_t req_addr; @@ -554,36 +458,38 @@ static void pci_msix(void) uint32_t free_head; uint8_t status; char *data; + QOSGraphObject *blk_object =3D obj; + QPCIDevice *pci_dev =3D blk_object->get_driver(blk_object, "pci-device= "); =20 - qs =3D pci_test_start(); - - dev =3D virtio_blk_pci_init(qs->pcibus, PCI_SLOT); - qpci_msix_enable(dev->pdev); + if (qpci_check_buggy_msi(pci_dev)) { + return; + } =20 - qvirtio_pci_set_msix_configuration_vector(dev, &qs->alloc, 0); + qpci_msix_enable(pdev->pdev); + qvirtio_pci_set_msix_configuration_vector(pdev, t_alloc, 0); =20 - capacity =3D qvirtio_config_readq(&dev->vdev, 0); + capacity =3D qvirtio_config_readq(dev, 0); g_assert_cmpint(capacity, =3D=3D, TEST_IMAGE_SIZE / 512); =20 - features =3D qvirtio_get_features(&dev->vdev); + 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) | (1u << VIRTIO_BLK_F_SCSI)); - qvirtio_set_features(&dev->vdev, features); + qvirtio_set_features(dev, features); =20 - vqpci =3D (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, &qs->alloc, 0); - qvirtqueue_pci_msix_setup(dev, vqpci, &qs->alloc, 1); + vq =3D qvirtqueue_setup(dev, t_alloc, 0); + qvirtqueue_pci_msix_setup(pdev, (QVirtQueuePCI *)vq, t_alloc, 1); =20 - qvirtio_set_driver_ok(&dev->vdev); + qvirtio_set_driver_ok(dev); =20 qmp_discard_response("{ 'execute': 'block_resize', " " 'arguments': { 'device': 'drive0', " " 'size': %d } }", n_size); =20 - qvirtio_wait_config_isr(&dev->vdev, QVIRTIO_BLK_TIMEOUT_US); + qvirtio_wait_config_isr(dev, QVIRTIO_BLK_TIMEOUT_US); =20 - capacity =3D qvirtio_config_readq(&dev->vdev, 0); + capacity =3D qvirtio_config_readq(dev, 0); g_assert_cmpint(capacity, =3D=3D, n_size / 512); =20 /* Write request */ @@ -593,22 +499,22 @@ static void pci_msix(void) req.data =3D g_malloc0(512); strcpy(req.data, "TEST"); =20 - req_addr =3D virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); + req_addr =3D virtio_blk_request(t_alloc, dev, &req, 512); =20 g_free(req.data); =20 - free_head =3D qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false); - qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head); + free_head =3D qvirtqueue_add(vq, req_addr, 16, false, true); + qvirtqueue_add(vq, req_addr + 16, 512, false, true); + qvirtqueue_add(vq, req_addr + 528, 1, true, false); + qvirtqueue_kick(dev, vq, free_head); =20 - qvirtio_wait_used_elem(&dev->vdev, &vqpci->vq, free_head, NULL, + qvirtio_wait_used_elem(dev, vq, free_head, NULL, QVIRTIO_BLK_TIMEOUT_US); =20 status =3D readb(req_addr + 528); g_assert_cmpint(status, =3D=3D, 0); =20 - guest_free(&qs->alloc, req_addr); + guest_free(t_alloc, req_addr); =20 /* Read request */ req.type =3D VIRTIO_BLK_T_IN; @@ -616,18 +522,18 @@ static void pci_msix(void) req.sector =3D 0; req.data =3D g_malloc0(512); =20 - req_addr =3D virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); + req_addr =3D virtio_blk_request(t_alloc, dev, &req, 512); =20 g_free(req.data); =20 - free_head =3D qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, true, true); - qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false); + free_head =3D qvirtqueue_add(vq, req_addr, 16, false, true); + qvirtqueue_add(vq, req_addr + 16, 512, true, true); + qvirtqueue_add(vq, req_addr + 528, 1, true, false); =20 - qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head); + qvirtqueue_kick(dev, vq, free_head); =20 =20 - qvirtio_wait_used_elem(&dev->vdev, &vqpci->vq, free_head, NULL, + qvirtio_wait_used_elem(dev, vq, free_head, NULL, QVIRTIO_BLK_TIMEOUT_US); =20 status =3D readb(req_addr + 528); @@ -638,22 +544,19 @@ static void pci_msix(void) g_assert_cmpstr(data, =3D=3D, "TEST"); g_free(data); =20 - guest_free(&qs->alloc, req_addr); + guest_free(t_alloc, req_addr); =20 /* End test */ - qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, &qs->alloc); - qpci_msix_disable(dev->pdev); - qvirtio_pci_device_disable(dev); - qvirtio_pci_device_free(dev); - g_free(dev); - qtest_shutdown(qs); + qpci_msix_disable(pdev->pdev); + qvirtqueue_cleanup(dev->bus, vq, t_alloc); } =20 -static void pci_idx(void) +static void idx(void *obj, void *u_data, QGuestAllocator *t_alloc) { - QVirtioPCIDevice *dev; - QOSState *qs; - QVirtQueuePCI *vqpci; + QVirtQueue *vq; + QVirtioBlkPCI *blk =3D obj; + QVirtioPCIDevice *pdev =3D &blk->pci_vdev; + QVirtioDevice *dev =3D &pdev->vdev; QVirtioBlkReq req; uint64_t req_addr; uint64_t capacity; @@ -663,28 +566,30 @@ static void pci_idx(void) uint32_t desc_idx; uint8_t status; char *data; + QOSGraphObject *blk_object =3D obj; + QPCIDevice *pci_dev =3D blk_object->get_driver(blk_object, "pci-device= "); =20 - qs =3D pci_test_start(); - - dev =3D virtio_blk_pci_init(qs->pcibus, PCI_SLOT); - qpci_msix_enable(dev->pdev); + if (qpci_check_buggy_msi(pci_dev)) { + return; + } =20 - qvirtio_pci_set_msix_configuration_vector(dev, &qs->alloc, 0); + qpci_msix_enable(pdev->pdev); + qvirtio_pci_set_msix_configuration_vector(pdev, t_alloc, 0); =20 - capacity =3D qvirtio_config_readq(&dev->vdev, 0); + capacity =3D qvirtio_config_readq(dev, 0); g_assert_cmpint(capacity, =3D=3D, TEST_IMAGE_SIZE / 512); =20 - features =3D qvirtio_get_features(&dev->vdev); + features =3D qvirtio_get_features(dev); features =3D features & ~(QVIRTIO_F_BAD_FEATURE | (1u << VIRTIO_RING_F_INDIRECT_DESC) | (1u << VIRTIO_F_NOTIFY_ON_EMPTY) | (1u << VIRTIO_BLK_F_SCSI)); - qvirtio_set_features(&dev->vdev, features); + qvirtio_set_features(dev, features); =20 - vqpci =3D (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, &qs->alloc, 0); - qvirtqueue_pci_msix_setup(dev, vqpci, &qs->alloc, 1); + vq =3D qvirtqueue_setup(dev, t_alloc, 0); + qvirtqueue_pci_msix_setup(pdev, (QVirtQueuePCI *)vq, t_alloc, 1); =20 - qvirtio_set_driver_ok(&dev->vdev); + qvirtio_set_driver_ok(dev); =20 /* Write request */ req.type =3D VIRTIO_BLK_T_OUT; @@ -693,16 +598,16 @@ static void pci_idx(void) req.data =3D g_malloc0(512); strcpy(req.data, "TEST"); =20 - req_addr =3D virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); + req_addr =3D virtio_blk_request(t_alloc, dev, &req, 512); =20 g_free(req.data); =20 - free_head =3D qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false); - qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head); + free_head =3D qvirtqueue_add(vq, req_addr, 16, false, true); + qvirtqueue_add(vq, req_addr + 16, 512, false, true); + qvirtqueue_add(vq, req_addr + 528, 1, true, false); + qvirtqueue_kick(dev, vq, free_head); =20 - qvirtio_wait_used_elem(&dev->vdev, &vqpci->vq, free_head, NULL, + qvirtio_wait_used_elem(dev, vq, free_head, NULL, QVIRTIO_BLK_TIMEOUT_US); =20 /* Write request */ @@ -712,25 +617,25 @@ static void pci_idx(void) req.data =3D g_malloc0(512); strcpy(req.data, "TEST"); =20 - req_addr =3D virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); + req_addr =3D virtio_blk_request(t_alloc, dev, &req, 512); =20 g_free(req.data); =20 /* Notify after processing the third request */ - qvirtqueue_set_used_event(&vqpci->vq, 2); - free_head =3D qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false); - qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head); + qvirtqueue_set_used_event(vq, 2); + free_head =3D qvirtqueue_add(vq, req_addr, 16, false, true); + qvirtqueue_add(vq, req_addr + 16, 512, false, true); + qvirtqueue_add(vq, req_addr + 528, 1, true, false); + qvirtqueue_kick(dev, vq, free_head); write_head =3D free_head; =20 /* No notification expected */ - status =3D qvirtio_wait_status_byte_no_isr(&dev->vdev, - &vqpci->vq, req_addr + 528, + status =3D qvirtio_wait_status_byte_no_isr(dev, + vq, req_addr + 528, QVIRTIO_BLK_TIMEOUT_US); g_assert_cmpint(status, =3D=3D, 0); =20 - guest_free(&qs->alloc, req_addr); + guest_free(t_alloc, req_addr); =20 /* Read request */ req.type =3D VIRTIO_BLK_T_IN; @@ -738,20 +643,20 @@ static void pci_idx(void) req.sector =3D 1; req.data =3D g_malloc0(512); =20 - req_addr =3D virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); + req_addr =3D virtio_blk_request(t_alloc, dev, &req, 512); =20 g_free(req.data); =20 - free_head =3D qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, true, true); - qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false); + free_head =3D qvirtqueue_add(vq, req_addr, 16, false, true); + qvirtqueue_add(vq, req_addr + 16, 512, true, true); + qvirtqueue_add(vq, req_addr + 528, 1, true, false); =20 - qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head); + qvirtqueue_kick(dev, vq, free_head); =20 /* We get just one notification for both requests */ - qvirtio_wait_used_elem(&dev->vdev, &vqpci->vq, write_head, NULL, + qvirtio_wait_used_elem(dev, vq, write_head, NULL, QVIRTIO_BLK_TIMEOUT_US); - g_assert(qvirtqueue_get_buf(&vqpci->vq, &desc_idx, NULL)); + g_assert(qvirtqueue_get_buf(vq, &desc_idx, NULL)); g_assert_cmpint(desc_idx, =3D=3D, free_head); =20 status =3D readb(req_addr + 528); @@ -762,125 +667,114 @@ static void pci_idx(void) g_assert_cmpstr(data, =3D=3D, "TEST"); g_free(data); =20 - guest_free(&qs->alloc, req_addr); + guest_free(t_alloc, req_addr); =20 /* End test */ - qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, &qs->alloc); - qpci_msix_disable(dev->pdev); - qvirtio_pci_device_disable(dev); - qvirtio_pci_device_free(dev); - g_free(dev); - qtest_shutdown(qs); + qpci_msix_disable(pdev->pdev); + + qvirtqueue_cleanup(dev->bus, vq, t_alloc); } =20 -static void pci_hotplug(void) +static void pci_hotplug(void *obj, void *data, QGuestAllocator *t_alloc) { + QVirtioPCIDevice *dev1 =3D obj; QVirtioPCIDevice *dev; - QOSState *qs; - const char *arch =3D qtest_get_arch(); - - qs =3D pci_test_start(); =20 /* plug secondary disk */ qtest_qmp_device_add("virtio-blk-pci", "drv1", "{'addr': %s, 'drive': 'drive1'}", - stringify(PCI_SLOT_HP)); + stringify(PCI_SLOT_HP) ".0"); =20 - dev =3D virtio_blk_pci_init(qs->pcibus, PCI_SLOT_HP); - g_assert(dev); + dev =3D virtio_pci_new(dev1->pdev->bus, + &(QPCIAddress) { .devfn =3D QPCI_DEVFN(PCI_SLOT_H= P, 0) }); + g_assert_nonnull(dev); + g_assert_cmpint(dev->vdev.device_type, =3D=3D, VIRTIO_ID_BLOCK); qvirtio_pci_device_disable(dev); - qvirtio_pci_device_free(dev); - g_free(dev); + qos_object_destroy((QOSGraphObject *)dev); =20 /* unplug secondary disk */ - if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0) { - qpci_unplug_acpi_device_test("drv1", PCI_SLOT_HP); - } - qtest_shutdown(qs); + qpci_unplug_acpi_device_test("drv1", PCI_SLOT_HP); } =20 /* * Check that setting the vring addr on a non-existent virtqueue does * not crash. */ -static void test_nonexistent_virtqueue(void) +static void test_nonexistent_virtqueue(void *obj, void *data, + QGuestAllocator *t_alloc) { + QVirtioBlkPCI *blk =3D obj; + QVirtioPCIDevice *pdev =3D &blk->pci_vdev; QPCIBar bar0; - QOSState *qs; QPCIDevice *dev; =20 - qs =3D pci_test_start(); - dev =3D qpci_device_find(qs->pcibus, QPCI_DEVFN(4, 0)); + dev =3D qpci_device_find(pdev->pdev->bus, QPCI_DEVFN(4, 0)); g_assert(dev !=3D NULL); - qpci_device_enable(dev); + bar0 =3D qpci_iomap(dev, 0, NULL); =20 qpci_io_writeb(dev, bar0, VIRTIO_PCI_QUEUE_SEL, 2); qpci_io_writel(dev, bar0, VIRTIO_PCI_QUEUE_PFN, 1); =20 + g_free(dev); - qtest_shutdown(qs); } =20 -static void mmio_basic(void) +static void resize(void *obj, void *data, QGuestAllocator *t_alloc) { - QVirtioMMIODevice *dev; - QVirtQueue *vq; - QGuestAllocator alloc; + QVirtioBlk *blk_if =3D obj; + QVirtioDevice *dev =3D blk_if->vdev; int n_size =3D TEST_IMAGE_SIZE / 2; uint64_t capacity; + QVirtQueue *vq; =20 - arm_test_start(); - - dev =3D g_malloc0(sizeof(QVirtioMMIODevice)); - qvirtio_mmio_init_device(dev, global_qtest, MMIO_DEV_BASE_ADDR, MMIO_P= AGE_SIZE); - g_assert(dev !=3D NULL); - g_assert_cmphex(dev->vdev.device_type, =3D=3D, VIRTIO_ID_BLOCK); - - qvirtio_start_device(&dev->vdev); - - generic_alloc_init(&alloc, MMIO_RAM_ADDR, MMIO_RAM_SIZE, MMIO_PAGE_SIZ= E); - vq =3D qvirtqueue_setup(&dev->vdev, &alloc, 0); + vq =3D qvirtqueue_setup(dev, t_alloc, 0); =20 - test_basic(&dev->vdev, &alloc, vq); + test_basic(dev, t_alloc, vq); =20 qmp_discard_response("{ 'execute': 'block_resize', " " 'arguments': { 'device': 'drive0', " " 'size': %d } }", n_size); =20 - qvirtio_wait_queue_isr(&dev->vdev, vq, QVIRTIO_BLK_TIMEOUT_US); + qvirtio_wait_queue_isr(dev, vq, QVIRTIO_BLK_TIMEOUT_US); =20 - capacity =3D qvirtio_config_readq(&dev->vdev, 0); + capacity =3D qvirtio_config_readq(dev, 0); g_assert_cmpint(capacity, =3D=3D, n_size / 512); =20 - /* End test */ - qvirtqueue_cleanup(dev->vdev.bus, vq, &alloc); - g_free(dev); - alloc_destroy(&alloc); - test_end(); + qvirtqueue_cleanup(dev->bus, vq, t_alloc); + } =20 -int main(int argc, char **argv) +static void *virtio_blk_test_setup(GString *cmd_line, void *arg) { - const char *arch =3D qtest_get_arch(); - - g_test_init(&argc, &argv, NULL); - - if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0 || - strcmp(arch, "ppc64") =3D=3D 0) { - qtest_add_func("/virtio/blk/pci/basic", pci_basic); - qtest_add_func("/virtio/blk/pci/indirect", pci_indirect); - qtest_add_func("/virtio/blk/pci/config", pci_config); - qtest_add_func("/virtio/blk/pci/nxvirtq", test_nonexistent_virtque= ue); - if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D= 0) { - qtest_add_func("/virtio/blk/pci/msix", pci_msix); - qtest_add_func("/virtio/blk/pci/idx", pci_idx); - } - qtest_add_func("/virtio/blk/pci/hotplug", pci_hotplug); - } else if (strcmp(arch, "arm") =3D=3D 0) { - qtest_add_func("/virtio/blk/mmio/basic", mmio_basic); - } + char *tmp_path =3D drive_create(); =20 - return g_test_run(); + g_string_append_printf(cmd_line, + " -drive if=3Dnone,id=3Ddrive0,file=3D%s,format= =3Draw " + "-drive if=3Dnone,id=3Ddrive1,file=3Dnull-co://= ,format=3Draw ", + tmp_path); + + return arg; } + +static void register_virtio_blk_test(void) +{ + QOSGraphTestOptions opts =3D { + .before =3D virtio_blk_test_setup, + }; + + qos_add_test("indirect", "virtio-blk", indirect, &opts); + qos_add_test("config", "virtio-blk", config, &opts); + qos_add_test("basic", "virtio-blk", basic, &opts); + qos_add_test("resize", "virtio-blk", resize, &opts); + + /* tests just for virtio-blk-pci */ + qos_add_test("msix", "virtio-blk-pci", msix, &opts); + qos_add_test("idx", "virtio-blk-pci", idx, &opts); + qos_add_test("nxvirtq", "virtio-blk-pci", + test_nonexistent_virtqueue, &opts); + qos_add_test("hotplug", "virtio-blk-pci", pci_hotplug, &opts); +} + +libqos_init(register_virtio_blk_test); --=20 1.8.3.1