From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: stefanha@gmail.com, "Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [PULL 17/21] tests: add /char/pipe test
Date: Thu, 4 May 2017 15:42:28 +0400 [thread overview]
Message-ID: <20170504114232.20318-18-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20170504114232.20318-1-marcandre.lureau@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
tests/test-char.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 90 insertions(+)
diff --git a/tests/test-char.c b/tests/test-char.c
index 2811644bcd..2b155ffcb7 100644
--- a/tests/test-char.c
+++ b/tests/test-char.c
@@ -1,4 +1,5 @@
#include "qemu/osdep.h"
+#include <glib/gstdio.h>
#include "qemu-common.h"
#include "qemu/config-file.h"
@@ -7,12 +8,28 @@
#include "qapi/error.h"
#include "qmp-commands.h"
+static bool quit;
+
typedef struct FeHandler {
int read_count;
int last_event;
char read_buf[128];
} FeHandler;
+#ifndef _WIN32
+static void main_loop(void)
+{
+ bool nonblocking;
+ int last_io = 0;
+
+ quit = false;
+ do {
+ nonblocking = last_io > 0;
+ last_io = main_loop_wait(nonblocking);
+ } while (!quit);
+}
+#endif
+
static int fe_can_read(void *opaque)
{
FeHandler *h = opaque;
@@ -28,6 +45,7 @@ static void fe_read(void *opaque, const uint8_t *buf, int size)
memcpy(h->read_buf + h->read_count, buf, size);
h->read_count += size;
+ quit = true;
}
static void fe_event(void *opaque, int event)
@@ -35,6 +53,7 @@ static void fe_event(void *opaque, int event)
FeHandler *h = opaque;
h->last_event = event;
+ quit = true;
}
#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
@@ -192,6 +211,72 @@ static void char_mux_test(void)
object_unparent(OBJECT(chr));
}
+#ifndef _WIN32
+static void char_pipe_test(void)
+{
+ gchar *tmp_path = g_dir_make_tmp("qemu-test-char.XXXXXX", NULL);
+ gchar *tmp, *in, *out, *pipe = g_build_filename(tmp_path, "pipe", NULL);
+ Chardev *chr;
+ CharBackend be;
+ int ret, fd;
+ char buf[10];
+ FeHandler fe = { 0, };
+
+ in = g_strdup_printf("%s.in", pipe);
+ if (mkfifo(in, 0600) < 0) {
+ abort();
+ }
+ out = g_strdup_printf("%s.out", pipe);
+ if (mkfifo(out, 0600) < 0) {
+ abort();
+ }
+
+ tmp = g_strdup_printf("pipe:%s", pipe);
+ chr = qemu_chr_new("pipe", tmp);
+ g_assert_nonnull(chr);
+ g_free(tmp);
+
+ qemu_chr_fe_init(&be, chr, &error_abort);
+
+ ret = qemu_chr_fe_write(&be, (void *)"pipe-out", 9);
+ g_assert_cmpint(ret, ==, 9);
+
+ fd = open(out, O_RDWR);
+ ret = read(fd, buf, sizeof(buf));
+ g_assert_cmpint(ret, ==, 9);
+ g_assert_cmpstr(buf, ==, "pipe-out");
+ close(fd);
+
+ fd = open(in, O_WRONLY);
+ ret = write(fd, "pipe-in", 8);
+ g_assert_cmpint(ret, ==, 8);
+ close(fd);
+
+ qemu_chr_fe_set_handlers(&be,
+ fe_can_read,
+ fe_read,
+ fe_event,
+ &fe,
+ NULL, true);
+
+ main_loop();
+
+ g_assert_cmpint(fe.read_count, ==, 8);
+ g_assert_cmpstr(fe.read_buf, ==, "pipe-in");
+
+ qemu_chr_fe_deinit(&be);
+ object_unparent(OBJECT(chr));
+
+ g_assert(g_unlink(in) == 0);
+ g_assert(g_unlink(out) == 0);
+ g_assert(g_rmdir(tmp_path) == 0);
+ g_free(in);
+ g_free(out);
+ g_free(tmp_path);
+ g_free(pipe);
+}
+#endif
+
static void char_null_test(void)
{
Error *err = NULL;
@@ -245,6 +330,8 @@ static void char_invalid_test(void)
int main(int argc, char **argv)
{
+ qemu_init_main_loop(&error_abort);
+
g_test_init(&argc, &argv, NULL);
module_call_init(MODULE_INIT_QOM);
@@ -258,6 +345,9 @@ int main(int argc, char **argv)
g_test_add_func("/char/stdio/subprocess", char_stdio_test_subprocess);
g_test_add_func("/char/stdio", char_stdio_test);
#endif
+#ifndef _WIN32
+ g_test_add_func("/char/pipe", char_pipe_test);
+#endif
return g_test_run();
}
--
2.12.0.191.gc5d8de91d
next prev parent reply other threads:[~2017-05-04 11:44 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-04 11:42 [Qemu-devel] [PULL 00/21] Chr tests patches Marc-André Lureau
2017-05-04 11:42 ` [Qemu-devel] [PULL 01/21] char: remove qemu_chr_be_generic_open Marc-André Lureau
2017-05-04 11:42 ` [Qemu-devel] [PULL 02/21] mux: simplfy muxes_realize_done Marc-André Lureau
2017-05-04 11:42 ` [Qemu-devel] [PULL 03/21] xen: use a better chardev type check Marc-André Lureau
2017-05-04 11:42 ` [Qemu-devel] [PULL 04/21] container: don't leak container reference Marc-André Lureau
2017-05-04 11:42 ` [Qemu-devel] [PULL 05/21] char: add a /chardevs container Marc-André Lureau
2017-05-04 11:42 ` [Qemu-devel] [PULL 06/21] vl: add todo note about root container cleanup Marc-André Lureau
2017-05-04 11:42 ` [Qemu-devel] [PULL 07/21] char: use /chardevs container instead of chardevs list Marc-André Lureau
2017-05-04 11:42 ` [Qemu-devel] [PULL 08/21] char: remove qemu_chardev_add Marc-André Lureau
2017-05-04 11:42 ` [Qemu-devel] [PULL 09/21] char: remove chardevs list Marc-André Lureau
2017-05-04 11:42 ` [Qemu-devel] [PULL 10/21] char: useless NULL check Marc-André Lureau
2017-05-04 11:42 ` [Qemu-devel] [PULL 11/21] char-socket: introduce update_disconnected_filename() Marc-André Lureau
2017-05-04 11:42 ` [Qemu-devel] [PULL 12/21] char-socket: update local address after listen Marc-André Lureau
2017-05-04 11:42 ` [Qemu-devel] [PULL 13/21] char-socket: add 'addr' property Marc-André Lureau
2017-05-04 11:42 ` [Qemu-devel] [PULL 14/21] char-socket: add 'connected' property Marc-André Lureau
2017-05-04 11:42 ` [Qemu-devel] [PULL 15/21] char-udp: flush as much buffer as possible Marc-André Lureau
2017-05-04 11:42 ` [Qemu-devel] [PULL 16/21] tests: add alias check in /char/ringbuf Marc-André Lureau
2017-05-04 11:42 ` Marc-André Lureau [this message]
2017-05-04 11:42 ` [Qemu-devel] [PULL 18/21] tests: add /char/file test Marc-André Lureau
2017-05-04 11:42 ` [Qemu-devel] [PULL 19/21] tests: add /char/socket test Marc-André Lureau
2017-05-04 11:42 ` [Qemu-devel] [PULL 20/21] tests: add /char/udp test Marc-André Lureau
2017-05-04 11:42 ` [Qemu-devel] [PULL 21/21] tests: add /char/console test Marc-André Lureau
2017-05-05 16:08 ` [Qemu-devel] [PULL 00/21] Chr tests patches Stefan Hajnoczi
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=20170504114232.20318-18-marcandre.lureau@redhat.com \
--to=marcandre.lureau@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
/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).