From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55285) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1ZfN-0004Oi-JP for qemu-devel@nongnu.org; Wed, 25 Nov 2015 07:59:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1ZfM-0001Jb-A6 for qemu-devel@nongnu.org; Wed, 25 Nov 2015 07:59:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33871) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1ZfL-0001JG-RY for qemu-devel@nongnu.org; Wed, 25 Nov 2015 07:59:20 -0500 From: marcandre.lureau@redhat.com Date: Wed, 25 Nov 2015 13:59:12 +0100 Message-Id: <1448456352-14143-3-git-send-email-marcandre.lureau@redhat.com> In-Reply-To: <1448456352-14143-1-git-send-email-marcandre.lureau@redhat.com> References: <1448456352-14143-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 v3 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?= , mdroth@linux.vnet.ibm.com 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 | 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(gconstp= ointer fix) static void test_qga_file_ops(gconstpointer fix) { const TestFixture *fixture =3D fix; - const guchar helloworld[] =3D "Hello World!\n"; + const unsigned char helloworld[] =3D "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); } =20 +static void test_qga_file_write_read(gconstpointer fix) +{ + const TestFixture *fixture =3D fix; + const unsigned char 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