Received: from eggs.gnu.org ([2001:4830:134:3::10]:35760) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCAot-00041I-R5 for qemu-devel@nongnu.org; Wed, 30 Nov 2016 14:45:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cCAos-000245-NC for qemu-devel@nongnu.org; Wed, 30 Nov 2016 14:45:31 -0500 From: Eric Blake Date: Wed, 30 Nov 2016 13:44:35 -0600 Message-Id: <1480535094-23831-18-git-send-email-eblake@redhat.com> In-Reply-To: <1480535094-23831-1-git-send-email-eblake@redhat.com> References: <1480535094-23831-1-git-send-email-eblake@redhat.com> Subject: [Qemu-devel] [PATCH 17/36] qtest: Avoid dynamic JSON in ahci-test List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: armbru@redhat.com, pbonzini@redhat.com, John Snow , "open list:IDE" As argued elsewhere, it's less code to maintain if we convert from a dynamic string passed to qobject_from_jsonv() to instead use a hand-built QDict. Rather than build up a QDict by manual qdict_put*() calls, we can let QAPI do the work for us. The result is more lines of code to initialize the QAPI struct, but the result will force us to track any changes to the qapi (whereas the dynamic JSON string would not detect qapi changes until runtime). Signed-off-by: Eric Blake --- tests/ahci-test.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/tests/ahci-test.c b/tests/ahci-test.c index ef17629..dfa9c52 100644 --- a/tests/ahci-test.c +++ b/tests/ahci-test.c @@ -32,6 +32,8 @@ #include "qemu-common.h" #include "qemu/host-utils.h" +#include "qapi/qmp/qjson.h" +#include "qapi/qobject-output-visitor.h" #include "hw/pci/pci_ids.h" #include "hw/pci/pci_regs.h" @@ -1576,6 +1578,7 @@ static void test_atapi_tray(void) uint8_t port, sense, asc; uint64_t iso_size = ATAPI_SECTOR_SIZE; QDict *rsp; + QObject *args; fd = prepare_iso(iso_size, &tx, &iso); ahci = ahci_boot_and_enable("-drive if=none,id=drive0,file=%s,format=raw " @@ -1607,11 +1610,24 @@ static void test_atapi_tray(void) atapi_wait_tray(true); /* Re-insert media */ - qmp_discard_response("{'execute': 'blockdev-add', " - "'arguments': {'node-name': 'node0', " - "'driver': 'raw', " - "'file': { 'driver': 'file', " - "'filename': %s }}}", iso); + { + BlockdevRef ref = { + .type = QTYPE_QDICT, + .u.definition = { + .driver = BLOCKDEV_DRIVER_FILE, + .u.file.filename = iso, + }, + }; + BlockdevOptions opts = { + .has_node_name = true, + .node_name = (char *)"node0", + .driver = BLOCKDEV_DRIVER_RAW, + .u.raw.file = &ref, + }; + args = QAPI_TO_QOBJECT(BlockdevOptions, &opts, &error_abort); + } + + qmp_cmd_discard_response("blockdev-add", qobject_to_qdict(args)); qmp_discard_response("{'execute': 'x-blockdev-insert-medium'," "'arguments': { 'device': 'drive0', " "'node-name': 'node0' }}"); -- 2.7.4