From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpPDP-0002fu-Dz for qemu-devel@nongnu.org; Wed, 19 Jun 2013 16:42:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UpPDN-0005TF-FQ for qemu-devel@nongnu.org; Wed, 19 Jun 2013 16:42:51 -0400 Received: from e32.co.us.ibm.com ([32.97.110.150]:50631) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpPDN-0005SS-0r for qemu-devel@nongnu.org; Wed, 19 Jun 2013 16:42:49 -0400 Received: from /spool/local by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 19 Jun 2013 14:42:47 -0600 From: Anthony Liguori Date: Wed, 19 Jun 2013 15:40:28 -0500 Message-Id: <1371674435-14973-6-git-send-email-aliguori@us.ibm.com> In-Reply-To: <1371674435-14973-1-git-send-email-aliguori@us.ibm.com> References: <1371674435-14973-1-git-send-email-aliguori@us.ibm.com> Subject: [Qemu-devel] [PATCH 05/12] spapr-vty: add qtest test case List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori , Alexey Kardashevskiy , Alex Graf , qemu-ppc@nongnu.org, Paul Mackerras , Andreas Faerber Pretty basic for the moment but the interface is pretty simple. 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 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 + * + * 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 = 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; + + 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); + } + + 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