From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btTcC-00074d-C2 for qemu-devel@nongnu.org; Mon, 10 Oct 2016 01:59:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1btTc9-0004S7-Qd for qemu-devel@nongnu.org; Mon, 10 Oct 2016 01:59:07 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:34561) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btTc8-0004QM-BX for qemu-devel@nongnu.org; Mon, 10 Oct 2016 01:59:05 -0400 Date: Mon, 10 Oct 2016 15:52:13 +1100 From: David Gibson Message-ID: <20161010045213.GB22498@umbus.fritz.box> References: <1475835267-7300-1-git-send-email-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="NMuMz9nt05w80d4+" Content-Disposition: inline In-Reply-To: <1475835267-7300-1-git-send-email-lvivier@redhat.com> Subject: Re: [Qemu-devel] [PATCH v2] qtest: ask endianness of the target in qtest_init() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Laurent Vivier Cc: qemu-devel@nongnu.org, Greg Kurz , Peter Maydell --NMuMz9nt05w80d4+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Oct 07, 2016 at 12:14:27PM +0200, Laurent Vivier wrote: > The target endianness is not deduced anymore from > the architecture name but asked directly to the guest, > using a new qtest command: "endianness". As it can't > change (this is the value of TARGET_WORDS_BIGENDIAN), > we store it to not have to ask every time we want to > know if we have to byte-swap a value. >=20 > Signed-off-by: Laurent Vivier > CC: Greg Kurz > CC: David Gibson > CC: Peter Maydell Reviewed-by: David Gibson As with Greg, I think this is an improvement over the current situation, even though I still have concerns about other things related to this. > --- > v2: > - move the "endianness" command to a function and > don't move the qtest_init()/qtest_quit() functions >=20 > qtest.c | 7 +++++ > tests/libqos/virtio-pci.c | 2 +- > tests/libqtest.c | 68 ++++++++++++++++-------------------------= ------ > tests/libqtest.h | 16 ++++++++--- > tests/virtio-blk-test.c | 2 +- > 5 files changed, 45 insertions(+), 50 deletions(-) >=20 > diff --git a/qtest.c b/qtest.c > index 22482cc..b53b39c 100644 > --- a/qtest.c > +++ b/qtest.c > @@ -537,6 +537,13 @@ static void qtest_process_command(CharDriverState *c= hr, gchar **words) > =20 > qtest_send_prefix(chr); > qtest_send(chr, "OK\n"); > + } else if (strcmp(words[0], "endianness") =3D=3D 0) { > + qtest_send_prefix(chr); > +#if defined(TARGET_WORDS_BIGENDIAN) > + qtest_sendf(chr, "OK big\n"); > +#else > + qtest_sendf(chr, "OK little\n"); > +#endif > #ifdef TARGET_PPC64 > } else if (strcmp(words[0], "rtas") =3D=3D 0) { > uint64_t res, args, ret; > diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c > index 18b92b9..6e005c1 100644 > --- a/tests/libqos/virtio-pci.c > +++ b/tests/libqos/virtio-pci.c > @@ -86,7 +86,7 @@ static uint64_t qvirtio_pci_config_readq(QVirtioDevice = *d, uint64_t addr) > int i; > uint64_t u64 =3D 0; > =20 > - if (qtest_big_endian()) { > + if (target_big_endian()) { > for (i =3D 0; i < 8; ++i) { > u64 |=3D (uint64_t)qpci_io_readb(dev->pdev, > (void *)(uintptr_t)addr + i) << (7 - i) = * 8; > diff --git a/tests/libqtest.c b/tests/libqtest.c > index 6f6bdf1..d4e6bff 100644 > --- a/tests/libqtest.c > +++ b/tests/libqtest.c > @@ -37,6 +37,7 @@ struct QTestState > bool irq_level[MAX_IRQ]; > GString *rx; > pid_t qemu_pid; /* our child QEMU process */ > + bool big_endian; > }; > =20 > static GHookList abrt_hooks; > @@ -47,6 +48,8 @@ static struct sigaction sigact_old; > g_assert_cmpint(ret, !=3D, -1); \ > } while (0) > =20 > +static int qtest_query_target_endianness(QTestState *s); > + > static int init_socket(const char *socket_path) > { > struct sockaddr_un addr; > @@ -209,6 +212,10 @@ QTestState *qtest_init(const char *extra_args) > kill(s->qemu_pid, SIGSTOP); > } > =20 > + /* ask endianness of the target */ > + > + s->big_endian =3D qtest_query_target_endianness(s); > + > return s; > } > =20 > @@ -342,6 +349,20 @@ redo: > return words; > } > =20 > +static int qtest_query_target_endianness(QTestState *s) > +{ > + gchar **args; > + int big_endian; > + > + qtest_sendf(s, "endianness\n"); > + args =3D qtest_rsp(s, 1); > + g_assert(strcmp(args[1], "big") =3D=3D 0 || strcmp(args[1], "little"= ) =3D=3D 0); > + big_endian =3D strcmp(args[1], "big") =3D=3D 0; > + g_strfreev(args); > + > + return big_endian; > +} > + > typedef struct { > JSONMessageParser parser; > QDict *response; > @@ -886,50 +907,7 @@ char *hmp(const char *fmt, ...) > return ret; > } > =20 > -bool qtest_big_endian(void) > +bool qtest_big_endian(QTestState *s) > { > - const char *arch =3D qtest_get_arch(); > - int i; > - > - static const struct { > - const char *arch; > - bool big_endian; > - } endianness[] =3D { > - { "aarch64", false }, > - { "alpha", false }, > - { "arm", false }, > - { "cris", false }, > - { "i386", false }, > - { "lm32", true }, > - { "m68k", true }, > - { "microblaze", true }, > - { "microblazeel", false }, > - { "mips", true }, > - { "mips64", true }, > - { "mips64el", false }, > - { "mipsel", false }, > - { "moxie", true }, > - { "or32", true }, > - { "ppc", true }, > - { "ppc64", true }, > - { "ppcemb", true }, > - { "s390x", true }, > - { "sh4", false }, > - { "sh4eb", true }, > - { "sparc", true }, > - { "sparc64", true }, > - { "unicore32", false }, > - { "x86_64", false }, > - { "xtensa", false }, > - { "xtensaeb", true }, > - {}, > - }; > - > - for (i =3D 0; endianness[i].arch; i++) { > - if (strcmp(endianness[i].arch, arch) =3D=3D 0) { > - return endianness[i].big_endian; > - } > - } > - > - return false; > + return s->big_endian; > } > diff --git a/tests/libqtest.h b/tests/libqtest.h > index f7402e0..4be1f77 100644 > --- a/tests/libqtest.h > +++ b/tests/libqtest.h > @@ -410,6 +410,14 @@ int64_t qtest_clock_step(QTestState *s, int64_t step= ); > int64_t qtest_clock_set(QTestState *s, int64_t val); > =20 > /** > + * qtest_big_endian: > + * @s: QTestState instance to operate on. > + * > + * Returns: True if the architecture under test has a big endian configu= ration. > + */ > +bool qtest_big_endian(QTestState *s); > + > +/** > * qtest_get_arch: > * > * Returns: The architecture for the QEMU executable under test. > @@ -874,12 +882,14 @@ static inline int64_t clock_set(int64_t val) > } > =20 > /** > - * qtest_big_endian: > + * target_big_endian: > * > * Returns: True if the architecture under test has a big endian configu= ration. > */ > -bool qtest_big_endian(void); > - > +static inline bool target_big_endian(void) > +{ > + return qtest_big_endian(global_qtest); > +} > =20 > QDict *qmp_fd_receive(int fd); > void qmp_fd_sendv(int fd, const char *fmt, va_list ap); > diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c > index 3c4fecc..0506917 100644 > --- a/tests/virtio-blk-test.c > +++ b/tests/virtio-blk-test.c > @@ -125,7 +125,7 @@ static inline void virtio_blk_fix_request(QVirtioBlkR= eq *req) > bool host_endian =3D false; > #endif > =20 > - if (qtest_big_endian() !=3D host_endian) { > + if (target_big_endian() !=3D host_endian) { > req->type =3D bswap32(req->type); > req->ioprio =3D bswap32(req->ioprio); > req->sector =3D bswap64(req->sector); --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --NMuMz9nt05w80d4+ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJX+x56AAoJEGw4ysog2bOSf5kP/j6IP92llrnMQDgCf9f8Qr7f 3Lth7x97BCFYlwplNU1dOCjOGaopH6GlM46CIZj4f/AeYWWNmMFYm4OLbKDXVHEA 5IpdiMT8P9wgxcrDDWEPvlqcJf6DeKh9BYuWJ6jPAC9kqzPDBW4QwGFbfbAOQxWv sFlgkoByoHtri6UBy73jewz+hxDQm6Wtvo1u+Cv8W0+KOWRMSQYqbhx+DhTrbnCl OX+2IPwlksme/h/sTrILlfivaVJA86TLmI3M4sZw5j92PrUJNZuJpvwrxCcS5xxu yhHwGFXctbIJWkvKwf7iqaiEfJ1M8qCuLA5zOzo1BGWpr9imnM1nKnjK92yr77Zn wBbp7iokRz2owG8A4+JtCbpx0sAujcfnGY8Q4wDp6E3SAvyqaXiOsiUVdauajeIx LIYeHQX+ahj+98mKsCj1ViH8ZYtjToH+UShasJ9usAuC5lliukacOzNUeIgKoD0v SDIKwza71vwtqtTQu4AcToul1LIH/x1ZUhBOKm0olChsUq2ACNLkndhWIMsmJ28n MHRG3XxP2kcIfDFx3FFtqyO3qspHwM1h4NZPw3WkqXE+bE7AS5ZdwPu3N5nzZ+Hk V7I+9bRtEFpALK2x0a8JmPKu3V0vNsBWKBqXMaWZUYPBMKeI+IDkRtruw6fEt/vZ h9emzdBciJVABL3ZilK3 =b23x -----END PGP SIGNATURE----- --NMuMz9nt05w80d4+--