From patchwork Wed Nov 30 19:44:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 9454747 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F095B6071C for ; Wed, 30 Nov 2016 19:50:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1E0C2849A for ; Wed, 30 Nov 2016 19:50:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6B272849D; Wed, 30 Nov 2016 19:50:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DBC512849A for ; Wed, 30 Nov 2016 19:50:44 +0000 (UTC) Received: from localhost ([::1]:46083 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCAtw-0007cq-40 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 30 Nov 2016 14:50:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35418) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCAog-0003nV-CU for qemu-devel@nongnu.org; Wed, 30 Nov 2016 14:45:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cCAof-0001rP-Af for qemu-devel@nongnu.org; Wed, 30 Nov 2016 14:45:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51170) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cCAof-0001qx-2M for qemu-devel@nongnu.org; Wed, 30 Nov 2016 14:45:17 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (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 36F24486DA for ; Wed, 30 Nov 2016 19:45:16 +0000 (UTC) Received: from red.redhat.com (ovpn-116-172.phx2.redhat.com [10.3.116.172]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uAUJj2nF025934; Wed, 30 Nov 2016 14:45:15 -0500 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 30 Nov 2016 13:44:26 -0600 Message-Id: <1480535094-23831-9-git-send-email-eblake@redhat.com> In-Reply-To: <1480535094-23831-1-git-send-email-eblake@redhat.com> References: <1480535094-23831-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 30 Nov 2016 19:45:16 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 08/36] test-qga: Actually test 0xff sync bytes 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: pbonzini@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Commit 62c39b3 introduced test-qga, and at face value, appears to be testing the 'guest-sync' behavior that is recommended for guests in sending 0xff to QGA to force the parser to reset. But this aspect of the test has never actually done anything: the qmp_fd() call chain converts its string argument into QObject, then converts that QObject back to the actual string that is sent over the wire - and the conversion process silently drops the 0xff byte from the string sent to QGA, thus never resetting the QGA parser. An upcoming patch will get rid of the wasteful round trip through QObject, at which point the string in test-qga will be directly sent over the wire. But fixing qmp_fd() to actually send 0xff over the wire is not all we have to do - the actual QMP parser loudly complains that 0xff is not valid JSON, and sends an error message _prior_ to actually parsing the 'guest-sync' or 'guest-sync-delimited' command. With 'guest-sync', we cannot easily tell if this error message is a result of our command - which is WHY we invented the 'guest-sync-delimited' command. So for the testsuite, fix things to only check 0xff behavior on 'guest-sync-delimited', and to loop until we've consumed all garbage prior to the requested delimiter, which matches the documented actions that a real QGA client is supposed to do. Ideally, we'd fix the QGA JSON parser to silently ignore 0xff rather than sending an error message back, at which point we could enhance this test for 'guest-sync' as well as for 'guest-sync-delimited'. But for the sake of this patch, our testing of 'guest-sync' is no worse than it was pre-patch, because we have never been sending 0xff over the wire in the first place. Signed-off-by: Eric Blake --- tests/libqtest.c | 8 ++++++++ tests/test-qga.c | 12 +++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index 6f69752..429aaec 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -430,6 +430,14 @@ void qmp_fd_sendv(int fd, const char *fmt, va_list ap) va_list ap_copy; QObject *qobj; + /* qobject_from_jsonv() silently eats leading 0xff as invalid + * JSON, but we want to test sending them over the wire to force + * resyncs */ + if (*fmt == '\377') { + socket_send(fd, fmt, 1); + fmt++; + } + /* Going through qobject ensures we escape strings properly. * This seemingly unnecessary copy is required in case va_list * is an array type. diff --git a/tests/test-qga.c b/tests/test-qga.c index 868b02a..4b64630 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -151,9 +151,11 @@ static void test_qga_sync_delimited(gconstpointer fix) qmp_fd_send(fixture->fd, cmd); g_free(cmd); - v = read(fixture->fd, &c, 1); - g_assert_cmpint(v, ==, 1); - g_assert_cmpint(c, ==, 0xff); + /* Read and ignore garbage until resynchronized */ + do { + v = read(fixture->fd, &c, 1); + g_assert_cmpint(v, ==, 1); + } while (c != 0xff); ret = qmp_fd_receive(fixture->fd); g_assert_nonnull(ret); @@ -172,8 +174,8 @@ static void test_qga_sync(gconstpointer fix) QDict *ret; gchar *cmd; - cmd = g_strdup_printf("%c{'execute': 'guest-sync'," - " 'arguments': {'id': %u } }", 0xff, r); + cmd = g_strdup_printf("{'execute': 'guest-sync'," + " 'arguments': {'id': %u } }", r); ret = qmp_fd(fixture->fd, cmd); g_free(cmd);