[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v2 02/25] tests/test-char: add muxed chardev testing
From: |
Marc-André Lureau |
Subject: |
[Qemu-devel] [PULL v2 02/25] tests/test-char: add muxed chardev testing for open/close |
Date: |
Wed, 13 Feb 2019 17:18:50 +0100 |
From: Artem Pisarenko <address@hidden>
Validate that frontend callbacks for CHR_EVENT_OPENED/CHR_EVENT_CLOSED
events are being issued when expected and in strictly pairing order.
Signed-off-by: Artem Pisarenko <address@hidden>
Reviewed-by: Marc-André Lureau <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Marc-André Lureau <address@hidden>
---
tests/test-char.c | 80 +++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 78 insertions(+), 2 deletions(-)
diff --git a/tests/test-char.c b/tests/test-char.c
index 19c3efad72..018e2eed93 100644
--- a/tests/test-char.c
+++ b/tests/test-char.c
@@ -16,6 +16,9 @@ static bool quit;
typedef struct FeHandler {
int read_count;
+ bool is_open;
+ int openclose_count;
+ bool openclose_mismatch;
int last_event;
char read_buf[128];
} FeHandler;
@@ -49,10 +52,24 @@ static void fe_read(void *opaque, const uint8_t *buf, int
size)
static void fe_event(void *opaque, int event)
{
FeHandler *h = opaque;
+ bool new_open_state;
h->last_event = event;
- if (event != CHR_EVENT_BREAK) {
+ switch (event) {
+ case CHR_EVENT_BREAK:
+ break;
+ case CHR_EVENT_OPENED:
+ case CHR_EVENT_CLOSED:
+ h->openclose_count++;
+ new_open_state = (event == CHR_EVENT_OPENED);
+ if (h->is_open == new_open_state) {
+ h->openclose_mismatch = true;
+ }
+ h->is_open = new_open_state;
+ /* no break */
+ default:
quit = true;
+ break;
}
}
@@ -161,7 +178,7 @@ static void char_mux_test(void)
QemuOpts *opts;
Chardev *chr, *base;
char *data;
- FeHandler h1 = { 0, }, h2 = { 0, };
+ FeHandler h1 = { 0, false, 0, false, }, h2 = { 0, false, 0, false, };
CharBackend chr_be1, chr_be2;
opts = qemu_opts_create(qemu_find_opts("chardev"), "mux-label",
@@ -233,6 +250,65 @@ static void char_mux_test(void)
g_assert_cmpint(h1.last_event, ==, CHR_EVENT_BREAK);
g_assert_cmpint(h2.last_event, ==, CHR_EVENT_MUX_OUT);
+ /* open/close state and corresponding events */
+ g_assert_true(qemu_chr_fe_backend_open(&chr_be1));
+ g_assert_true(qemu_chr_fe_backend_open(&chr_be2));
+ g_assert_true(h1.is_open);
+ g_assert_false(h1.openclose_mismatch);
+ g_assert_true(h2.is_open);
+ g_assert_false(h2.openclose_mismatch);
+
+ h1.openclose_count = h2.openclose_count = 0;
+
+ qemu_chr_fe_set_handlers(&chr_be1, NULL, NULL, NULL, NULL,
+ NULL, NULL, false);
+ qemu_chr_fe_set_handlers(&chr_be2, NULL, NULL, NULL, NULL,
+ NULL, NULL, false);
+ g_assert_cmpint(h1.openclose_count, ==, 0);
+ g_assert_cmpint(h2.openclose_count, ==, 0);
+
+ h1.is_open = h2.is_open = false;
+ qemu_chr_fe_set_handlers(&chr_be1,
+ NULL,
+ NULL,
+ fe_event,
+ NULL,
+ &h1,
+ NULL, false);
+ qemu_chr_fe_set_handlers(&chr_be2,
+ NULL,
+ NULL,
+ fe_event,
+ NULL,
+ &h2,
+ NULL, false);
+ g_assert_cmpint(h1.openclose_count, ==, 1);
+ g_assert_false(h1.openclose_mismatch);
+ g_assert_cmpint(h2.openclose_count, ==, 1);
+ g_assert_false(h2.openclose_mismatch);
+
+ qemu_chr_be_event(base, CHR_EVENT_CLOSED);
+ qemu_chr_be_event(base, CHR_EVENT_OPENED);
+ g_assert_cmpint(h1.openclose_count, ==, 3);
+ g_assert_false(h1.openclose_mismatch);
+ g_assert_cmpint(h2.openclose_count, ==, 3);
+ g_assert_false(h2.openclose_mismatch);
+
+ qemu_chr_fe_set_handlers(&chr_be2,
+ fe_can_read,
+ fe_read,
+ fe_event,
+ NULL,
+ &h2,
+ NULL, false);
+ qemu_chr_fe_set_handlers(&chr_be1,
+ fe_can_read,
+ fe_read,
+ fe_event,
+ NULL,
+ &h1,
+ NULL, false);
+
/* remove first handler */
qemu_chr_fe_set_handlers(&chr_be1, NULL, NULL, NULL, NULL,
NULL, NULL, true);
--
2.21.0.rc0.1.g036caf7885
- [Qemu-devel] [PULL v2 00/25] Chardev patches, Marc-André Lureau, 2019/02/13
- [Qemu-devel] [PULL v2 04/25] io: add qio_task_wait_thread to join with a background thread, Marc-André Lureau, 2019/02/13
- [Qemu-devel] [PULL v2 10/25] chardev: remove unused 'sioc' variable & cleanup paths, Marc-André Lureau, 2019/02/13
- [Qemu-devel] [PULL v2 07/25] chardev: forbid 'wait' option with client sockets, Marc-André Lureau, 2019/02/13
- [Qemu-devel] [PULL v2 08/25] chardev: remove many local variables in qemu_chr_parse_socket, Marc-André Lureau, 2019/02/13
- [Qemu-devel] [PULL v2 02/25] tests/test-char: add muxed chardev testing for open/close,
Marc-André Lureau <=
- [Qemu-devel] [PULL v2 09/25] chardev: ensure qemu_chr_parse_compat reports missing driver error, Marc-André Lureau, 2019/02/13
- [Qemu-devel] [PULL v2 05/25] chardev: fix validation of options for QMP created chardevs, Marc-André Lureau, 2019/02/13
- [Qemu-devel] [PULL v2 03/25] io: store reference to thread information in the QIOTask struct, Marc-André Lureau, 2019/02/13
- [Qemu-devel] [PULL v2 01/25] chardev: fix mess in OPENED/CLOSED events when muxed, Marc-André Lureau, 2019/02/13
- [Qemu-devel] [PULL v2 06/25] chardev: forbid 'reconnect' option with server sockets, Marc-André Lureau, 2019/02/13
- [Qemu-devel] [PULL v2 12/25] chardev: split up qmp_chardev_open_socket connection code, Marc-André Lureau, 2019/02/13
- [Qemu-devel] [PULL v2 11/25] chardev: split tcp_chr_wait_connected into two methods, Marc-André Lureau, 2019/02/13
- [Qemu-devel] [PULL v2 14/25] chardev: honour the reconnect setting in tcp_chr_wait_connected, Marc-André Lureau, 2019/02/13
- [Qemu-devel] [PULL v2 13/25] chardev: use a state machine for socket connection state, Marc-André Lureau, 2019/02/13
- [Qemu-devel] [PULL v2 15/25] chardev: disallow TLS/telnet/websocket with tcp_chr_wait_connected, Marc-André Lureau, 2019/02/13