From nobody Sun Feb 8 16:11:55 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.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488703037734850.654365325048; Sun, 5 Mar 2017 00:37:17 -0800 (PST) Received: from localhost ([::1]:37947 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckRfI-0000Qk-9j for importer@patchew.org; Sun, 05 Mar 2017 03:37:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45596) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckReA-0000Oe-1O for qemu-devel@nongnu.org; Sun, 05 Mar 2017 03:36:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ckRe6-0002wu-Ll for qemu-devel@nongnu.org; Sun, 05 Mar 2017 03:36:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42676) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ckRe6-0002vm-Dr for qemu-devel@nongnu.org; Sun, 05 Mar 2017 03:36:02 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6E23B61B92 for ; Sun, 5 Mar 2017 08:36:01 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v258ZxF9024228 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Sun, 5 Mar 2017 03:36:01 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6D856113864D; Sun, 5 Mar 2017 09:35:58 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Sun, 5 Mar 2017 09:35:33 +0100 Message-Id: <1488702958-24336-3-git-send-email-armbru@redhat.com> In-Reply-To: <1488702958-24336-1-git-send-email-armbru@redhat.com> References: <1488702958-24336-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sun, 05 Mar 2017 08:36:01 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 02/27] libqtest: Work around a "QMP wants a newline" bug X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The next commit is going to add a test that calls qmp("null"). Curiously, this hangs. Here's why. qmp_fd_sendv() doesn't send newlines. Not even when @fmt contains some. At first glance, the QMP parser seems to be fine with that. However, it turns out that it fails to react to input until it sees either a newline, an object or an array. To reproduce, feed to a QMP monitor like this: $ echo -n 'null' | socat UNIX:/work/armbru/images/test-qmp STDIO {"QMP": {"version": {"qemu": {"micro": 50, "minor": 8, "major": 2}, "pa= ckage": " (v2.8.0-1195-gf84141e-dirty)"}, "capabilities": []}} No output after the greeting. Add a newline: $ echo 'null' | socat UNIX:/work/armbru/images/test-qmp STDIO {"QMP": {"version": {"qemu": {"micro": 50, "minor": 8, "major": 2}, "pa= ckage": " (v2.8.0-1195-gf84141e-dirty)"}, "capabilities": []}} {"error": {"class": "GenericError", "desc": "Expected 'object' in QMP i= nput"}} Correct output for input 'null'. Add an object instead: $ echo -n 'null { "execute": "qmp_capabilities" }' | socat UNIX:qmp-soc= ket STDIO {"QMP": {"version": {"qemu": {"micro": 50, "minor": 8, "major": 2}, "pa= ckage": " (v2.8.0-1195-gf84141e-dirty)"}, "capabilities": []}} {"error": {"class": "GenericError", "desc": "Expected 'object' in QMP i= nput"}} {"return": {}} Also correct output. Work around this QMP bug by having qmp_fd_sendv() append a newline. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <1488544368-30622-3-git-send-email-armbru@redhat.com> --- tests/libqtest.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index 3a0e0d6..951a3b4 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -442,14 +442,20 @@ void qmp_fd_sendv(int fd, const char *fmt, va_list ap) if (qobj) { int log =3D getenv("QTEST_LOG") !=3D NULL; QString *qstr =3D qobject_to_json(qobj); - const char *str =3D qstring_get_str(qstr); - size_t size =3D qstring_get_length(qstr); + const char *str; + + /* + * BUG: QMP doesn't react to input until it sees a newline, an + * object, or an array. Work-around: give it a newline. + */ + qstring_append_chr(qstr, '\n'); + str =3D qstring_get_str(qstr); =20 if (log) { fprintf(stderr, "%s", str); } /* Send QMP request */ - socket_send(fd, str, size); + socket_send(fd, str, qstring_get_length(qstr)); =20 QDECREF(qstr); qobject_decref(qobj); --=20 2.7.4