From nobody Fri Dec 19 19:06:27 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 1501811332960602.9015604841871; Thu, 3 Aug 2017 18:48:52 -0700 (PDT) Received: from localhost ([::1]:44542 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddRjP-00089X-Cc for importer@patchew.org; Thu, 03 Aug 2017 21:48:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60528) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddRNo-0000Ab-1O for qemu-devel@nongnu.org; Thu, 03 Aug 2017 21:26:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddRNm-0004fX-QT for qemu-devel@nongnu.org; Thu, 03 Aug 2017 21:26:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45352) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ddRNj-0004UV-7m; Thu, 03 Aug 2017 21:26:27 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2F1284E4F3; Fri, 4 Aug 2017 01:26:26 +0000 (UTC) Received: from red.redhat.com (ovpn-121-23.rdu2.redhat.com [10.10.121.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6542561F57; Fri, 4 Aug 2017 01:26:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2F1284E4F3 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 3 Aug 2017 20:25:49 -0500 Message-Id: <20170804012551.2714-21-eblake@redhat.com> In-Reply-To: <20170804012551.2714-1-eblake@redhat.com> References: <20170804012551.2714-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 04 Aug 2017 01:26:26 +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 v4 20/22] 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: , Cc: "open list:virtio-blk" , armbru@redhat.com, Stefan Hajnoczi 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" From: Markus Armbruster Leaving interpolation into JSON to qmp() is more robust than building QMP input manually, as explained in previous commits. 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 Message-Id: <1500645206-13559-7-git-send-email-armbru@redhat.com> [use qmp_args_dict for a slightly smaller diff, fix '%s' typo in ivshmem-te= st] Signed-off-by: Eric Blake --- tests/libqos/pci.h | 2 +- tests/ivshmem-test.c | 10 +++++----- tests/libqos/pci.c | 32 +++++++++++++++++--------------- tests/virtio-blk-test.c | 5 ++++- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/tests/libqos/pci.h b/tests/libqos/pci.h index ed480614ff..c981061703 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); 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/ivshmem-test.c b/tests/ivshmem-test.c index 37763425ee..4cb5a030da 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" #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); qtest_start(""); - 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); } qtest_end(); - g_free(opts); } static void test_ivshmem_memdev(void) diff --git a/tests/libqos/pci.c b/tests/libqos/pci.c index 2dcdeade2a..68623795b7 100644 --- a/tests/libqos/pci.c +++ b/tests/libqos/pci.c @@ -14,6 +14,7 @@ #include "libqos/pci.h" #include "hw/pci/pci_regs.h" +#include "qapi/qmp/qjson.h" #include "qemu/host-utils.h" void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id, @@ -392,22 +393,23 @@ QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t a= ddr) } 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_args_dict("device_add", args); + g_assert(response); g_assert(!qdict_haskey(response, "error")); QDECREF(response); diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index 649ba03c92..78a9ebfb0d 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" @@ -656,12 +657,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' }"); qs =3D pci_test_start(); /* plug secondary disk */ qpci_plug_device_test("virtio-blk-pci", "drv1", PCI_SLOT_HP, - "'drive': 'drive1'"); + qobject_to_qdict(extra_args)); dev =3D virtio_blk_pci_init(qs->pcibus, PCI_SLOT_HP); g_assert(dev); @@ -672,6 +674,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 2.13.3