From nobody Mon Feb 9 11:51:22 2026 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; 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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1543854364353612.4536453340431; Mon, 3 Dec 2018 08:26:04 -0800 (PST) Received: from localhost ([::1]:50440 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTr2o-00033x-F4 for importer@patchew.org; Mon, 03 Dec 2018 11:26:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52893) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTqGl-0002hc-89 for qemu-devel@nongnu.org; Mon, 03 Dec 2018 10:36:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gTqGj-00072V-2o for qemu-devel@nongnu.org; Mon, 03 Dec 2018 10:36:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42408) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gTqGi-00071U-Nh for qemu-devel@nongnu.org; Mon, 03 Dec 2018 10:36:21 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7DDCC85A04; Mon, 3 Dec 2018 15:36:19 +0000 (UTC) Received: from 640k.localdomain.com (ovpn-112-19.ams2.redhat.com [10.36.112.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 192936A6A6; Mon, 3 Dec 2018 15:36:16 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 3 Dec 2018 16:33:24 +0100 Message-Id: <1543851204-41186-72-git-send-email-pbonzini@redhat.com> In-Reply-To: <1543851204-41186-1-git-send-email-pbonzini@redhat.com> References: <1543851204-41186-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 03 Dec 2018 15:36:19 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 71/71] qos-test: megasas 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: Thomas Huth , Emanuele Giuseppe Esposito , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Convert tests/megasas-test to a driver node; the code to discover the PCI device is replaced by generic qgraph code. Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 3 +- tests/megasas-test.c | 80 +++++++++++++++++++++++++---------------------= ---- 2 files changed, 41 insertions(+), 42 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 0527342..014583f 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -145,7 +145,6 @@ check-qtest-pci-$(CONFIG_RTL8139_PCI) +=3D tests/rtl813= 9-test$(EXESUF) check-qtest-pci-y +=3D tests/display-vga-test$(EXESUF) check-qtest-pci-$(CONFIG_HDA) +=3D tests/intel-hda-test$(EXESUF) check-qtest-pci-$(CONFIG_IVSHMEM_DEVICE) +=3D tests/ivshmem-test$(EXESUF) -check-qtest-pci-y +=3D tests/megasas-test$(EXESUF) =20 check-qtest-i386-$(CONFIG_ISA_TESTDEV) =3D tests/endianness-test$(EXESUF) check-qtest-i386-y +=3D tests/fdc-test$(EXESUF) @@ -672,6 +671,7 @@ qos-test-obj-y +=3D tests/e1000e-test.o qos-test-obj-y +=3D tests/eepro100-test.o qos-test-obj-y +=3D tests/es1370-test.o qos-test-obj-y +=3D tests/ipoctal232-test.o +qos-test-obj-y +=3D tests/megasas-test.o qos-test-obj-y +=3D tests/ne2000-test.o qos-test-obj-y +=3D tests/nvme-test.o qos-test-obj-y +=3D tests/pci-test.o @@ -750,7 +750,6 @@ tests/test-filter-mirror$(EXESUF): tests/test-filter-mi= rror.o $(qtest-obj-y) tests/test-filter-redirector$(EXESUF): tests/test-filter-redirector.o $(qt= est-obj-y) tests/test-x86-cpuid-compat$(EXESUF): tests/test-x86-cpuid-compat.o $(qtes= t-obj-y) tests/ivshmem-test$(EXESUF): tests/ivshmem-test.o contrib/ivshmem-server/i= vshmem-server.o $(libqos-pc-obj-y) $(libqos-spapr-obj-y) -tests/megasas-test$(EXESUF): tests/megasas-test.o $(libqos-spapr-obj-y) $(= libqos-pc-obj-y) tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o $(test-util-ob= j-y) libvhost-user.a tests/test-uuid$(EXESUF): tests/test-uuid.o $(test-util-obj-y) tests/test-arm-mptimer$(EXESUF): tests/test-arm-mptimer.o diff --git a/tests/megasas-test.c b/tests/megasas-test.c index 81837e1..33aa970 100644 --- a/tests/megasas-test.c +++ b/tests/megasas-test.c @@ -10,55 +10,49 @@ #include "qemu/osdep.h" #include "libqtest.h" #include "qemu/bswap.h" -#include "libqos/libqos-pc.h" -#include "libqos/libqos-spapr.h" +#include "libqos/qgraph.h" +#include "libqos/pci.h" =20 -static QOSState *qmegasas_start(const char *extra_opts) +typedef struct QMegasas QMegasas; + +struct QMegasas { + QOSGraphObject obj; + QPCIDevice dev; +}; + +static void *megasas_get_driver(void *obj, const char *interface) { - QOSState *qs; - const char *arch =3D qtest_get_arch(); - const char *cmd =3D "-drive id=3Dhd0,if=3Dnone,file=3Dnull-co://,forma= t=3Draw " - "-device megasas,id=3Dscsi0,addr=3D04.0 " - "-device scsi-hd,bus=3Dscsi0.0,drive=3Dhd0 %s"; - - if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0) { - qs =3D qtest_pc_boot(cmd, extra_opts ? : ""); - global_qtest =3D qs->qts; - return qs; + QMegasas *megasas =3D obj; + + if (!g_strcmp0(interface, "pci-device")) { + return &megasas->dev; } =20 - g_printerr("virtio-scsi tests are only available on x86 or ppc64\n"); - exit(EXIT_FAILURE); + fprintf(stderr, "%s not present in megasas\n", interface); + g_assert_not_reached(); } =20 -static void qmegasas_stop(QOSState *qs) +static void *megasas_create(void *pci_bus, QGuestAllocator *alloc, void *a= ddr) { - qtest_shutdown(qs); -} + QMegasas *megasas =3D g_new0(QMegasas, 1); + QPCIBus *bus =3D pci_bus; =20 -/* Tests only initialization so far. TODO: Replace with functional tests */ -static void pci_nop(void) -{ - QOSState *qs; + qpci_device_init(&megasas->dev, bus, addr); + megasas->obj.get_driver =3D megasas_get_driver; =20 - qs =3D qmegasas_start(NULL); - qmegasas_stop(qs); + return &megasas->obj; } =20 /* This used to cause a NULL pointer dereference. */ -static void megasas_pd_get_info_fuzz(void) +static void megasas_pd_get_info_fuzz(void *obj, void *data, QGuestAllocato= r *alloc) { - QPCIDevice *dev; - QOSState *qs; + QMegasas *megasas =3D obj; + QPCIDevice *dev =3D &megasas->dev; QPCIBar bar; uint32_t context[256]; uint64_t context_pa; int i; =20 - qs =3D qmegasas_start(NULL); - dev =3D qpci_device_find(qs->pcibus, QPCI_DEVFN(4,0)); - g_assert(dev !=3D NULL); - qpci_device_enable(dev); bar =3D qpci_iomap(dev, 0, NULL); =20 @@ -71,19 +65,25 @@ static void megasas_pd_get_info_fuzz(void) context[6] =3D cpu_to_le32(0x02020000); context[7] =3D cpu_to_le32(0); =20 - context_pa =3D qmalloc(qs, sizeof(context)); + context_pa =3D guest_alloc(alloc, sizeof(context)); memwrite(context_pa, context, sizeof(context)); qpci_io_writel(dev, bar, 0x40, context_pa); - - g_free(dev); - qmegasas_stop(qs); } =20 -int main(int argc, char **argv) +static void megasas_register_nodes(void) { - g_test_init(&argc, &argv, NULL); - qtest_add_func("/megasas/pci/nop", pci_nop); - qtest_add_func("/megasas/dcmd/pd-get-info/fuzz", megasas_pd_get_info_f= uzz); + QOSGraphEdgeOptions opts =3D { + .extra_device_opts =3D "addr=3D04.0,id=3Dscsi0", + .before_cmd_line =3D "-drive id=3Ddrv0,if=3Dnone,file=3Dnull-co://= ,format=3Draw", + .after_cmd_line =3D "-device scsi-hd,bus=3Dscsi0.0,drive=3Ddrv0", + }; + + add_qpci_address(&opts, &(QPCIAddress) { .devfn =3D QPCI_DEVFN(4, 0) }= ); + + qos_node_create_driver("megasas", megasas_create); + qos_node_consumes("megasas", "pci-bus", &opts); + qos_node_produces("megasas", "pci-device"); =20 - return g_test_run(); + qos_add_test("dcmd/pd-get-info/fuzz", "megasas", megasas_pd_get_info_f= uzz, NULL); } +libqos_init(megasas_register_nodes); --=20 1.8.3.1