From nobody Sat Feb 7 09:12:01 2026 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 1534408779452203.78305347597302; Thu, 16 Aug 2018 01:39:39 -0700 (PDT) Received: from localhost ([::1]:54229 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDoa-000244-Fi for importer@patchew.org; Thu, 16 Aug 2018 04:39:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50517) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDmT-0000qb-3F for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmH-0005CJ-RS for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:16 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51366 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 1fqDmB-00058s-Tp for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:06 -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 601EA40150E3 for ; Thu, 16 Aug 2018 08:37:03 +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 1E9AD76F3 for ; Thu, 16 Aug 2018 08:37:03 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id D840F1138651; Thu, 16 Aug 2018 10:37:01 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:36:37 +0200 Message-Id: <20180816083701.3932-2-armbru@redhat.com> In-Reply-To: <20180816083701.3932-1-armbru@redhat.com> References: <20180816083701.3932-1-armbru@redhat.com> MIME-Version: 1.0 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.6]); Thu, 16 Aug 2018 08:37:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 16 Aug 2018 08:37:03 +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:'' Content-Transfer-Encoding: quoted-printable 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 01/25] libqtest: Rename functions to send QMP messages 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: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The functions to receive messages are called qtest_qmp_receive() and qmp_receive(), qmp_fd_receive(). The ones to send messages are called qtest_async_qmp(), qtest_async_qmpv(), qmp_async(), qmp_fd_send(), qmp_fd_sendv(). Inconsistent. Rename the *_async* ones to qmp_send(), qtest_qmp_send(), qtest_qmp_vsend(). Rename qmp_fd_sendv() to qmp_fd_vsend(). Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-2-armbru@redhat.com> --- tests/ahci-test.c | 10 +++++----- tests/libqos/ahci.c | 4 ++-- tests/libqtest.c | 20 ++++++++++---------- tests/libqtest.h | 14 +++++++------- tests/qmp-test.c | 18 +++++++++--------- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/tests/ahci-test.c b/tests/ahci-test.c index 1a7b761304..7e3491b5bd 100644 --- a/tests/ahci-test.c +++ b/tests/ahci-test.c @@ -1389,7 +1389,7 @@ static void test_flush_migrate(void) =20 /* Complete the command */ s =3D "{'execute':'cont' }"; - qmp_async(s); + qmp_send(s); qmp_eventwait("RESUME"); ahci_command_wait(dst, cmd); ahci_command_verify(dst, cmd); @@ -1592,8 +1592,8 @@ static void test_atapi_tray(void) atapi_wait_tray(false); =20 /* Remove media */ - qmp_async("{'execute': 'blockdev-open-tray', " - "'arguments': {'id': 'cd0'}}"); + qmp_send("{'execute': 'blockdev-open-tray'," + " 'arguments': {'id': 'cd0'}}"); atapi_wait_tray(true); rsp =3D qmp_receive(); qobject_unref(rsp); @@ -1619,8 +1619,8 @@ static void test_atapi_tray(void) "'node-name': 'node0' }}"); =20 /* Again, the event shows up first */ - qmp_async("{'execute': 'blockdev-close-tray', " - "'arguments': {'id': 'cd0'}}"); + qmp_send("{'execute': 'blockdev-close-tray'," + " 'arguments': {'id': 'cd0'}}"); atapi_wait_tray(false); rsp =3D qmp_receive(); qobject_unref(rsp); diff --git a/tests/libqos/ahci.c b/tests/libqos/ahci.c index 42d3f76933..63fbc9e3c9 100644 --- a/tests/libqos/ahci.c +++ b/tests/libqos/ahci.c @@ -674,7 +674,7 @@ void ahci_exec(AHCIQState *ahci, uint8_t port, g_assert_cmpint(rc, =3D=3D, 0); } if (opts->error) { - qtest_async_qmp(ahci->parent->qts, "{'execute':'cont' }"); + qtest_qmp_send(ahci->parent->qts, "{'execute':'cont' }"); qtest_qmp_eventwait(ahci->parent->qts, "RESUME"); } =20 @@ -712,7 +712,7 @@ AHCICommand *ahci_guest_io_halt(AHCIQState *ahci, uint8= _t port, void ahci_guest_io_resume(AHCIQState *ahci, AHCICommand *cmd) { /* Complete the command */ - qtest_async_qmp(ahci->parent->qts, "{'execute':'cont' }"); + qtest_qmp_send(ahci->parent->qts, "{'execute':'cont' }"); qtest_qmp_eventwait(ahci->parent->qts, "RESUME"); ahci_command_wait(ahci, cmd); ahci_command_verify(ahci, cmd); diff --git a/tests/libqtest.c b/tests/libqtest.c index 098af6aec4..9cb4096639 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -484,7 +484,7 @@ QDict *qtest_qmp_receive(QTestState *s) * in the case that they choose to discard all replies up until * a particular EVENT is received. */ -void qmp_fd_sendv(int fd, const char *fmt, va_list ap) +void qmp_fd_vsend(int fd, const char *fmt, va_list ap) { va_list ap_copy; QObject *qobj; @@ -529,21 +529,21 @@ void qmp_fd_sendv(int fd, const char *fmt, va_list ap) } } =20 -void qtest_async_qmpv(QTestState *s, const char *fmt, va_list ap) +void qtest_qmp_vsend(QTestState *s, const char *fmt, va_list ap) { - qmp_fd_sendv(s->qmp_fd, fmt, ap); + qmp_fd_vsend(s->qmp_fd, fmt, ap); } =20 QDict *qmp_fdv(int fd, const char *fmt, va_list ap) { - qmp_fd_sendv(fd, fmt, ap); + qmp_fd_vsend(fd, fmt, ap); =20 return qmp_fd_receive(fd); } =20 QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap) { - qtest_async_qmpv(s, fmt, ap); + qtest_qmp_vsend(s, fmt, ap); =20 /* Receive reply */ return qtest_qmp_receive(s); @@ -565,7 +565,7 @@ void qmp_fd_send(int fd, const char *fmt, ...) va_list ap; =20 va_start(ap, fmt); - qmp_fd_sendv(fd, fmt, ap); + qmp_fd_vsend(fd, fmt, ap); va_end(ap); } =20 @@ -580,12 +580,12 @@ QDict *qtest_qmp(QTestState *s, const char *fmt, ...) return response; } =20 -void qtest_async_qmp(QTestState *s, const char *fmt, ...) +void qtest_qmp_send(QTestState *s, const char *fmt, ...) { va_list ap; =20 va_start(ap, fmt); - qtest_async_qmpv(s, fmt, ap); + qtest_qmp_vsend(s, fmt, ap); va_end(ap); } =20 @@ -968,12 +968,12 @@ QDict *qmp(const char *fmt, ...) return response; } =20 -void qmp_async(const char *fmt, ...) +void qmp_send(const char *fmt, ...) { va_list ap; =20 va_start(ap, fmt); - qtest_async_qmpv(global_qtest, fmt, ap); + qtest_qmp_vsend(global_qtest, fmt, ap); va_end(ap); } =20 diff --git a/tests/libqtest.h b/tests/libqtest.h index ac52872cbe..c1af40106f 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -92,13 +92,13 @@ void qtest_qmp_discard_response(QTestState *s, const ch= ar *fmt, ...); QDict *qtest_qmp(QTestState *s, const char *fmt, ...); =20 /** - * qtest_async_qmp: + * qtest_qmp_send: * @s: #QTestState instance to operate on. * @fmt...: QMP message to send to qemu * * Sends a QMP message to QEMU and leaves the response in the stream. */ -void qtest_async_qmp(QTestState *s, const char *fmt, ...); +void qtest_qmp_send(QTestState *s, const char *fmt, ...); =20 /** * qtest_qmpv_discard_response: @@ -121,14 +121,14 @@ void qtest_qmpv_discard_response(QTestState *s, const= char *fmt, va_list ap); QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap); =20 /** - * qtest_async_qmpv: + * qtest_qmp_vsend: * @s: #QTestState instance to operate on. * @fmt: QMP message to send to QEMU * @ap: QMP message arguments * * 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_qmp_vsend(QTestState *s, const char *fmt, va_list ap); =20 /** * qtest_receive: @@ -568,12 +568,12 @@ static inline void qtest_end(void) QDict *qmp(const char *fmt, ...); =20 /** - * qmp_async: + * qmp_send: * @fmt...: QMP message to send to qemu * * Sends a QMP message to QEMU and leaves the response in the stream. */ -void qmp_async(const char *fmt, ...); +void qmp_send(const char *fmt, ...); =20 /** * qmp_discard_response: @@ -940,7 +940,7 @@ 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_vsend(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, ...); diff --git a/tests/qmp-test.c b/tests/qmp-test.c index b9774084f8..5eb15daebc 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -159,12 +159,12 @@ static void cleanup_blocking_cmd(void) =20 static void send_cmd_that_blocks(QTestState *s, const char *id) { - qtest_async_qmp(s, "{ 'execute': 'blockdev-add', 'id': %s," - " 'arguments': {" - " 'driver': 'blkdebug', 'node-name': %s," - " 'config': %s," - " 'image': { 'driver': 'null-co' } } }", - id, id, fifo_name); + qtest_qmp_send(s, "{ 'execute': 'blockdev-add', 'id': %s," + " 'arguments': {" + " 'driver': 'blkdebug', 'node-name': %s," + " 'config': %s," + " 'image': { 'driver': 'null-co' } } }", + id, id, fifo_name); } =20 static void unblock_blocked_cmd(void) @@ -176,7 +176,7 @@ static void unblock_blocked_cmd(void) =20 static void send_oob_cmd_that_fails(QTestState *s, const char *id) { - qtest_async_qmp(s, "{ 'exec-oob': 'migrate-pause', 'id': %s }", id); + qtest_qmp_send(s, "{ 'exec-oob': 'migrate-pause', 'id': %s }", id); } =20 static void recv_cmd_id(QTestState *s, const char *id) @@ -235,7 +235,7 @@ static void test_qmp_oob(void) /* OOB command overtakes slow in-band command */ setup_blocking_cmd(); send_cmd_that_blocks(qts, "ib-blocks-1"); - qtest_async_qmp(qts, "{ 'execute': 'query-name', 'id': 'ib-quick-1' }"= ); + qtest_qmp_send(qts, "{ 'execute': 'query-name', 'id': 'ib-quick-1' }"); send_oob_cmd_that_fails(qts, "oob-1"); recv_cmd_id(qts, "oob-1"); unblock_blocked_cmd(); @@ -244,7 +244,7 @@ static void test_qmp_oob(void) =20 /* Even malformed in-band command fails in-band */ send_cmd_that_blocks(qts, "blocks-2"); - qtest_async_qmp(qts, "{ 'id': 'err-2' }"); + qtest_qmp_send(qts, "{ 'id': 'err-2' }"); unblock_blocked_cmd(); recv_cmd_id(qts, "blocks-2"); recv_cmd_id(qts, "err-2"); --=20 2.17.1 From nobody Sat Feb 7 09:12:01 2026 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1534408780269649.4827534527564; Thu, 16 Aug 2018 01:39:40 -0700 (PDT) Received: from localhost ([::1]:54231 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDoe-000296-Ps for importer@patchew.org; Thu, 16 Aug 2018 04:39:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50515) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDmT-0000qa-3D for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmH-0005Bq-PG for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:16 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53660 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 1fqDmB-00058r-To for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:04 -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 4748C406E81C for ; Thu, 16 Aug 2018 08:37:03 +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 1EDEE2166BA0 for ; Thu, 16 Aug 2018 08:37:03 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id DBC341138656; Thu, 16 Aug 2018 10:37:01 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:36:38 +0200 Message-Id: <20180816083701.3932-3-armbru@redhat.com> In-Reply-To: <20180816083701.3932-1-armbru@redhat.com> References: <20180816083701.3932-1-armbru@redhat.com> MIME-Version: 1.0 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:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 16 Aug 2018 08:37:03 +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:'' Content-Transfer-Encoding: quoted-printable 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 02/25] libqtest: Clean up how we read device_del messages 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: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" qtest_qmp_device_del() still uses the qmp("") hack to receive a message, even though we have qmp_receive() since commit 66e0c7b187e. Put it to use. 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: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Thomas Huth Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-3-armbru@redhat.com> --- tests/libqtest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index 9cb4096639..071d7eb7b1 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -1090,7 +1090,7 @@ void qtest_qmp_device_del(const char *id) g_assert(response1); g_assert(!qdict_haskey(response1, "error")); =20 - response2 =3D qmp(""); + response2 =3D qmp_receive(); g_assert(response2); g_assert(!qdict_haskey(response2, "error")); =20 --=20 2.17.1 From nobody Sat Feb 7 09:12:01 2026 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 1534408941468229.35167235346603; Thu, 16 Aug 2018 01:42:21 -0700 (PDT) Received: from localhost ([::1]:54250 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDrI-0004zt-8y for importer@patchew.org; Thu, 16 Aug 2018 04:42:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50512) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDmU-0000qk-2r for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmH-0005Bz-RD for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:16 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51364 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 1fqDmB-00058q-Tw for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:06 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4B6924012990 for ; Thu, 16 Aug 2018 08:37:03 +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 1EC7A1010415 for ; Thu, 16 Aug 2018 08:37:03 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id DF55E1138657; Thu, 16 Aug 2018 10:37:01 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:36:39 +0200 Message-Id: <20180816083701.3932-4-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.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 16 Aug 2018 08:37:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 16 Aug 2018 08:37:03 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 03/25] 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: RDMRC_1 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 66e0c7b187e. 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: Thomas Huth Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-4-armbru@redhat.com> --- tests/libqtest.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index 071d7eb7b1..c2c08a890c 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -249,9 +249,11 @@ QTestState *qtest_init_without_qmp_handshake(bool use_= oob, QTestState *qtest_init(const char *extra_args) { QTestState *s =3D qtest_init_without_qmp_handshake(false, 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); + qobject_unref(greeting); qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }"); =20 return s; --=20 2.17.1 From nobody Sat Feb 7 09:12:01 2026 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1534409111444464.69845986514235; Thu, 16 Aug 2018 01:45:11 -0700 (PDT) Received: from localhost ([::1]:54263 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDtv-0000X1-4b for importer@patchew.org; Thu, 16 Aug 2018 04:45:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50513) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDmU-0000ql-2v for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmH-0005C9-Qv for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:16 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53664 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 1fqDmB-00058u-Tu for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:06 -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 640DB406E81D for ; Thu, 16 Aug 2018 08:37:03 +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 1F04D2166BA5 for ; Thu, 16 Aug 2018 08:37:03 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id E2B7A1138659; Thu, 16 Aug 2018 10:37:01 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:36:40 +0200 Message-Id: <20180816083701.3932-5-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:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 16 Aug 2018 08:37:03 +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 04/25] libqtest: Remove qtest_qmp_discard_response() & friends 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: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" qtest_qmp_discard_response(...) is shorthand for qobject_unref(qtest_qmp(...), except it's not actually shorter. Moreover, the presence of these functions encourage sloppy testing. Remove them from libqtest. Add them as macros to the tests that use them, with a TODO comment asking for cleanup. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-5-armbru@redhat.com> Reviewed-by: Thomas Huth --- tests/ahci-test.c | 3 +++ tests/boot-order-test.c | 5 ++++- tests/drive_del-test.c | 3 +++ tests/fdc-test.c | 4 ++++ tests/ide-test.c | 5 ++++- tests/libqtest.c | 27 +-------------------------- tests/libqtest.h | 27 --------------------------- tests/migration-test.c | 3 +++ tests/test-filter-mirror.c | 4 ++++ tests/test-filter-redirector.c | 4 ++++ tests/virtio-blk-test.c | 4 ++++ 11 files changed, 34 insertions(+), 55 deletions(-) diff --git a/tests/ahci-test.c b/tests/ahci-test.c index 7e3491b5bd..555f02112e 100644 --- a/tests/ahci-test.c +++ b/tests/ahci-test.c @@ -37,6 +37,9 @@ #include "hw/pci/pci_ids.h" #include "hw/pci/pci_regs.h" =20 +/* TODO actually test the results and get rid of this */ +#define qmp_discard_response(...) qobject_unref(qmp(__VA_ARGS__)) + /* Test images sizes in MB */ #define TEST_IMAGE_SIZE_MB_LARGE (200 * 1024) #define TEST_IMAGE_SIZE_MB_SMALL 64 diff --git a/tests/boot-order-test.c b/tests/boot-order-test.c index e70f5dedba..9096a4b5df 100644 --- a/tests/boot-order-test.c +++ b/tests/boot-order-test.c @@ -13,9 +13,12 @@ #include "qemu/osdep.h" #include "libqos/fw_cfg.h" #include "libqtest.h" - +#include "qapi/qmp/qdict.h" #include "hw/nvram/fw_cfg_keys.h" =20 +/* TODO actually test the results and get rid of this */ +#define qmp_discard_response(...) qobject_unref(qmp(__VA_ARGS__)) + typedef struct { const char *args; uint64_t expected_boot; diff --git a/tests/drive_del-test.c b/tests/drive_del-test.c index 852fefc8f3..2d0b176b36 100644 --- a/tests/drive_del-test.c +++ b/tests/drive_del-test.c @@ -15,6 +15,9 @@ #include "libqos/virtio.h" #include "qapi/qmp/qdict.h" =20 +/* TODO actually test the results and get rid of this */ +#define qmp_discard_response(...) qobject_unref(qmp(__VA_ARGS__)) + static void drive_add(void) { char *resp =3D hmp("drive_add 0 if=3Dnone,id=3Ddrive0"); diff --git a/tests/fdc-test.c b/tests/fdc-test.c index 325712e0f2..88f1abfa10 100644 --- a/tests/fdc-test.c +++ b/tests/fdc-test.c @@ -26,8 +26,12 @@ =20 =20 #include "libqtest.h" +#include "qapi/qmp/qdict.h" #include "qemu-common.h" =20 +/* TODO actually test the results and get rid of this */ +#define qmp_discard_response(...) qobject_unref(qmp(__VA_ARGS__)) + #define TEST_IMAGE_SIZE 1440 * 1024 =20 #define FLOPPY_BASE 0x3f0 diff --git a/tests/ide-test.c b/tests/ide-test.c index 2384c2c3e2..7ab09c3448 100644 --- a/tests/ide-test.c +++ b/tests/ide-test.c @@ -29,12 +29,15 @@ #include "libqos/libqos.h" #include "libqos/pci-pc.h" #include "libqos/malloc-pc.h" - +#include "qapi/qmp/qdict.h" #include "qemu-common.h" #include "qemu/bswap.h" #include "hw/pci/pci_ids.h" #include "hw/pci/pci_regs.h" =20 +/* TODO actually test the results and get rid of this */ +#define qmp_discard_response(...) qobject_unref(qmp(__VA_ARGS__)) + #define TEST_IMAGE_SIZE 64 * 1024 * 1024 =20 #define IDE_PCI_DEV 1 diff --git a/tests/libqtest.c b/tests/libqtest.c index c2c08a890c..2fe0f4dc29 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -254,7 +254,7 @@ QTestState *qtest_init(const char *extra_args) /* Read the QMP greeting and then do the handshake */ greeting =3D qtest_qmp_receive(s); qobject_unref(greeting); - qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }"); + qobject_unref(qtest_qmp(s, "{ 'execute': 'qmp_capabilities' }")); =20 return s; } @@ -591,23 +591,6 @@ void qtest_qmp_send(QTestState *s, const char *fmt, ..= .) va_end(ap); } =20 -void qtest_qmpv_discard_response(QTestState *s, const char *fmt, va_list a= p) -{ - QDict *response =3D qtest_qmpv(s, fmt, ap); - qobject_unref(response); -} - -void qtest_qmp_discard_response(QTestState *s, const char *fmt, ...) -{ - va_list ap; - QDict *response; - - va_start(ap, fmt); - response =3D qtest_qmpv(s, fmt, ap); - va_end(ap); - qobject_unref(response); -} - QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event) { QDict *response; @@ -979,14 +962,6 @@ void qmp_send(const char *fmt, ...) va_end(ap); } =20 -void qmp_discard_response(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - qtest_qmpv_discard_response(global_qtest, fmt, ap); - va_end(ap); -} char *hmp(const char *fmt, ...) { va_list ap; diff --git a/tests/libqtest.h b/tests/libqtest.h index c1af40106f..3eecd5e9a7 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -73,15 +73,6 @@ QTestState *qtest_init_without_qmp_handshake(bool use_oo= b, */ void qtest_quit(QTestState *s); =20 -/** - * qtest_qmp_discard_response: - * @s: #QTestState instance to operate on. - * @fmt...: QMP message to send to qemu - * - * Sends a QMP message to QEMU and consumes the response. - */ -void qtest_qmp_discard_response(QTestState *s, const char *fmt, ...); - /** * qtest_qmp: * @s: #QTestState instance to operate on. @@ -100,16 +91,6 @@ QDict *qtest_qmp(QTestState *s, const char *fmt, ...); */ void qtest_qmp_send(QTestState *s, const char *fmt, ...); =20 -/** - * qtest_qmpv_discard_response: - * @s: #QTestState instance to operate on. - * @fmt: QMP message to send to QEMU - * @ap: QMP message arguments - * - * Sends a QMP message to QEMU and consumes the response. - */ -void qtest_qmpv_discard_response(QTestState *s, const char *fmt, va_list a= p); - /** * qtest_qmpv: * @s: #QTestState instance to operate on. @@ -575,14 +556,6 @@ QDict *qmp(const char *fmt, ...); */ void qmp_send(const char *fmt, ...); =20 -/** - * qmp_discard_response: - * @fmt...: QMP message to send to qemu - * - * Sends a QMP message to QEMU and consumes the response. - */ -void qmp_discard_response(const char *fmt, ...); - /** * qmp_receive: * diff --git a/tests/migration-test.c b/tests/migration-test.c index e079e0bdb6..bbe9c9e95d 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -20,6 +20,9 @@ #include "chardev/char.h" #include "sysemu/sysemu.h" =20 +/* TODO actually test the results and get rid of this */ +#define qtest_qmp_discard_response(...) qobject_unref(qtest_qmp(__VA_ARGS_= _)) + const unsigned start_address =3D 1024 * 1024; const unsigned end_address =3D 100 * 1024 * 1024; bool got_stop; diff --git a/tests/test-filter-mirror.c b/tests/test-filter-mirror.c index 6c6f710dc6..de5ba155db 100644 --- a/tests/test-filter-mirror.c +++ b/tests/test-filter-mirror.c @@ -10,11 +10,15 @@ =20 #include "qemu/osdep.h" #include "libqtest.h" +#include "qapi/qmp/qdict.h" #include "qemu/iov.h" #include "qemu/sockets.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" =20 +/* TODO actually test the results and get rid of this */ +#define qmp_discard_response(...) qobject_unref(qmp(__VA_ARGS__)) + static void test_mirror(void) { int send_sock[2], recv_sock; diff --git a/tests/test-filter-redirector.c b/tests/test-filter-redirector.c index fbaf19bbd8..896f900e98 100644 --- a/tests/test-filter-redirector.c +++ b/tests/test-filter-redirector.c @@ -52,11 +52,15 @@ =20 #include "qemu/osdep.h" #include "libqtest.h" +#include "qapi/qmp/qdict.h" #include "qemu/iov.h" #include "qemu/sockets.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" =20 +/* TODO actually test the results and get rid of this */ +#define qmp_discard_response(...) qobject_unref(qmp(__VA_ARGS__)) + static const char *get_devstr(void) { if (g_str_equal(qtest_get_arch(), "s390x")) { diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index 9be9ffb378..06226b8717 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/qdict.h" #include "qemu/bswap.h" #include "standard-headers/linux/virtio_ids.h" #include "standard-headers/linux/virtio_config.h" @@ -23,6 +24,9 @@ #include "standard-headers/linux/virtio_blk.h" #include "standard-headers/linux/virtio_pci.h" =20 +/* TODO actually test the results and get rid of this */ +#define qmp_discard_response(...) qobject_unref(qmp(__VA_ARGS__)) + #define TEST_IMAGE_SIZE (64 * 1024 * 1024) #define QVIRTIO_BLK_TIMEOUT_US (30 * 1000 * 1000) #define PCI_SLOT_HP 0x06 --=20 2.17.1 From nobody Sat Feb 7 09:12:01 2026 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 1534409454598537.3304781184105; Thu, 16 Aug 2018 01:50:54 -0700 (PDT) Received: from localhost ([::1]:54302 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDzW-0001W6-C9 for importer@patchew.org; Thu, 16 Aug 2018 04:50:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50604) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDmf-0000yj-HJ for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmT-0005G2-41 for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:25 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57656 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 1fqDmJ-00059N-Lk for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:16 -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 804F572645 for ; Thu, 16 Aug 2018 08:37:04 +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 3B9DC2166BA0; Thu, 16 Aug 2018 08:37:04 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id E62CC113865A; Thu, 16 Aug 2018 10:37:01 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:36:41 +0200 Message-Id: <20180816083701.3932-6-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.2]); Thu, 16 Aug 2018 08:37:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 16 Aug 2018 08:37:04 +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 05/25] libqtest: 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: RDMRC_1 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: qtest_hmp() etc. work like sprintf(), and qtest_qmp() etc. work like qobject_from_jsonf(). Spell that out in the comments. Also add GCC_FMT_ATTR() to qtest_hmp() etc. so that the compiler can flag incorrect use. We have some cleanup work to do before we can do the same for qtest_qmp() etc. This would get us the same better-than-nothing checking we already have for qobject_from_jsonf(): common incorrect uses of supported conversion specifications will be flagged (e.g. passing a double for %d), but use of unsupported ones won't. Signed-off-by: Eric Blake Reviewed-by: Stefan Hajnoczi Reviewed-by: Markus Armbruster [Rebased, comment wording tweaked, commit message rewritten] Signed-off-by: Markus Armbruster Message-Id: <20180806065344.7103-6-armbru@redhat.com> --- tests/libqtest.h | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/tests/libqtest.h b/tests/libqtest.h index 3eecd5e9a7..da13ea00ef 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -76,7 +76,9 @@ void qtest_quit(QTestState *s); /** * qtest_qmp: * @s: #QTestState instance to operate on. - * @fmt...: QMP message to send to qemu + * @fmt...: QMP message to send to qemu, formatted like + * qobject_from_jsonf(). See parse_escape() for what's supported + * after '%'. * * Sends a QMP message to QEMU and returns the response. */ @@ -85,7 +87,9 @@ QDict *qtest_qmp(QTestState *s, const char *fmt, ...); /** * qtest_qmp_send: * @s: #QTestState instance to operate on. - * @fmt...: QMP message to send to qemu + * @fmt...: QMP message to send to qemu, formatted like + * qobject_from_jsonf(). See parse_escape() for what's supported + * after '%'. * * Sends a QMP message to QEMU and leaves the response in the stream. */ @@ -94,7 +98,9 @@ void qtest_qmp_send(QTestState *s, const char *fmt, ...); /** * qtest_qmpv: * @s: #QTestState instance to operate on. - * @fmt: QMP message to send to QEMU + * @fmt: QMP message to send to QEMU, formatted like + * qobject_from_jsonf(). See parse_escape() for what's supported + * after '%'. * @ap: QMP message arguments * * Sends a QMP message to QEMU and returns the response. @@ -104,7 +110,9 @@ QDict *qtest_qmpv(QTestState *s, const char *fmt, va_li= st ap); /** * qtest_qmp_vsend: * @s: #QTestState instance to operate on. - * @fmt: QMP message to send to QEMU + * @fmt: QMP message to send to QEMU, formatted like + * qobject_from_jsonf(). See parse_escape() for what's supported + * after '%'. * @ap: QMP message arguments * * Sends a QMP message to QEMU and leaves the response in the stream. @@ -153,7 +161,7 @@ char *qtest_hmp(QTestState *s, const char *fmt, ...) GC= C_FMT_ATTR(2, 3); /** * qtest_hmpv: * @s: #QTestState instance to operate on. - * @fmt: HMP command to send to QEMU + * @fmt: HMP command to send to QEMU, formats arguments like vsprintf(). * @ap: HMP command arguments * * Send HMP command to QEMU via QMP's human-monitor-command. @@ -161,7 +169,8 @@ char *qtest_hmp(QTestState *s, const char *fmt, ...) GC= C_FMT_ATTR(2, 3); * * 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: @@ -542,7 +551,9 @@ static inline void qtest_end(void) =20 /** * qmp: - * @fmt...: QMP message to send to qemu + * @fmt...: QMP message to send to qemu, formatted like + * qobject_from_jsonf(). See parse_escape() for what's supported + * after '%'. * * Sends a QMP message to QEMU and returns the response. */ @@ -550,7 +561,9 @@ QDict *qmp(const char *fmt, ...); =20 /** * qmp_send: - * @fmt...: QMP message to send to qemu + * @fmt...: QMP message to send to qemu, formatted like + * qobject_from_jsonf(). See parse_escape() for what's supported + * after '%'. * * Sends a QMP message to QEMU and leaves the response in the stream. */ --=20 2.17.1 From nobody Sat Feb 7 09:12:01 2026 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 1534409111471827.7253115846338; Thu, 16 Aug 2018 01:45:11 -0700 (PDT) Received: from localhost ([::1]:54265 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDty-0000Z9-K6 for importer@patchew.org; Thu, 16 Aug 2018 04:45:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50606) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDmf-0000yk-HD for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmS-0005Fn-Dm for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:25 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37564 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 1fqDmH-00059X-Uf for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:14 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DF1EA406C7A3 for ; Thu, 16 Aug 2018 08:37:04 +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 3B67D1010416 for ; Thu, 16 Aug 2018 08:37:04 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id E9A991138662; Thu, 16 Aug 2018 10:37:01 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:36:42 +0200 Message-Id: <20180816083701.3932-7-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.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 16 Aug 2018 08:37:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 16 Aug 2018 08:37:04 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 06/25] qobject: Replace qobject_from_jsonf() by qobject_from_jsonf_nofail() 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: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Commit ab45015a968 "qobject: Let qobject_from_jsonf() fail instead of abort" fails to accomplish its stated aim: the function can still abort due to its use of &error_abort. Its rationale for letting it fail is that all remaining users cope fine with failure. Well, they're just fine with aborting, too; it's what they do on failure. Simply reverting the broken commit would bring back the unfortunate asymmetry between qobject_from_jsonf() and qobject_from_jsonv(): one aborts, the other returns null. So also rename it to qobject_from_jsonf_nofail(). Signed-off-by: Markus Armbruster Reviewed-by: Thomas Huth Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-7-armbru@redhat.com> --- include/qapi/qmp/qjson.h | 6 ++++-- qobject/qjson.c | 8 +++++++- tests/check-qjson.c | 15 ++++++++------- tests/libqtest.h | 24 ++++++++++++------------ 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/include/qapi/qmp/qjson.h b/include/qapi/qmp/qjson.h index 43b2ce2f33..dc509d51ae 100644 --- a/include/qapi/qmp/qjson.h +++ b/include/qapi/qmp/qjson.h @@ -15,11 +15,13 @@ #define QJSON_H =20 QObject *qobject_from_json(const char *string, Error **errp); -QObject *qobject_from_jsonf(const char *string, ...) GCC_FMT_ATTR(1, 2); QObject *qobject_from_jsonv(const char *string, va_list *ap, Error **errp) GCC_FMT_ATTR(1, 0); =20 -QDict *qdict_from_jsonf_nofail(const char *string, ...) GCC_FMT_ATTR(1, 2); +QObject *qobject_from_jsonf_nofail(const char *string, ...) + GCC_FMT_ATTR(1, 2); +QDict *qdict_from_jsonf_nofail(const char *string, ...) + GCC_FMT_ATTR(1, 2); =20 QString *qobject_to_json(const QObject *obj); QString *qobject_to_json_pretty(const QObject *obj); diff --git a/qobject/qjson.c b/qobject/qjson.c index 2f6a590e44..4a9dcff343 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -59,7 +59,12 @@ QObject *qobject_from_json(const char *string, Error **e= rrp) return qobject_from_jsonv(string, NULL, errp); } =20 -QObject *qobject_from_jsonf(const char *string, ...) +/* + * Parse @string as JSON value with %-escapes interpolated. + * Abort on error. Do not use with untrusted @string. + * Return the resulting QObject. It is never null. + */ +QObject *qobject_from_jsonf_nofail(const char *string, ...) { QObject *obj; va_list ap; @@ -68,6 +73,7 @@ QObject *qobject_from_jsonf(const char *string, ...) obj =3D qobject_from_jsonv(string, &ap, &error_abort); va_end(ap); =20 + assert(obj); return obj; } =20 diff --git a/tests/check-qjson.c b/tests/check-qjson.c index da582df3e9..eaf5d20663 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -865,7 +865,8 @@ static void vararg_string(void) QString *str; =20 str =3D qobject_to(QString, - qobject_from_jsonf("%s", test_cases[i].decoded)); + qobject_from_jsonf_nofail("%s", + test_cases[i].decoded)); g_assert(str); g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) =3D= =3D 0); =20 @@ -998,17 +999,17 @@ static void vararg_number(void) double valuef =3D 2.323423423; int64_t val; =20 - qnum =3D qobject_to(QNum, qobject_from_jsonf("%d", value)); + qnum =3D qobject_to(QNum, qobject_from_jsonf_nofail("%d", value)); g_assert(qnum_get_try_int(qnum, &val)); g_assert_cmpint(val, =3D=3D, value); qobject_unref(qnum); =20 - qnum =3D qobject_to(QNum, qobject_from_jsonf("%lld", value_ll)); + qnum =3D qobject_to(QNum, qobject_from_jsonf_nofail("%lld", value_ll)); g_assert(qnum_get_try_int(qnum, &val)); g_assert_cmpint(val, =3D=3D, value_ll); qobject_unref(qnum); =20 - qnum =3D qobject_to(QNum, qobject_from_jsonf("%f", valuef)); + qnum =3D qobject_to(QNum, qobject_from_jsonf_nofail("%f", valuef)); g_assert(qnum_get_double(qnum) =3D=3D valuef); qobject_unref(qnum); } @@ -1042,13 +1043,13 @@ static void keyword_literal(void) =20 qobject_unref(qbool); =20 - qbool =3D qobject_to(QBool, qobject_from_jsonf("%i", false)); + qbool =3D qobject_to(QBool, qobject_from_jsonf_nofail("%i", false)); g_assert(qbool); g_assert(qbool_get_bool(qbool) =3D=3D false); qobject_unref(qbool); =20 /* Test that non-zero values other than 1 get collapsed to true */ - qbool =3D qobject_to(QBool, qobject_from_jsonf("%i", 2)); + qbool =3D qobject_to(QBool, qobject_from_jsonf_nofail("%i", 2)); g_assert(qbool); g_assert(qbool_get_bool(qbool) =3D=3D true); qobject_unref(qbool); @@ -1298,7 +1299,7 @@ static void simple_varargs(void) embedded_obj =3D qobject_from_json("[32, 42]", &error_abort); g_assert(embedded_obj !=3D NULL); =20 - obj =3D qobject_from_jsonf("[%d, 2, %p]", 1, embedded_obj); + obj =3D qobject_from_jsonf_nofail("[%d, 2, %p]", 1, embedded_obj); g_assert(qlit_equal_qobject(&decoded, obj)); =20 qobject_unref(obj); diff --git a/tests/libqtest.h b/tests/libqtest.h index da13ea00ef..0eff8763ce 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -77,8 +77,8 @@ void qtest_quit(QTestState *s); * qtest_qmp: * @s: #QTestState instance to operate on. * @fmt...: QMP message to send to qemu, formatted like - * qobject_from_jsonf(). See parse_escape() for what's supported - * after '%'. + * qobject_from_jsonf_nofail(). See parse_escape() for what's + * supported after '%'. * * Sends a QMP message to QEMU and returns the response. */ @@ -88,8 +88,8 @@ QDict *qtest_qmp(QTestState *s, const char *fmt, ...); * qtest_qmp_send: * @s: #QTestState instance to operate on. * @fmt...: QMP message to send to qemu, formatted like - * qobject_from_jsonf(). See parse_escape() for what's supported - * after '%'. + * qobject_from_jsonf_nofail(). See parse_escape() for what's + * supported after '%'. * * Sends a QMP message to QEMU and leaves the response in the stream. */ @@ -99,8 +99,8 @@ void qtest_qmp_send(QTestState *s, const char *fmt, ...); * qtest_qmpv: * @s: #QTestState instance to operate on. * @fmt: QMP message to send to QEMU, formatted like - * qobject_from_jsonf(). See parse_escape() for what's supported - * after '%'. + * qobject_from_jsonf_nofail(). See parse_escape() for what's + * supported after '%'. * @ap: QMP message arguments * * Sends a QMP message to QEMU and returns the response. @@ -111,8 +111,8 @@ QDict *qtest_qmpv(QTestState *s, const char *fmt, va_li= st ap); * qtest_qmp_vsend: * @s: #QTestState instance to operate on. * @fmt: QMP message to send to QEMU, formatted like - * qobject_from_jsonf(). See parse_escape() for what's supported - * after '%'. + * qobject_from_jsonf_nofail(). See parse_escape() for what's + * supported after '%'. * @ap: QMP message arguments * * Sends a QMP message to QEMU and leaves the response in the stream. @@ -552,8 +552,8 @@ static inline void qtest_end(void) /** * qmp: * @fmt...: QMP message to send to qemu, formatted like - * qobject_from_jsonf(). See parse_escape() for what's supported - * after '%'. + * qobject_from_jsonf_nofail(). See parse_escape() for what's + * supported after '%'. * * Sends a QMP message to QEMU and returns the response. */ @@ -562,8 +562,8 @@ QDict *qmp(const char *fmt, ...); /** * qmp_send: * @fmt...: QMP message to send to qemu, formatted like - * qobject_from_jsonf(). See parse_escape() for what's supported - * after '%'. + * qobject_from_jsonf_nofail(). See parse_escape() for what's + * supported after '%'. * * Sends a QMP message to QEMU and leaves the response in the stream. */ --=20 2.17.1 From nobody Sat Feb 7 09:12:01 2026 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 1534408780366388.0656998382833; Thu, 16 Aug 2018 01:39:40 -0700 (PDT) Received: from localhost ([::1]:54230 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDoe-00027L-EK for importer@patchew.org; Thu, 16 Aug 2018 04:39:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50555) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDmV-0000rJ-Bm for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmM-0005Dz-Fu for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:18 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37562 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 1fqDmE-00059K-Mj for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:09 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7DA5F406C7A0 for ; Thu, 16 Aug 2018 08:37:04 +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 3B4E8112D197 for ; Thu, 16 Aug 2018 08:37:04 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id ED1461138663; Thu, 16 Aug 2018 10:37:01 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:36:43 +0200 Message-Id: <20180816083701.3932-8-armbru@redhat.com> In-Reply-To: <20180816083701.3932-1-armbru@redhat.com> References: <20180816083701.3932-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 16 Aug 2018 08:37:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 16 Aug 2018 08:37:04 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'armbru@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable 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 07/25] qobject: New qobject_from_vjsonf_nofail(), qdict_from_vjsonf_nofail() 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: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Every printf()-like function sooner or later needs its vprintf()-like buddy. The next commit will need qobject_from_jsonf_nofail()'s buddy, and qdict_from_jsonf_nofail()'s buddy will be used later in this series. Add both. Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-8-armbru@redhat.com> --- include/qapi/qmp/qjson.h | 4 ++++ qobject/qjson.c | 44 +++++++++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/include/qapi/qmp/qjson.h b/include/qapi/qmp/qjson.h index dc509d51ae..dce78583dc 100644 --- a/include/qapi/qmp/qjson.h +++ b/include/qapi/qmp/qjson.h @@ -18,8 +18,12 @@ QObject *qobject_from_json(const char *string, Error **e= rrp); QObject *qobject_from_jsonv(const char *string, va_list *ap, Error **errp) GCC_FMT_ATTR(1, 0); =20 +QObject *qobject_from_vjsonf_nofail(const char *string, va_list ap) + GCC_FMT_ATTR(1, 0); QObject *qobject_from_jsonf_nofail(const char *string, ...) GCC_FMT_ATTR(1, 2); +QDict *qdict_from_vjsonf_nofail(const char *string, va_list ap) + GCC_FMT_ATTR(1, 0); QDict *qdict_from_jsonf_nofail(const char *string, ...) GCC_FMT_ATTR(1, 2); =20 diff --git a/qobject/qjson.c b/qobject/qjson.c index 4a9dcff343..2e450231ff 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -59,6 +59,25 @@ QObject *qobject_from_json(const char *string, Error **e= rrp) return qobject_from_jsonv(string, NULL, errp); } =20 +/* + * Parse @string as JSON value with %-escapes interpolated. + * Abort on error. Do not use with untrusted @string. + * Return the resulting QObject. It is never null. + */ +QObject *qobject_from_vjsonf_nofail(const char *string, va_list ap) +{ + va_list ap_copy; + QObject *obj; + + /* va_copy() is needed when va_list is an array type */ + va_copy(ap_copy, ap); + obj =3D qobject_from_jsonv(string, &ap_copy, &error_abort); + va_end(ap_copy); + + assert(obj); + return obj; +} + /* * Parse @string as JSON value with %-escapes interpolated. * Abort on error. Do not use with untrusted @string. @@ -70,13 +89,26 @@ QObject *qobject_from_jsonf_nofail(const char *string, = ...) va_list ap; =20 va_start(ap, string); - obj =3D qobject_from_jsonv(string, &ap, &error_abort); + obj =3D qobject_from_vjsonf_nofail(string, ap); va_end(ap); =20 - assert(obj); return obj; } =20 +/* + * Parse @string as JSON object with %-escapes interpolated. + * Abort on error. Do not use with untrusted @string. + * Return the resulting QDict. It is never null. + */ +QDict *qdict_from_vjsonf_nofail(const char *string, va_list ap) +{ + QDict *qdict; + + qdict =3D qobject_to(QDict, qobject_from_vjsonf_nofail(string, ap)); + assert(qdict); + return qdict; +} + /* * Parse @string as JSON object with %-escapes interpolated. * Abort on error. Do not use with untrusted @string. @@ -84,15 +116,13 @@ QObject *qobject_from_jsonf_nofail(const char *string,= ...) */ QDict *qdict_from_jsonf_nofail(const char *string, ...) { - QDict *obj; + QDict *qdict; va_list ap; =20 va_start(ap, string); - obj =3D qobject_to(QDict, qobject_from_jsonv(string, &ap, &error_abort= )); + qdict =3D qdict_from_vjsonf_nofail(string, ap); va_end(ap); - - assert(obj); - return obj; + return qdict; } =20 typedef struct ToJsonIterState --=20 2.17.1 From nobody Sat Feb 7 09:12:01 2026 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1534408782021484.4885899002404; Thu, 16 Aug 2018 01:39:42 -0700 (PDT) Received: from localhost ([::1]:54228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDoY-00020n-DL for importer@patchew.org; Thu, 16 Aug 2018 04:39:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50519) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDmT-0000qd-3N for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmL-0005DW-Ia for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:16 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51370 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 1fqDmE-00059F-Ba for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:08 -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 60FF9401298C for ; Thu, 16 Aug 2018 08:37:04 +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 3D55420180F4 for ; Thu, 16 Aug 2018 08:37:04 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id F07161138664; Thu, 16 Aug 2018 10:37:01 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:36:44 +0200 Message-Id: <20180816083701.3932-9-armbru@redhat.com> In-Reply-To: <20180816083701.3932-1-armbru@redhat.com> References: <20180816083701.3932-1-armbru@redhat.com> MIME-Version: 1.0 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, 16 Aug 2018 08:37:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 16 Aug 2018 08:37:04 +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:'' Content-Transfer-Encoding: quoted-printable 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 08/25] libqtest: Simplify qmp_fd_vsend() a bit 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: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-9-armbru@redhat.com> --- tests/libqtest.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index 2fe0f4dc29..9e3870bb7d 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -488,24 +488,20 @@ QDict *qtest_qmp_receive(QTestState *s) */ void qmp_fd_vsend(int fd, const char *fmt, va_list ap) { - va_list ap_copy; QObject *qobj; =20 - /* qobject_from_jsonv() silently eats leading 0xff as invalid - * JSON, but we want to test sending them over the wire to force - * resyncs */ + /* + * qobject_from_vjsonf_nofail() chokes on leading 0xff as invalid + * JSON, but tests/test-qga.c needs to send that to test QGA + * synchronization + */ if (*fmt =3D=3D '\377') { socket_send(fd, fmt, 1); fmt++; } =20 - /* Going through qobject ensures we escape strings properly. - * This seemingly unnecessary copy is required in case va_list - * is an array type. - */ - va_copy(ap_copy, ap); - qobj =3D qobject_from_jsonv(fmt, &ap_copy, &error_abort); - va_end(ap_copy); + /* Going through qobject ensures we escape strings properly */ + qobj =3D qobject_from_vjsonf_nofail(fmt, ap); =20 /* No need to send anything for an empty QObject. */ if (qobj) { --=20 2.17.1 From nobody Sat Feb 7 09:12:01 2026 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 1534409455043776.9166886607092; Thu, 16 Aug 2018 01:50:55 -0700 (PDT) Received: from localhost ([::1]:54301 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDzW-0001Vq-6H for importer@patchew.org; Thu, 16 Aug 2018 04:50:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50669) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDmo-000182-6s 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 1fqDmb-0005LV-M4 for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:33 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51372 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 1fqDmS-00059J-Cs for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:23 -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 77A554012997 for ; Thu, 16 Aug 2018 08:37:04 +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 531C110190 for ; Thu, 16 Aug 2018 08:37:04 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id F3DC91138666; Thu, 16 Aug 2018 10:37:01 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:36:45 +0200 Message-Id: <20180816083701.3932-10-armbru@redhat.com> In-Reply-To: <20180816083701.3932-1-armbru@redhat.com> References: <20180816083701.3932-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.6]); Thu, 16 Aug 2018 08:37:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 16 Aug 2018 08:37:04 +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] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 09/25] test-qobject-input-visitor: Avoid format string ambiguity 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: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When visitor_input_test_init_internal()'s argument @ap is null, then @json_string is interpreted literally, else it's gets %-escapes interpolated. This is awkward. One caller always passes null @ap, and the others never do. Lift the building of the QObject into the callers, where it can be done without such ambiguity. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-10-armbru@redhat.com> --- tests/test-qobject-input-visitor.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-= visitor.c index 0f4d234c3f..caa90b3d7e 100644 --- a/tests/test-qobject-input-visitor.c +++ b/tests/test-qobject-input-visitor.c @@ -47,15 +47,13 @@ static void visitor_input_teardown(TestInputVisitorData= *data, /* The various test_init functions are provided instead of a test setup function so that the JSON string used by the tests are kept in the test functions (and not in main()). */ -static Visitor *visitor_input_test_init_internal(TestInputVisitorData *dat= a, - bool keyval, - const char *json_string, - va_list *ap) + +static Visitor *test_init_internal(TestInputVisitorData *data, bool keyval, + QObject *obj) { visitor_input_teardown(data, NULL); =20 - data->obj =3D qobject_from_jsonv(json_string, ap, &error_abort); - g_assert(data->obj); + data->obj =3D obj; =20 if (keyval) { data->qiv =3D qobject_input_visitor_new_keyval(data->obj); @@ -75,7 +73,8 @@ Visitor *visitor_input_test_init_full(TestInputVisitorDat= a *data, va_list ap; =20 va_start(ap, json_string); - v =3D visitor_input_test_init_internal(data, keyval, json_string, &ap); + v =3D test_init_internal(data, keyval, + qobject_from_vjsonf_nofail(json_string, ap)); va_end(ap); return v; } @@ -88,7 +87,8 @@ Visitor *visitor_input_test_init(TestInputVisitorData *da= ta, va_list ap; =20 va_start(ap, json_string); - v =3D visitor_input_test_init_internal(data, false, json_string, &ap); + v =3D test_init_internal(data, false, + qobject_from_vjsonf_nofail(json_string, ap)); va_end(ap); return v; } @@ -103,7 +103,8 @@ Visitor *visitor_input_test_init(TestInputVisitorData *= data, static Visitor *visitor_input_test_init_raw(TestInputVisitorData *data, const char *json_string) { - return visitor_input_test_init_internal(data, false, json_string, NULL= ); + return test_init_internal(data, false, + qobject_from_json(json_string, &error_abort)= ); } =20 static void test_visitor_in_int(TestInputVisitorData *data, --=20 2.17.1 From nobody Sat Feb 7 09:12:01 2026 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 1534409012614409.13784364119556; Thu, 16 Aug 2018 01:43:32 -0700 (PDT) Received: from localhost ([::1]:54253 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDsQ-00060E-Gw for importer@patchew.org; Thu, 16 Aug 2018 04:43:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDmf-0000yo-I6 for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmV-0005HJ-Cx for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:26 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37560 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 1fqDmM-00059H-Ek for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:18 -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 774D2406C77F for ; Thu, 16 Aug 2018 08:37:04 +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 532C920180F5 for ; Thu, 16 Aug 2018 08:37:04 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 032AC1138667; Thu, 16 Aug 2018 10:37:02 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:36:46 +0200 Message-Id: <20180816083701.3932-11-armbru@redhat.com> In-Reply-To: <20180816083701.3932-1-armbru@redhat.com> References: <20180816083701.3932-1-armbru@redhat.com> MIME-Version: 1.0 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.5]); Thu, 16 Aug 2018 08:37:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 16 Aug 2018 08:37:04 +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:'' Content-Transfer-Encoding: quoted-printable 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 10/25] qobject: qobject_from_jsonv() is dangerous, hide it away 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: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" qobject_from_jsonv() takes ownership of %p arguments. On failure, we can't generally know whether we failed before or after %p, so ownership becomes indeterminate. To avoid leaks, callers passing %p must terminate on error, e.g. by passing &error_abort. Trap for the unwary; document and give the function internal linkage. Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-11-armbru@redhat.com> --- include/qapi/qmp/qjson.h | 2 -- qobject/qjson.c | 13 ++++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/qapi/qmp/qjson.h b/include/qapi/qmp/qjson.h index dce78583dc..5ebbe5a118 100644 --- a/include/qapi/qmp/qjson.h +++ b/include/qapi/qmp/qjson.h @@ -15,8 +15,6 @@ #define QJSON_H =20 QObject *qobject_from_json(const char *string, Error **errp); -QObject *qobject_from_jsonv(const char *string, va_list *ap, Error **errp) - GCC_FMT_ATTR(1, 0); =20 QObject *qobject_from_vjsonf_nofail(const char *string, va_list ap) GCC_FMT_ATTR(1, 0); diff --git a/qobject/qjson.c b/qobject/qjson.c index 2e450231ff..ab4040f235 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -39,7 +39,18 @@ static void parse_json(JSONMessageParser *parser, GQueue= *tokens) s->result =3D json_parser_parse_err(tokens, s->ap, &s->err); } =20 -QObject *qobject_from_jsonv(const char *string, va_list *ap, Error **errp) +/* + * Parse @string as JSON value. + * If @ap is non-null, interpolate %-escapes. + * Takes ownership of %p arguments. + * On success, return the JSON value. + * On failure, store an error through @errp and return NULL. + * Ownership of %p arguments becomes indeterminate then. To avoid + * leaks, callers passing %p must terminate on error, e.g. by passing + * &error_abort. + */ +static QObject *qobject_from_jsonv(const char *string, va_list *ap, + Error **errp) { JSONParsingState state =3D {}; =20 --=20 2.17.1 From nobody Sat Feb 7 09:12:01 2026 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 1534409742037871.2621493593936; Thu, 16 Aug 2018 01:55:42 -0700 (PDT) Received: from localhost ([::1]:54323 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqE4C-0007PU-TP for importer@patchew.org; Thu, 16 Aug 2018 04:55:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50691) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDmq-0001AK-H1 for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmf-0005NQ-Hk for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:39 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53666 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 1fqDmT-00059P-2G for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:25 -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 79C854076076 for ; Thu, 16 Aug 2018 08:37:04 +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 567A410194 for ; Thu, 16 Aug 2018 08:37:04 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 068591138668; Thu, 16 Aug 2018 10:37:02 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:36:47 +0200 Message-Id: <20180816083701.3932-12-armbru@redhat.com> In-Reply-To: <20180816083701.3932-1-armbru@redhat.com> References: <20180816083701.3932-1-armbru@redhat.com> MIME-Version: 1.0 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, 16 Aug 2018 08:37:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 16 Aug 2018 08:37:04 +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:'' Content-Transfer-Encoding: quoted-printable 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 11/25] 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: RDMRC_1 RSF_0 Z_629925259 SPT_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: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-12-armbru@redhat.com> --- 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 555f02112e..60ba32f4f2 100644 --- a/tests/ahci-test.c +++ b/tests/ahci-test.c @@ -1355,7 +1355,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"); @@ -1391,8 +1390,7 @@ static void test_flush_migrate(void) ahci_migrate(src, dst, uri); =20 /* Complete the command */ - s =3D "{'execute':'cont' }"; - qmp_send(s); + qmp_send("{'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 7ab09c3448..89c4468c83 100644 --- a/tests/ide-test.c +++ b/tests/ide-test.c @@ -697,7 +697,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 @@ -725,8 +724,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.17.1 From nobody Sat Feb 7 09:12:01 2026 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 1534409656711817.2533018956789; Thu, 16 Aug 2018 01:54:16 -0700 (PDT) Received: from localhost ([::1]:54312 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqE2p-0004Xa-Gh for importer@patchew.org; Thu, 16 Aug 2018 04:54:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50750) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDmt-0001Ci-Rq for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmq-0005XY-L4 for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:47 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51376 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 1fqDml-0005CN-BY for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:42 -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 BE522401299A for ; Thu, 16 Aug 2018 08:37:04 +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 5E0142166BB1 for ; Thu, 16 Aug 2018 08:37:04 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0A09C1138669; Thu, 16 Aug 2018 10:37:02 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:36:48 +0200 Message-Id: <20180816083701.3932-13-armbru@redhat.com> In-Reply-To: <20180816083701.3932-1-armbru@redhat.com> References: <20180816083701.3932-1-armbru@redhat.com> MIME-Version: 1.0 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.6]); Thu, 16 Aug 2018 08:37:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 16 Aug 2018 08:37:04 +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:'' Content-Transfer-Encoding: quoted-printable 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 12/25] 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: RDMRC_1 RSF_0 Z_629925259 SPT_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_vjsonf_nofail() would abort. A sufficiently nasty @uri could even inject unwanted members into the arguments object. 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 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-13-armbru@redhat.com> --- tests/libqos/pci-pc.c | 9 +-- tests/libqtest.c | 7 +- tests/migration-test.c | 8 +-- tests/test-qga.c | 150 ++++++++++++++++++---------------------- tests/tpm-util.c | 9 +-- tests/vhost-user-test.c | 6 +- 6 files changed, 77 insertions(+), 112 deletions(-) diff --git a/tests/libqos/pci-pc.c b/tests/libqos/pci-pc.c index a7803308b7..585f5289ec 100644 --- a/tests/libqos/pci-pc.c +++ b/tests/libqos/pci-pc.c @@ -160,14 +160,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")); qobject_unref(response); diff --git a/tests/libqtest.c b/tests/libqtest.c index 9e3870bb7d..81b17f6fc9 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -1054,12 +1054,9 @@ void qtest_qmp_device_add(const char *driver, const = char *id, const char *fmt, void qtest_qmp_device_del(const char *id) { QDict *response1, *response2, *event =3D NULL; - char *cmd; =20 - cmd =3D g_strdup_printf("{'execute': 'device_del'," - " 'arguments': { 'id': '%s' }}", id); - response1 =3D qmp(cmd); - g_free(cmd); + response1 =3D qmp("{'execute': 'device_del', 'arguments': {'id': %s}}", + id); g_assert(response1); g_assert(!qdict_haskey(response1, "error")); =20 diff --git a/tests/migration-test.c b/tests/migration-test.c index bbe9c9e95d..486059580c 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -532,14 +532,12 @@ 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; - gchar *cmd; char *expected; int64_t result_int; =20 - cmd =3D g_strdup_printf("{ 'execute': 'migrate_set_downtime'," - "'arguments': { 'value': %g } }", value); - rsp =3D qtest_qmp(who, cmd); - g_free(cmd); + 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; diff --git a/tests/test-qga.c b/tests/test-qga.c index d638b1571a..c552cc0125 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -146,12 +146,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. @@ -188,7 +187,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 @@ -201,10 +199,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); @@ -428,7 +425,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; @@ -446,10 +443,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 @@ -459,23 +456,20 @@ static void test_qga_file_ops(gconstpointer fix) g_assert_cmpint(count, =3D=3D, sizeof(helloworld)); g_assert_cmpint(eof, =3D=3D, 0); qobject_unref(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); qobject_unref(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); qobject_unref(ret); - g_free(cmd); =20 /* check content */ path =3D g_build_filename(fixture->test_dir, "foo", NULL); @@ -497,10 +491,10 @@ static void test_qga_file_ops(gconstpointer fix) qobject_unref(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"); @@ -510,14 +504,13 @@ static void test_qga_file_ops(gconstpointer fix) g_assert_cmpstr(b64, =3D=3D, enc); =20 qobject_unref(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"); @@ -526,14 +519,13 @@ static void test_qga_file_ops(gconstpointer fix) g_assert(eof); g_assert_cmpstr(b64, =3D=3D, ""); qobject_unref(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"); @@ -541,13 +533,12 @@ static void test_qga_file_ops(gconstpointer fix) g_assert_cmpint(count, =3D=3D, 6); g_assert(!eof); qobject_unref(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"); @@ -560,15 +551,13 @@ static void test_qga_file_ops(gconstpointer fix) g_free(dec); =20 qobject_unref(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); qobject_unref(ret); - g_free(cmd); } =20 static void test_qga_file_write_read(gconstpointer fix) @@ -576,7 +565,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; @@ -591,10 +580,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 @@ -604,13 +593,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); qobject_unref(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"); @@ -619,14 +607,13 @@ static void test_qga_file_write_read(gconstpointer fi= x) g_assert(eof); g_assert_cmpstr(b64, =3D=3D, ""); qobject_unref(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"); @@ -634,13 +621,12 @@ static void test_qga_file_write_read(gconstpointer fi= x) g_assert_cmpint(count, =3D=3D, 0); g_assert(!eof); qobject_unref(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"); @@ -649,16 +635,14 @@ static void test_qga_file_write_read(gconstpointer fi= x) g_assert(eof); g_assert_cmpstr(b64, =3D=3D, enc); qobject_unref(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); qobject_unref(ret); - g_free(cmd); } =20 static void test_qga_get_time(gconstpointer fix) @@ -814,7 +798,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': {" @@ -829,10 +812,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"); @@ -842,7 +825,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/tpm-util.c b/tests/tpm-util.c index 672cedf905..3bd2887f1e 100644 --- a/tests/tpm-util.c +++ b/tests/tpm-util.c @@ -239,13 +239,10 @@ void tpm_util_swtpm_kill(GPid pid) void tpm_util_migrate(QTestState *who, const char *uri) { QDict *rsp; - gchar *cmd; =20 - cmd =3D g_strdup_printf("{ 'execute': 'migrate'," - "'arguments': { 'uri': '%s' } }", - uri); - rsp =3D qtest_qmp(who, cmd); - g_free(cmd); + rsp =3D qtest_qmp(who, + "{ 'execute': 'migrate', 'arguments': { 'uri': %s } }", + uri); g_assert(qdict_haskey(rsp, "return")); qobject_unref(rsp); } diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c index fecc832d99..ca6251f5f8 100644 --- a/tests/vhost-user-test.c +++ b/tests/vhost-user-test.c @@ -709,11 +709,7 @@ static void test_migrate(void) g_assert(qdict_haskey(rsp, "return")); qobject_unref(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")); qobject_unref(rsp); =20 --=20 2.17.1 From nobody Sat Feb 7 09:12:01 2026 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 1534409176081157.6707738094982; Thu, 16 Aug 2018 01:46:16 -0700 (PDT) Received: from localhost ([::1]:54271 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDv5-0003V9-0S for importer@patchew.org; Thu, 16 Aug 2018 04:46:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50657) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDml-000152-CV for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmY-0005II-Kj for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:29 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53668 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-00059R-9Y for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:20 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 860D84076510 for ; Thu, 16 Aug 2018 08:37:04 +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 5F72710EE991; Thu, 16 Aug 2018 08:37:04 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0D73C113866C; Thu, 16 Aug 2018 10:37:02 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:36:49 +0200 Message-Id: <20180816083701.3932-14-armbru@redhat.com> In-Reply-To: <20180816083701.3932-1-armbru@redhat.com> References: <20180816083701.3932-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 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:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 16 Aug 2018 08:37:04 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'armbru@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable 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 13/25] cpu-plug-test: Don't pass integers as strings to device_add 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: Thomas Huth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" test_plug_with_device_add_x86() plugs Haswell-i386-cpu and Haswell-x86_64-cpu with device_add. It passes socket-id, core-id, thread-id as JSON strings. The properties are actually integers. test_plug_with_device_add_coreid() plugs power8_v2.0-spapr-cpu-core and qemu-s390x-cpu with device_add. It passes core-id as JSON string. The properties are actually integers. Passing JSON string values to integer properties works only due to device_add implementation accidents. Fix the test to pass JSON numbers. While there, use %u rather than %i with unsigned int. Cc: Thomas Huth Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Thomas Huth Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-14-armbru@redhat.com> --- tests/cpu-plug-test.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/cpu-plug-test.c b/tests/cpu-plug-test.c index 5f39ba0df3..ab3bf6df90 100644 --- a/tests/cpu-plug-test.c +++ b/tests/cpu-plug-test.c @@ -88,8 +88,8 @@ static void test_plug_with_device_add_x86(gconstpointer d= ata) for (c =3D 0; c < td->cores; c++) { for (t =3D 0; t < td->threads; t++) { char *id =3D g_strdup_printf("id-%i-%i-%i", s, c, t); - qtest_qmp_device_add(td->device_model, id, "'socket-id':'%= i', " - "'core-id':'%i', 'thread-id':'%i'", + qtest_qmp_device_add(td->device_model, id, "'socket-id':%u= , " + "'core-id':%u, 'thread-id':%u", s, c, t); g_free(id); } @@ -114,7 +114,7 @@ static void test_plug_with_device_add_coreid(gconstpoin= ter data) =20 for (c =3D td->cores; c < td->maxcpus / td->sockets / td->threads; c++= ) { char *id =3D g_strdup_printf("id-%i", c); - qtest_qmp_device_add(td->device_model, id, "'core-id':'%i'", c); + qtest_qmp_device_add(td->device_model, id, "'core-id':%u", c); g_free(id); } =20 --=20 2.17.1 From nobody Sat Feb 7 09:12:01 2026 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 1534409811607760.0064521295236; Thu, 16 Aug 2018 01:56:51 -0700 (PDT) Received: from localhost ([::1]:54328 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqE5K-0008Ug-8U for importer@patchew.org; Thu, 16 Aug 2018 04:56:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50749) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDmt-0001Ch-Ro for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmq-0005XH-Hu for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:47 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51378 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 1fqDmf-0005CO-HT for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:39 -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 C6DCD4005F79 for ; Thu, 16 Aug 2018 08:37:04 +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 617FA2166BB3; Thu, 16 Aug 2018 08:37:04 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 110DC113866D; Thu, 16 Aug 2018 10:37:02 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:36:50 +0200 Message-Id: <20180816083701.3932-15-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.6]); Thu, 16 Aug 2018 08:37:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 16 Aug 2018 08:37:04 +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 14/25] tests: Clean up string interpolation around qtest_qmp_device_add() 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: Thomas Huth 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 commit before previous. qtest_qmp_device_add() and its wrappers interpolate into JSON as follows: * qtest_qmp_device_add() interpolates members into a JSON object. * So do its wrappers qpci_plug_device_test() and usb_test_hotplug(). * usb_test_hotplug() additionally interpolates strings and numbers into JSON strings. Clean them up: * Have qtest_qmp_device_add() take its extra device properties as arguments for qdict_from_jsonf_nofail() instead of a string containing JSON members. * Drop qpci_plug_device_test(), use qtest_qmp_device_add() directly. * Change usb_test_hotplug() parameter @port to string, to avoid interpolation. Interpolate @hcd_id separately. Bonus: gets rid of a non-literal format string. A step towards compile-time format string checking without triggering -Wformat-nonliteral. Cc: Thomas Huth Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-15-armbru@redhat.com> --- tests/cpu-plug-test.c | 7 ++++--- tests/e1000e-test.c | 6 ++---- tests/ivshmem-test.c | 8 +++----- tests/libqos/pci.c | 7 ------- tests/libqos/pci.h | 2 -- tests/libqos/usb.c | 10 ++++++---- tests/libqos/usb.h | 2 +- tests/libqtest.c | 27 +++++++++++---------------- tests/libqtest.h | 4 +++- tests/usb-hcd-ehci-test.c | 2 +- tests/usb-hcd-ohci-test.c | 2 +- tests/usb-hcd-uhci-test.c | 4 ++-- tests/usb-hcd-xhci-test.c | 10 +++++----- tests/virtio-blk-test.c | 5 +++-- tests/virtio-net-test.c | 3 ++- tests/virtio-rng-test.c | 3 ++- tests/virtio-scsi-test.c | 2 +- tests/virtio-serial-test.c | 2 +- 18 files changed, 48 insertions(+), 58 deletions(-) diff --git a/tests/cpu-plug-test.c b/tests/cpu-plug-test.c index ab3bf6df90..f5d57da60e 100644 --- a/tests/cpu-plug-test.c +++ b/tests/cpu-plug-test.c @@ -88,8 +88,9 @@ static void test_plug_with_device_add_x86(gconstpointer d= ata) for (c =3D 0; c < td->cores; c++) { for (t =3D 0; t < td->threads; t++) { char *id =3D g_strdup_printf("id-%i-%i-%i", s, c, t); - qtest_qmp_device_add(td->device_model, id, "'socket-id':%u= , " - "'core-id':%u, 'thread-id':%u", + qtest_qmp_device_add(td->device_model, id, + "{'socket-id':%u, 'core-id':%u," + " 'thread-id':%u}", s, c, t); g_free(id); } @@ -114,7 +115,7 @@ static void test_plug_with_device_add_coreid(gconstpoin= ter data) =20 for (c =3D td->cores; c < td->maxcpus / td->sockets / td->threads; c++= ) { char *id =3D g_strdup_printf("id-%i", c); - qtest_qmp_device_add(td->device_model, id, "'core-id':%u", c); + qtest_qmp_device_add(td->device_model, id, "{'core-id':%u}", c); g_free(id); } =20 diff --git a/tests/e1000e-test.c b/tests/e1000e-test.c index 32aa738b72..c9408a5d1f 100644 --- a/tests/e1000e-test.c +++ b/tests/e1000e-test.c @@ -456,12 +456,10 @@ static void test_e1000e_multiple_transfers(gconstpoin= ter data) =20 static void test_e1000e_hotplug(gconstpointer data) { - static const uint8_t slot =3D 0x06; - qtest_start("-device e1000e"); =20 - qpci_plug_device_test("e1000e", "e1000e_net", slot, NULL); - qpci_unplug_acpi_device_test("e1000e_net", slot); + qtest_qmp_device_add("e1000e", "e1000e_net", "{'addr': '0x06'}"); + qpci_unplug_acpi_device_test("e1000e_net", 0x06); =20 qtest_end(); } diff --git a/tests/ivshmem-test.c b/tests/ivshmem-test.c index 9b407a3e42..c37b196b32 100644 --- a/tests/ivshmem-test.c +++ b/tests/ivshmem-test.c @@ -420,19 +420,17 @@ static void test_ivshmem_server_irq(void) static void test_ivshmem_hotplug(void) { const char *arch =3D qtest_get_arch(); - gchar *opts; =20 qtest_start(""); =20 - opts =3D g_strdup_printf("'shm': '%s', 'size': '1M'", tmpshm); - - qpci_plug_device_test("ivshmem", "iv1", PCI_SLOT_HP, opts); + qtest_qmp_device_add("ivshmem", + "iv1", "{'addr': %s, 'shm': %s, 'size': '1M'}", + stringify(PCI_SLOT_HP), tmpshm); 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 0b73cb23d0..e8c342c257 100644 --- a/tests/libqos/pci.c +++ b/tests/libqos/pci.c @@ -395,10 +395,3 @@ QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t ad= dr) QPCIBar bar =3D { .addr =3D addr }; return bar; } - -void qpci_plug_device_test(const char *driver, const char *id, - uint8_t slot, const char *opts) -{ - qtest_qmp_device_add(driver, id, "'addr': '%d'%s%s", slot, - opts ? ", " : "", opts ? opts : ""); -} diff --git a/tests/libqos/pci.h b/tests/libqos/pci.h index 429c382282..0b7e936174 100644 --- a/tests/libqos/pci.h +++ b/tests/libqos/pci.h @@ -109,7 +109,5 @@ QPCIBar qpci_iomap(QPCIDevice *dev, int barno, uint64_t= *sizeptr); 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); void qpci_unplug_acpi_device_test(const char *id, uint8_t slot); #endif diff --git a/tests/libqos/usb.c b/tests/libqos/usb.c index 2a476049a8..49e2f4bc0a 100644 --- a/tests/libqos/usb.c +++ b/tests/libqos/usb.c @@ -37,13 +37,14 @@ void uhci_port_test(struct qhc *hc, int port, uint16_t = expect) g_assert((value & mask) =3D=3D (expect & mask)); } =20 -void usb_test_hotplug(const char *hcd_id, const int port, +void usb_test_hotplug(const char *hcd_id, const char *port, void (*port_check)(void)) { - char *id =3D g_strdup_printf("usbdev%d", port); + char *id =3D g_strdup_printf("usbdev%s", port); + char *bus =3D g_strdup_printf("%s.0", hcd_id); =20 - qtest_qmp_device_add("usb-tablet", id, "'port': '%d', 'bus': '%s.0'", - port, hcd_id); + qtest_qmp_device_add("usb-tablet", id, "{'port': %s, 'bus': %s}", + port, bus); =20 if (port_check) { port_check(); @@ -51,5 +52,6 @@ void usb_test_hotplug(const char *hcd_id, const int port, =20 qtest_qmp_device_del(id); =20 + g_free(bus); g_free(id); } diff --git a/tests/libqos/usb.h b/tests/libqos/usb.h index 297cfc564d..c506418a13 100644 --- a/tests/libqos/usb.h +++ b/tests/libqos/usb.h @@ -13,6 +13,6 @@ void qusb_pci_init_one(QPCIBus *pcibus, struct qhc *hc, void uhci_port_test(struct qhc *hc, int port, uint16_t expect); void uhci_deinit(struct qhc *hc); =20 -void usb_test_hotplug(const char *bus_name, const int port, +void usb_test_hotplug(const char *bus_name, const char *port, void (*port_check)(void)); #endif diff --git a/tests/libqtest.c b/tests/libqtest.c index 81b17f6fc9..17c91f5c47 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -1007,26 +1007,21 @@ void qtest_cb_for_every_machine(void (*cb)(const ch= ar *machine)) /* * Generic hot-plugging test via the device_add QMP command. */ -void qtest_qmp_device_add(const char *driver, const char *id, const char *= fmt, - ...) +void qtest_qmp_device_add(const char *driver, const char *id, + const char *fmt, ...) { - QDict *response; - char *cmd, *opts =3D NULL; - va_list va; + QDict *args, *response; + va_list ap; =20 - if (fmt) { - va_start(va, fmt); - opts =3D g_strdup_vprintf(fmt, va); - va_end(va); - } + va_start(ap, fmt); + args =3D qdict_from_vjsonf_nofail(fmt, ap); + va_end(ap); =20 - cmd =3D g_strdup_printf("{'execute': 'device_add'," - " 'arguments': { 'driver': '%s', 'id': '%s'%s%s = }}", - driver, id, opts ? ", " : "", opts ? opts : ""); - g_free(opts); + g_assert(!qdict_haskey(args, "driver") && !qdict_haskey(args, "id")); + qdict_put_str(args, "driver", driver); + qdict_put_str(args, "id", id); =20 - response =3D qmp(cmd); - g_free(cmd); + response =3D qmp("{'execute': 'device_add', 'arguments': %p}", args); g_assert(response); g_assert(!qdict_haskey(response, "event")); /* We don't expect any eve= nts */ g_assert(!qdict_haskey(response, "error")); diff --git a/tests/libqtest.h b/tests/libqtest.h index 0eff8763ce..70e9c5157c 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -943,7 +943,9 @@ void qtest_cb_for_every_machine(void (*cb)(const char *= machine)); * qtest_qmp_device_add: * @driver: Name of the device that should be added * @id: Identification string - * @fmt: printf-like format string for further options to device_add + * @fmt...: QMP message to send to qemu, formatted like + * qobject_from_jsonf_nofail(). See parse_escape() for what's + * supported after '%'. * * Generic hot-plugging test via the device_add QMP command. */ diff --git a/tests/usb-hcd-ehci-test.c b/tests/usb-hcd-ehci-test.c index 55d4743a2a..f28ea27f37 100644 --- a/tests/usb-hcd-ehci-test.c +++ b/tests/usb-hcd-ehci-test.c @@ -139,7 +139,7 @@ static void pci_ehci_port_3_hotplug(void) =20 static void pci_ehci_port_hotplug(void) { - usb_test_hotplug("ich9-ehci-1", 3, pci_ehci_port_3_hotplug); + usb_test_hotplug("ich9-ehci-1", "3", pci_ehci_port_3_hotplug); } =20 =20 diff --git a/tests/usb-hcd-ohci-test.c b/tests/usb-hcd-ohci-test.c index 4758813d78..48ddbfd26d 100644 --- a/tests/usb-hcd-ohci-test.c +++ b/tests/usb-hcd-ohci-test.c @@ -19,7 +19,7 @@ static void test_ohci_init(void) =20 static void test_ohci_hotplug(void) { - usb_test_hotplug("ohci", 1, NULL); + usb_test_hotplug("ohci", "1", NULL); } =20 int main(int argc, char **argv) diff --git a/tests/usb-hcd-uhci-test.c b/tests/usb-hcd-uhci-test.c index 6a7e5a2fed..a119d6d5c8 100644 --- a/tests/usb-hcd-uhci-test.c +++ b/tests/usb-hcd-uhci-test.c @@ -43,12 +43,12 @@ static void test_port_2(void) =20 static void test_uhci_hotplug(void) { - usb_test_hotplug("uhci", 2, test_port_2); + usb_test_hotplug("uhci", "2", test_port_2); } =20 static void test_usb_storage_hotplug(void) { - qtest_qmp_device_add("usb-storage", "usbdev0", "'drive': 'drive0'"); + qtest_qmp_device_add("usb-storage", "usbdev0", "{'drive': 'drive0'}"); =20 qtest_qmp_device_del("usbdev0"); } diff --git a/tests/usb-hcd-xhci-test.c b/tests/usb-hcd-xhci-test.c index 5b1b681bf2..9eb24b00e4 100644 --- a/tests/usb-hcd-xhci-test.c +++ b/tests/usb-hcd-xhci-test.c @@ -18,13 +18,13 @@ static void test_xhci_init(void) =20 static void test_xhci_hotplug(void) { - usb_test_hotplug("xhci", 1, NULL); + usb_test_hotplug("xhci", "1", NULL); } =20 static void test_usb_uas_hotplug(void) { - qtest_qmp_device_add("usb-uas", "uas", NULL); - qtest_qmp_device_add("scsi-hd", "scsihd", "'drive': 'drive0'"); + qtest_qmp_device_add("usb-uas", "uas", "{}"); + qtest_qmp_device_add("scsi-hd", "scsihd", "{'drive': 'drive0'}"); =20 /* TODO: UAS HBA driver in libqos, to check that @@ -37,10 +37,10 @@ static void test_usb_uas_hotplug(void) =20 static void test_usb_ccid_hotplug(void) { - qtest_qmp_device_add("usb-ccid", "ccid", NULL); + qtest_qmp_device_add("usb-ccid", "ccid", "{}"); qtest_qmp_device_del("ccid"); /* check the device can be added again */ - qtest_qmp_device_add("usb-ccid", "ccid", NULL); + qtest_qmp_device_add("usb-ccid", "ccid", "{}"); qtest_qmp_device_del("ccid"); } =20 diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index 06226b8717..571489d763 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -666,8 +666,9 @@ static void pci_hotplug(void) qs =3D pci_test_start(); =20 /* plug secondary disk */ - qpci_plug_device_test("virtio-blk-pci", "drv1", PCI_SLOT_HP, - "'drive': 'drive1'"); + qtest_qmp_device_add("virtio-blk-pci", "drv1", + "{'addr': %s, 'drive': 'drive1'}", + stringify(PCI_SLOT_HP)); =20 dev =3D virtio_blk_pci_init(qs->pcibus, PCI_SLOT_HP); g_assert(dev); diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c index b285a262e9..dcb87a8b6e 100644 --- a/tests/virtio-net-test.c +++ b/tests/virtio-net-test.c @@ -249,7 +249,8 @@ static void hotplug(void) =20 qtest_start("-device virtio-net-pci"); =20 - qpci_plug_device_test("virtio-net-pci", "net1", PCI_SLOT_HP, NULL); + qtest_qmp_device_add("virtio-net-pci", "net1", + "{'addr': %s}", stringify(PCI_SLOT_HP)); =20 if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0) { qpci_unplug_acpi_device_test("net1", PCI_SLOT_HP); diff --git a/tests/virtio-rng-test.c b/tests/virtio-rng-test.c index dcecf77463..657d9a4105 100644 --- a/tests/virtio-rng-test.c +++ b/tests/virtio-rng-test.c @@ -22,7 +22,8 @@ static void hotplug(void) { const char *arch =3D qtest_get_arch(); =20 - qpci_plug_device_test("virtio-rng-pci", "rng1", PCI_SLOT_HP, NULL); + qtest_qmp_device_add("virtio-rng-pci", "rng1", + "{'addr': %s}", stringify(PCI_SLOT_HP)); =20 if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0) { qpci_unplug_acpi_device_test("rng1", PCI_SLOT_HP); diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c index 037872bb98..0d4f25d369 100644 --- a/tests/virtio-scsi-test.c +++ b/tests/virtio-scsi-test.c @@ -199,7 +199,7 @@ static void hotplug(void) =20 qs =3D qvirtio_scsi_start( "-drive id=3Ddrv1,if=3Dnone,file=3Dnull-co://,format=3Draw"); - qtest_qmp_device_add("scsi-hd", "scsihd", "'drive': 'drv1'"); + qtest_qmp_device_add("scsi-hd", "scsihd", "{'drive': 'drv1'}"); qtest_qmp_device_del("scsihd"); qvirtio_scsi_stop(qs); } diff --git a/tests/virtio-serial-test.c b/tests/virtio-serial-test.c index 7cc7060264..e4b18b1c8a 100644 --- a/tests/virtio-serial-test.c +++ b/tests/virtio-serial-test.c @@ -18,7 +18,7 @@ static void virtio_serial_nop(void) =20 static void hotplug(void) { - qtest_qmp_device_add("virtserialport", "hp-port", NULL); + qtest_qmp_device_add("virtserialport", "hp-port", "{}"); =20 qtest_qmp_device_del("hp-port"); } --=20 2.17.1 From nobody Sat Feb 7 09:12:01 2026 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 1534409348344420.38371363459805; Thu, 16 Aug 2018 01:49:08 -0700 (PDT) Received: from localhost ([::1]:54284 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDxr-000797-6W for importer@patchew.org; Thu, 16 Aug 2018 04:49:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50693) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDmq-0001AL-H7 for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmf-0005NL-Ho for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:39 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51384 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 1fqDmV-0005CV-67 for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:25 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A010D4028152 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 56AED100F350; Thu, 16 Aug 2018 08:37:05 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 1489711386AB; Thu, 16 Aug 2018 10:37:02 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:36:51 +0200 Message-Id: <20180816083701.3932-16-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.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 16 Aug 2018 08:37:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 16 Aug 2018 08:37:05 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 15/25] migration-test: Make wait_command() return the "return" member 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" All callers of wait_command() are only interested in the success response's "return" member. Lift its extraction into wait_command(). 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-16-armbru@redhat.com> --- tests/migration-test.c | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/tests/migration-test.c b/tests/migration-test.c index 486059580c..db652e30a0 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -155,7 +155,7 @@ static void wait_for_serial(const char *side) static QDict *wait_command(QTestState *who, const char *command) { const char *event_string; - QDict *response; + QDict *response, *ret; =20 response =3D qtest_qmp(who, command); =20 @@ -168,7 +168,12 @@ static QDict *wait_command(QTestState *who, const char= *command) qobject_unref(response); response =3D qtest_qmp_receive(who); } - return response; + + ret =3D qdict_get_qdict(response, "return"); + g_assert(ret); + qobject_ref(ret); + qobject_unref(response); + return ret; } =20 /* @@ -177,15 +182,7 @@ static QDict *wait_command(QTestState *who, const char= *command) */ static QDict *migrate_query(QTestState *who) { - QDict *rsp, *rsp_return; - - rsp =3D wait_command(who, "{ 'execute': 'query-migrate' }"); - rsp_return =3D qdict_get_qdict(rsp, "return"); - g_assert(rsp_return); - qobject_ref(rsp_return); - qobject_unref(rsp); - - return rsp_return; + return wait_command(who, "{ 'execute': 'query-migrate' }"); } =20 /* @@ -327,16 +324,16 @@ static void cleanup(const char *filename) static void migrate_check_parameter(QTestState *who, const char *parameter, const char *value) { - QDict *rsp, *rsp_return; + QDict *rsp_return; char *result; =20 - rsp =3D wait_command(who, "{ 'execute': 'query-migrate-parameters' }"); - rsp_return =3D qdict_get_qdict(rsp, "return"); + 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); - qobject_unref(rsp); + qobject_unref(rsp_return); } =20 static void migrate_set_parameter(QTestState *who, const char *parameter, @@ -360,7 +357,6 @@ static void migrate_pause(QTestState *who) QDict *rsp; =20 rsp =3D wait_command(who, "{ 'execute': 'migrate-pause' }"); - g_assert(qdict_haskey(rsp, "return")); qobject_unref(rsp); } =20 @@ -373,7 +369,6 @@ static void migrate_recover(QTestState *who, const char= *uri) " 'arguments': { 'uri': '%s' } }", uri); =20 rsp =3D wait_command(who, cmd); - g_assert(qdict_haskey(rsp, "return")); g_free(cmd); qobject_unref(rsp); } @@ -414,7 +409,6 @@ static void migrate_postcopy_start(QTestState *from, QT= estState *to) QDict *rsp; =20 rsp =3D wait_command(from, "{ 'execute': 'migrate-start-postcopy' }"); - g_assert(qdict_haskey(rsp, "return")); qobject_unref(rsp); =20 if (!got_stop) { @@ -692,7 +686,7 @@ static void test_postcopy_recovery(void) static void test_baddest(void) { QTestState *from, *to; - QDict *rsp, *rsp_return; + QDict *rsp_return; char *status; bool failed; =20 @@ -708,12 +702,10 @@ static void test_baddest(void) } while (!failed); =20 /* Is the machine currently running? */ - rsp =3D wait_command(from, "{ 'execute': 'query-status' }"); - g_assert(qdict_haskey(rsp, "return")); - rsp_return =3D qdict_get_qdict(rsp, "return"); + rsp_return =3D wait_command(from, "{ 'execute': 'query-status' }"); g_assert(qdict_haskey(rsp_return, "running")); g_assert(qdict_get_bool(rsp_return, "running")); - qobject_unref(rsp); + qobject_unref(rsp_return); =20 test_migrate_end(from, to, false); } --=20 2.17.1 From nobody Sat Feb 7 09:12:01 2026 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 1534409907752922.1484017551346; Thu, 16 Aug 2018 01:58:27 -0700 (PDT) Received: from localhost ([::1]:54337 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqE6n-0001NZ-Ik for importer@patchew.org; Thu, 16 Aug 2018 04:58:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50704) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDmr-0001B3-0S for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmn-0005SE-Sr for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:44 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57664 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 1fqDma-0005AR-Jm for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:32 -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 56E185A754; Thu, 16 Aug 2018 08:37:06 +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 605EF20180F4; Thu, 16 Aug 2018 08:37:05 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 1836811386AE; Thu, 16 Aug 2018 10:37:02 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:36:52 +0200 Message-Id: <20180816083701.3932-17-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.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 16 Aug 2018 08:37:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 16 Aug 2018 08:37:06 +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] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 16/25] tests: New helper qtest_qmp_receive_success() 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: Thomas Huth , Stefan Berger , "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" Commit b21373d0713 copied wait_command() from tests/migration-test.c to tests/tpm-util.c. Replace both copies by new libqtest helper qtest_qmp_receive_success(). Also use it to simplify qtest_qmp_device_del(). Bonus: gets rid of a non-literal format string. A step towards compile-time format string checking without triggering -Wformat-nonliteral. Cc: Thomas Huth Cc: Juan Quintela Cc: Dr. David Alan Gilbert Cc: Stefan Berger Signed-off-by: Markus Armbruster Reviewed-by: Juan Quintela Reviewed-by: Stefan Berger Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-17-armbru@redhat.com> --- tests/libqtest.c | 69 ++++++++++++++++++++++++++++++------------ tests/libqtest.h | 17 +++++++++++ tests/migration-test.c | 29 ++++++------------ tests/tpm-util.c | 32 +++----------------- 4 files changed, 80 insertions(+), 67 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index 17c91f5c47..2f81bc6382 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -1004,6 +1004,35 @@ void qtest_cb_for_every_machine(void (*cb)(const cha= r *machine)) qobject_unref(response); } =20 +QDict *qtest_qmp_receive_success(QTestState *s, + void (*event_cb)(void *opaque, + const char *event, + QDict *data), + void *opaque) +{ + QDict *response, *ret, *data; + const char *event; + + for (;;) { + response =3D qtest_qmp_receive(s); + g_assert(!qdict_haskey(response, "error")); + ret =3D qdict_get_qdict(response, "return"); + if (ret) { + break; + } + event =3D qdict_get_str(response, "event"); + data =3D qdict_get_qdict(response, "data"); + if (event_cb) { + event_cb(opaque, event, data); + } + qobject_unref(response); + } + + qobject_ref(ret); + qobject_unref(response); + return ret; +} + /* * Generic hot-plugging test via the device_add QMP command. */ @@ -1028,6 +1057,14 @@ void qtest_qmp_device_add(const char *driver, const = char *id, qobject_unref(response); } =20 +static void device_deleted_cb(void *opaque, const char *name, QDict *data) +{ + bool *got_event =3D opaque; + + g_assert_cmpstr(name, =3D=3D, "DEVICE_DELETED"); + *got_event =3D true; +} + /* * Generic hot-unplugging test via the device_del QMP command. * Device deletion will get one response and one event. For example: @@ -1048,27 +1085,21 @@ void qtest_qmp_device_add(const char *driver, const= char *id, */ void qtest_qmp_device_del(const char *id) { - QDict *response1, *response2, *event =3D NULL; + bool got_event =3D false; + QDict *rsp; =20 - response1 =3D qmp("{'execute': 'device_del', 'arguments': {'id': %s}}", - id); - g_assert(response1); - g_assert(!qdict_haskey(response1, "error")); - - response2 =3D qmp_receive(); - g_assert(response2); - g_assert(!qdict_haskey(response2, "error")); - - if (qdict_haskey(response1, "event")) { - event =3D response1; - } else if (qdict_haskey(response2, "event")) { - event =3D response2; + qtest_qmp_send(global_qtest, + "{'execute': 'device_del', 'arguments': {'id': %s}}", + id); + rsp =3D qtest_qmp_receive_success(global_qtest, device_deleted_cb, + &got_event); + qobject_unref(rsp); + if (!got_event) { + rsp =3D qmp_receive(); + g_assert_cmpstr(qdict_get_try_str(rsp, "event"), + =3D=3D, "DEVICE_DELETED"); + qobject_unref(rsp); } - g_assert(event); - g_assert_cmpstr(qdict_get_str(event, "event"), =3D=3D, "DEVICE_DELETED= "); - - qobject_unref(response1); - qobject_unref(response2); } =20 bool qmp_rsp_is_err(QDict *rsp) diff --git a/tests/libqtest.h b/tests/libqtest.h index 70e9c5157c..d3da42623e 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -146,6 +146,23 @@ void qtest_qmp_eventwait(QTestState *s, const char *ev= ent); */ QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event); =20 +/** + * qtest_qmp_receive_success: + * @s: #QTestState instance to operate on + * @event_cb: Event callback + * @opaque: Argument for @event_cb + * + * Poll QMP messages until a command success response is received. + * If @event_cb, call it for each event received, passing @opaque, + * the event's name and data. + * Return the success response's "return" member. + */ +QDict *qtest_qmp_receive_success(QTestState *s, + void (*event_cb)(void *opaque, + const char *name, + QDict *data), + void *opaque); + /** * qtest_hmp: * @s: #QTestState instance to operate on. diff --git a/tests/migration-test.c b/tests/migration-test.c index db652e30a0..402c82bdc4 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -149,31 +149,20 @@ static void wait_for_serial(const char *side) } while (true); } =20 +static void stop_cb(void *opaque, const char *name, QDict *data) +{ + if (!strcmp(name, "STOP")) { + got_stop =3D true; + } +} + /* * Events can get in the way of responses we are actually waiting for. */ static QDict *wait_command(QTestState *who, const char *command) { - const char *event_string; - QDict *response, *ret; - - response =3D qtest_qmp(who, command); - - while (qdict_haskey(response, "event")) { - /* OK, it was an event */ - event_string =3D qdict_get_str(response, "event"); - if (!strcmp(event_string, "STOP")) { - got_stop =3D true; - } - qobject_unref(response); - response =3D qtest_qmp_receive(who); - } - - ret =3D qdict_get_qdict(response, "return"); - g_assert(ret); - qobject_ref(ret); - qobject_unref(response); - return ret; + qtest_qmp_send(who, command); + return qtest_qmp_receive_success(who, stop_cb, NULL); } =20 /* diff --git a/tests/tpm-util.c b/tests/tpm-util.c index 3bd2887f1e..9f3f156e42 100644 --- a/tests/tpm-util.c +++ b/tests/tpm-util.c @@ -22,8 +22,6 @@ #define TIS_REG(LOCTY, REG) \ (TPM_TIS_ADDR_BASE + ((LOCTY) << 12) + REG) =20 -static bool got_stop; - void tpm_util_crb_transfer(QTestState *s, const unsigned char *req, size_t req_size, unsigned char *rsp, size_t rsp_size) @@ -247,41 +245,19 @@ void tpm_util_migrate(QTestState *who, const char *ur= i) qobject_unref(rsp); } =20 -/* - * Events can get in the way of responses we are actually waiting for. - */ -static QDict *tpm_util_wait_command(QTestState *who, const char *command) -{ - const char *event_string; - QDict *response; - - response =3D qtest_qmp(who, command); - - while (qdict_haskey(response, "event")) { - /* OK, it was an event */ - event_string =3D qdict_get_str(response, "event"); - if (!strcmp(event_string, "STOP")) { - got_stop =3D true; - } - qobject_unref(response); - response =3D qtest_qmp_receive(who); - } - return response; -} - void tpm_util_wait_for_migration_complete(QTestState *who) { while (true) { - QDict *rsp, *rsp_return; + QDict *rsp_return; bool completed; const char *status; =20 - rsp =3D tpm_util_wait_command(who, "{ 'execute': 'query-migrate' }= "); - rsp_return =3D qdict_get_qdict(rsp, "return"); + qtest_qmp_send(who, "{ 'execute': 'query-migrate' }"); + rsp_return =3D qtest_qmp_receive_success(who, NULL, NULL); status =3D qdict_get_str(rsp_return, "status"); completed =3D strcmp(status, "completed") =3D=3D 0; g_assert_cmpstr(status, !=3D, "failed"); - qobject_unref(rsp); + qobject_unref(rsp_return); if (completed) { return; } --=20 2.17.1 From nobody Sat Feb 7 09:12:01 2026 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 1534409599167403.68967017169405; Thu, 16 Aug 2018 01:53:19 -0700 (PDT) Received: from localhost ([::1]:54311 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqE1u-0003q0-3e for importer@patchew.org; Thu, 16 Aug 2018 04:53:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50656) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDml-000151-CQ for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmY-0005ID-Kc for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:29 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53670 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-00059f-87 for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:20 -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 919CB40776DB 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 6BD9A76F3; Thu, 16 Aug 2018 08:37:05 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 1BB4611386B2; Thu, 16 Aug 2018 10:37:02 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:36:53 +0200 Message-Id: <20180816083701.3932-18-armbru@redhat.com> In-Reply-To: <20180816083701.3932-1-armbru@redhat.com> References: <20180816083701.3932-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, 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.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] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 17/25] migration-test: Make wait_command() cope with '%' 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" wait_command() passes its argument @command to qtest_qmp_send(). Falls apart if @command contain '%'. Two ways to disarm this trap: suppress interpretation of '%' by passing @command as argument to format string "%s", or fix it by having wait_command() take the variable arguments to go with @command. Do the latter. This is another 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-18-armbru@redhat.com> --- tests/migration-test.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/migration-test.c b/tests/migration-test.c index 402c82bdc4..7bffcd2e4d 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -159,9 +159,14 @@ static void stop_cb(void *opaque, const char *name, QD= ict *data) /* * Events can get in the way of responses we are actually waiting for. */ -static QDict *wait_command(QTestState *who, const char *command) +static QDict *wait_command(QTestState *who, const char *command, ...) { - qtest_qmp_send(who, command); + va_list ap; + + va_start(ap, command); + qtest_qmp_vsend(who, command, ap); + va_end(ap); + return qtest_qmp_receive_success(who, stop_cb, NULL); } =20 --=20 2.17.1 From nobody Sat Feb 7 09:12:01 2026 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 153440927643465.61002089598355; Thu, 16 Aug 2018 01:47:56 -0700 (PDT) Received: from localhost ([::1]:54282 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDwh-00069A-6z for importer@patchew.org; Thu, 16 Aug 2018 04:47:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50603) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDmf-0000yi-HH for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmQ-0005F8-JD for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:25 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37568 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 1fqDmH-00059z-Pi for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:11 -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 350DD406C7A9 for ; Thu, 16 Aug 2018 08:37:06 +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 6B97B20180F5; Thu, 16 Aug 2018 08:37:05 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 1F36411386B6; Thu, 16 Aug 2018 10:37:02 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:36:54 +0200 Message-Id: <20180816083701.3932-19-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.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 16 Aug 2018 08:37:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 16 Aug 2018 08:37:06 +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] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 18/25] migration-test: Clean up string interpolation into QMP, part 1 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)". migrate_recover() builds QMP input manually because wait_command() can't interpolate. Well, it can since the previous commit. Simplify accordingly. 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 Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-19-armbru@redhat.com> --- tests/migration-test.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/migration-test.c b/tests/migration-test.c index 7bffcd2e4d..4b8d4cc119 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -159,6 +159,7 @@ static void stop_cb(void *opaque, const char *name, QDi= ct *data) /* * Events can get in the way of responses we are actually waiting for. */ +GCC_FMT_ATTR(2, 3) static QDict *wait_command(QTestState *who, const char *command, ...) { va_list ap; @@ -357,13 +358,12 @@ static void migrate_pause(QTestState *who) static void migrate_recover(QTestState *who, const char *uri) { QDict *rsp; - gchar *cmd =3D g_strdup_printf( - "{ 'execute': 'migrate-recover', " - " 'id': 'recover-cmd', " - " 'arguments': { 'uri': '%s' } }", uri); =20 - rsp =3D wait_command(who, cmd); - g_free(cmd); + rsp =3D wait_command(who, + "{ 'execute': 'migrate-recover', " + " 'id': 'recover-cmd', " + " 'arguments': { 'uri': %s } }", + uri); qobject_unref(rsp); } =20 --=20 2.17.1 From nobody Sat Feb 7 09:12:01 2026 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 1534409602182238.7235645442713; Thu, 16 Aug 2018 01:53:22 -0700 (PDT) Received: from localhost ([::1]:54310 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqE1r-0003pe-Rc for importer@patchew.org; Thu, 16 Aug 2018 04:53:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50695) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDmq-0001AM-H9 for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmf-0005Nd-In for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:39 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37566 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 1fqDmW-00059l-4o for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37: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 B25B1406C7A7 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 6E4C27C37; Thu, 16 Aug 2018 08:37:05 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 22BB511386B9; Thu, 16 Aug 2018 10:37:02 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:36:55 +0200 Message-Id: <20180816083701.3932-20-armbru@redhat.com> In-Reply-To: <20180816083701.3932-1-armbru@redhat.com> References: <20180816083701.3932-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.5]); Thu, 16 Aug 2018 08:37:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 16 Aug 2018 08:37:05 +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] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 19/25] 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: 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)". 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 Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-20-armbru@redhat.com> --- tests/migration-test.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/tests/migration-test.c b/tests/migration-test.c index 4b8d4cc119..c7f3267fa0 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" @@ -384,16 +385,25 @@ 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) +/* + * Send QMP command "migrate". + * Arguments are built from @fmt... (formatted like + * qobject_from_jsonf_nofail()) with "uri": @uri spliced in. + */ +GCC_FMT_ATTR(3, 4) +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); } @@ -585,7 +595,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); @@ -668,7 +678,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 */ @@ -687,7 +697,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"))); @@ -725,7 +735,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 From nobody Sat Feb 7 09:12:01 2026 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 From nobody Sat Feb 7 09:12:01 2026 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 1534409513126821.160480936479; Thu, 16 Aug 2018 01:51:53 -0700 (PDT) Received: from localhost ([::1]:54303 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqE0W-0002o3-45 for importer@patchew.org; Thu, 16 Aug 2018 04:51:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50721) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDmr-0001BO-DC for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmq-0005XC-Hl for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:45 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51380 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 1fqDmi-0005CP-6q for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:39 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 937FB40201D7 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 6FC0C112D197 for ; Thu, 16 Aug 2018 08:37:05 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 29B2711386C0; Thu, 16 Aug 2018 10:37:02 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:36:57 +0200 Message-Id: <20180816083701.3932-22-armbru@redhat.com> In-Reply-To: <20180816083701.3932-1-armbru@redhat.com> References: <20180816083701.3932-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 16 Aug 2018 08:37:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 16 Aug 2018 08:37:05 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'armbru@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable 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 21/25] 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: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" qtest_qmp() & friends pass their format string and variable arguments to qobject_from_vjsonf_nofail(). 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: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-22-armbru@redhat.com> --- tests/libqtest.h | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/tests/libqtest.h b/tests/libqtest.h index d3da42623e..712ac023d6 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -82,7 +82,8 @@ void qtest_quit(QTestState *s); * * 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_qmp_send: @@ -93,7 +94,8 @@ QDict *qtest_qmp(QTestState *s, const char *fmt, ...); * * Sends a QMP message to QEMU and leaves the response in the stream. */ -void qtest_qmp_send(QTestState *s, const char *fmt, ...); +void qtest_qmp_send(QTestState *s, const char *fmt, ...) + GCC_FMT_ATTR(2, 3); =20 /** * qtest_qmpv: @@ -105,7 +107,8 @@ void qtest_qmp_send(QTestState *s, const char *fmt, ...= ); * * 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_qmp_vsend: @@ -117,7 +120,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_qmp_vsend(QTestState *s, const char *fmt, va_list ap); +void qtest_qmp_vsend(QTestState *s, const char *fmt, va_list ap) + GCC_FMT_ATTR(2, 0); =20 /** * qtest_receive: @@ -574,7 +578,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_send: @@ -584,7 +588,7 @@ QDict *qmp(const char *fmt, ...); * * Sends a QMP message to QEMU and leaves the response in the stream. */ -void qmp_send(const char *fmt, ...); +void qmp_send(const char *fmt, ...) GCC_FMT_ATTR(1, 2); =20 /** * qmp_receive: @@ -943,10 +947,10 @@ static inline int64_t clock_set(int64_t val) } =20 QDict *qmp_fd_receive(int fd); -void qmp_fd_vsend(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_vsend(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.17.1 From nobody Sat Feb 7 09:12:01 2026 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 1534409111672515.0397201116263; Thu, 16 Aug 2018 01:45:11 -0700 (PDT) Received: from localhost ([::1]:54264 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDtz-0000YO-3E for importer@patchew.org; Thu, 16 Aug 2018 04:45:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50607) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDmf-0000yl-HL for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmQ-0005F7-J9 for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:25 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57660 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 1fqDmH-00059p-O7 for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:11 -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 D69FC5A753 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 718F32156714 for ; Thu, 16 Aug 2018 08:37:05 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 2D39911386C1; Thu, 16 Aug 2018 10:37:02 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:36:58 +0200 Message-Id: <20180816083701.3932-23-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.2]); Thu, 16 Aug 2018 08:37:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); 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 22/25] libqtest: Replace qtest_startf() by qtest_initf() 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: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" qtest_init() creates a new QTestState, and leaves @global_qtest alone. qtest_start() additionally assigns it to @global_qtest, but qtest_startf() additionally assigns NULL to @global_qtest. This makes no sense. Replace it by qtest_initf() that works like qtest_init(), i.e. leaves @global_qtest alone. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-23-armbru@redhat.com> --- tests/boot-order-test.c | 8 ++++---- tests/boot-serial-test.c | 10 +++++----- tests/cdrom-test.c | 6 +++--- tests/endianness-test.c | 24 ++++++++++++------------ tests/ipmi-bt-test.c | 2 +- tests/libqtest.c | 9 ++++----- tests/libqtest.h | 17 ++++++++--------- tests/m25p80-test.c | 6 +++--- tests/m48t59-test.c | 2 +- tests/machine-none-test.c | 2 +- tests/numa-test.c | 4 ++-- tests/pnv-xscom-test.c | 8 ++++---- tests/prom-env-test.c | 10 +++++----- tests/qmp-test.c | 2 +- tests/sdhci-test.c | 6 +++--- tests/tco-test.c | 6 +++--- tests/test-filter-mirror.c | 2 +- tests/test-filter-redirector.c | 4 ++-- tests/virtio-balloon-test.c | 4 ++-- tests/virtio-blk-test.c | 8 ++++---- tests/virtio-console-test.c | 12 ++++++------ tests/virtio-serial-test.c | 4 ++-- tests/vmgenid-test.c | 6 +++--- 23 files changed, 80 insertions(+), 82 deletions(-) diff --git a/tests/boot-order-test.c b/tests/boot-order-test.c index 9096a4b5df..9d98c48a3d 100644 --- a/tests/boot-order-test.c +++ b/tests/boot-order-test.c @@ -33,10 +33,10 @@ static void test_a_boot_order(const char *machine, { uint64_t actual; =20 - global_qtest =3D qtest_startf("-nodefaults%s%s %s", - machine ? " -M " : "", - machine ?: "", - test_args); + global_qtest =3D qtest_initf("-nodefaults%s%s %s", + machine ? " -M " : "", + machine ?: "", + test_args); actual =3D read_boot_order(); g_assert_cmphex(actual, =3D=3D, expected_boot); qmp_discard_response("{ 'execute': 'system_reset' }"); diff --git a/tests/boot-serial-test.c b/tests/boot-serial-test.c index 952a2e7ead..1355df924d 100644 --- a/tests/boot-serial-test.c +++ b/tests/boot-serial-test.c @@ -172,11 +172,11 @@ static void test_machine(const void *data) * Make sure that this test uses tcg if available: It is used as a * fast-enough smoketest for that. */ - global_qtest =3D qtest_startf("%s %s -M %s,accel=3Dtcg:kvm " - "-chardev file,id=3Dserial0,path=3D%s " - "-no-shutdown -serial chardev:serial0 %s", - codeparam, code ? codetmp : "", - test->machine, serialtmp, test->extra); + global_qtest =3D qtest_initf("%s %s -M %s,accel=3Dtcg:kvm " + "-chardev file,id=3Dserial0,path=3D%s " + "-no-shutdown -serial chardev:serial0 %s", + codeparam, code ? codetmp : "", + test->machine, serialtmp, test->extra); if (code) { unlink(codetmp); } diff --git a/tests/cdrom-test.c b/tests/cdrom-test.c index 7a1fce5dfb..9b43dc9ab4 100644 --- a/tests/cdrom-test.c +++ b/tests/cdrom-test.c @@ -99,7 +99,7 @@ static void test_cdrom_param(gconstpointer data) QTestState *qts; char *resp; =20 - qts =3D qtest_startf("-M %s -cdrom %s", (const char *)data, isoimage); + qts =3D qtest_initf("-M %s -cdrom %s", (const char *)data, isoimage); resp =3D qtest_hmp(qts, "info block"); g_assert(strstr(resp, isoimage) !=3D 0); g_free(resp); @@ -120,8 +120,8 @@ static void test_cdboot(gconstpointer data) { QTestState *qts; =20 - qts =3D qtest_startf("-accel kvm:tcg -no-shutdown %s%s", (const char *= )data, - isoimage); + qts =3D qtest_initf("-accel kvm:tcg -no-shutdown %s%s", (const char *)= data, + isoimage); boot_sector_test(qts); qtest_quit(qts); } diff --git a/tests/endianness-test.c b/tests/endianness-test.c index 546e0969e4..48680cd131 100644 --- a/tests/endianness-test.c +++ b/tests/endianness-test.c @@ -115,10 +115,10 @@ static void test_endianness(gconstpointer data) { const TestCase *test =3D data; =20 - global_qtest =3D qtest_startf("-M %s%s%s -device pc-testdev", - test->machine, - test->superio ? " -device " : "", - test->superio ?: ""); + global_qtest =3D qtest_initf("-M %s%s%s -device pc-testdev", + test->machine, + test->superio ? " -device " : "", + test->superio ?: ""); isa_outl(test, 0xe0, 0x87654321); g_assert_cmphex(isa_inl(test, 0xe0), =3D=3D, 0x87654321); g_assert_cmphex(isa_inw(test, 0xe2), =3D=3D, 0x8765); @@ -187,10 +187,10 @@ static void test_endianness_split(gconstpointer data) { const TestCase *test =3D data; =20 - global_qtest =3D qtest_startf("-M %s%s%s -device pc-testdev", - test->machine, - test->superio ? " -device " : "", - test->superio ?: ""); + global_qtest =3D qtest_initf("-M %s%s%s -device pc-testdev", + test->machine, + test->superio ? " -device " : "", + test->superio ?: ""); isa_outl(test, 0xe8, 0x87654321); g_assert_cmphex(isa_inl(test, 0xe0), =3D=3D, 0x87654321); g_assert_cmphex(isa_inw(test, 0xe2), =3D=3D, 0x8765); @@ -231,10 +231,10 @@ static void test_endianness_combine(gconstpointer dat= a) { const TestCase *test =3D data; =20 - global_qtest =3D qtest_startf("-M %s%s%s -device pc-testdev", - test->machine, - test->superio ? " -device " : "", - test->superio ?: ""); + global_qtest =3D qtest_initf("-M %s%s%s -device pc-testdev", + test->machine, + test->superio ? " -device " : "", + test->superio ?: ""); isa_outl(test, 0xe0, 0x87654321); g_assert_cmphex(isa_inl(test, 0xe8), =3D=3D, 0x87654321); g_assert_cmphex(isa_inw(test, 0xea), =3D=3D, 0x8765); diff --git a/tests/ipmi-bt-test.c b/tests/ipmi-bt-test.c index 8be18e3f42..f4a81b5265 100644 --- a/tests/ipmi-bt-test.c +++ b/tests/ipmi-bt-test.c @@ -414,7 +414,7 @@ int main(int argc, char **argv) /* Run the tests */ g_test_init(&argc, &argv, NULL); =20 - global_qtest =3D qtest_startf( + global_qtest =3D qtest_initf( " -chardev socket,id=3Dipmi0,host=3Dlocalhost,port=3D%d,reconnect= =3D10" " -device ipmi-bmc-extern,chardev=3Dipmi0,id=3Dbmc0" " -device isa-ipmi-bt,bmc=3Dbmc0", emu_port); diff --git a/tests/libqtest.c b/tests/libqtest.c index 2f81bc6382..a0d44793fa 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -259,24 +259,23 @@ QTestState *qtest_init(const char *extra_args) return s; } =20 -QTestState *qtest_vstartf(const char *fmt, va_list ap) +QTestState *qtest_vinitf(const char *fmt, va_list ap) { char *args =3D g_strdup_vprintf(fmt, ap); QTestState *s; =20 - s =3D qtest_start(args); + s =3D qtest_init(args); g_free(args); - global_qtest =3D NULL; return s; } =20 -QTestState *qtest_startf(const char *fmt, ...) +QTestState *qtest_initf(const char *fmt, ...) { va_list ap; QTestState *s; =20 va_start(ap, fmt); - s =3D qtest_vstartf(fmt, ap); + s =3D qtest_vinitf(fmt, ap); va_end(ap); return s; } diff --git a/tests/libqtest.h b/tests/libqtest.h index 712ac023d6..b92a8070a5 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -22,33 +22,32 @@ typedef struct QTestState QTestState; extern QTestState *global_qtest; =20 /** - * qtest_startf: + * qtest_initf: * @fmt...: Format for creating other arguments to pass to QEMU, formatted * like sprintf(). * - * Start QEMU and return the resulting #QTestState (but unlike qtest_start= (), - * #global_qtest is left at NULL). + * Convenience wrapper around qtest_start(). * * Returns: #QTestState instance. */ -QTestState *qtest_startf(const char *fmt, ...) GCC_FMT_ATTR(1, 2); +QTestState *qtest_initf(const char *fmt, ...) GCC_FMT_ATTR(1, 2); =20 /** - * qtest_vstartf: + * qtest_vinitf: * @fmt: Format for creating other arguments to pass to QEMU, formatted * like vsprintf(). * @ap: Format arguments. * - * Start QEMU and return the resulting #QTestState (but unlike qtest_start= (), - * #global_qtest is left at NULL). + * Convenience wrapper around qtest_start(). * * Returns: #QTestState instance. */ -QTestState *qtest_vstartf(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0); +QTestState *qtest_vinitf(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0); =20 /** * qtest_init: - * @extra_args: other arguments to pass to QEMU. + * @extra_args: other arguments to pass to QEMU. CAUTION: these + * arguments are subject to word splitting and shell evaluation. * * Returns: #QTestState instance. */ diff --git a/tests/m25p80-test.c b/tests/m25p80-test.c index c276e738e9..055f7246a8 100644 --- a/tests/m25p80-test.c +++ b/tests/m25p80-test.c @@ -363,9 +363,9 @@ int main(int argc, char **argv) g_assert(ret =3D=3D 0); close(fd); =20 - global_qtest =3D qtest_startf("-m 256 -machine palmetto-bmc " - "-drive file=3D%s,format=3Draw,if=3Dmtd", - tmp_path); + global_qtest =3D qtest_initf("-m 256 -machine palmetto-bmc " + "-drive file=3D%s,format=3Draw,if=3Dmtd", + tmp_path); =20 qtest_add_func("/m25p80/read_jedec", test_read_jedec); qtest_add_func("/m25p80/erase_sector", test_erase_sector); diff --git a/tests/m48t59-test.c b/tests/m48t59-test.c index 5b695971c7..4abf9c605c 100644 --- a/tests/m48t59-test.c +++ b/tests/m48t59-test.c @@ -146,7 +146,7 @@ static void cmos_get_date_time(QTestState *s, struct tm= *date) =20 static QTestState *m48t59_qtest_start(void) { - return qtest_startf("-M %s -rtc clock=3Dvm", base_machine); + return qtest_initf("-M %s -rtc clock=3Dvm", base_machine); } =20 static void bcd_check_time(void) diff --git a/tests/machine-none-test.c b/tests/machine-none-test.c index f286557b3e..7e72466354 100644 --- a/tests/machine-none-test.c +++ b/tests/machine-none-test.c @@ -84,7 +84,7 @@ static void test_machine_cpu_cli(void) } return; /* TODO: die here to force all targets have a test */ } - global_qtest =3D qtest_startf("-machine none -cpu '%s'", cpu_model); + global_qtest =3D qtest_initf("-machine none -cpu '%s'", cpu_model); =20 response =3D qmp("{ 'execute': 'quit' }"); g_assert(qdict_haskey(response, "return")); diff --git a/tests/numa-test.c b/tests/numa-test.c index 893f826acb..9824fdd587 100644 --- a/tests/numa-test.c +++ b/tests/numa-test.c @@ -267,8 +267,8 @@ static void pc_dynamic_cpu_cfg(const void *data) QList *cpus; QTestState *qs; =20 - qs =3D qtest_startf("%s %s", data ? (char *)data : "", - "-nodefaults --preconfig -smp 2"); + qs =3D qtest_initf("%s -nodefaults --preconfig -smp 2", + data ? (char *)data : ""); =20 /* create 2 numa nodes */ g_assert(!qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," diff --git a/tests/pnv-xscom-test.c b/tests/pnv-xscom-test.c index efb7c838b5..70f4c84d1b 100644 --- a/tests/pnv-xscom-test.c +++ b/tests/pnv-xscom-test.c @@ -79,8 +79,8 @@ static void test_cfam_id(const void *data) { const PnvChip *chip =3D data; =20 - global_qtest =3D qtest_startf("-M powernv,accel=3Dtcg -cpu %s", - chip->cpu_model); + global_qtest =3D qtest_initf("-M powernv,accel=3Dtcg -cpu %s", + chip->cpu_model); test_xscom_cfam_id(chip); qtest_quit(global_qtest); } @@ -114,8 +114,8 @@ static void test_core(const void *data) { const PnvChip *chip =3D data; =20 - global_qtest =3D qtest_startf("-M powernv,accel=3Dtcg -cpu %s", - chip->cpu_model); + global_qtest =3D qtest_initf("-M powernv,accel=3Dtcg -cpu %s", + chip->cpu_model); test_xscom_core(chip); qtest_quit(global_qtest); } diff --git a/tests/prom-env-test.c b/tests/prom-env-test.c index 8c867e631a..198d007f1b 100644 --- a/tests/prom-env-test.c +++ b/tests/prom-env-test.c @@ -49,11 +49,11 @@ static void test_machine(const void *machine) /* The pseries firmware boots much faster without the default devices = */ extra_args =3D strcmp(machine, "pseries") =3D=3D 0 ? "-nodefaults" : "= "; =20 - global_qtest =3D qtest_startf("-M %s,accel=3Dtcg %s " - "-prom-env 'use-nvramrc?=3Dtrue' " - "-prom-env 'nvramrc=3D%x %x l!' ", - (const char *)machine, extra_args, - MAGIC, ADDRESS); + global_qtest =3D qtest_initf("-M %s,accel=3Dtcg %s " + "-prom-env 'use-nvramrc?=3Dtrue' " + "-prom-env 'nvramrc=3D%x %x l!' ", + (const char *)machine, extra_args, + MAGIC, ADDRESS); check_guest_memory(); qtest_quit(global_qtest); } diff --git a/tests/qmp-test.c b/tests/qmp-test.c index 5eb15daebc..487ef946ed 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -436,7 +436,7 @@ static void add_query_tests(QmpSchema *schema) static void test_qmp_preconfig(void) { QDict *rsp, *ret; - QTestState *qs =3D qtest_startf("%s --preconfig", common_args); + QTestState *qs =3D qtest_initf("%s --preconfig", common_args); =20 /* preconfig state */ /* enabled commands, no error expected */ diff --git a/tests/sdhci-test.c b/tests/sdhci-test.c index 1d825eb010..982f5ebbb2 100644 --- a/tests/sdhci-test.c +++ b/tests/sdhci-test.c @@ -184,8 +184,8 @@ static QSDHCI *machine_start(const struct sdhci_t *test) uint16_t vendor_id, device_id; uint64_t barsize; =20 - global_qtest =3D qtest_startf("-machine %s -device sdhci-pci", - test->machine); + global_qtest =3D qtest_initf("-machine %s -device sdhci-pci", + test->machine); =20 s->pci.bus =3D qpci_init_pc(global_qtest, NULL); =20 @@ -200,7 +200,7 @@ static QSDHCI *machine_start(const struct sdhci_t *test) qpci_device_enable(s->pci.dev); } else { /* SysBus */ - global_qtest =3D qtest_startf("-machine %s", test->machine); + global_qtest =3D qtest_initf("-machine %s", test->machine); s->addr =3D test->sdhci.addr; } =20 diff --git a/tests/tco-test.c b/tests/tco-test.c index 9945fb8469..6bee9a37d3 100644 --- a/tests/tco-test.c +++ b/tests/tco-test.c @@ -58,9 +58,9 @@ static void test_init(TestData *d) { QTestState *qs; =20 - qs =3D qtest_startf("-machine q35 %s %s", - d->noreboot ? "" : "-global ICH9-LPC.noreboot=3Dfals= e", - !d->args ? "" : d->args); + qs =3D qtest_initf("-machine q35 %s %s", + d->noreboot ? "" : "-global ICH9-LPC.noreboot=3Dfalse= ", + !d->args ? "" : d->args); global_qtest =3D qs; qtest_irq_intercept_in(qs, "ioapic"); =20 diff --git a/tests/test-filter-mirror.c b/tests/test-filter-mirror.c index de5ba155db..d15917e2cf 100644 --- a/tests/test-filter-mirror.c +++ b/tests/test-filter-mirror.c @@ -40,7 +40,7 @@ static void test_mirror(void) ret =3D mkstemp(sock_path); g_assert_cmpint(ret, !=3D, -1); =20 - global_qtest =3D qtest_startf( + global_qtest =3D qtest_initf( "-netdev socket,id=3Dqtest-bn0,fd=3D%d " "-device %s,netdev=3Dqtest-bn0,id=3Dqtest-e0 " "-chardev socket,id=3Dmirror0,path=3D%s,server,nowait " diff --git a/tests/test-filter-redirector.c b/tests/test-filter-redirector.c index 896f900e98..615ff5cb9f 100644 --- a/tests/test-filter-redirector.c +++ b/tests/test-filter-redirector.c @@ -90,7 +90,7 @@ static void test_redirector_tx(void) ret =3D mkstemp(sock_path1); g_assert_cmpint(ret, !=3D, -1); =20 - global_qtest =3D qtest_startf( + global_qtest =3D qtest_initf( "-netdev socket,id=3Dqtest-bn0,fd=3D%d " "-device %s,netdev=3Dqtest-bn0,id=3Dqtest-e0 " "-chardev socket,id=3Dredirector0,path=3D%s,server,nowait " @@ -159,7 +159,7 @@ static void test_redirector_rx(void) ret =3D mkstemp(sock_path1); g_assert_cmpint(ret, !=3D, -1); =20 - global_qtest =3D qtest_startf( + global_qtest =3D qtest_initf( "-netdev socket,id=3Dqtest-bn0,fd=3D%d " "-device %s,netdev=3Dqtest-bn0,id=3Dqtest-e0 " "-chardev socket,id=3Dredirector0,path=3D%s,server,nowait " diff --git a/tests/virtio-balloon-test.c b/tests/virtio-balloon-test.c index 0a07e036bb..5a1d0ccbb7 100644 --- a/tests/virtio-balloon-test.c +++ b/tests/virtio-balloon-test.c @@ -23,8 +23,8 @@ int main(int argc, char **argv) g_test_init(&argc, &argv, NULL); qtest_add_func("/virtio/balloon/nop", balloon_nop); =20 - global_qtest =3D qtest_startf("-device virtio-balloon-%s", - qvirtio_get_dev_type()); + global_qtest =3D qtest_initf("-device virtio-balloon-%s", + qvirtio_get_dev_type()); ret =3D g_test_run(); =20 qtest_end(); diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index 571489d763..04c608764b 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -93,10 +93,10 @@ static void arm_test_start(void) =20 tmp_path =3D drive_create(); =20 - global_qtest =3D qtest_startf("-machine virt " - "-drive if=3Dnone,id=3Ddrive0,file=3D%s,fo= rmat=3Draw " - "-device virtio-blk-device,drive=3Ddrive0", - tmp_path); + global_qtest =3D qtest_initf("-machine virt " + "-drive if=3Dnone,id=3Ddrive0,file=3D%s,for= mat=3Draw " + "-device virtio-blk-device,drive=3Ddrive0", + tmp_path); unlink(tmp_path); g_free(tmp_path); } diff --git a/tests/virtio-console-test.c b/tests/virtio-console-test.c index 945bae5a15..a7c6f167c3 100644 --- a/tests/virtio-console-test.c +++ b/tests/virtio-console-test.c @@ -14,17 +14,17 @@ /* Tests only initialization so far. TODO: Replace with functional tests */ static void console_nop(void) { - global_qtest =3D qtest_startf("-device virtio-serial-%s,id=3Dvser0 " - "-device virtconsole,bus=3Dvser0.0", - qvirtio_get_dev_type()); + global_qtest =3D qtest_initf("-device virtio-serial-%s,id=3Dvser0 " + "-device virtconsole,bus=3Dvser0.0", + qvirtio_get_dev_type()); qtest_end(); } =20 static void serialport_nop(void) { - global_qtest =3D qtest_startf("-device virtio-serial-%s,id=3Dvser0 " - "-device virtserialport,bus=3Dvser0.0", - qvirtio_get_dev_type()); + global_qtest =3D qtest_initf("-device virtio-serial-%s,id=3Dvser0 " + "-device virtserialport,bus=3Dvser0.0", + qvirtio_get_dev_type()); qtest_end(); } =20 diff --git a/tests/virtio-serial-test.c b/tests/virtio-serial-test.c index e4b18b1c8a..8da9980a24 100644 --- a/tests/virtio-serial-test.c +++ b/tests/virtio-serial-test.c @@ -31,8 +31,8 @@ int main(int argc, char **argv) qtest_add_func("/virtio/serial/nop", virtio_serial_nop); qtest_add_func("/virtio/serial/hotplug", hotplug); =20 - global_qtest =3D qtest_startf("-device virtio-serial-%s", - qvirtio_get_dev_type()); + global_qtest =3D qtest_initf("-device virtio-serial-%s", + qvirtio_get_dev_type()); ret =3D g_test_run(); =20 qtest_end(); diff --git a/tests/vmgenid-test.c b/tests/vmgenid-test.c index 8d915c610c..0a6fb55f2e 100644 --- a/tests/vmgenid-test.c +++ b/tests/vmgenid-test.c @@ -142,7 +142,7 @@ static void vmgenid_set_guid_test(void) =20 g_assert(qemu_uuid_parse(VGID_GUID, &expected) =3D=3D 0); =20 - global_qtest =3D qtest_startf(GUID_CMD(VGID_GUID)); + global_qtest =3D qtest_initf(GUID_CMD(VGID_GUID)); =20 /* Read the GUID from accessing guest memory */ read_guid_from_memory(&measured); @@ -155,7 +155,7 @@ static void vmgenid_set_guid_auto_test(void) { QemuUUID measured; =20 - global_qtest =3D qtest_startf(GUID_CMD("auto")); + global_qtest =3D qtest_initf(GUID_CMD("auto")); =20 read_guid_from_memory(&measured); =20 @@ -171,7 +171,7 @@ static void vmgenid_query_monitor_test(void) =20 g_assert(qemu_uuid_parse(VGID_GUID, &expected) =3D=3D 0); =20 - global_qtest =3D qtest_startf(GUID_CMD(VGID_GUID)); + global_qtest =3D qtest_initf(GUID_CMD(VGID_GUID)); =20 /* Read the GUID via the monitor */ read_guid_from_monitor(&measured); --=20 2.17.1 From nobody Sat Feb 7 09:12:01 2026 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 1534409274463461.75207334252184; Thu, 16 Aug 2018 01:47:54 -0700 (PDT) Received: from localhost ([::1]:54281 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDwf-00068z-8g for importer@patchew.org; Thu, 16 Aug 2018 04:47:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50650) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDmi-00011s-NO for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmV-0005HL-D1 for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:27 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51382 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 1fqDmM-0005CQ-Mu for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:18 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 96C124027E54 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 734111010416 for ; Thu, 16 Aug 2018 08:37:05 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 30B8111386C2; Thu, 16 Aug 2018 10:37:02 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:36:59 +0200 Message-Id: <20180816083701.3932-24-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.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 16 Aug 2018 08:37:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 16 Aug 2018 08:37:05 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 23/25] libqtest: Rename qtest_FOOv() to qtest_vFOO() for consistency 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: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 13 of 13 C99 library function pairs taking ... or a va_list parameter are called FOO() and vFOO(). In QEMU, we sometimes call the one taking a va_list FOOv() instead. Bad taste. libqtest.h uses both spellings. Normalize it to the standard spelling. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-24-armbru@redhat.com> --- tests/libqtest.c | 12 ++++++------ tests/libqtest.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index a0d44793fa..3706f30aa2 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -538,7 +538,7 @@ QDict *qmp_fdv(int fd, const char *fmt, va_list ap) return qmp_fd_receive(fd); } =20 -QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap) +QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap) { qtest_qmp_vsend(s, fmt, ap); =20 @@ -572,7 +572,7 @@ QDict *qtest_qmp(QTestState *s, const char *fmt, ...) QDict *response; =20 va_start(ap, fmt); - response =3D qtest_qmpv(s, fmt, ap); + response =3D qtest_vqmp(s, fmt, ap); va_end(ap); return response; } @@ -608,7 +608,7 @@ void qtest_qmp_eventwait(QTestState *s, const char *eve= nt) qobject_unref(response); } =20 -char *qtest_hmpv(QTestState *s, const char *fmt, va_list ap) +char *qtest_vhmp(QTestState *s, const char *fmt, va_list ap) { char *cmd; QDict *resp; @@ -637,7 +637,7 @@ char *qtest_hmp(QTestState *s, const char *fmt, ...) char *ret; =20 va_start(ap, fmt); - ret =3D qtest_hmpv(s, fmt, ap); + ret =3D qtest_vhmp(s, fmt, ap); va_end(ap); return ret; } @@ -943,7 +943,7 @@ QDict *qmp(const char *fmt, ...) QDict *response; =20 va_start(ap, fmt); - response =3D qtest_qmpv(global_qtest, fmt, ap); + response =3D qtest_vqmp(global_qtest, fmt, ap); va_end(ap); return response; } @@ -963,7 +963,7 @@ char *hmp(const char *fmt, ...) char *ret; =20 va_start(ap, fmt); - ret =3D qtest_hmpv(global_qtest, fmt, ap); + ret =3D qtest_vhmp(global_qtest, fmt, ap); va_end(ap); return ret; } diff --git a/tests/libqtest.h b/tests/libqtest.h index b92a8070a5..def1edaafa 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -106,7 +106,7 @@ void qtest_qmp_send(QTestState *s, const char *fmt, ...) * * Sends a QMP message to QEMU and returns the response. */ -QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap) +QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0); =20 /** @@ -189,7 +189,7 @@ char *qtest_hmp(QTestState *s, const char *fmt, ...) GC= C_FMT_ATTR(2, 3); * * Returns: the command's output. The caller should g_free() it. */ -char *qtest_hmpv(QTestState *s, const char *fmt, va_list ap) +char *qtest_vhmp(QTestState *s, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0); =20 /** --=20 2.17.1 From nobody Sat Feb 7 09:12:01 2026 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 1534409970935379.85862140038785; Thu, 16 Aug 2018 01:59:30 -0700 (PDT) Received: from localhost ([::1]:54341 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqE7t-0002Lz-Rd for importer@patchew.org; Thu, 16 Aug 2018 04:59:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50764) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDn0-0001J3-BQ for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmr-0005Xo-3B for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:50 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53676 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-0005C3-0K for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:44 -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 54B5240776FD for ; Thu, 16 Aug 2018 08:37:06 +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 763B820180F6; Thu, 16 Aug 2018 08:37:05 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 342EA11386C3; Thu, 16 Aug 2018 10:37:02 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:37:00 +0200 Message-Id: <20180816083701.3932-25-armbru@redhat.com> In-Reply-To: <20180816083701.3932-1-armbru@redhat.com> References: <20180816083701.3932-1-armbru@redhat.com> MIME-Version: 1.0 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.7]); Thu, 16 Aug 2018 08:37:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 16 Aug 2018 08:37:06 +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:'' Content-Transfer-Encoding: quoted-printable 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 24/25] tests/libqtest: Improve kill_qemu() 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: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Eric Blake In kill_qemu() we have an assert that checks that the QEMU process didn't dump core: assert(!WCOREDUMP(wstatus)); Unfortunately the WCOREDUMP macro here means the resulting message is not very easy to comprehend on at least some systems: ahci-test: tests/libqtest.c:113: kill_qemu: Assertion `!(((__extension__ ((= (union { __typeof(wstatus) __in; int __i; }) { .__in =3D (wstatus) }).__i))= ) & 0x80)' failed. and it doesn't identify what signal the process took. What's more, WCOREDUMP is not reliable - in some cases, setrlimit() coupled with kernel dump settings can result in the flag not being set. It's better to log ALL death by signal, instead of caring whether a core dump was attempted (although once we know a signal happened, also mentioning if a core dump is present can be helpful). Furthermore, we are NOT detecting EINTR (while EINTR shouldn't be happening if we didn't install signal handlers, it's still better to always be robust). Finally, even non-signal death with a non-zero status is suspicious, since qemu's SIGINT handler is supposed to result in exit(0). Instead of using a raw assert, print the information in an easier to understand way: /i386/ahci/sanity: tests/libqtest.c:129: kill_qemu() detected QEMU death fr= om signal 11 (Segmentation fault) (core dumped) (Of course, the really useful information would be why the QEMU process dumped core in the first place, but we don't have that by the time the test program has picked up the exit status.) Suggested-by: Peter Maydell Signed-off-by: Eric Blake Message-Id: <20180810132800.38549-1-eblake@redhat.com> Reviewed-by: Markus Armbruster [Core dump reporting and commit message tweaked] Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/libqtest.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index 3706f30aa2..b703fca26d 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -107,10 +107,28 @@ static void kill_qemu(QTestState *s) pid_t pid; =20 kill(s->qemu_pid, SIGTERM); - pid =3D waitpid(s->qemu_pid, &wstatus, 0); + TFR(pid =3D waitpid(s->qemu_pid, &wstatus, 0)); =20 - if (pid =3D=3D s->qemu_pid && WIFSIGNALED(wstatus)) { - assert(!WCOREDUMP(wstatus)); + assert(pid =3D=3D s->qemu_pid); + /* + * We expect qemu to exit with status 0; anything else is + * fishy and should be logged with as much detail as possible. + */ + if (wstatus) { + if (WIFEXITED(wstatus)) { + fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEM= U " + "process but encountered exit status %d\n", + __FILE__, __LINE__, WEXITSTATUS(wstatus)); + } else if (WIFSIGNALED(wstatus)) { + int sig =3D WTERMSIG(wstatus); + const char *signame =3D strsignal(sig) ?: "unknown ???"; + const char *dump =3D WCOREDUMP(wstatus) ? " (core dumped)"= : ""; + + fprintf(stderr, "%s:%d: kill_qemu() detected QEMU death " + "from signal %d (%s)%s\n", + __FILE__, __LINE__, sig, signame, dump); + } + abort(); } } } --=20 2.17.1 From nobody Sat Feb 7 09:12:01 2026 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 1534408942041219.35143878996212; Thu, 16 Aug 2018 01:42:22 -0700 (PDT) Received: from localhost ([::1]:54251 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDrI-00051s-Sx for importer@patchew.org; Thu, 16 Aug 2018 04:42:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50558) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqDmV-0000rK-C0 for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqDmM-0005E3-Fu for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:18 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57658 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 1fqDmF-00059h-CJ for qemu-devel@nongnu.org; Thu, 16 Aug 2018 04:37:09 -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 97200F2B53 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 7386E7C54 for ; Thu, 16 Aug 2018 08:37:05 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 37B5511386C8; Thu, 16 Aug 2018 10:37:02 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Aug 2018 10:37:01 +0200 Message-Id: <20180816083701.3932-26-armbru@redhat.com> In-Reply-To: <20180816083701.3932-1-armbru@redhat.com> References: <20180816083701.3932-1-armbru@redhat.com> MIME-Version: 1.0 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.2]); Thu, 16 Aug 2018 08:37:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 16 Aug 2018 08:37:05 +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:'' Content-Transfer-Encoding: quoted-printable 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 25/25] libqtest: Improve error reporting for bad read from QEMU 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: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When read() from the qtest socket or the QMP socket fails or EOFs, we report "Broken pipe" and exit(1). This commonly happens when QEMU crashes. It also happens when QEMU refuses to run because the test passed it bad arguments. Sadly, we neglect to report either. Improve this by calling abort() instead of exit(1), so kill_qemu() runs, and reports how QEMU died. This improves error reporting to something like /x86_64/device/introspect/list: Broken pipe tests/libqtest.c:129: kill_qemu() detected QEMU death from signal 6 (Ab= orted) (dumped core) Three exit() remain in libqtest.c: * In qmp_response(), when we can't parse a QMP reply read from the QMP socket. Change to abort() for consistency. * In qtest_qemu_binary(), when QTEST_QEMU_BINARY isn't in the environment. This can only happen before we start QEMU. Leave alone. * In qtest_init_without_qmp_handshake(), when the fork()ed child fails to execlp(). Leave alone. exit() elsewhere are unlikely due to QEMU dying on us. If that should turn out to be wrong, we can move kill_qemu() from @abrt_hooks to atexit() or something. Signed-off-by: Markus Armbruster Message-Id: <20180815141945.10457-2-armbru@redhat.com> Reviewed-by: Philippe Mathieu-Daud=C3=A9 [Commit message tweaked slightly] --- tests/libqtest.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index b703fca26d..852ccff1ce 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -367,7 +367,7 @@ static GString *qtest_recv_line(QTestState *s) =20 if (len =3D=3D -1 || len =3D=3D 0) { fprintf(stderr, "Broken pipe\n"); - exit(1); + abort(); } =20 g_string_append_len(s->rx, buffer, len); @@ -454,7 +454,7 @@ static void qmp_response(JSONMessageParser *parser, GQu= eue *tokens) obj =3D json_parser_parse(tokens, NULL); if (!obj) { fprintf(stderr, "QMP JSON response parsing failed\n"); - exit(1); + abort(); } =20 g_assert(!qmp->response); @@ -480,7 +480,7 @@ QDict *qmp_fd_receive(int fd) =20 if (len =3D=3D -1 || len =3D=3D 0) { fprintf(stderr, "Broken pipe\n"); - exit(1); + abort(); } =20 if (log) { --=20 2.17.1