Received: from eggs.gnu.org ([2001:4830:134:3::10]:45391) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpPgu-00011O-JK for qemu-devel@nongnu.org; Wed, 19 Jun 2013 17:13:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UpPgs-00006Z-Aa for qemu-devel@nongnu.org; Wed, 19 Jun 2013 17:13:20 -0400 Mime-Version: 1.0 (Apple Message framework v1278) Content-Type: text/plain; charset=us-ascii From: Alexander Graf In-Reply-To: <1371674435-14973-6-git-send-email-aliguori@us.ibm.com> Date: Wed, 19 Jun 2013 23:13:14 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: <3CCEF1E4-C499-4265-9392-CD53CB5C43DD@suse.de> References: <1371674435-14973-1-git-send-email-aliguori@us.ibm.com> <1371674435-14973-6-git-send-email-aliguori@us.ibm.com> Subject: Re: [Qemu-devel] [PATCH 05/12] spapr-vty: add qtest test case List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Alexey Kardashevskiy , qemu-ppc@nongnu.org, Paul Mackerras , qemu-devel@nongnu.org, Andreas Faerber On 19.06.2013, at 22:40, Anthony Liguori wrote: > Pretty basic for the moment but the interface is pretty simple. >=20 > Signed-off-by: Anthony Liguori > --- > tests/Makefile | 3 ++ > tests/spapr-vty-test.c | 89 = ++++++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 92 insertions(+) > create mode 100644 tests/spapr-vty-test.c >=20 > diff --git a/tests/Makefile b/tests/Makefile > index c107489..7c0ce1a 100644 > --- a/tests/Makefile > +++ b/tests/Makefile > @@ -67,6 +67,8 @@ gcov-files-sparc64-y +=3D hw/m48t59.c > check-qtest-arm-y =3D tests/tmp105-test$(EXESUF) > gcov-files-arm-y +=3D hw/tmp105.c >=20 > +check-qtest-ppc64-y =3D tests/spapr-vty-test$(EXESUF) > + > GENERATED_HEADERS +=3D tests/test-qapi-types.h tests/test-qapi-visit.h = tests/test-qmp-commands.h >=20 > test-obj-y =3D tests/check-qint.o tests/check-qstring.o = tests/check-qdict.o \ > @@ -133,6 +135,7 @@ tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o > tests/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y) > tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y) > tests/fw_cfg-test$(EXESUF): tests/fw_cfg-test.o $(libqos-pc-obj-y) > +tests/spapr-vty-test$(EXESUF): tests/spapr-vty-test.o >=20 > # QTest rules >=20 > diff --git a/tests/spapr-vty-test.c b/tests/spapr-vty-test.c > new file mode 100644 > index 0000000..8e3908b > --- /dev/null > +++ b/tests/spapr-vty-test.c > @@ -0,0 +1,89 @@ > +/* > + * QTest testcase for the sPAPR VTY > + * > + * Copyright IBM, Corp. 2013 > + * > + * Authors: > + * Anthony Liguori > + * > + * This work is licensed under the terms of the GNU GPL, version 2 or = later. > + * See the COPYING file in the top-level directory. > + * > + */ > +#include "libqtest.h" > + > +#include > +#include > +#include > +#include > +#include > + > +#define H_GET_TERM_CHAR 0x54 > +#define H_PUT_TERM_CHAR 0x58 > + > +static char *qmp_ringbuf_read(const char *device, int max_len) > +{ > + size_t len; > + char *ret; > + char *ptr; > + > + ret =3D qtest_qmp(global_qtest, > + "{ 'execute': 'ringbuf-read', " > + " 'arguments': { 'device': '%s', 'size': %d } = }", > + device, max_len); > + len =3D strlen(ret); > + > + /* Skip pass {"return" */ > + ptr =3D strchr(ret, '"'); > + g_assert(ptr !=3D NULL); > + ptr =3D strchr(ptr + 1, '"'); > + g_assert(ptr !=3D NULL); > + > + /* Start of data */ > + ptr =3D strchr(ptr + 1, '"'); > + g_assert(ptr !=3D NULL); > + ptr +=3D 1; > + > + len -=3D ptr - ret; > + memmove(ret, ptr, len); > + ret[len] =3D 0; > + > + ptr =3D strrchr(ret, '"'); > + g_assert(ptr !=3D NULL); > + *ptr =3D 0; Can't this be moved to a more generic function? Something along the = lines of char *qmp_execute(const char *device, int max_len, const char *func, = const char *args) and then call it like: return qmp_execute(device, max_len, "ringbuf-read", ""); here? Or let the caller do the argument gathering completely. But a = function like surely occurs in other places too, no? > + > + return ret; > +} > + > +static void vty_ping(void) > +{ > + const char *greeting =3D "Hello, world!"; > + char *data; > + int i; > + > + for (i =3D 0; greeting[i]; i++) { > + spapr_hcall3(H_PUT_TERM_CHAR, 0, 1, (uint64_t)greeting[i] << = 56); This looks like endianness breakage? Hypercall arguments should go in = native endianness. Registers don't have endianness. Only memory accesses = do. Alex > + } > + > + save_restore(); > + > + data =3D qmp_ringbuf_read("ring0", 16); > + g_assert_cmpstr(data, =3D=3D, greeting); > +} > + > +int main(int argc, char **argv) > +{ > + int ret; > + > + g_test_init(&argc, &argv, NULL); > + > + qtest_start("-display none -serial chardev:ring0 " > + "-machine pseries -chardev memory,id=3Dring0,save=3Don"= ); > + > + qtest_add_func("/vty/ping", vty_ping); > + ret =3D g_test_run(); > + > + qtest_quit(global_qtest); > + > + return ret; > +} > --=20 > 1.8.0 >=20