From nobody Wed Nov 5 02:51:23 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; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500645580729184.78567134117316; Fri, 21 Jul 2017 06:59:40 -0700 (PDT) Received: from localhost ([::1]:43357 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYYSx-0004Wg-C2 for importer@patchew.org; Fri, 21 Jul 2017 09:59:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48322) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYYN2-0007g2-Tv for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYYN1-00046K-JJ for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39616) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYYN1-00045T-9w for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:31 -0400 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 3CD0F461FE for ; Fri, 21 Jul 2017 13:53:30 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-60.ams2.redhat.com [10.36.116.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D32238BE24; Fri, 21 Jul 2017 13:53:29 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 9EDF01138650; Fri, 21 Jul 2017 15:53:26 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3CD0F461FE Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3CD0F461FE From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 21 Jul 2017 15:53:23 +0200 Message-Id: <1500645206-13559-7-git-send-email-armbru@redhat.com> In-Reply-To: <1500645206-13559-1-git-send-email-armbru@redhat.com> References: <1500645206-13559-1-git-send-email-armbru@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.29]); Fri, 21 Jul 2017 13:53:30 +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 6/9] tests/libqos/pci: Clean up string interpolation into QMP input 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Leaving interpolation into JSON to qmp() is more robust than building QMP input manually, as explained in the commit before previous. The case in qpci_plug_device_test() is a bit complicated: it interpolates several JSON object members, not just a value. Clean it up by passing them in as QDict rather than string, so we can leave interpolation to qmp() here and to qobject_from_jsonf() in callers. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- tests/ivshmem-test.c | 10 +++++----- tests/libqos/pci.c | 33 ++++++++++++++++++--------------- tests/libqos/pci.h | 2 +- tests/virtio-blk-test.c | 5 ++++- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/tests/ivshmem-test.c b/tests/ivshmem-test.c index 3776342..38044bb 100644 --- a/tests/ivshmem-test.c +++ b/tests/ivshmem-test.c @@ -14,6 +14,7 @@ #include "libqos/libqos-pc.h" #include "libqos/libqos-spapr.h" #include "libqtest.h" +#include "qapi/qmp/qjson.h" #include "qemu-common.h" =20 #define TMPSHMSIZE (1 << 20) @@ -419,19 +420,18 @@ static void test_ivshmem_server_irq(void) static void test_ivshmem_hotplug(void) { const char *arch =3D qtest_get_arch(); - gchar *opts; + QObject *extra_args =3D qobject_from_jsonf("{ 'shm': '%s', 'size': '1M= ' }", + tmpshm); =20 qtest_start(""); =20 - opts =3D g_strdup_printf("'shm': '%s', 'size': '1M'", tmpshm); - - qpci_plug_device_test("ivshmem", "iv1", PCI_SLOT_HP, opts); + qpci_plug_device_test("ivshmem", "iv1", PCI_SLOT_HP, + qobject_to_qdict(extra_args)); if (strcmp(arch, "ppc64") !=3D 0) { qpci_unplug_acpi_device_test("iv1", PCI_SLOT_HP); } =20 qtest_end(); - g_free(opts); } =20 static void test_ivshmem_memdev(void) diff --git a/tests/libqos/pci.c b/tests/libqos/pci.c index 2dcdead..4068305 100644 --- a/tests/libqos/pci.c +++ b/tests/libqos/pci.c @@ -14,6 +14,7 @@ #include "libqos/pci.h" =20 #include "hw/pci/pci_regs.h" +#include "qapi/qmp/qjson.h" #include "qemu/host-utils.h" =20 void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id, @@ -392,23 +393,25 @@ QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t a= ddr) } =20 void qpci_plug_device_test(const char *driver, const char *id, - uint8_t slot, const char *opts) + uint8_t slot, QDict *extra_args) { - QDict *response; - char *cmd; - - cmd =3D g_strdup_printf("{'execute': 'device_add'," - " 'arguments': {" - " 'driver': '%s'," - " 'addr': '%d'," - " %s%s" - " 'id': '%s'" - "}}", driver, slot, - opts ? opts : "", opts ? "," : "", - id); - response =3D qmp(cmd); - g_free(cmd); + char addr[8]; + QDict *args, *response; + + sprintf(addr, "%d", slot); + args =3D qobject_to_qdict( + qobject_from_jsonf("{ 'driver': %s, 'addr': %s, 'id': %s}", + driver, addr, id)); + + if (extra_args) { + qdict_join(args, extra_args, true); + QDECREF(extra_args); + } + + response =3D qmp("{'execute': 'device_add', 'arguments': %p }", args); + g_assert(response); g_assert(!qdict_haskey(response, "error")); + QDECREF(args); QDECREF(response); } diff --git a/tests/libqos/pci.h b/tests/libqos/pci.h index ed48061..c981061 100644 --- a/tests/libqos/pci.h +++ b/tests/libqos/pci.h @@ -109,6 +109,6 @@ void qpci_iounmap(QPCIDevice *dev, QPCIBar addr); QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr); =20 void qpci_plug_device_test(const char *driver, const char *id, - uint8_t slot, const char *opts); + uint8_t slot, QDict *extra_args); void qpci_unplug_acpi_device_test(const char *id, uint8_t slot); #endif diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index 0576cb1..64a48f4 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -16,6 +16,7 @@ #include "libqos/virtio-pci.h" #include "libqos/virtio-mmio.h" #include "libqos/malloc-generic.h" +#include "qapi/qmp/qjson.h" #include "qemu/bswap.h" #include "standard-headers/linux/virtio_ids.h" #include "standard-headers/linux/virtio_config.h" @@ -658,12 +659,13 @@ static void pci_hotplug(void) QVirtioPCIDevice *dev; QOSState *qs; const char *arch =3D qtest_get_arch(); + QObject *extra_args =3D qobject_from_jsonf("{ 'drive': 'drive1' }"); =20 qs =3D pci_test_start(); =20 /* plug secondary disk */ qpci_plug_device_test("virtio-blk-pci", "drv1", PCI_SLOT_HP, - "'drive': 'drive1'"); + qobject_to_qdict(extra_args)); =20 dev =3D virtio_blk_pci_init(qs->pcibus, PCI_SLOT_HP); g_assert(dev); @@ -674,6 +676,7 @@ static void pci_hotplug(void) 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); } =20 --=20 2.7.5