From nobody Wed Nov 5 12:52:43 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1534520520111463.78954730412136; Fri, 17 Aug 2018 08:42:00 -0700 (PDT) Received: from localhost ([::1]:34826 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqgsw-0003cN-Jj for importer@patchew.org; Fri, 17 Aug 2018 11:41:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46183) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqgKG-00033x-59 for qemu-devel@nongnu.org; Fri, 17 Aug 2018 11:06:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqgKC-0001hQ-QQ for qemu-devel@nongnu.org; Fri, 17 Aug 2018 11:06:07 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56202 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 1fqgKC-0001gY-Ck for qemu-devel@nongnu.org; Fri, 17 Aug 2018 11:06:04 -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 117C55A755; Fri, 17 Aug 2018 15:06: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 BD0252026D6C; Fri, 17 Aug 2018 15:06:03 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id F1D4A115606F; Fri, 17 Aug 2018 17:05:59 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 17 Aug 2018 17:05:05 +0200 Message-Id: <20180817150559.16243-7-armbru@redhat.com> In-Reply-To: <20180817150559.16243-1-armbru@redhat.com> References: <20180817150559.16243-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]); Fri, 17 Aug 2018 15:06:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 17 Aug 2018 15:06: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:'' 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] [PATCH v2 06/60] test-qga: Clean up how we test QGA synchronization 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: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com 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" To permit recovering from arbitrary JSON parse errors, the JSON parser resets itself on lexical errors. We recommend sending a 0xff byte for that purpose, and test-qga covers this usage since commit 5229564b832. That commit had to add an ugly hack to qmp_fd_vsend() to make capable of sending this byte (it's designed to send only valid JSON). The previous commit added a way to send arbitrary text. Put that to use for this purpose, and drop the hack from qmp_fd_vsend(). Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/libqtest.c | 39 +++++++++++++++++++++------------------ tests/libqtest.h | 2 ++ tests/test-qga.c | 3 ++- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index dc42347da3..a7ad09fc86 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -507,16 +507,6 @@ void qmp_fd_vsend(int fd, const char *fmt, va_list ap) { QObject *qobj; =20 - /* - * 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++; - } - /* Going through qobject ensures we escape strings properly */ qobj =3D qobject_from_vjsonf_nofail(fmt, ap); =20 @@ -604,23 +594,36 @@ void qtest_qmp_send(QTestState *s, const char *fmt, .= ..) va_end(ap); } =20 -void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...) +void qmp_fd_vsend_raw(int fd, const char *fmt, va_list ap) { bool log =3D getenv("QTEST_LOG") !=3D NULL; - va_list ap; - char *str; - - va_start(ap, fmt); - str =3D g_strdup_vprintf(fmt, ap); - va_end(ap); + char *str =3D g_strdup_vprintf(fmt, ap); =20 if (log) { fprintf(stderr, "%s", str); } - socket_send(s->qmp_fd, str, strlen(str)); + socket_send(fd, str, strlen(str)); g_free(str); } =20 +void qmp_fd_send_raw(int fd, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + qmp_fd_vsend_raw(fd, fmt, ap); + va_end(ap); +} + +void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + qmp_fd_vsend_raw(s->qmp_fd, fmt, ap); + va_end(ap); +} + QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event) { QDict *response; diff --git a/tests/libqtest.h b/tests/libqtest.h index 1e831973ff..2d1eb4b282 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -959,6 +959,8 @@ static inline int64_t clock_set(int64_t val) QDict *qmp_fd_receive(int fd); 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); +void qmp_fd_send_raw(int fd, const char *fmt, ...) GCC_FMT_ATTR(2, 3); +void qmp_fd_vsend_raw(int fd, const char *fmt, va_list ap) GCC_FMT_ATTR(2,= 0); 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 diff --git a/tests/test-qga.c b/tests/test-qga.c index c552cc0125..f69cdf6c03 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -147,8 +147,9 @@ static void test_qga_sync_delimited(gconstpointer fix) unsigned char c; QDict *ret; =20 + qmp_fd_send_raw(fixture->fd, "\xff"); qmp_fd_send(fixture->fd, - "\xff{'execute': 'guest-sync-delimited'," + "{'execute': 'guest-sync-delimited'," " 'arguments': {'id': %u } }", r); =20 --=20 2.17.1