Received: from eggs.gnu.org ([2001:4830:134:3::10]:52081) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1Hrm-00075W-BH for qemu-devel@nongnu.org; Tue, 24 Nov 2015 12:58:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1Hrj-0004oO-2b for qemu-devel@nongnu.org; Tue, 24 Nov 2015 12:58:58 -0500 Received: from mx6-phx2.redhat.com ([209.132.183.39]:49362) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1Hri-0004o8-RQ for qemu-devel@nongnu.org; Tue, 24 Nov 2015 12:58:55 -0500 Date: Tue, 24 Nov 2015 12:58:51 -0500 (EST) From: =?utf-8?Q?Marc-Andr=C3=A9?= Lureau Message-ID: <1709209797.16598918.1448387931887.JavaMail.zimbra@redhat.com> In-Reply-To: <56549E87.4060200@redhat.com> References: <1448382858-28616-1-git-send-email-marcandre.lureau@redhat.com> <1448382858-28616-2-git-send-email-marcandre.lureau@redhat.com> <56549E87.4060200@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 2/2] tests: add file-write-read test List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: marcandre lureau , qemu-devel@nongnu.org, Markus Armbruster , Michael Roth Hi ----- Original Message ----- > On 11/24/2015 09:34 AM, marcandre.lureau@redhat.com wrote: > > From: Marc-Andr=C3=A9 Lureau > >=20 > > 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. > >=20 > > Related to: > > https://bugzilla.redhat.com/show_bug.cgi?id=3D1210246 > >=20 > > Signed-off-by: Marc-Andr=C3=A9 Lureau > > --- > > tests/test-qga.c | 91 > > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 91 insertions(+) > >=20 > > 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"; >=20 > Do we have to use guchar, or can we just stick with 'char' or 'unsigned > char'? We can switch to "unsigned char" >=20 >=20 > > + > > + /* read (check implicit flush) */ >=20 > Here, the term implicit is okay; while the previous patch is adding an > explicit flush at the low level, it is doing so in order to avoid having > to make clients need an explicit flush operation (clients can rely on an > implicit flush). ok >=20 > > + 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*/ >=20 > Space before */ fixed >=20 > > + cmd =3D g_strdup_printf("{'execute': 'guest-file-seek'," > > + " 'arguments': { 'handle': %" PRId64 ", " > > + " 'offset': %d, 'whence': %d } }", > > + id, 0, SEEK_SET); >=20 > EWWWW. We seriously released this interface as taking an integer for > whence? SEEK_SET is not required to be the same value on every > platform. Which is a severe problem if the guest and the host are on > different OS with different choices of values for the constants (if > SEEK_CUR on my host is 1, but 1 maps to SEEK_END on my guest OS, what > behavior am I going to get?). >=20 > It would be worth a patch to qga to document the actual integer values > that we have hard-coded (0 for set, 1 for cur, 2 for end; even if that > differs from the guest's local definition of the SEEK_ constants), > and/or to fix the interface to take symbolic names rather than integers > for the whence argument. >=20 > Our whole guest-file-* API is lousy. Are you going to send a patch for this? (hopefully, we can expose a "real" filesystem protocol in the near future)