qtest: Add floppy media change test
cover qtest: Add floppy media change test
Kevin Wolf (2):
qtest: Add function to send QMP commands
qtest: Add floppy test
tests/Makefile | 2 + tests/fdc-test.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/libqtest.c | 123 ++++++++++++++++++++++++++++-------- tests/libqtest.h | 17 +++++ 4 files changed, 301 insertions(+), 27 deletions(-) create mode 100644 tests/fdc-test.c
Signature · 1 line
1.7.6.5
PATCH 2/2 qtest: Add floppy test
Let's start with testing media change.
--- tests/Makefile | 2 + tests/fdc-test.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+), 0 deletions(-) create mode 100644 tests/fdc-test.c
tests/Makefile +2 -0
@@ -19,6 +19,7 @@ check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh # All QTests for now are POSIX-only, but the dependencies are # really in libqtest, not in the testcases themselves. check-qtest-i386-y = tests/rtc-test +check-qtest-i386-y = tests/fdc-test check-qtest-x86_64-y = $(check-qtest-i386-y) check-qtest-sparc-y = tests/m48t59-test$(EXESUF) check-qtest-sparc64-y = tests/m48t59-test$(EXESUF)
@@ -67,6 +68,7 @@ tests/test-qmp-commands$(EXESUF): tests/test-qmp-commands.o tests/test-qmp-marsh tests/rtc-test$(EXESUF): tests/rtc-test.o $(trace-obj-y) tests/m48t59-test$(EXESUF): tests/m48t59-test.o $(trace-obj-y) +tests/fdc-test$(EXESUF): tests/fdc-test.o tests/libqtest.o # QTest rules
tests/fdc-test.c new file +186 -0
186 lines not on this page · raw message
Signature · 1 line
1.7.6.5
PATCH 1/2 qtest: Add function to send QMP commands
In reply to Kevin Wolf--- tests/libqtest.c | 123 ++++++++++++++++++++++++++++++++++++++++++------------ tests/libqtest.h | 17 +++++++ 2 files changed, 113 insertions(+), 27 deletions(-)
tests/libqtest.c +96 -27
@@ -36,6 +36,7 @@ QTestState *global_qtest;struct QTestState {int fd; +int qmp_fd;bool irq_level[MAX_IRQ ];GString *rx;gchar *pid_file;
@@ -45,48 +46,76 @@ struct QTestState g_assert_cmpint(ret, !=, -1); \ }while (0 ) +static int init_socket(const char *socket_path) +{ +struct sockaddr_un addr; +int sock; +int ret; + + sock =socket (PF_UNIX ,SOCK_STREAM ,0 ); +g_assert_no_errno (sock); + + addr.sun_family =AF_UNIX ; +snprintf (addr.sun_path,sizeof (addr.sun_path),"%s" , socket_path); +qemu_set_cloexec (sock); + +do { + ret =bind (sock, (struct sockaddr *)&addr,sizeof (addr)); + }while (ret ==-1 && errno ==EINTR ); +g_assert_no_errno (ret); +listen (sock,1 ); + +return sock; +} + +static int socket_accept (int sock) +{ +struct sockaddr_un addr; +socklen_t addrlen; +int ret; + +do { + ret =accept (sock, (struct sockaddr *)&addr, &addrlen); + }while (ret ==-1 && errno ==EINTR ); +g_assert_no_errno (ret); +close (sock); + +return ret; +} +QTestState *qtest_init (const char *extra_args) {QTestState *s; -struct sockaddr_un addr; -int sock, ret, i; +int sock, qmpsock, ret, i;gchar *socket_path; +gchar *qmp_socket_path;gchar *pid_file;gchar *command;const char *qemu_binary;pid_t pid; -socklen_t addrlen; qemu_binary =getenv ("QTEST_QEMU_BINARY" );g_assert (qemu_binary !=NULL ); socket_path =g_strdup_printf ("/tmp/qtest-%d.sock" ,getpid ()); + qmp_socket_path =g_strdup_printf ("/tmp/qtest-%d.qmp" ,getpid ()); pid_file =g_strdup_printf ("/tmp/qtest-%d.pid" ,getpid ()); s =g_malloc (sizeof (*s)); - sock =socket (PF_UNIX ,SOCK_STREAM ,0 ); -g_assert_no_errno (sock); - - addr.sun_family =AF_UNIX ; -snprintf (addr.sun_path,sizeof (addr.sun_path),"%s" , socket_path); -qemu_set_cloexec (sock); - -do { - ret =bind (sock, (struct sockaddr *)&addr,sizeof (addr)); - }while (ret ==-1 && errno ==EINTR ); -g_assert_no_errno (ret); -listen (sock,1 ); + sock =init_socket (socket_path); + qmpsock =init_socket (qmp_socket_path); pid =fork ();if (pid ==0 ) { command =g_strdup_printf ("%s " "-qtest unix:%s,nowait " "-qtest-log /dev/null " +"-qmp unix:%s,nowait " "-pidfile %s " "-machine accel=qtest " "%s" , qemu_binary, socket_path, - pid_file, + qmp_socket_path, pid_file, extra_args ?:"" ); ret =system (command);
@@ -94,13 +123,9 @@ QTestState *qtest_init(const char *extra_args)g_free (command); } -do { - ret =accept (sock, (struct sockaddr *)&addr, &addrlen); - }while (ret ==-1 && errno ==EINTR ); -g_assert_no_errno (ret); -close (sock); + s->fd =socket_accept (sock); + s->qmp_fd =socket_accept (qmpsock); - s->fd = ret; s->rx =g_string_new ("" ); s->pid_file = pid_file;for (i =0 ; i <MAX_IRQ ; i++) {
@@ -108,6 +133,11 @@ QTestState *qtest_init(const char *extra_args) }g_free (socket_path); +g_free (qmp_socket_path); + +/* Read the QMP greeting and then do the handshake */ +qtest_qmp (s,"" ); +qtest_qmp (s,"{ 'execute': 'qmp_capabilities' }" );return s; }
@@ -131,22 +161,19 @@ void qtest_quit(QTestState *s) } } -static void GCC_FMT_ATTR(2, 3) qtest_sendf(QTestState *s, const char *fmt, ...) +static void socket_sendf (int fd,const char *fmt,va_list ap) { -va_list ap;gchar *str;size_t size, offset; -va_start (ap, fmt); str =g_strdup_vprintf (fmt, ap); -va_end (ap); size =strlen (str); offset =0 ;while (offset < size) {ssize_t len; - len =write (s->fd, str + offset, size - offset); + len =write (fd, str + offset, size - offset);if (len ==-1 && errno ==EINTR ) {continue ; }
@@ -158,6 +185,15 @@ static void GCC_FMT_ATTR(2, 3) qtest_sendf(QTestState *s, const char *fmt, ...) } } +static void GCC_FMT_ATTR(2, 3) qtest_sendf(QTestState *s, const char *fmt, ...) +{ +va_list ap; + +va_start (ap, fmt); +socket_sendf (s->fd, fmt, ap); +va_end (ap); +} +static GString *qtest_recv_line (QTestState *s) {GString *line;
@@ -233,6 +269,39 @@ redo:return words; } +void qtest_qmp (QTestState *s,const char *fmt, ...) +{ +va_list ap; +bool has_reply = false; +int nesting =0 ; + +/* Send QMP request */ +va_start (ap, fmt); +socket_sendf (s->qmp_fd, fmt, ap); +va_end (ap); + +/* Receive reply */ +while (!has_reply || nesting >0 ) { +ssize_t len; +char c; + + len =read (s->qmp_fd, &c,1 ); +if (len ==-1 && errno ==EINTR ) { +continue ; + } + +switch (c) { +case '{' : + nesting++; + has_reply = true; +break ; +case '}' : + nesting--; +break ; + } + } +} +const char *qtest_get_arch (void ) {const char *qemu =getenv ("QTEST_QEMU_BINARY" );
tests/libqtest.h +17 -0
@@ -38,6 +38,15 @@ QTestState *qtest_init(const char *extra_args);void qtest_quit (QTestState *s);/** +* qtest_qmp: +* @s: QTestState instance to operate on. +* @fmt...: QMP message to send to qemu +* +* Sends a QMP message to QEMU +*/ +void qtest_qmp (QTestState *s,const char *fmt, ...); + +/** * qtest_get_irq: * @s: QTestState instance to operate on. * @num: Interrupt to observe.
@@ -207,6 +216,14 @@ void qtest_add_func(const char *str, void (*fn)); )/** +* qmp: +* @fmt...: QMP message to send to qemu +* +* Sends a QMP message to QEMU +*/ +#define qmp (fmt, ...) qtest_qmp(global_qtest, fmt, ## __VA_ARGS__) + +/** * get_irq: * @num: Interrupt to observe. *
Signature · 1 line
1.7.6.5
Re: [Qemu-devel] [PATCH 2/2] qtest: Add floppy test
In reply to Kevin WolfAm 08.05.2012 17:51, schrieb Kevin Wolf:
Quoted 14 lines
Let's start with testing media change.
Signed-off-by Kevin Wolf <[email protected]>--- tests/Makefile | 2 + tests/fdc-test.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+), 0 deletions(-) create mode 100644 tests/fdc-test.ctests/Makefile +0
-0
tests/Makefile check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh · line 22
Quoted 4 lines
tests/Makefile +1
-0@@ -19,6 +19,7 @@ check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh # All QTests for now are POSIX-only, but the dependencies are # really in libqtest, not in the testcases themselves. check-qtest-i386-y = tests/rtc-test +check-qtest-i386-y = tests/fdc-test
$(EXESUF)?
tests/Makefile check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh · line 25
Quoted 3 lines
tests/Makefile +0
-0check-qtest-x86_64-y = $(check-qtest-i386-y) check-qtest-sparc-y = tests/m48t59-test$(EXESUF) check-qtest-sparc64-y = tests/m48t59-test$(EXESUF)
Or are these wrong?
Andreas
Quoted 8 lines
tests/Makefile +1
-0@@ -67,6 +68,7 @@ tests/test-qmp-commands$(EXESUF): tests/test-qmp-commands.o tests/test-qmp-marsh tests/rtc-test$(EXESUF): tests/rtc-test.o $(trace-obj-y) tests/m48t59-test$(EXESUF): tests/m48t59-test.o $(trace-obj-y) +tests/fdc-test$(EXESUF): tests/fdc-test.o tests/libqtest.o # QTest rules
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH 2/2] qtest: Add floppy test
Am 09.05.2012 19:11, schrieb Andreas Färber:
Quoted 22 lines
Am 08.05.2012 17:51, schrieb Kevin Wolf:
Quoted 14 lines
Let's start with testing media change.
Signed-off-by Kevin Wolf <[email protected]>--- tests/Makefile | 2 + tests/fdc-test.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+), 0 deletions(-) create mode 100644 tests/fdc-test.ctests/Makefile +0
-0tests/Makefile check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh · line 22
Quoted 4 lines
tests/Makefile +1
-0@@ -19,6 +19,7 @@ check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh # All QTests for now are POSIX-only, but the dependencies are # really in libqtest, not in the testcases themselves. check-qtest-i386-y = tests/rtc-test +check-qtest-i386-y = tests/fdc-test$(EXESUF)?
Quoted 5 lines
tests/Makefile check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh · line 25
Quoted 3 lines
tests/Makefile +0
-0check-qtest-x86_64-y = $(check-qtest-i386-y) check-qtest-sparc-y = tests/m48t59-test$(EXESUF) check-qtest-sparc64-y = tests/m48t59-test$(EXESUF)Or are these wrong?
I think we should add $(EXESUF) indeed. I copied the rtc-test line where it's missing as well, so I'll send a patch on top that fixes both.
Kevin
Re: [Qemu-devel] [PATCH 2/2] qtest: Add floppy test
In reply to Andreas FärberIl 09/05/2012 19:11, Andreas Färber ha scritto:
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
# All QTests for now are POSIX-only, but the dependencies are
# really in libqtest, not in the testcases themselves. check-qtest-i386-y = tests/rtc-test +check-qtest-i386-y = tests/fdc-test$(EXESUF)?
In practice qtests will only run on machines with empty EXESUF, so it makes really no difference. Consistency would be nice though.
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
check-qtest-x86_64-y = $(check-qtest-i386-y) check-qtest-sparc-y = tests/m48t59-test$(EXESUF) check-qtest-sparc64-y = tests/m48t59-test$(EXESUF)
Or are these wrong?
Paolo
Il 08/05/2012 17:51, Kevin Wolf ha scritto:
Quoted 11 lines
Kevin Wolf (2):
qtest: Add function to send QMP commands
qtest: Add floppy testtests/Makefile | 2 + tests/fdc-test.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/libqtest.c | 123 ++++++++++++++++++++++++++++-------- tests/libqtest.h | 17 +++++ 4 files changed, 301 insertions(+), 27 deletions(-) create mode 100644 tests/fdc-test.c
Thanks for the QMP bits especially!