From nobody Wed Nov 5 13:10:56 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 153440974258523.293687021035907; Thu, 16 Aug 2018 01:55:42 -0700 (PDT) Received: from localhost ([::1]:54322 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqE4D-0007Oa-CL for importer@patchew.org; Thu, 16 Aug 2018 04:55:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50670) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDmo-000183-71 for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmZ-0005Ig-De for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:33 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53674 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 1fqDmQ-0005C0-Ic for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:21 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BA56F40776F4 for ; Thu, 16 Aug 2018 08:37:05 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-56.ams2.redhat.com [10.36.116.56]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6E7CD2156712; Thu, 16 Aug 2018 08:37:05 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 2632011386BF; Thu, 16 Aug 2018 10:37:02 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:36:56 +0200 Message-Id: <20180816083701.3932-21-armbru@redhat.com> In-Reply-To: <20180816083701.3932-1-armbru@redhat.com> References: <20180816083701.3932-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 16 Aug 2018 08:37:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 16 Aug 2018 08:37:05 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 20/25] migration-test: Clean up string interpolation into QMP, part 3 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: RDMRC_1 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)". migration-test.c interpolates strings into JSON in a few places: * migrate_set_parameter() interpolates string parameter @value as a JSON number. Change it to long long. This requires changing migrate_check_parameter() similarly. * migrate_set_capability() interpolates string parameter @value as a JSON boolean. Change it to bool. * deprecated_set_speed() interpolates string parameter @value as a JSON number. Change it to long long. Bonus: gets rid of non-literal format strings. 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 Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-21-armbru@redhat.com> --- tests/migration-test.c | 74 +++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 45 deletions(-) diff --git a/tests/migration-test.c b/tests/migration-test.c index c7f3267fa0..eb58d0a48e 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -318,31 +318,25 @@ static void cleanup(const char *filename) } =20 static void migrate_check_parameter(QTestState *who, const char *parameter, - const char *value) + long long value) { QDict *rsp_return; - char *result; =20 rsp_return =3D wait_command(who, "{ 'execute': 'query-migrate-parameters' }"); - result =3D g_strdup_printf("%" PRId64, - qdict_get_try_int(rsp_return, parameter, -1)= ); - g_assert_cmpstr(result, =3D=3D, value); - g_free(result); + g_assert_cmpint(qdict_get_int(rsp_return, parameter), =3D=3D, value); qobject_unref(rsp_return); } =20 static void migrate_set_parameter(QTestState *who, const char *parameter, - const char *value) + long long value) { QDict *rsp; - gchar *cmd; =20 - cmd =3D g_strdup_printf("{ 'execute': 'migrate-set-parameters'," - "'arguments': { '%s': %s } }", - parameter, value); - rsp =3D qtest_qmp(who, cmd); - g_free(cmd); + rsp =3D qtest_qmp(who, + "{ 'execute': 'migrate-set-parameters'," + "'arguments': { %s: %lld } }", + parameter, value); g_assert(qdict_haskey(rsp, "return")); qobject_unref(rsp); migrate_check_parameter(who, parameter, value); @@ -369,18 +363,16 @@ static void migrate_recover(QTestState *who, const ch= ar *uri) } =20 static void migrate_set_capability(QTestState *who, const char *capability, - const char *value) + bool value) { QDict *rsp; - gchar *cmd; =20 - cmd =3D g_strdup_printf("{ 'execute': 'migrate-set-capabilities'," - "'arguments': { " - "'capabilities': [ { " - "'capability': '%s', 'state': %s } ] } }", - capability, value); - rsp =3D qtest_qmp(who, cmd); - g_free(cmd); + rsp =3D qtest_qmp(who, + "{ 'execute': 'migrate-set-capabilities'," + "'arguments': { " + "'capabilities': [ { " + "'capability': %s, 'state': %i } ] } }", + capability, value); g_assert(qdict_haskey(rsp, "return")); qobject_unref(rsp); } @@ -530,29 +522,21 @@ static void test_migrate_end(QTestState *from, QTestS= tate *to, bool test_dest) static void deprecated_set_downtime(QTestState *who, const double value) { QDict *rsp; - char *expected; - int64_t result_int; =20 rsp =3D qtest_qmp(who, "{ 'execute': 'migrate_set_downtime'," " 'arguments': { 'value': %f } }", value); g_assert(qdict_haskey(rsp, "return")); qobject_unref(rsp); - result_int =3D value * 1000L; - expected =3D g_strdup_printf("%" PRId64, result_int); - migrate_check_parameter(who, "downtime-limit", expected); - g_free(expected); + migrate_check_parameter(who, "downtime-limit", value * 1000); } =20 -static void deprecated_set_speed(QTestState *who, const char *value) +static void deprecated_set_speed(QTestState *who, long long value) { QDict *rsp; - gchar *cmd; =20 - cmd =3D g_strdup_printf("{ 'execute': 'migrate_set_speed'," - "'arguments': { 'value': %s } }", value); - rsp =3D qtest_qmp(who, cmd); - g_free(cmd); + rsp =3D qtest_qmp(who, "{ 'execute': 'migrate_set_speed'," + "'arguments': { 'value': %lld } }", value); g_assert(qdict_haskey(rsp, "return")); qobject_unref(rsp); migrate_check_parameter(who, "max-bandwidth", value); @@ -565,7 +549,7 @@ static void test_deprecated(void) from =3D qtest_start(""); =20 deprecated_set_downtime(from, 0.12345); - deprecated_set_speed(from, "12345"); + deprecated_set_speed(from, 12345); =20 qtest_quit(from); } @@ -581,16 +565,16 @@ static int migrate_postcopy_prepare(QTestState **from= _ptr, return -1; } =20 - migrate_set_capability(from, "postcopy-ram", "true"); - migrate_set_capability(to, "postcopy-ram", "true"); - migrate_set_capability(to, "postcopy-blocktime", "true"); + migrate_set_capability(from, "postcopy-ram", true); + migrate_set_capability(to, "postcopy-ram", true); + migrate_set_capability(to, "postcopy-blocktime", true); =20 /* We want to pick a speed slow enough that the test completes * quickly, but that it doesn't complete precopy even on a slow * machine, so also set the downtime. */ - migrate_set_parameter(from, "max-bandwidth", "100000000"); - migrate_set_parameter(from, "downtime-limit", "1"); + migrate_set_parameter(from, "max-bandwidth", 100000000); + migrate_set_parameter(from, "downtime-limit", 1); =20 /* Wait for the first serial output from the source */ wait_for_serial("src_serial"); @@ -641,7 +625,7 @@ static void test_postcopy_recovery(void) } =20 /* Turn postcopy speed down, 4K/s is slow enough on any machines */ - migrate_set_parameter(from, "max-postcopy-bandwidth", "4096"); + migrate_set_parameter(from, "max-postcopy-bandwidth", 4096); =20 /* Now we start the postcopy */ migrate_postcopy_start(from, to); @@ -682,7 +666,7 @@ static void test_postcopy_recovery(void) g_free(uri); =20 /* Restore the postcopy bandwidth to unlimited */ - migrate_set_parameter(from, "max-postcopy-bandwidth", "0"); + migrate_set_parameter(from, "max-postcopy-bandwidth", 0); =20 migrate_postcopy_complete(from, to); } @@ -728,9 +712,9 @@ static void test_precopy_unix(void) * machine, so also set the downtime. */ /* 1 ms should make it not converge*/ - migrate_set_parameter(from, "downtime-limit", "1"); + migrate_set_parameter(from, "downtime-limit", 1); /* 1GB/s */ - migrate_set_parameter(from, "max-bandwidth", "1000000000"); + migrate_set_parameter(from, "max-bandwidth", 1000000000); =20 /* Wait for the first serial output from the source */ wait_for_serial("src_serial"); @@ -740,7 +724,7 @@ static void test_precopy_unix(void) wait_for_migration_pass(from); =20 /* 300 ms should converge */ - migrate_set_parameter(from, "downtime-limit", "300"); + migrate_set_parameter(from, "downtime-limit", 300); =20 if (!got_stop) { qtest_qmp_eventwait(from, "STOP"); --=20 2.17.1