From nobody Wed Nov 5 00:31:17 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500645487209553.1190534146368; Fri, 21 Jul 2017 06:58:07 -0700 (PDT) Received: from localhost ([::1]:43352 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYYRQ-00030s-MF for importer@patchew.org; Fri, 21 Jul 2017 09:58:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48320) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYYN2-0007fy-Tc for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYYMz-00044e-OV for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49124) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYYMz-000446-Hq for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:29 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 77E1B7EA87 for ; Fri, 21 Jul 2017 13:53:28 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-60.ams2.redhat.com [10.36.116.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1968217160; Fri, 21 Jul 2017 13:53:28 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 74D331138647; Fri, 21 Jul 2017 15:53:26 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 77E1B7EA87 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 77E1B7EA87 From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 21 Jul 2017 15:53:18 +0200 Message-Id: <1500645206-13559-2-git-send-email-armbru@redhat.com> In-Reply-To: <1500645206-13559-1-git-send-email-armbru@redhat.com> References: <1500645206-13559-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 21 Jul 2017 13:53:28 +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 1/9] qtest: Avoid passing raw strings through hmp() 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: , 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" From: Eric Blake The next patch will add __attribute__((__format__)) to hmp(), which in turn causes gcc to warn about non-literal format strings. Rather than risk an arbitrary string containing % being mis-handled, always pass variable strings along with a %s format. It also makes it easier to prove correctness locally, rather than auditing all the source strings. Signed-off-by: Eric Blake Reviewed-by: Markus Armbruster Message-Id: <20170720214008.28494-4-eblake@redhat.com> Signed-off-by: Markus Armbruster Reviewed-by: Stefan Hajnoczi --- tests/test-hmp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-hmp.c b/tests/test-hmp.c index d77b3c8..0af0664 100644 --- a/tests/test-hmp.c +++ b/tests/test-hmp.c @@ -80,7 +80,7 @@ static void test_commands(void) if (verbose) { fprintf(stderr, "\t%s\n", hmp_cmds[i]); } - response =3D hmp(hmp_cmds[i]); + response =3D hmp("%s", hmp_cmds[i]); g_free(response); } =20 @@ -103,7 +103,7 @@ static void test_info_commands(void) if (verbose) { fprintf(stderr, "\t%s\n", info); } - resp =3D hmp(info); + resp =3D hmp("%s", info); g_free(resp); /* And move forward to the next line */ info =3D strchr(endp + 1, '\n'); --=20 2.7.5 From nobody Wed Nov 5 00:31:17 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500645474942498.37160713247465; Fri, 21 Jul 2017 06:57:54 -0700 (PDT) Received: from localhost ([::1]:43351 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYYRE-0002tz-H1 for importer@patchew.org; Fri, 21 Jul 2017 09:57:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48317) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYYN2-0007fv-TJ for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYYMz-00044q-UI for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37124) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYYMz-000448-LA for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:29 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 766E1A0CD8 for ; Fri, 21 Jul 2017 13:53:28 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-60.ams2.redhat.com [10.36.116.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 19DA08BE20; Fri, 21 Jul 2017 13:53:28 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 81D701138648; Fri, 21 Jul 2017 15:53:26 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 766E1A0CD8 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 766E1A0CD8 From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 21 Jul 2017 15:53:19 +0200 Message-Id: <1500645206-13559-3-git-send-email-armbru@redhat.com> In-Reply-To: <1500645206-13559-1-git-send-email-armbru@redhat.com> References: <1500645206-13559-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 21 Jul 2017 13:53:28 +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 2/9] qtest: Document calling conventions 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: , 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" From: Eric Blake We have two flavors of vararg usage in qtest; make it clear that qmp() has different semantics than hmp(), and let the compiler enforce that hmp() is used correctly. However, qmp() (and friends) only accept a subset of printf flags look-alikes (namely, those that our JSON parser understands), and what is worse, qmp("true") (the JSON keyword 'true') is different from qmp("%s", "true") (the JSON string '"true"'), so marking those as printf-like would produce more harm from bogus warnings than it helps (we may have made a mistake in previously marking qobject_from_jsonf(), but this patch is not addressing that). Signed-off-by: Eric Blake Message-Id: <20170720214008.28494-5-eblake@redhat.com> Signed-off-by: Markus Armbruster Reviewed-by: Stefan Hajnoczi --- tests/libqtest.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/libqtest.h b/tests/libqtest.h index 38bc1e9..ae57282 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -50,7 +50,8 @@ void qtest_quit(QTestState *s); /** * qtest_qmp_discard_response: * @s: #QTestState instance to operate on. - * @fmt...: QMP message to send to qemu + * @fmt...: QMP message to send to qemu; formats arguments through + * json-lexer.c (only understands '%((l|ll|I64)?d|[ipsf])'). * * Sends a QMP message to QEMU and consumes the response. */ @@ -59,7 +60,8 @@ void qtest_qmp_discard_response(QTestState *s, const char= *fmt, ...); /** * qtest_qmp: * @s: #QTestState instance to operate on. - * @fmt...: QMP message to send to qemu + * @fmt...: QMP message to send to qemu; formats arguments through + * json-lexer.c (only understands '%((l|ll|I64)?d|[ipsf])'). * * Sends a QMP message to QEMU and returns the response. */ @@ -68,7 +70,8 @@ QDict *qtest_qmp(QTestState *s, const char *fmt, ...); /** * qtest_async_qmp: * @s: #QTestState instance to operate on. - * @fmt...: QMP message to send to qemu + * @fmt...: QMP message to send to qemu; formats arguments through + * json-lexer.c (only understands '%((l|ll|I64)?d|[ipsf])'). * * Sends a QMP message to QEMU and leaves the response in the stream. */ @@ -134,7 +137,7 @@ QDict *qtest_qmp_eventwait_ref(QTestState *s, const cha= r *event); /** * qtest_hmp: * @s: #QTestState instance to operate on. - * @fmt...: HMP command to send to QEMU + * @fmt...: HMP command to send to QEMU, formats arguments like vsprintf(). * * Send HMP command to QEMU via QMP's human-monitor-command. * QMP events are discarded. @@ -535,7 +538,8 @@ static inline void qtest_end(void) =20 /** * qmp: - * @fmt...: QMP message to send to qemu + * @fmt...: QMP message to send to qemu; formats arguments through + * json-lexer.c (only understands '%((l|ll|I64)?d|[ipsf])'). * * Sends a QMP message to QEMU and returns the response. */ @@ -543,7 +547,8 @@ QDict *qmp(const char *fmt, ...); =20 /** * qmp_async: - * @fmt...: QMP message to send to qemu + * @fmt...: QMP message to send to qemu; formats arguments through + * json-lexer.c (only understands '%((l|ll|I64)?d|[ipsf])'). * * Sends a QMP message to QEMU and leaves the response in the stream. */ @@ -551,7 +556,8 @@ void qmp_async(const char *fmt, ...); =20 /** * qmp_discard_response: - * @fmt...: QMP message to send to qemu + * @fmt...: QMP message to send to qemu; formats arguments through + * json-lexer.c (only understands '%((l|ll|I64)?d|[ipsf])'). * * Sends a QMP message to QEMU and consumes the response. */ @@ -592,7 +598,7 @@ static inline QDict *qmp_eventwait_ref(const char *even= t) =20 /** * hmp: - * @fmt...: HMP command to send to QEMU + * @fmt...: HMP command to send to QEMU, formats arguments like vsprintf(). * * Send HMP command to QEMU via QMP's human-monitor-command. * --=20 2.7.5 From nobody Wed Nov 5 00:31:17 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500645745993858.4382661458444; Fri, 21 Jul 2017 07:02:25 -0700 (PDT) Received: from localhost ([::1]:43374 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYYVa-0006wF-LB for importer@patchew.org; Fri, 21 Jul 2017 10:02:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48321) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYYN2-0007g1-Tu for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYYN0-00044x-59 for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41978) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYYMz-00044K-V1 for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:30 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DCA35272BC for ; Fri, 21 Jul 2017 13:53:28 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-60.ams2.redhat.com [10.36.116.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 23C86900AA; Fri, 21 Jul 2017 13:53:28 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 85213113864A; Fri, 21 Jul 2017 15:53:26 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DCA35272BC Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com DCA35272BC From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 21 Jul 2017 15:53:20 +0200 Message-Id: <1500645206-13559-4-git-send-email-armbru@redhat.com> In-Reply-To: <1500645206-13559-1-git-send-email-armbru@redhat.com> References: <1500645206-13559-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 21 Jul 2017 13:53:29 +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 3/9] tests: Pass literal format strings directly to qmp_FOO() 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: , 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" The qmp_FOO() take a printf-like format string. In a few places, we assign a string literal to a variable and pass that instead of simply passing the literal. Clean that up. Bonus: gets rid of non-literal format strings. A step towards compile-time format string checking without triggering -Wformat-nonliteral. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- tests/ahci-test.c | 4 +--- tests/ide-test.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/ahci-test.c b/tests/ahci-test.c index 999121b..97622e0 100644 --- a/tests/ahci-test.c +++ b/tests/ahci-test.c @@ -1350,7 +1350,6 @@ static void test_flush_migrate(void) AHCIQState *src, *dst; AHCICommand *cmd; uint8_t px; - const char *s; char *uri =3D g_strdup_printf("unix:%s", mig_socket); =20 prepare_blkdebug_script(debug_path, "flush_to_disk"); @@ -1386,8 +1385,7 @@ static void test_flush_migrate(void) ahci_migrate(src, dst, uri); =20 /* Complete the command */ - s =3D "{'execute':'cont' }"; - qmp_async(s); + qmp_async("{'execute':'cont' }"); qmp_eventwait("RESUME"); ahci_command_wait(dst, cmd); ahci_command_verify(dst, cmd); diff --git a/tests/ide-test.c b/tests/ide-test.c index bfd79dd..ea2657d 100644 --- a/tests/ide-test.c +++ b/tests/ide-test.c @@ -624,7 +624,6 @@ static void test_retry_flush(const char *machine) QPCIDevice *dev; QPCIBar bmdma_bar, ide_bar; uint8_t data; - const char *s; =20 prepare_blkdebug_script(debug_path, "flush_to_disk"); =20 @@ -652,8 +651,7 @@ static void test_retry_flush(const char *machine) qmp_eventwait("STOP"); =20 /* Complete the command */ - s =3D "{'execute':'cont' }"; - qmp_discard_response(s); + qmp_discard_response("{'execute':'cont' }"); =20 /* Check registers */ data =3D qpci_io_readb(dev, ide_bar, reg_device); --=20 2.7.5 From nobody Wed Nov 5 00:31:17 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500645718934739.9214588364448; Fri, 21 Jul 2017 07:01:58 -0700 (PDT) Received: from localhost ([::1]:43372 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYYV7-0006ZG-7H for importer@patchew.org; Fri, 21 Jul 2017 10:01:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48384) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYYN4-0007jp-E2 for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYYN2-00046u-2H for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33676) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYYN1-00045p-Ok for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:31 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A5E3D883B4 for ; Fri, 21 Jul 2017 13:53:30 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-60.ams2.redhat.com [10.36.116.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C3F874440; Fri, 21 Jul 2017 13:53:28 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 8E63D113864C; Fri, 21 Jul 2017 15:53:26 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A5E3D883B4 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A5E3D883B4 From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 21 Jul 2017 15:53:21 +0200 Message-Id: <1500645206-13559-5-git-send-email-armbru@redhat.com> In-Reply-To: <1500645206-13559-1-git-send-email-armbru@redhat.com> References: <1500645206-13559-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 21 Jul 2017 13:53:30 +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 4/9] tests: Clean up string interpolation into QMP input (simple cases) 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: , 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" When you build QMP input manually like this cmd =3D g_strdup_printf("{ 'execute': 'migrate'," "'arguments': { 'uri': '%s' } }", uri); rsp =3D qmp(cmd); g_free(cmd); you're responsible for escaping the interpolated values for JSON. Not done here, and therefore works only for sufficiently nice @uri. For instance, if @uri contained a single "'", qobject_from_jsonv() would fail, qmp_fd_sendv() would misinterpret the failure as empty input and do nothing, and the test would hang waiting for a response that never comes. Leaving interpolation into JSON to qmp() is more robust: rsp =3D qmp("{ 'execute': 'migrate', 'arguments': { 'uri': %s } }", uri= ); It's also more concise. Clean up the simple cases where we interpolate exactly a JSON value. Bonus: gets rid of non-literal format strings. A step towards compile-time format string checking without triggering -Wformat-nonliteral. Signed-off-by: Markus Armbruster --- tests/libqos/libqos.c | 16 +---- tests/libqos/pci-pc.c | 9 +-- tests/postcopy-test.c | 8 +-- tests/test-qga.c | 160 +++++++++++++++++++++-----------------------= ---- tests/vhost-user-test.c | 6 +- 5 files changed, 77 insertions(+), 122 deletions(-) diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c index 6226546..42c5315 100644 --- a/tests/libqos/libqos.c +++ b/tests/libqos/libqos.c @@ -86,20 +86,12 @@ void set_context(QOSState *s) =20 static QDict *qmp_execute(const char *command) { - char *fmt; - QDict *rsp; - - fmt =3D g_strdup_printf("{ 'execute': '%s' }", command); - rsp =3D qmp(fmt); - g_free(fmt); - - return rsp; + return qmp("{ 'execute': %s }", command); } =20 void migrate(QOSState *from, QOSState *to, const char *uri) { const char *st; - char *s; QDict *rsp, *sub; bool running; =20 @@ -114,11 +106,7 @@ void migrate(QOSState *from, QOSState *to, const char = *uri) QDECREF(rsp); =20 /* Issue the migrate command. */ - s =3D g_strdup_printf("{ 'execute': 'migrate'," - "'arguments': { 'uri': '%s' } }", - uri); - rsp =3D qmp(s); - g_free(s); + rsp =3D qmp("{ 'execute': 'migrate', 'arguments': { 'uri': %s } }", ur= i); g_assert(qdict_haskey(rsp, "return")); QDECREF(rsp); =20 diff --git a/tests/libqos/pci-pc.c b/tests/libqos/pci-pc.c index ded1c54..d40aa9d 100644 --- a/tests/libqos/pci-pc.c +++ b/tests/libqos/pci-pc.c @@ -159,14 +159,9 @@ void qpci_free_pc(QPCIBus *bus) void qpci_unplug_acpi_device_test(const char *id, uint8_t slot) { QDict *response; - char *cmd; =20 - cmd =3D g_strdup_printf("{'execute': 'device_del'," - " 'arguments': {" - " 'id': '%s'" - "}}", id); - response =3D qmp(cmd); - g_free(cmd); + response =3D qmp("{'execute': 'device_del', 'arguments': {'id': %s}}", + id); g_assert(response); g_assert(!qdict_haskey(response, "error")); QDECREF(response); diff --git a/tests/postcopy-test.c b/tests/postcopy-test.c index 8142f2a..e2ead87 100644 --- a/tests/postcopy-test.c +++ b/tests/postcopy-test.c @@ -358,7 +358,7 @@ static void test_migrate(void) char *uri =3D g_strdup_printf("unix:%s/migsocket", tmpfs); QTestState *global =3D global_qtest, *from, *to; unsigned char dest_byte_a, dest_byte_b, dest_byte_c, dest_byte_d; - gchar *cmd, *cmd_src, *cmd_dst; + gchar *cmd_src, *cmd_dst; QDict *rsp; =20 char *bootpath =3D g_strdup_printf("%s/bootsect", tmpfs); @@ -445,11 +445,7 @@ static void test_migrate(void) /* Wait for the first serial output from the source */ wait_for_serial("src_serial"); =20 - cmd =3D g_strdup_printf("{ 'execute': 'migrate'," - "'arguments': { 'uri': '%s' } }", - uri); - rsp =3D qmp(cmd); - g_free(cmd); + rsp =3D qmp("{ 'execute': 'migrate', 'arguments': { 'uri': %s } }", ur= i); g_assert(qdict_haskey(rsp, "return")); QDECREF(rsp); =20 diff --git a/tests/test-qga.c b/tests/test-qga.c index 06783e7..91a7b6e 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -144,12 +144,11 @@ static void test_qga_sync_delimited(gconstpointer fix) guint32 v, r =3D g_random_int(); unsigned char c; QDict *ret; - gchar *cmd; =20 - cmd =3D g_strdup_printf("\xff{'execute': 'guest-sync-delimited'," - " 'arguments': {'id': %u } }", r); - qmp_fd_send(fixture->fd, cmd); - g_free(cmd); + qmp_fd_send(fixture->fd, + "\xff{'execute': 'guest-sync-delimited'," + " 'arguments': {'id': %u } }", + r); =20 /* * Read and ignore garbage until resynchronized. @@ -186,7 +185,6 @@ static void test_qga_sync(gconstpointer fix) const TestFixture *fixture =3D fix; guint32 v, r =3D g_random_int(); QDict *ret; - gchar *cmd; =20 /* * TODO guest-sync is inherently limited: we cannot distinguish @@ -199,10 +197,9 @@ static void test_qga_sync(gconstpointer fix) * invalid JSON. Testing of '\xff' handling is done in * guest-sync-delimited instead. */ - cmd =3D g_strdup_printf("{'execute': 'guest-sync'," - " 'arguments': {'id': %u } }", r); - ret =3D qmp_fd(fixture->fd, cmd); - g_free(cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-sync', 'arguments': {'id': %u } }", + r); =20 g_assert_nonnull(ret); qmp_assert_no_error(ret); @@ -393,7 +390,7 @@ static void test_qga_file_ops(gconstpointer fix) const TestFixture *fixture =3D fix; const unsigned char helloworld[] =3D "Hello World!\n"; const char *b64; - gchar *cmd, *path, *enc; + gchar *path, *enc; unsigned char *dec; QDict *ret, *val; int64_t id, eof; @@ -411,10 +408,10 @@ static void test_qga_file_ops(gconstpointer fix) =20 enc =3D g_base64_encode(helloworld, sizeof(helloworld)); /* write */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-write'," - " 'arguments': { 'handle': %" PRId64 "," - " 'buf-b64': '%s' } }", id, enc); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-write'," + " 'arguments': { 'handle': %" PRId64 ", 'buf-b64': %s } }= ", + id, enc); g_assert_nonnull(ret); qmp_assert_no_error(ret); =20 @@ -424,23 +421,20 @@ static void test_qga_file_ops(gconstpointer fix) g_assert_cmpint(count, =3D=3D, sizeof(helloworld)); g_assert_cmpint(eof, =3D=3D, 0); QDECREF(ret); - g_free(cmd); =20 /* flush */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-flush'," - " 'arguments': {'handle': %" PRId64 "} }", - id); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-flush'," + " 'arguments': {'handle': %" PRId64 "} }", + id); QDECREF(ret); - g_free(cmd); =20 /* close */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-close'," - " 'arguments': {'handle': %" PRId64 "} }", - id); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-close'," + " 'arguments': {'handle': %" PRId64 "} }", + id); QDECREF(ret); - g_free(cmd); =20 /* check content */ path =3D g_build_filename(fixture->test_dir, "foo", NULL); @@ -462,10 +456,10 @@ static void test_qga_file_ops(gconstpointer fix) QDECREF(ret); =20 /* read */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-read'," - " 'arguments': { 'handle': %" PRId64 "} }", - id); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-read'," + " 'arguments': { 'handle': %" PRId64 "} }", + id); val =3D qdict_get_qdict(ret, "return"); count =3D qdict_get_int(val, "count"); eof =3D qdict_get_bool(val, "eof"); @@ -475,14 +469,13 @@ static void test_qga_file_ops(gconstpointer fix) g_assert_cmpstr(b64, =3D=3D, enc); =20 QDECREF(ret); - g_free(cmd); g_free(enc); =20 /* read eof */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-read'," - " 'arguments': { 'handle': %" PRId64 "} }", - id); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-read'," + " 'arguments': { 'handle': %" PRId64 "} }", + id); val =3D qdict_get_qdict(ret, "return"); count =3D qdict_get_int(val, "count"); eof =3D qdict_get_bool(val, "eof"); @@ -491,14 +484,13 @@ static void test_qga_file_ops(gconstpointer fix) g_assert(eof); g_assert_cmpstr(b64, =3D=3D, ""); QDECREF(ret); - g_free(cmd); =20 /* seek */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-seek'," - " 'arguments': { 'handle': %" PRId64 ", " - " 'offset': %d, 'whence': '%s' } }", - id, 6, "set"); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-seek'," + " 'arguments': { 'handle': %" PRId64 ", " + " 'offset': %d, 'whence': %s } }", + id, 6, "set"); qmp_assert_no_error(ret); val =3D qdict_get_qdict(ret, "return"); count =3D qdict_get_int(val, "position"); @@ -506,13 +498,12 @@ static void test_qga_file_ops(gconstpointer fix) g_assert_cmpint(count, =3D=3D, 6); g_assert(!eof); QDECREF(ret); - g_free(cmd); =20 /* partial read */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-read'," - " 'arguments': { 'handle': %" PRId64 "} }", - id); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-read'," + " 'arguments': { 'handle': %" PRId64 "} }", + id); val =3D qdict_get_qdict(ret, "return"); count =3D qdict_get_int(val, "count"); eof =3D qdict_get_bool(val, "eof"); @@ -525,15 +516,13 @@ static void test_qga_file_ops(gconstpointer fix) g_free(dec); =20 QDECREF(ret); - g_free(cmd); =20 /* close */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-close'," - " 'arguments': {'handle': %" PRId64 "} }", - id); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-close'," + " 'arguments': {'handle': %" PRId64 "} }", + id); QDECREF(ret); - g_free(cmd); } =20 static void test_qga_file_write_read(gconstpointer fix) @@ -541,7 +530,7 @@ static void test_qga_file_write_read(gconstpointer fix) const TestFixture *fixture =3D fix; const unsigned char helloworld[] =3D "Hello World!\n"; const char *b64; - gchar *cmd, *enc; + gchar *enc; QDict *ret, *val; int64_t id, eof; gsize count; @@ -556,10 +545,10 @@ static void test_qga_file_write_read(gconstpointer fi= x) =20 enc =3D g_base64_encode(helloworld, sizeof(helloworld)); /* write */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-write'," - " 'arguments': { 'handle': %" PRId64 "," - " 'buf-b64': '%s' } }", id, enc); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-write'," + " 'arguments': { 'handle': %" PRId64 "," + " 'buf-b64': %s } }", id, enc); g_assert_nonnull(ret); qmp_assert_no_error(ret); =20 @@ -569,13 +558,12 @@ static void test_qga_file_write_read(gconstpointer fi= x) g_assert_cmpint(count, =3D=3D, sizeof(helloworld)); g_assert_cmpint(eof, =3D=3D, 0); QDECREF(ret); - g_free(cmd); =20 /* read (check implicit flush) */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-read'," - " 'arguments': { 'handle': %" PRId64 "} }", - id); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-read'," + " 'arguments': { 'handle': %" PRId64 "} }", + id); val =3D qdict_get_qdict(ret, "return"); count =3D qdict_get_int(val, "count"); eof =3D qdict_get_bool(val, "eof"); @@ -584,14 +572,13 @@ static void test_qga_file_write_read(gconstpointer fi= x) g_assert(eof); g_assert_cmpstr(b64, =3D=3D, ""); QDECREF(ret); - g_free(cmd); =20 /* seek to 0 */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-seek'," - " 'arguments': { 'handle': %" PRId64 ", " - " 'offset': %d, 'whence': '%s' } }", - id, 0, "set"); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-seek'," + " 'arguments': { 'handle': %" PRId64 ", " + " 'offset': %d, 'whence': %s } }", + id, 0, "set"); qmp_assert_no_error(ret); val =3D qdict_get_qdict(ret, "return"); count =3D qdict_get_int(val, "position"); @@ -599,13 +586,12 @@ static void test_qga_file_write_read(gconstpointer fi= x) g_assert_cmpint(count, =3D=3D, 0); g_assert(!eof); QDECREF(ret); - g_free(cmd); =20 /* read */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-read'," - " 'arguments': { 'handle': %" PRId64 "} }", - id); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-read'," + " 'arguments': { 'handle': %" PRId64 "} }", + id); val =3D qdict_get_qdict(ret, "return"); count =3D qdict_get_int(val, "count"); eof =3D qdict_get_bool(val, "eof"); @@ -614,16 +600,14 @@ static void test_qga_file_write_read(gconstpointer fi= x) g_assert(eof); g_assert_cmpstr(b64, =3D=3D, enc); QDECREF(ret); - g_free(cmd); g_free(enc); =20 /* close */ - cmd =3D g_strdup_printf("{'execute': 'guest-file-close'," - " 'arguments': {'handle': %" PRId64 "} }", - id); - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-file-close'," + " 'arguments': {'handle': %" PRId64 "} }", + id); QDECREF(ret); - g_free(cmd); } =20 static void test_qga_get_time(gconstpointer fix) @@ -647,7 +631,6 @@ static void test_qga_set_time(gconstpointer fix) const TestFixture *fixture =3D fix; QDict *ret; int64_t current, time; - gchar *cmd; =20 /* get current time */ ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-get-time'}"); @@ -673,11 +656,10 @@ static void test_qga_set_time(gconstpointer fix) QDECREF(ret); =20 /* set back current time */ - cmd =3D g_strdup_printf("{'execute': 'guest-set-time'," - " 'arguments': { 'time': %" PRId64 " } }", - current + time * 1000); - ret =3D qmp_fd(fixture->fd, cmd); - g_free(cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-set-time'," + " 'arguments': { 'time': %" PRId64 " } }", + current + time * 1000); g_assert_nonnull(ret); qmp_assert_no_error(ret); QDECREF(ret); @@ -864,7 +846,6 @@ static void test_qga_guest_exec(gconstpointer fix) int64_t pid, now, exitcode; gsize len; bool exited; - char *cmd; =20 /* exec 'echo foo bar' */ ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-exec', 'arguments': {" @@ -879,10 +860,10 @@ static void test_qga_guest_exec(gconstpointer fix) =20 /* wait for completion */ now =3D g_get_monotonic_time(); - cmd =3D g_strdup_printf("{'execute': 'guest-exec-status'," - " 'arguments': { 'pid': %" PRId64 " } }", pid); do { - ret =3D qmp_fd(fixture->fd, cmd); + ret =3D qmp_fd(fixture->fd, + "{'execute': 'guest-exec-status'," + " 'arguments': { 'pid': %" PRId64 " } }", pid); g_assert_nonnull(ret); val =3D qdict_get_qdict(ret, "return"); exited =3D qdict_get_bool(val, "exited"); @@ -892,7 +873,6 @@ static void test_qga_guest_exec(gconstpointer fix) } while (!exited && g_get_monotonic_time() < now + 5 * G_TIME_SPAN_SECOND); g_assert(exited); - g_free(cmd); =20 /* check stdout */ exitcode =3D qdict_get_int(val, "exitcode"); diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c index d4da09f..f2a2b6c 100644 --- a/tests/vhost-user-test.c +++ b/tests/vhost-user-test.c @@ -662,11 +662,7 @@ static void test_migrate(void) g_assert(qdict_haskey(rsp, "return")); QDECREF(rsp); =20 - cmd =3D g_strdup_printf("{ 'execute': 'migrate'," - "'arguments': { 'uri': '%s' } }", - uri); - rsp =3D qmp(cmd); - g_free(cmd); + rsp =3D qmp("{ 'execute': 'migrate', 'arguments': { 'uri': %s } }", ur= i); g_assert(qdict_haskey(rsp, "return")); QDECREF(rsp); =20 --=20 2.7.5 From nobody Wed Nov 5 00:31:17 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500645339823279.2285404823713; Fri, 21 Jul 2017 06:55:39 -0700 (PDT) Received: from localhost ([::1]:43339 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYYP3-00011E-Dl for importer@patchew.org; Fri, 21 Jul 2017 09:55:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48318) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYYN2-0007fw-Tt for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYYN1-000460-CE for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37272) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYYN1-00045L-5p for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:31 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 23B778E3D7 for ; Fri, 21 Jul 2017 13:53:30 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-60.ams2.redhat.com [10.36.116.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D2072183C5; Fri, 21 Jul 2017 13:53:29 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 947E4113864D; Fri, 21 Jul 2017 15:53:26 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 23B778E3D7 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 23B778E3D7 From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 21 Jul 2017 15:53:22 +0200 Message-Id: <1500645206-13559-6-git-send-email-armbru@redhat.com> In-Reply-To: <1500645206-13559-1-git-send-email-armbru@redhat.com> References: <1500645206-13559-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 21 Jul 2017 13:53:30 +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 5/9] tests/libqos/usb: Clean up string interpolation into QMP input 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: , 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 previous commit. The case in usb_test_hotplug() slightly more complicated: it interpolates *into* JSON values. Clean it up by building the values separately, so we can again leave interpolation to qmp(). Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- tests/libqos/usb.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/tests/libqos/usb.c b/tests/libqos/usb.c index 0cdfaec..f88d4a6 100644 --- a/tests/libqos/usb.c +++ b/tests/libqos/usb.c @@ -40,18 +40,20 @@ void uhci_port_test(struct qhc *hc, int port, uint16_t = expect) void usb_test_hotplug(const char *hcd_id, const int port, void (*port_check)(void)) { + char id[32]; + char *bus; QDict *response; - char *cmd; =20 - cmd =3D g_strdup_printf("{'execute': 'device_add'," - " 'arguments': {" - " 'driver': 'usb-tablet'," - " 'port': '%d'," - " 'bus': '%s.0'," - " 'id': 'usbdev%d'" - "}}", port, hcd_id, port); - response =3D qmp(cmd); - g_free(cmd); + sprintf(id, "usbdev%d", port); + bus =3D g_strdup_printf("%s.0", hcd_id); + response =3D qmp("{'execute': 'device_add'," + " 'arguments': {" + " 'driver': 'usb-tablet'," + " 'port': %s," + " 'bus': %s," + " 'id': %s" + " }}", id + 6, bus, id); + g_free(bus); g_assert(response); g_assert(!qdict_haskey(response, "error")); QDECREF(response); @@ -60,12 +62,8 @@ void usb_test_hotplug(const char *hcd_id, const int port, port_check(); } =20 - cmd =3D g_strdup_printf("{'execute': 'device_del'," - " 'arguments': {" - " 'id': 'usbdev%d'" - "}}", port); - response =3D qmp(cmd); - g_free(cmd); + response =3D qmp("{'execute': 'device_del', 'arguments': { 'id': %s }}= ", + id); g_assert(response); g_assert(qdict_haskey(response, "event")); g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED")); --=20 2.7.5 From nobody Wed Nov 5 00:31:17 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500645580729184.78567134117316; Fri, 21 Jul 2017 06:59:40 -0700 (PDT) Received: from localhost ([::1]:43357 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYYSx-0004Wg-C2 for importer@patchew.org; Fri, 21 Jul 2017 09:59:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48322) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYYN2-0007g2-Tv for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYYN1-00046K-JJ for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39616) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYYN1-00045T-9w for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:31 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3CD0F461FE for ; Fri, 21 Jul 2017 13:53:30 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-60.ams2.redhat.com [10.36.116.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D32238BE24; Fri, 21 Jul 2017 13:53:29 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 9EDF01138650; Fri, 21 Jul 2017 15:53:26 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3CD0F461FE Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3CD0F461FE From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 21 Jul 2017 15:53:23 +0200 Message-Id: <1500645206-13559-7-git-send-email-armbru@redhat.com> In-Reply-To: <1500645206-13559-1-git-send-email-armbru@redhat.com> References: <1500645206-13559-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 21 Jul 2017 13:53:30 +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 6/9] tests/libqos/pci: Clean up string interpolation into QMP input 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: , 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 commit before previous. The case in qpci_plug_device_test() is a bit complicated: it interpolates several JSON object members, not just a value. Clean it up by passing them in as QDict rather than string, so we can leave interpolation to qmp() here and to qobject_from_jsonf() in callers. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- tests/ivshmem-test.c | 10 +++++----- tests/libqos/pci.c | 33 ++++++++++++++++++--------------- tests/libqos/pci.h | 2 +- tests/virtio-blk-test.c | 5 ++++- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/tests/ivshmem-test.c b/tests/ivshmem-test.c index 3776342..38044bb 100644 --- a/tests/ivshmem-test.c +++ b/tests/ivshmem-test.c @@ -14,6 +14,7 @@ #include "libqos/libqos-pc.h" #include "libqos/libqos-spapr.h" #include "libqtest.h" +#include "qapi/qmp/qjson.h" #include "qemu-common.h" =20 #define TMPSHMSIZE (1 << 20) @@ -419,19 +420,18 @@ static void test_ivshmem_server_irq(void) static void test_ivshmem_hotplug(void) { const char *arch =3D qtest_get_arch(); - gchar *opts; + QObject *extra_args =3D qobject_from_jsonf("{ 'shm': '%s', 'size': '1M= ' }", + tmpshm); =20 qtest_start(""); =20 - opts =3D g_strdup_printf("'shm': '%s', 'size': '1M'", tmpshm); - - qpci_plug_device_test("ivshmem", "iv1", PCI_SLOT_HP, opts); + qpci_plug_device_test("ivshmem", "iv1", PCI_SLOT_HP, + qobject_to_qdict(extra_args)); if (strcmp(arch, "ppc64") !=3D 0) { qpci_unplug_acpi_device_test("iv1", PCI_SLOT_HP); } =20 qtest_end(); - g_free(opts); } =20 static void test_ivshmem_memdev(void) diff --git a/tests/libqos/pci.c b/tests/libqos/pci.c index 2dcdead..4068305 100644 --- a/tests/libqos/pci.c +++ b/tests/libqos/pci.c @@ -14,6 +14,7 @@ #include "libqos/pci.h" =20 #include "hw/pci/pci_regs.h" +#include "qapi/qmp/qjson.h" #include "qemu/host-utils.h" =20 void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id, @@ -392,23 +393,25 @@ QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t a= ddr) } =20 void qpci_plug_device_test(const char *driver, const char *id, - uint8_t slot, const char *opts) + uint8_t slot, QDict *extra_args) { - QDict *response; - char *cmd; - - cmd =3D g_strdup_printf("{'execute': 'device_add'," - " 'arguments': {" - " 'driver': '%s'," - " 'addr': '%d'," - " %s%s" - " 'id': '%s'" - "}}", driver, slot, - opts ? opts : "", opts ? "," : "", - id); - response =3D qmp(cmd); - g_free(cmd); + char addr[8]; + QDict *args, *response; + + sprintf(addr, "%d", slot); + args =3D qobject_to_qdict( + qobject_from_jsonf("{ 'driver': %s, 'addr': %s, 'id': %s}", + driver, addr, id)); + + if (extra_args) { + qdict_join(args, extra_args, true); + QDECREF(extra_args); + } + + response =3D qmp("{'execute': 'device_add', 'arguments': %p }", args); + g_assert(response); g_assert(!qdict_haskey(response, "error")); + QDECREF(args); QDECREF(response); } diff --git a/tests/libqos/pci.h b/tests/libqos/pci.h index ed48061..c981061 100644 --- a/tests/libqos/pci.h +++ b/tests/libqos/pci.h @@ -109,6 +109,6 @@ void qpci_iounmap(QPCIDevice *dev, QPCIBar addr); QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr); =20 void qpci_plug_device_test(const char *driver, const char *id, - uint8_t slot, const char *opts); + uint8_t slot, QDict *extra_args); void qpci_unplug_acpi_device_test(const char *id, uint8_t slot); #endif diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index 0576cb1..64a48f4 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -16,6 +16,7 @@ #include "libqos/virtio-pci.h" #include "libqos/virtio-mmio.h" #include "libqos/malloc-generic.h" +#include "qapi/qmp/qjson.h" #include "qemu/bswap.h" #include "standard-headers/linux/virtio_ids.h" #include "standard-headers/linux/virtio_config.h" @@ -658,12 +659,13 @@ static void pci_hotplug(void) QVirtioPCIDevice *dev; QOSState *qs; const char *arch =3D qtest_get_arch(); + QObject *extra_args =3D qobject_from_jsonf("{ 'drive': 'drive1' }"); =20 qs =3D pci_test_start(); =20 /* plug secondary disk */ qpci_plug_device_test("virtio-blk-pci", "drv1", PCI_SLOT_HP, - "'drive': 'drive1'"); + qobject_to_qdict(extra_args)); =20 dev =3D virtio_blk_pci_init(qs->pcibus, PCI_SLOT_HP); g_assert(dev); @@ -674,6 +676,7 @@ static void pci_hotplug(void) if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0) { qpci_unplug_acpi_device_test("drv1", PCI_SLOT_HP); } + qtest_shutdown(qs); } =20 --=20 2.7.5 From nobody Wed Nov 5 00:31:17 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500645600386457.062123290041; Fri, 21 Jul 2017 07:00:00 -0700 (PDT) Received: from localhost ([::1]:43358 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYYTH-0004n9-3e for importer@patchew.org; Fri, 21 Jul 2017 09:59:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48335) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYYN3-0007gW-B7 for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYYN1-00046T-NH for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38136) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYYN1-00045W-F1 for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:31 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 59476C07046F for ; Fri, 21 Jul 2017 13:53:30 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-60.ams2.redhat.com [10.36.116.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D1D448885E; Fri, 21 Jul 2017 13:53:29 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id A5AF91138651; Fri, 21 Jul 2017 15:53:26 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 59476C07046F Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 59476C07046F From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 21 Jul 2017 15:53:24 +0200 Message-Id: <1500645206-13559-8-git-send-email-armbru@redhat.com> In-Reply-To: <1500645206-13559-1-git-send-email-armbru@redhat.com> References: <1500645206-13559-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 21 Jul 2017 13:53:30 +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 7/9] tests: Clean up wait for event 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: , 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" We still use hacks like qmp("") to wait for an event, even though we have qmp_eventwait() since commit 8fe941f, and qmp_eventwait_ref() since commit 7ffe312. Both commits neglected to convert all the existing hacks. Make up what they missed. Bonus: gets rid of empty format strings. A step towards compile-time format string checking without triggering -Wformat-zero-length. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- tests/boot-order-test.c | 2 +- tests/libqos/pci-pc.c | 6 +----- tests/tco-test.c | 3 +-- tests/usb-hcd-uhci-test.c | 6 +----- tests/usb-hcd-xhci-test.c | 12 ++---------- tests/wdt_ib700-test.c | 35 ++++++++++------------------------- 6 files changed, 16 insertions(+), 48 deletions(-) diff --git a/tests/boot-order-test.c b/tests/boot-order-test.c index fc1e794..9d51683 100644 --- a/tests/boot-order-test.c +++ b/tests/boot-order-test.c @@ -43,7 +43,7 @@ static void test_a_boot_order(const char *machine, * system_reset only requests reset. We get a RESET event after * the actual reset completes. Need to wait for that. */ - qmp_discard_response(""); /* HACK: wait for event */ + qmp_eventwait("RESET"); actual =3D read_boot_order(); g_assert_cmphex(actual, =3D=3D, expected_reboot); qtest_quit(global_qtest); diff --git a/tests/libqos/pci-pc.c b/tests/libqos/pci-pc.c index d40aa9d..e4be809 100644 --- a/tests/libqos/pci-pc.c +++ b/tests/libqos/pci-pc.c @@ -168,9 +168,5 @@ void qpci_unplug_acpi_device_test(const char *id, uint8= _t slot) =20 outb(ACPI_PCIHP_ADDR + PCI_EJ_BASE, 1 << slot); =20 - response =3D qmp(""); - g_assert(response); - g_assert(qdict_haskey(response, "event")); - g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED")); - QDECREF(response); + qmp_eventwait("DEVICE_DELETED"); } diff --git a/tests/tco-test.c b/tests/tco-test.c index c4c264e..f2ed6ed 100644 --- a/tests/tco-test.c +++ b/tests/tco-test.c @@ -237,9 +237,8 @@ static void test_tco_max_timeout(void) =20 static QDict *get_watchdog_action(void) { - QDict *ev =3D qmp(""); + QDict *ev =3D qmp_eventwait_ref("WATCHDOG"); QDict *data; - g_assert(!strcmp(qdict_get_str(ev, "event"), "WATCHDOG")); =20 data =3D qdict_get_qdict(ev, "data"); QINCREF(data); diff --git a/tests/usb-hcd-uhci-test.c b/tests/usb-hcd-uhci-test.c index 5b500fe..0fb7f8d 100644 --- a/tests/usb-hcd-uhci-test.c +++ b/tests/usb-hcd-uhci-test.c @@ -68,11 +68,7 @@ static void test_usb_storage_hotplug(void) g_assert(!qdict_haskey(response, "error")); QDECREF(response); =20 - response =3D qmp(""); - g_assert(response); - g_assert(qdict_haskey(response, "event")); - g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED")); - QDECREF(response); + qmp_eventwait("DEVICE_DELETED"); } =20 int main(int argc, char **argv) diff --git a/tests/usb-hcd-xhci-test.c b/tests/usb-hcd-xhci-test.c index 031764d..c05a339 100644 --- a/tests/usb-hcd-xhci-test.c +++ b/tests/usb-hcd-xhci-test.c @@ -57,11 +57,7 @@ static void test_usb_uas_hotplug(void) g_assert(!qdict_haskey(response, "error")); QDECREF(response); =20 - response =3D qmp(""); - g_assert(qdict_haskey(response, "event")); - g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED")); - QDECREF(response); - + qmp_eventwait("DEVICE_DELETED"); =20 response =3D qmp("{'execute': 'device_del'," " 'arguments': {" @@ -71,11 +67,7 @@ static void test_usb_uas_hotplug(void) g_assert(!qdict_haskey(response, "error")); QDECREF(response); =20 - response =3D qmp(""); - g_assert(response); - g_assert(qdict_haskey(response, "event")); - g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED")); - QDECREF(response); + qmp_eventwait("DEVICE_DELETED"); } =20 int main(int argc, char **argv) diff --git a/tests/wdt_ib700-test.c b/tests/wdt_ib700-test.c index 49f4f0c..4fc8eea 100644 --- a/tests/wdt_ib700-test.c +++ b/tests/wdt_ib700-test.c @@ -18,26 +18,10 @@ static void qmp_check_no_event(void) QDECREF(resp); } =20 -static QDict *qmp_get_event(const char *name) -{ - QDict *event =3D qmp(""); - QDict *data; - g_assert(qdict_haskey(event, "event")); - g_assert(!strcmp(qdict_get_str(event, "event"), name)); - - if (qdict_haskey(event, "data")) { - data =3D qdict_get_qdict(event, "data"); - QINCREF(data); - } else { - data =3D NULL; - } - - QDECREF(event); - return data; -} - static QDict *ib700_program_and_wait(QTestState *s) { + QDict *event, *data; + clock_step(NANOSECONDS_PER_SECOND * 40); qmp_check_no_event(); =20 @@ -61,7 +45,11 @@ static QDict *ib700_program_and_wait(QTestState *s) clock_step(3 * NANOSECONDS_PER_SECOND); qmp_check_no_event(); clock_step(2 * NANOSECONDS_PER_SECOND); - return qmp_get_event("WATCHDOG"); + event =3D qmp_eventwait_ref("WATCHDOG"); + data =3D qdict_get_qdict(event, "data"); + QINCREF(data); + QDECREF(event); + return data; } =20 =20 @@ -73,8 +61,7 @@ static void ib700_pause(void) d =3D ib700_program_and_wait(s); g_assert(!strcmp(qdict_get_str(d, "action"), "pause")); QDECREF(d); - d =3D qmp_get_event("STOP"); - QDECREF(d); + qmp_eventwait("STOP"); qtest_end(); } =20 @@ -86,8 +73,7 @@ static void ib700_reset(void) d =3D ib700_program_and_wait(s); g_assert(!strcmp(qdict_get_str(d, "action"), "reset")); QDECREF(d); - d =3D qmp_get_event("RESET"); - QDECREF(d); + qmp_eventwait("RESET"); qtest_end(); } =20 @@ -99,8 +85,7 @@ static void ib700_shutdown(void) d =3D ib700_program_and_wait(s); g_assert(!strcmp(qdict_get_str(d, "action"), "reset")); QDECREF(d); - d =3D qmp_get_event("SHUTDOWN"); - QDECREF(d); + qmp_eventwait("SHUTDOWN"); qtest_end(); } =20 --=20 2.7.5 From nobody Wed Nov 5 00:31:17 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500645329217510.1868299138798; Fri, 21 Jul 2017 06:55:29 -0700 (PDT) Received: from localhost ([::1]:43333 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYYOs-0000lL-G7 for importer@patchew.org; Fri, 21 Jul 2017 09:55:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48319) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYYN2-0007fx-Te for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYYN1-000466-Cr for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38078) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYYN1-00045O-71 for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:31 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 33D251E2ED for ; Fri, 21 Jul 2017 13:53:30 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-60.ams2.redhat.com [10.36.116.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D3D1188D62; Fri, 21 Jul 2017 13:53:29 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id AFD741138657; Fri, 21 Jul 2017 15:53:26 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 33D251E2ED Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 33D251E2ED From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 21 Jul 2017 15:53:25 +0200 Message-Id: <1500645206-13559-9-git-send-email-armbru@redhat.com> In-Reply-To: <1500645206-13559-1-git-send-email-armbru@redhat.com> References: <1500645206-13559-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 21 Jul 2017 13:53:30 +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 8/9] tests/libqtest: Clean up how we read the QMP greeting 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: , 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" qtest_init() still uses the qtest_qmp_discard_response(s, "") hack to receive the greeting, even though we have qtest_qmp_receive() since commit 66e0c7b. Put it to use. Bonus: gets rid of an empty format string. A step towards compile-time format string checking without triggering -Wformat-zero-length. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- tests/libqtest.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index 4a5492a..7e5425d 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -230,9 +230,11 @@ QTestState *qtest_init_without_qmp_handshake(const cha= r *extra_args) QTestState *qtest_init(const char *extra_args) { QTestState *s =3D qtest_init_without_qmp_handshake(extra_args); + QDict *greeting; =20 /* Read the QMP greeting and then do the handshake */ - qtest_qmp_discard_response(s, ""); + greeting =3D qtest_qmp_receive(s); + QDECREF(greeting); qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }"); =20 return s; --=20 2.7.5 From nobody Wed Nov 5 00:31:17 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500645741602641.8544066650468; Fri, 21 Jul 2017 07:02:21 -0700 (PDT) Received: from localhost ([::1]:43373 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYYVS-0006oW-8k for importer@patchew.org; Fri, 21 Jul 2017 10:02:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48353) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYYN3-0007hk-Of for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYYN1-00046l-VC for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39636) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYYN1-00045n-Mj for qemu-devel@nongnu.org; Fri, 21 Jul 2017 09:53:31 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A28B746269 for ; Fri, 21 Jul 2017 13:53:30 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-60.ams2.redhat.com [10.36.116.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3BD76845B8; Fri, 21 Jul 2017 13:53:30 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id B526D113866C; Fri, 21 Jul 2017 15:53:26 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A28B746269 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A28B746269 From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 21 Jul 2017 15:53:26 +0200 Message-Id: <1500645206-13559-10-git-send-email-armbru@redhat.com> In-Reply-To: <1500645206-13559-1-git-send-email-armbru@redhat.com> References: <1500645206-13559-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 21 Jul 2017 13:53:30 +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 9/9] tests/libqtest: Enable compile-time format string checking 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: , 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" qtest_qmp() & friends pass their format string and variable arguments to qobject_from_jsonv(). Unlike qobject_from_jsonv(), they aren't decorated with GCC_FMT_ATTR(). Fix that to get compile-time format string checking. Signed-off-by: Markus Armbruster Reviewed-by: Stefan Hajnoczi --- tests/libqtest.h | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/tests/libqtest.h b/tests/libqtest.h index ae57282..435012d 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -55,7 +55,8 @@ void qtest_quit(QTestState *s); * * Sends a QMP message to QEMU and consumes the response. */ -void qtest_qmp_discard_response(QTestState *s, const char *fmt, ...); +void qtest_qmp_discard_response(QTestState *s, const char *fmt, ...) + GCC_FMT_ATTR(2, 3); =20 /** * qtest_qmp: @@ -65,7 +66,8 @@ void qtest_qmp_discard_response(QTestState *s, const char= *fmt, ...); * * Sends a QMP message to QEMU and returns the response. */ -QDict *qtest_qmp(QTestState *s, const char *fmt, ...); +QDict *qtest_qmp(QTestState *s, const char *fmt, ...) + GCC_FMT_ATTR(2, 3); =20 /** * qtest_async_qmp: @@ -75,7 +77,8 @@ QDict *qtest_qmp(QTestState *s, const char *fmt, ...); * * Sends a QMP message to QEMU and leaves the response in the stream. */ -void qtest_async_qmp(QTestState *s, const char *fmt, ...); +void qtest_async_qmp(QTestState *s, const char *fmt, ...) + GCC_FMT_ATTR(2, 3); =20 /** * qtest_qmpv_discard_response: @@ -85,7 +88,8 @@ void qtest_async_qmp(QTestState *s, const char *fmt, ...); * * Sends a QMP message to QEMU and consumes the response. */ -void qtest_qmpv_discard_response(QTestState *s, const char *fmt, va_list a= p); +void qtest_qmpv_discard_response(QTestState *s, const char *fmt, va_list a= p) + GCC_FMT_ATTR(2, 0); =20 /** * qtest_qmpv: @@ -95,7 +99,8 @@ void qtest_qmpv_discard_response(QTestState *s, const cha= r *fmt, va_list ap); * * Sends a QMP message to QEMU and returns the response. */ -QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap); +QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap) + GCC_FMT_ATTR(2, 0); =20 /** * qtest_async_qmpv: @@ -105,7 +110,8 @@ QDict *qtest_qmpv(QTestState *s, const char *fmt, va_li= st ap); * * Sends a QMP message to QEMU and leaves the response in the stream. */ -void qtest_async_qmpv(QTestState *s, const char *fmt, va_list ap); +void qtest_async_qmpv(QTestState *s, const char *fmt, va_list ap) + GCC_FMT_ATTR(2, 0); =20 /** * qtest_receive: @@ -144,7 +150,8 @@ QDict *qtest_qmp_eventwait_ref(QTestState *s, const cha= r *event); * * Returns: the command's output. The caller should g_free() it. */ -char *qtest_hmp(QTestState *s, const char *fmt, ...); +char *qtest_hmp(QTestState *s, const char *fmt, ...) + GCC_FMT_ATTR(2, 3); =20 /** * qtest_hmpv: @@ -157,7 +164,8 @@ char *qtest_hmp(QTestState *s, const char *fmt, ...); * * Returns: the command's output. The caller should g_free() it. */ -char *qtest_hmpv(QTestState *s, const char *fmt, va_list ap); +char *qtest_hmpv(QTestState *s, const char *fmt, va_list ap) + GCC_FMT_ATTR(2, 0); =20 /** * qtest_get_irq: @@ -543,7 +551,7 @@ static inline void qtest_end(void) * * Sends a QMP message to QEMU and returns the response. */ -QDict *qmp(const char *fmt, ...); +QDict *qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2); =20 /** * qmp_async: @@ -552,7 +560,7 @@ QDict *qmp(const char *fmt, ...); * * Sends a QMP message to QEMU and leaves the response in the stream. */ -void qmp_async(const char *fmt, ...); +void qmp_async(const char *fmt, ...) GCC_FMT_ATTR(1, 2); =20 /** * qmp_discard_response: @@ -561,7 +569,7 @@ void qmp_async(const char *fmt, ...); * * Sends a QMP message to QEMU and consumes the response. */ -void qmp_discard_response(const char *fmt, ...); +void qmp_discard_response(const char *fmt, ...) GCC_FMT_ATTR(1, 2); =20 /** * qmp_receive: @@ -604,7 +612,7 @@ static inline QDict *qmp_eventwait_ref(const char *even= t) * * Returns: the command's output. The caller should g_free() it. */ -char *hmp(const char *fmt, ...); +char *hmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2); =20 /** * get_irq: @@ -920,10 +928,10 @@ static inline int64_t clock_set(int64_t val) } =20 QDict *qmp_fd_receive(int fd); -void qmp_fd_sendv(int fd, const char *fmt, va_list ap); -void qmp_fd_send(int fd, const char *fmt, ...); -QDict *qmp_fdv(int fd, const char *fmt, va_list ap); -QDict *qmp_fd(int fd, const char *fmt, ...); +void qmp_fd_sendv(int fd, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0); +void qmp_fd_send(int fd, const char *fmt, ...) GCC_FMT_ATTR(2, 3); +QDict *qmp_fdv(int fd, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0); +QDict *qmp_fd(int fd, const char *fmt, ...) GCC_FMT_ATTR(2, 3); =20 /** * qtest_cb_for_every_machine: --=20 2.7.5