[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 14/49] vhost-user-test: create a main loop per TestSe
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 14/49] vhost-user-test: create a main loop per TestServer |
Date: |
Mon, 21 Jan 2019 19:05:45 +0100 |
This makes the tests more independent and removes the need to defer
test_server_free
via an idle event source.
Reviewed-by: Marc-André Lureau <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
Message-Id: <address@hidden>
---
tests/vhost-user-test.c | 37 +++++++++++++++----------------------
1 file changed, 15 insertions(+), 22 deletions(-)
diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c
index 15e3bbf..6aa62ac 100644
--- a/tests/vhost-user-test.c
+++ b/tests/vhost-user-test.c
@@ -146,6 +146,8 @@ typedef struct TestServer {
int fds_num;
int fds[VHOST_MEMORY_MAX_NREGIONS];
VhostUserMemory memory;
+ GMainLoop *loop;
+ GThread *thread;
GMutex data_mutex;
GCond data_cond;
int log_fd;
@@ -495,6 +497,10 @@ static TestServer *test_server_new(const gchar *name)
{
TestServer *server = g_new0(TestServer, 1);
+ server->loop = g_main_loop_new(NULL, FALSE);
+ /* run the main loop thread so the chardev may operate */
+ server->thread = g_thread_new(NULL, thread_function, server->loop);
+
server->socket_path = g_strdup_printf("%s/%s.sock", tmpfs, name);
server->mig_path = g_strdup_printf("%s/%s.mig", tmpfs, name);
server->chr_name = g_strdup_printf("chr-%s", name);
@@ -538,10 +544,18 @@ static void test_server_listen(TestServer *server)
test_server_create_chr(server, ",server,nowait");
}
-static gboolean _test_server_free(TestServer *server)
+static void test_server_free(TestServer *server)
{
int i;
+ /* finish the helper thread and dispatch pending sources */
+ g_main_loop_quit(server->loop);
+ g_thread_join(server->thread);
+ while (g_main_context_pending(NULL)) {
+ g_main_context_iteration(NULL, TRUE);
+ }
+ g_main_loop_unref(server->loop);
+
qemu_chr_fe_deinit(&server->chr, true);
for (i = 0; i < server->fds_num; i++) {
@@ -563,13 +577,6 @@ static gboolean _test_server_free(TestServer *server)
qpci_free_pc(server->bus);
g_free(server);
-
- return FALSE;
-}
-
-static void test_server_free(TestServer *server)
-{
- g_idle_add((GSourceFunc)_test_server_free, server);
}
static void wait_for_log_fd(TestServer *s)
@@ -974,8 +981,6 @@ int main(int argc, char **argv)
const char *hugefs;
int ret;
char template[] = "/tmp/vhost-test-XXXXXX";
- GMainLoop *loop;
- GThread *thread;
g_test_init(&argc, &argv, NULL);
@@ -997,10 +1002,6 @@ int main(int argc, char **argv)
}
#endif
- loop = g_main_loop_new(NULL, FALSE);
- /* run the main loop thread so the chardev may operate */
- thread = g_thread_new(NULL, thread_function, loop);
-
if (qemu_memfd_check(0)) {
qtest_add_data_func("/vhost-user/read-guest-mem/memfd",
GINT_TO_POINTER(TEST_MEMFD_YES),
@@ -1028,14 +1029,6 @@ int main(int argc, char **argv)
/* cleanup */
- /* finish the helper thread and dispatch pending sources */
- g_main_loop_quit(loop);
- g_thread_join(thread);
- while (g_main_context_pending(NULL)) {
- g_main_context_iteration (NULL, TRUE);
- }
- g_main_loop_unref(loop);
-
ret = rmdir(tmpfs);
if (ret != 0) {
g_test_message("unable to rmdir: path (%s): %s\n",
--
1.8.3.1
- [Qemu-devel] [PULL 06/49] vhost-net: compile it on all targets that have virtio-net., (continued)
- [Qemu-devel] [PULL 06/49] vhost-net: compile it on all targets that have virtio-net., Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 04/49] vhost-net-user: add stubs for when no virtio-net device is present, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 08/49] vhost-user-test: use g_cond_broadcast, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 09/49] vhost-user-test: signal data_cond when s->rings changes, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 07/49] vhost-net: revamp configure logic, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 10/49] vhost-user: support cross-endian vnet headers, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 01/49] scripts/update-linux-headers.sh: adjust for Linux 4.21-rc1 (or 5.0-rc1), Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 11/49] vhost-user-test: support VHOST_USER_PROTOCOL_F_CROSS_ENDIAN, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 17/49] tap: flush STDOUT on newline, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 19/49] cpu-exec: add assert_no_pages_locked() after longjmp, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 14/49] vhost-user-test: create a main loop per TestServer,
Paolo Bonzini <=
- [Qemu-devel] [PULL 20/49] cpu-exec: reset BQL after longjmp in cpu_exec_step_atomic, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 12/49] vhost-user-test: skip if there is no memory at address 0, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 03/49] vhost-net: move stubs to a separate file, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 13/49] vhost-user-test: reduce usage of global_qtest, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 05/49] vhost: restrict Linux dependency to kernel vhost, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 15/49] vhost-user-test: small changes to init_hugepagefs, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 16/49] vhost-user-test: create a temporary directory per TestServer, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 18/49] tests/hexloader-test: Don't pass -nographic to the QEMU under test, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 21/49] configure: Add a proper check for openpty() in libutil, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 22/49] cpus: ignore ESRCH in qemu_cpu_kick_thread(), Paolo Bonzini, 2019/01/21