From patchwork Wed Nov 30 19:44:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 701177 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tTWwJ1qBFz9sxS for ; Thu, 1 Dec 2016 07:19:12 +1100 (AEDT) Received: from localhost ([::1]:46239 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCBLR-0006mO-5M for incoming@patchwork.ozlabs.org; Wed, 30 Nov 2016 15:19:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35743) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCAot-00040m-9h 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 1cCAop-00020b-9w for qemu-devel@nongnu.org; Wed, 30 Nov 2016 14:45:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44532) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cCAom-0001wM-O9; Wed, 30 Nov 2016 14:45:24 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9ABE8C057FA6; Wed, 30 Nov 2016 19:45:23 +0000 (UTC) Received: from red.redhat.com (ovpn-116-172.phx2.redhat.com [10.3.116.172]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uAUJj2nP025934; Wed, 30 Nov 2016 14:45:22 -0500 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 30 Nov 2016 13:44:36 -0600 Message-Id: <1480535094-23831-19-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> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 30 Nov 2016 19:45:23 +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 18/36] qtest: Avoid dynamic JSON in fdc-test 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: pbonzini@redhat.com, John Snow , armbru@redhat.com, "open list:Floppy" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: John Snow --- tests/fdc-test.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/fdc-test.c b/tests/fdc-test.c index f5ff68d..ac75e87 100644 --- a/tests/fdc-test.c +++ b/tests/fdc-test.c @@ -27,6 +27,8 @@ #include "libqtest.h" #include "qemu-common.h" +#include "qapi/qmp/qjson.h" +#include "qapi/qobject-output-visitor.h" #define TEST_IMAGE_SIZE 1440 * 1024 @@ -295,13 +297,19 @@ static void test_read_without_media(void) static void test_media_insert(void) { uint8_t dir; + QObject *args; + BlockdevChangeMedium bcm = { + .has_device = true, + .device = (char *)"floppy0", + .filename = test_image, + .has_format = true, + .format = (char *)"raw", + }; /* Insert media in drive. DSKCHK should not be reset until a step pulse * is sent. */ - qmp_discard_response("{'execute':'blockdev-change-medium', 'arguments':{" - " 'device':'floppy0', 'filename': %s, " - "'format': 'raw' }}", - test_image); + args = QAPI_TO_QOBJECT(BlockdevChangeMedium, &bcm, &error_abort); + qmp_cmd_discard_response("blockdev-change-medium", qobject_to_qdict(args)); dir = inb(FLOPPY_BASE + reg_dir); assert_bit_set(dir, DSKCHG);