From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51798) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1GYA-0005tu-6P for qemu-devel@nongnu.org; Tue, 24 Nov 2015 11:34:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1GY6-000575-29 for qemu-devel@nongnu.org; Tue, 24 Nov 2015 11:34:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57414) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1GY5-00056o-Q0 for qemu-devel@nongnu.org; Tue, 24 Nov 2015 11:34:33 -0500 From: marcandre.lureau@redhat.com Date: Tue, 24 Nov 2015 17:34:18 +0100 Message-Id: <1448382858-28616-2-git-send-email-marcandre.lureau@redhat.com> In-Reply-To: <1448382858-28616-1-git-send-email-marcandre.lureau@redhat.com> References: <1448382858-28616-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 2/2] tests: add file-write-read test List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth From: Marc-Andr=C3=A9 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=3D1210246 Signed-off-by: Marc-Andr=C3=A9 Lureau --- tests/test-qga.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++= ++++++ 1 file changed, 91 insertions(+) diff --git a/tests/test-qga.c b/tests/test-qga.c index 6473846..6b6963e 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -496,6 +496,96 @@ static void test_qga_file_ops(gconstpointer fix) g_free(cmd); } =20 +static void test_qga_file_write_read(gconstpointer fix) +{ + const TestFixture *fixture =3D fix; + const guchar helloworld[] =3D "Hello World!\n"; + const char *b64; + gchar *cmd, *enc; + QDict *ret, *val; + int64_t id, eof; + gsize count; + + /* open */ + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-file-open'," + " 'arguments': { 'path': 'foo', 'mode': 'w+' } }"); + g_assert_nonnull(ret); + qmp_assert_no_error(ret); + id =3D qdict_get_int(ret, "return"); + QDECREF(ret); + + 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); + g_assert_nonnull(ret); + qmp_assert_no_error(ret); + + val =3D qdict_get_qdict(ret, "return"); + count =3D qdict_get_int(val, "count"); + eof =3D qdict_get_bool(val, "eof"); + g_assert_cmpint(count, =3D=3D, sizeof(helloworld)); + g_assert_cmpint(eof, =3D=3D, 0); + QDECREF(ret); + g_free(cmd); + + /* read (check implicit flush) */ + cmd =3D g_strdup_printf("{'execute': 'guest-file-read'," + " 'arguments': { 'handle': %" PRId64 "} }", + id); + ret =3D qmp_fd(fixture->fd, cmd); + val =3D qdict_get_qdict(ret, "return"); + count =3D qdict_get_int(val, "count"); + eof =3D qdict_get_bool(val, "eof"); + b64 =3D qdict_get_str(val, "buf-b64"); + g_assert_cmpint(count, =3D=3D, 0); + g_assert(eof); + g_assert_cmpstr(b64, =3D=3D, ""); + QDECREF(ret); + g_free(cmd); + + /* seek to 0*/ + cmd =3D g_strdup_printf("{'execute': 'guest-file-seek'," + " 'arguments': { 'handle': %" PRId64 ", " + " 'offset': %d, 'whence': %d } }", + id, 0, SEEK_SET); + ret =3D qmp_fd(fixture->fd, cmd); + qmp_assert_no_error(ret); + val =3D qdict_get_qdict(ret, "return"); + count =3D qdict_get_int(val, "position"); + eof =3D qdict_get_bool(val, "eof"); + g_assert_cmpint(count, =3D=3D, 0); + g_assert(!eof); + QDECREF(ret); + g_free(cmd); + + /* read */ + cmd =3D g_strdup_printf("{'execute': 'guest-file-read'," + " 'arguments': { 'handle': %" PRId64 "} }", + id); + ret =3D qmp_fd(fixture->fd, cmd); + val =3D qdict_get_qdict(ret, "return"); + count =3D qdict_get_int(val, "count"); + eof =3D qdict_get_bool(val, "eof"); + b64 =3D qdict_get_str(val, "buf-b64"); + g_assert_cmpint(count, =3D=3D, sizeof(helloworld)); + g_assert(eof); + g_assert_cmpstr(b64, =3D=3D, enc); + QDECREF(ret); + g_free(cmd); + g_free(enc); + + /* close */ + cmd =3D g_strdup_printf("{'execute': 'guest-file-close'," + " 'arguments': {'handle': %" PRId64 "} }", + id); + ret =3D qmp_fd(fixture->fd, cmd); + QDECREF(ret); + g_free(cmd); +} + static void test_qga_get_time(gconstpointer fix) { const TestFixture *fixture =3D 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_wri= te_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, --=20 2.5.0