From patchwork Thu Jul 12 11:12:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 942937 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 41RD3z3Bxrz9s1R for ; Thu, 12 Jul 2018 21:19:43 +1000 (AEST) Received: from localhost ([::1]:58687 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fdZdM-0003ni-4g for incoming@patchwork.ozlabs.org; Thu, 12 Jul 2018 07:19:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47967) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fdZWQ-0007AW-T7 for qemu-devel@nongnu.org; Thu, 12 Jul 2018 07:12:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fdZWM-0006rx-Pl for qemu-devel@nongnu.org; Thu, 12 Jul 2018 07:12:30 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49026 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-0006qu-Ip for qemu-devel@nongnu.org; Thu, 12 Jul 2018 07:12:26 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 363EE40201BF for ; Thu, 12 Jul 2018 11:12:26 +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 8F7FD2026D74; Thu, 12 Jul 2018 11:12:25 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 22A261132CB0; Thu, 12 Jul 2018 13:12:22 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 12 Jul 2018 13:12:20 +0200 Message-Id: <20180712111221.20326-20-armbru@redhat.com> In-Reply-To: <20180712111221.20326-1-armbru@redhat.com> References: <20180712111221.20326-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 12 Jul 2018 11:12:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 12 Jul 2018 11:12:26 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 19/20] 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+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)". 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 --- 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 4a4db88b61..8359e2ff78 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -315,31 +315,25 @@ static void cleanup(const char *filename) } static void migrate_check_parameter(QTestState *who, const char *parameter, - const char *value) + long long value) { QDict *rsp_return; - char *result; rsp_return = wait_command(who, "{ 'execute': 'query-migrate-parameters' }"); - result = g_strdup_printf("%" PRId64, - qdict_get_try_int(rsp_return, parameter, -1)); - g_assert_cmpstr(result, ==, value); - g_free(result); + g_assert_cmpint(qdict_get_int(rsp_return, parameter), ==, value); qobject_unref(rsp_return); } static void migrate_set_parameter(QTestState *who, const char *parameter, - const char *value) + long long value) { QDict *rsp; - gchar *cmd; - cmd = g_strdup_printf("{ 'execute': 'migrate-set-parameters'," - "'arguments': { '%s': %s } }", - parameter, value); - rsp = qtest_qmp(who, cmd); - g_free(cmd); + rsp = 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); @@ -366,18 +360,16 @@ static void migrate_recover(QTestState *who, const char *uri) } static void migrate_set_capability(QTestState *who, const char *capability, - const char *value) + bool value) { QDict *rsp; - gchar *cmd; - cmd = g_strdup_printf("{ 'execute': 'migrate-set-capabilities'," - "'arguments': { " - "'capabilities': [ { " - "'capability': '%s', 'state': %s } ] } }", - capability, value); - rsp = qtest_qmp(who, cmd); - g_free(cmd); + rsp = qtest_qmp(who, + "{ 'execute': 'migrate-set-capabilities'," + "'arguments': { " + "'capabilities': [ { " + "'capability': %s, 'state': %i } ] } }", + capability, value); g_assert(qdict_haskey(rsp, "return")); qobject_unref(rsp); } @@ -521,29 +513,21 @@ static void test_migrate_end(QTestState *from, QTestState *to, bool test_dest) static void deprecated_set_downtime(QTestState *who, const double value) { QDict *rsp; - char *expected; - int64_t result_int; rsp = qtest_qmp(who, "{ 'execute': 'migrate_set_downtime'," " 'arguments': { 'value': %f } }", value); g_assert(qdict_haskey(rsp, "return")); qobject_unref(rsp); - result_int = value * 1000L; - expected = g_strdup_printf("%" PRId64, result_int); - migrate_check_parameter(who, "downtime-limit", expected); - g_free(expected); + migrate_check_parameter(who, "downtime-limit", value * 1000); } -static void deprecated_set_speed(QTestState *who, const char *value) +static void deprecated_set_speed(QTestState *who, long long value) { QDict *rsp; - gchar *cmd; - cmd = g_strdup_printf("{ 'execute': 'migrate_set_speed'," - "'arguments': { 'value': %s } }", value); - rsp = qtest_qmp(who, cmd); - g_free(cmd); + rsp = 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); @@ -556,7 +540,7 @@ static void test_deprecated(void) from = qtest_start(""); deprecated_set_downtime(from, 0.12345); - deprecated_set_speed(from, "12345"); + deprecated_set_speed(from, 12345); qtest_quit(from); } @@ -572,16 +556,16 @@ static int migrate_postcopy_prepare(QTestState **from_ptr, return -1; } - 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); /* 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); /* Wait for the first serial output from the source */ wait_for_serial("src_serial"); @@ -632,7 +616,7 @@ static void test_postcopy_recovery(void) } /* 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); /* Now we start the postcopy */ migrate_postcopy_start(from, to); @@ -673,7 +657,7 @@ static void test_postcopy_recovery(void) g_free(uri); /* Restore the postcopy bandwidth to unlimited */ - migrate_set_parameter(from, "max-postcopy-bandwidth", "0"); + migrate_set_parameter(from, "max-postcopy-bandwidth", 0); migrate_postcopy_complete(from, to); } @@ -719,9 +703,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); /* Wait for the first serial output from the source */ wait_for_serial("src_serial"); @@ -731,7 +715,7 @@ static void test_precopy_unix(void) wait_for_migration_pass(from); /* 300 ms should converge */ - migrate_set_parameter(from, "downtime-limit", "300"); + migrate_set_parameter(from, "downtime-limit", 300); if (!got_stop) { qtest_qmp_eventwait(from, "STOP");