aboutsummaryrefslogtreecommitdiff
path: root/tests/vhost-user-test.c
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2016-10-22 12:52:55 +0300
committerPaolo Bonzini <pbonzini@redhat.com>2016-10-24 15:27:21 +0200
commit5345fdb4467816c44f6752b3a1f4e73aa25919f9 (patch)
tree9930cf4370d2325d113408f7b314cd77aa43f8a3 /tests/vhost-user-test.c
parentfbf3cc3a67a7131e258764aa1f19d5324e9e9f7a (diff)
char: use qemu_chr_fe* functions with CharBackend argument
This also switches from qemu_chr_add_handlers() to qemu_chr_fe_set_handlers(). Note that qemu_chr_fe_set_handlers() now takes the focus when fe_open (qemu_chr_add_handlers() did take the focus) Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20161022095318.17775-16-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tests/vhost-user-test.c')
-rw-r--r--tests/vhost-user-test.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c
index 6e5383d8c2..2d86de1749 100644
--- a/tests/vhost-user-test.c
+++ b/tests/vhost-user-test.c
@@ -11,6 +11,7 @@
#include "qemu/osdep.h"
#include "libqtest.h"
+#include "qapi/error.h"
#include "qemu/option.h"
#include "qemu/range.h"
#include "qemu/sockets.h"
@@ -268,7 +269,7 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
int fd;
if (s->test_fail) {
- qemu_chr_fe_disconnect(chr->chr);
+ qemu_chr_fe_disconnect(chr);
/* now switch to non-failure */
s->test_fail = false;
}
@@ -283,7 +284,7 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
if (msg.size) {
p += VHOST_USER_HDR_SIZE;
- size = qemu_chr_fe_read_all(chr->chr, p, msg.size);
+ size = qemu_chr_fe_read_all(chr, p, msg.size);
if (size != msg.size) {
g_test_message("Wrong message size received %d != %d\n",
size, msg.size);
@@ -306,14 +307,14 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
s->test_flags = TEST_FLAGS_END;
}
p = (uint8_t *) &msg;
- qemu_chr_fe_write_all(chr->chr, p, VHOST_USER_HDR_SIZE + msg.size);
+ qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size);
break;
case VHOST_USER_SET_FEATURES:
g_assert_cmpint(msg.payload.u64 & (0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES),
!=, 0ULL);
if (s->test_flags == TEST_FLAGS_DISCONNECT) {
- qemu_chr_fe_disconnect(chr->chr);
+ qemu_chr_fe_disconnect(chr);
s->test_flags = TEST_FLAGS_BAD;
}
break;
@@ -327,7 +328,7 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
msg.payload.u64 |= 1 << VHOST_USER_PROTOCOL_F_MQ;
}
p = (uint8_t *) &msg;
- qemu_chr_fe_write_all(chr->chr, p, VHOST_USER_HDR_SIZE + msg.size);
+ qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size);
break;
case VHOST_USER_GET_VRING_BASE:
@@ -336,7 +337,7 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
msg.size = sizeof(m.payload.state);
msg.payload.state.num = 0;
p = (uint8_t *) &msg;
- qemu_chr_fe_write_all(chr->chr, p, VHOST_USER_HDR_SIZE + msg.size);
+ qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size);
assert(msg.payload.state.index < s->queues * 2);
s->rings &= ~(0x1ULL << msg.payload.state.index);
@@ -345,7 +346,7 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
case VHOST_USER_SET_MEM_TABLE:
/* received the mem table */
memcpy(&s->memory, &msg.payload.memory, sizeof(msg.payload.memory));
- s->fds_num = qemu_chr_fe_get_msgfds(chr->chr, s->fds,
+ s->fds_num = qemu_chr_fe_get_msgfds(chr, s->fds,
G_N_ELEMENTS(s->fds));
/* signal the test that it can continue */
@@ -355,7 +356,7 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
case VHOST_USER_SET_VRING_KICK:
case VHOST_USER_SET_VRING_CALL:
/* consume the fd */
- qemu_chr_fe_get_msgfds(chr->chr, &fd, 1);
+ qemu_chr_fe_get_msgfds(chr, &fd, 1);
/*
* This is a non-blocking eventfd.
* The receive function forces it to be blocking,
@@ -369,11 +370,11 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
close(s->log_fd);
s->log_fd = -1;
}
- qemu_chr_fe_get_msgfds(chr->chr, &s->log_fd, 1);
+ qemu_chr_fe_get_msgfds(chr, &s->log_fd, 1);
msg.flags |= VHOST_USER_REPLY_MASK;
msg.size = 0;
p = (uint8_t *) &msg;
- qemu_chr_fe_write_all(chr->chr, p, VHOST_USER_HDR_SIZE);
+ qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE);
g_cond_signal(&s->data_cond);
break;
@@ -388,7 +389,7 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
msg.size = sizeof(m.payload.u64);
msg.payload.u64 = s->queues;
p = (uint8_t *) &msg;
- qemu_chr_fe_write_all(chr->chr, p, VHOST_USER_HDR_SIZE + msg.size);
+ qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size);
break;
default:
@@ -456,13 +457,14 @@ static void test_server_create_chr(TestServer *server, const gchar *opt)
{
gchar *chr_path;
CharDriverState *chr;
+
chr_path = g_strdup_printf("unix:%s%s", server->socket_path, opt);
chr = qemu_chr_new(server->chr_name, chr_path);
- qemu_chr_fe_init(&server->chr, chr, &error_abort);
g_free(chr_path);
- qemu_chr_add_handlers(server->chr.chr, chr_can_read, chr_read,
- chr_event, server);
+ qemu_chr_fe_init(&server->chr, chr, &error_abort);
+ qemu_chr_fe_set_handlers(&server->chr, chr_can_read, chr_read,
+ chr_event, server, NULL);
}
static void test_server_listen(TestServer *server)
@@ -486,8 +488,9 @@ static inline void test_server_connect(TestServer *server)
static gboolean _test_server_free(TestServer *server)
{
int i;
+ CharDriverState *chr = qemu_chr_fe_get_driver(&server->chr);
- qemu_chr_delete(server->chr.chr);
+ qemu_chr_delete(chr);
for (i = 0; i < server->fds_num; i++) {
close(server->fds[i]);
@@ -724,7 +727,7 @@ reconnect_cb(gpointer user_data)
{
TestServer *s = user_data;
- qemu_chr_fe_disconnect(s->chr.chr);
+ qemu_chr_fe_disconnect(&s->chr);
return FALSE;
}