From: Anthony Liguori <aliguori@us.ibm.com>
To: Alexander Graf <agraf@suse.de>
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>,
qemu-ppc@nongnu.org, Paul Mackerras <paulus@samba.org>,
qemu-devel@nongnu.org, Andreas Faerber <afaerber@suse.de>
Subject: Re: [Qemu-devel] [PATCH 05/12] spapr-vty: add qtest test case
Date: Wed, 19 Jun 2013 16:43:09 -0500 [thread overview]
Message-ID: <8738sdhj4i.fsf@codemonkey.ws> (raw)
In-Reply-To: <3CCEF1E4-C499-4265-9392-CD53CB5C43DD@suse.de>
Alexander Graf <agraf@suse.de> writes:
> On 19.06.2013, at 22:40, Anthony Liguori wrote:
>
>> Pretty basic for the moment but the interface is pretty simple.
>>
>> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
>> ---
>> tests/Makefile | 3 ++
>> tests/spapr-vty-test.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++
>> 2 files changed, 92 insertions(+)
>> create mode 100644 tests/spapr-vty-test.c
>>
>> 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 += hw/m48t59.c
>> check-qtest-arm-y = tests/tmp105-test$(EXESUF)
>> gcov-files-arm-y += hw/tmp105.c
>>
>> +check-qtest-ppc64-y = tests/spapr-vty-test$(EXESUF)
>> +
>> GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h tests/test-qmp-commands.h
>>
>> test-obj-y = 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
>>
>> # QTest rules
>>
>> 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 <aliguori@us.ibm.com>
>> + *
>> + * 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 <glib.h>
>> +#include <stdio.h>
>> +#include <string.h>
>> +#include <stdlib.h>
>> +#include <unistd.h>
>> +
>> +#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 = qtest_qmp(global_qtest,
>> + "{ 'execute': 'ringbuf-read', "
>> + " 'arguments': { 'device': '%s', 'size': %d } }",
>> + device, max_len);
>> + len = strlen(ret);
>> +
>> + /* Skip pass {"return" */
>> + ptr = strchr(ret, '"');
>> + g_assert(ptr != NULL);
>> + ptr = strchr(ptr + 1, '"');
>> + g_assert(ptr != NULL);
>> +
>> + /* Start of data */
>> + ptr = strchr(ptr + 1, '"');
>> + g_assert(ptr != NULL);
>> + ptr += 1;
>> +
>> + len -= ptr - ret;
>> + memmove(ret, ptr, len);
>> + ret[len] = 0;
>> +
>> + ptr = strrchr(ret, '"');
>> + g_assert(ptr != NULL);
>> + *ptr = 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", "");
Yeah, it's not that simple. We need to pull in the JSON parsing code
etc too.
I'm going to look into that but I think it's outside the scope of this series.
> here? Or let the caller do the argument gathering completely. But a
> function like surely occurs in other places too, no?
qmp support is pretty new in qtest and not quite baked yet. My
expectation is that this function will disappear over time.
>> +
>> + return ret;
>> +}
>> +
>> +static void vty_ping(void)
>> +{
>> + const char *greeting = "Hello, world!";
>> + char *data;
>> + int i;
>> +
>> + for (i = 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.
Yes, you are correct re: hcall args but it's not a breakage.
VTY is weird. The characters are packed into the arguments. So sending
two chars would look like:
spapr_hcall3(H_PUT_TERM_CHAR, 0, 2,
(uint64_t)greeting[0] << 56 |
(uint64_t)greeting[1] << 48);
It can take an additional argument too for the next 8 bytes.
So even within the Linux kernel or SLOF on big endian, the code would
look like this too.
Regards,
Anthony Liguori
>
>
> Alex
>
>> + }
>> +
>> + save_restore();
>> +
>> + data = qmp_ringbuf_read("ring0", 16);
>> + g_assert_cmpstr(data, ==, 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=ring0,save=on");
>> +
>> + qtest_add_func("/vty/ping", vty_ping);
>> + ret = g_test_run();
>> +
>> + qtest_quit(global_qtest);
>> +
>> + return ret;
>> +}
>> --
>> 1.8.0
>>
next prev parent reply other threads:[~2013-06-19 21:43 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-19 20:40 [Qemu-devel] [PATCH 00/12] spapr: add qtest support and refactor vty Anthony Liguori
2013-06-19 20:40 ` [Qemu-devel] [PATCH 01/12] chardev: ringbuf: add optional save parameter to save state Anthony Liguori
2013-06-20 19:49 ` Eric Blake
2013-06-19 20:40 ` [Qemu-devel] [PATCH 02/12] qtest: add spapr hypercall support Anthony Liguori
2013-06-20 15:20 ` Andreas Färber
2013-06-20 15:42 ` Anthony Liguori
2013-06-20 18:43 ` Alexander Graf
2013-06-20 18:58 ` Anthony Liguori
2013-06-20 19:28 ` [Qemu-devel] [Qemu-ppc] " Scott Wood
2013-06-20 21:57 ` [Qemu-devel] " Alexander Graf
2013-06-19 20:40 ` [Qemu-devel] [PATCH 03/12] qtest: return string from QMP commands Anthony Liguori
2013-06-20 15:24 ` Andreas Färber
2013-06-20 15:43 ` Anthony Liguori
2013-06-19 20:40 ` [Qemu-devel] [PATCH 04/12] qtest: add interface to save/restore Anthony Liguori
2013-06-20 15:38 ` Andreas Färber
2013-06-19 20:40 ` [Qemu-devel] [PATCH 05/12] spapr-vty: add qtest test case Anthony Liguori
2013-06-19 21:13 ` Alexander Graf
2013-06-19 21:43 ` Anthony Liguori [this message]
2013-06-19 21:47 ` Alexander Graf
2013-06-19 20:40 ` [Qemu-devel] [PATCH 06/12] spapr-vty: add copyright and license Anthony Liguori
2013-06-20 1:45 ` Michael Ellerman
2013-06-20 4:08 ` Alexey Kardashevskiy
2013-06-20 4:43 ` David Gibson
2013-06-20 8:52 ` Paolo Bonzini
2013-06-20 15:47 ` Andreas Färber
2013-06-19 20:40 ` [Qemu-devel] [PATCH 07/12] spapr-rtas: add CPU argument to RTAS calls Anthony Liguori
2013-06-19 21:15 ` Alexander Graf
2013-06-20 15:51 ` Andreas Färber
2013-06-20 16:10 ` Anthony Liguori
2013-06-19 20:40 ` [Qemu-devel] [PATCH 08/12] spapr-rtas: use hypercall interface and remove special vty interfaces Anthony Liguori
2013-06-19 21:24 ` Alexander Graf
2013-06-19 21:45 ` Anthony Liguori
2013-06-19 21:48 ` Alexander Graf
2013-06-19 20:40 ` [Qemu-devel] [PATCH 09/12] spapr-vio: move special case handling for reg=0 to vio Anthony Liguori
2013-06-19 21:28 ` Alexander Graf
2013-06-19 21:49 ` Anthony Liguori
2013-06-19 21:53 ` Alexander Graf
2013-06-19 23:20 ` Anthony Liguori
2013-06-19 23:07 ` Benjamin Herrenschmidt
2013-06-19 20:40 ` [Qemu-devel] [PATCH 10/12] spapr-vty: refactor the code to improve consistency Anthony Liguori
2013-06-19 21:37 ` Alexander Graf
2013-06-19 20:40 ` [Qemu-devel] [PATCH 11/12] spapr-vio: pass type to spapr_vio_find_by_reg() Anthony Liguori
2013-06-19 21:38 ` Alexander Graf
2013-06-19 21:56 ` Anthony Liguori
2013-06-19 20:40 ` [Qemu-devel] [PATCH 12/12] spapr-vty: remove unfixable FIXME Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8738sdhj4i.fsf@codemonkey.ws \
--to=aliguori@us.ibm.com \
--cc=afaerber@suse.de \
--cc=agraf@suse.de \
--cc=aik@ozlabs.ru \
--cc=paulus@samba.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).