From nobody Wed Nov 5 00:14:07 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531394469373163.4166107230244; Thu, 12 Jul 2018 04:21:09 -0700 (PDT) Received: from localhost ([::1]:58696 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fdZei-00054l-AG for importer@patchew.org; Thu, 12 Jul 2018 07:21:04 -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+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 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 @@ =20 #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, c= onst char *capability, qobject_unref(rsp); } =20 -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; =20 - cmd =3D g_strdup_printf("{ 'execute': 'migrate'," - " 'arguments': { 'uri': '%s' %s } }", - uri, extra ? extra : ""); - rsp =3D qtest_qmp(who, cmd); - g_free(cmd); + va_start(ap, fmt); + args =3D qdict_from_vjsonf_nofail(fmt, ap); + va_end(ap); + + g_assert(!qdict_haskey(args, "uri")); + qdict_put_str(args, "uri", uri); + + rsp =3D 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_p= tr, /* Wait for the first serial output from the source */ wait_for_serial("src_serial"); =20 - migrate(from, uri, NULL); + migrate(from, uri, "{}"); g_free(uri); =20 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); =20 /* 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 =3D 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"); =20 - migrate(from, uri, NULL); + migrate(from, uri, "{}"); =20 wait_for_migration_pass(from); =20 --=20 2.17.1