From patchwork Wed Nov 25 22:47:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 548801 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 0238A1401DA for ; Thu, 26 Nov 2015 09:51:33 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=wZm6B4WE; dkim-atps=neutral Received: from localhost ([::1]:48141 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1iuQ-0001Kx-Qh for incoming@patchwork.ozlabs.org; Wed, 25 Nov 2015 17:51:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35172) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1irJ-000543-OQ for qemu-devel@nongnu.org; Wed, 25 Nov 2015 17:48:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1irG-0006HT-FA for qemu-devel@nongnu.org; Wed, 25 Nov 2015 17:48:17 -0500 Received: from mail-oi0-x22e.google.com ([2607:f8b0:4003:c06::22e]:36632) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1irG-0006HN-AB for qemu-devel@nongnu.org; Wed, 25 Nov 2015 17:48:14 -0500 Received: by oiww189 with SMTP id w189so37617978oiw.3 for ; Wed, 25 Nov 2015 14:48:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=3nN3gUi9XpynrtFbhazSRJ8WfKfD+0HxR2JkNe2S5lw=; b=wZm6B4WEWAiMG099D6NOdFFrV7f6H3/O3KzhbaH2QraPfuqFXE6vcw10PBcXx4KVKi n+axocUWhzwuGTRwIWjtX1e/8RY/p2o6EjYhMKPLvyJRtZ0tqgYFeFO7HF/HbMibATnS QHzWEA4N28jgLmm31DJFPJjelbwFS+prnktQCEb6uUVJIA4qZSg3uYv2oMiteiDhKe0H BEzKKkVnhFwRqWJL/9Rb9xcEUBz6E4vrCIaEbrMmQagdLxra2yoCV7QGAFNzQVtjKiwU SzA0BwVV8PLCmQx9qBykOPN516BkC5S46IM4r2tx3/5nRFoas0zkekUuiHqoAXv+e3Ru fnMA== X-Received: by 10.202.173.17 with SMTP id w17mr25093626oie.52.1448491693965; Wed, 25 Nov 2015 14:48:13 -0800 (PST) Received: from localhost (104-184-96-177.lightspeed.austtx.sbcglobal.net. [104.184.96.177]) by smtp.gmail.com with ESMTPSA id c20sm11682924oig.4.2015.11.25.14.48.12 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 25 Nov 2015 14:48:12 -0800 (PST) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 25 Nov 2015 16:47:38 -0600 Message-Id: <1448491660-11890-5-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1448491660-11890-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1448491660-11890-1-git-send-email-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c06::22e Cc: peter.maydell@linaro.org, Michael Roth , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [Qemu-devel] [PULL for-2.5 4/6] tests: add file-write-read test X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Marc-André Lureau This test exhibits a POSIX behaviour regarding switching between write and read. It's undefined result if the application doesn't ensure a flush between the two operations (with glibc, the flush can be implicit when the buffer size is relatively small). The previous commit fixes this test. Related to: https://bugzilla.redhat.com/show_bug.cgi?id=1210246 Signed-off-by: Marc-André Lureau Reviewed-by: Eric Blake Signed-off-by: Michael Roth --- tests/test-qga.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 2 deletions(-) diff --git a/tests/test-qga.c b/tests/test-qga.c index 6473846..3b99d9d 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -352,10 +352,10 @@ static void test_qga_network_get_interfaces(gconstpointer fix) static void test_qga_file_ops(gconstpointer fix) { const TestFixture *fixture = fix; - const guchar helloworld[] = "Hello World!\n"; + const unsigned char helloworld[] = "Hello World!\n"; const char *b64; gchar *cmd, *path, *enc; - guchar *dec; + unsigned char *dec; QDict *ret, *val; int64_t id, eof; gsize count; @@ -496,6 +496,96 @@ static void test_qga_file_ops(gconstpointer fix) g_free(cmd); } +static void test_qga_file_write_read(gconstpointer fix) +{ + const TestFixture *fixture = fix; + const unsigned char helloworld[] = "Hello World!\n"; + const char *b64; + gchar *cmd, *enc; + QDict *ret, *val; + int64_t id, eof; + gsize count; + + /* open */ + ret = qmp_fd(fixture->fd, "{'execute': 'guest-file-open'," + " 'arguments': { 'path': 'foo', 'mode': 'w+' } }"); + g_assert_nonnull(ret); + qmp_assert_no_error(ret); + id = qdict_get_int(ret, "return"); + QDECREF(ret); + + enc = g_base64_encode(helloworld, sizeof(helloworld)); + /* write */ + cmd = g_strdup_printf("{'execute': 'guest-file-write'," + " 'arguments': { 'handle': %" PRId64 "," + " 'buf-b64': '%s' } }", id, enc); + ret = qmp_fd(fixture->fd, cmd); + g_assert_nonnull(ret); + qmp_assert_no_error(ret); + + val = qdict_get_qdict(ret, "return"); + count = qdict_get_int(val, "count"); + eof = qdict_get_bool(val, "eof"); + g_assert_cmpint(count, ==, sizeof(helloworld)); + g_assert_cmpint(eof, ==, 0); + QDECREF(ret); + g_free(cmd); + + /* read (check implicit flush) */ + cmd = g_strdup_printf("{'execute': 'guest-file-read'," + " 'arguments': { 'handle': %" PRId64 "} }", + id); + ret = qmp_fd(fixture->fd, cmd); + val = qdict_get_qdict(ret, "return"); + count = qdict_get_int(val, "count"); + eof = qdict_get_bool(val, "eof"); + b64 = qdict_get_str(val, "buf-b64"); + g_assert_cmpint(count, ==, 0); + g_assert(eof); + g_assert_cmpstr(b64, ==, ""); + QDECREF(ret); + g_free(cmd); + + /* seek to 0 */ + cmd = g_strdup_printf("{'execute': 'guest-file-seek'," + " 'arguments': { 'handle': %" PRId64 ", " + " 'offset': %d, 'whence': %d } }", + id, 0, SEEK_SET); + ret = qmp_fd(fixture->fd, cmd); + qmp_assert_no_error(ret); + val = qdict_get_qdict(ret, "return"); + count = qdict_get_int(val, "position"); + eof = qdict_get_bool(val, "eof"); + g_assert_cmpint(count, ==, 0); + g_assert(!eof); + QDECREF(ret); + g_free(cmd); + + /* read */ + cmd = g_strdup_printf("{'execute': 'guest-file-read'," + " 'arguments': { 'handle': %" PRId64 "} }", + id); + ret = qmp_fd(fixture->fd, cmd); + val = qdict_get_qdict(ret, "return"); + count = qdict_get_int(val, "count"); + eof = qdict_get_bool(val, "eof"); + b64 = qdict_get_str(val, "buf-b64"); + g_assert_cmpint(count, ==, sizeof(helloworld)); + g_assert(eof); + g_assert_cmpstr(b64, ==, enc); + QDECREF(ret); + g_free(cmd); + g_free(enc); + + /* close */ + cmd = g_strdup_printf("{'execute': 'guest-file-close'," + " 'arguments': {'handle': %" PRId64 "} }", + id); + ret = qmp_fd(fixture->fd, cmd); + QDECREF(ret); + g_free(cmd); +} + static void test_qga_get_time(gconstpointer fix) { const TestFixture *fixture = fix; @@ -762,6 +852,7 @@ int main(int argc, char **argv) g_test_add_data_func("/qga/get-memory-blocks", &fix, test_qga_get_memory_blocks); g_test_add_data_func("/qga/file-ops", &fix, test_qga_file_ops); + g_test_add_data_func("/qga/file-write-read", &fix, test_qga_file_write_read); g_test_add_data_func("/qga/get-time", &fix, test_qga_get_time); g_test_add_data_func("/qga/invalid-cmd", &fix, test_qga_invalid_cmd); g_test_add_data_func("/qga/fsfreeze-status", &fix,