From patchwork Thu Jul 12 11:12:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 942935 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 41RD3t5pHTz9rxx for ; Thu, 12 Jul 2018 21:19:38 +1000 (AEST) Received: from localhost ([::1]:58683 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fdZdH-0003i6-Et for incoming@patchwork.ozlabs.org; Thu, 12 Jul 2018 07:19:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47883) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fdZWO-000788-Pz for qemu-devel@nongnu.org; Thu, 12 Jul 2018 07:12:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fdZWM-0006rE-Cz for qemu-devel@nongnu.org; Thu, 12 Jul 2018 07:12:28 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47664 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fdZWM-0006qQ-4u for qemu-devel@nongnu.org; Thu, 12 Jul 2018 07:12:26 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BA5C4406DE36 for ; Thu, 12 Jul 2018 11:12:25 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-125.ams2.redhat.com [10.36.116.125]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8F73C1C672; Thu, 12 Jul 2018 11:12:25 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 1AAB01132CAF; Thu, 12 Jul 2018 13:12:22 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 12 Jul 2018 13:12:19 +0200 Message-Id: <20180712111221.20326-19-armbru@redhat.com> In-Reply-To: <20180712111221.20326-1-armbru@redhat.com> References: <20180712111221.20326-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 12 Jul 2018 11:12:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 12 Jul 2018 11:12:25 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'armbru@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 18/20] migration-test: Clean up string interpolation into QMP, part 2 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: "Dr . David Alan Gilbert" , Juan Quintela Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Leaving interpolation into JSON to qmp() is more robust than building QMP input manually, as explained in the recent commit "tests: Clean up string interpolation into QMP input (simple cases)". migrate() interpolates members into a JSON object. Change it to take its extra QMP arguments as arguments for qdict_from_jsonf_nofail() instead of a string containing JSON members. Bonus: gets rid of a non-literal format string. A step towards compile-time format string checking without triggering -Wformat-nonliteral. Cc: Juan Quintela Cc: Dr. David Alan Gilbert Signed-off-by: Markus Armbruster Reviewed-by: Juan Quintela --- tests/migration-test.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/tests/migration-test.c b/tests/migration-test.c index 66a4cd2395..4a4db88b61 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -14,6 +14,7 @@ #include "libqtest.h" #include "qapi/qmp/qdict.h" +#include "qapi/qmp/qjson.h" #include "qemu/option.h" #include "qemu/range.h" #include "qemu/sockets.h" @@ -381,16 +382,19 @@ static void migrate_set_capability(QTestState *who, const char *capability, qobject_unref(rsp); } -static void migrate(QTestState *who, const char *uri, const char *extra) +static void migrate(QTestState *who, const char *uri, const char *fmt, ...) { - QDict *rsp; - gchar *cmd; + va_list ap; + QDict *args, *rsp; - cmd = g_strdup_printf("{ 'execute': 'migrate'," - " 'arguments': { 'uri': '%s' %s } }", - uri, extra ? extra : ""); - rsp = qtest_qmp(who, cmd); - g_free(cmd); + va_start(ap, fmt); + args = qdict_from_vjsonf_nofail(fmt, ap); + va_end(ap); + + g_assert(!qdict_haskey(args, "uri")); + qdict_put_str(args, "uri", uri); + + rsp = qmp("{ 'execute': 'migrate', 'arguments': %p}", args); g_assert(qdict_haskey(rsp, "return")); qobject_unref(rsp); } @@ -582,7 +586,7 @@ static int migrate_postcopy_prepare(QTestState **from_ptr, /* Wait for the first serial output from the source */ wait_for_serial("src_serial"); - migrate(from, uri, NULL); + migrate(from, uri, "{}"); g_free(uri); wait_for_migration_pass(from); @@ -665,7 +669,7 @@ static void test_postcopy_recovery(void) * the newly created channel */ wait_for_migration_status(from, "postcopy-paused"); - migrate(from, uri, ", 'resume': true"); + migrate(from, uri, "{'resume': true}"); g_free(uri); /* Restore the postcopy bandwidth to unlimited */ @@ -684,7 +688,7 @@ static void test_baddest(void) if (test_migrate_start(&from, &to, "tcp:0:0", true)) { return; } - migrate(from, "tcp:0:0", NULL); + migrate(from, "tcp:0:0", "{}"); do { status = migrate_query_status(from); g_assert(!strcmp(status, "setup") || !(strcmp(status, "failed"))); @@ -722,7 +726,7 @@ static void test_precopy_unix(void) /* Wait for the first serial output from the source */ wait_for_serial("src_serial"); - migrate(from, uri, NULL); + migrate(from, uri, "{}"); wait_for_migration_pass(from);