From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 14/50] vhost-user-test: create a main loop per TestServer
Date: Fri, 25 Jan 2019 18:17:55 +0100 [thread overview]
Message-ID: <1548436676-31749-2-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1548436676-31749-1-git-send-email-pbonzini@redhat.com>
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 <marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <1543851204-41186-13-git-send-email-pbonzini@redhat.com>
---
tests/vhost-user-test.c | 40 ++++++++++++++++++----------------------
1 file changed, 18 insertions(+), 22 deletions(-)
diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c
index 15e3bbf..4ea33b5 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;
@@ -494,6 +496,13 @@ static const char *init_hugepagefs(const char *path)
static TestServer *test_server_new(const gchar *name)
{
TestServer *server = g_new0(TestServer, 1);
+ GMainContext *context = g_main_context_new();
+
+ server->loop = g_main_loop_new(context, FALSE);
+ g_main_context_unref(context);
+
+ /* 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);
@@ -538,10 +547,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 +580,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 +984,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 +1005,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 +1032,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
next prev parent reply other threads:[~2019-01-25 17:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-25 17:17 [Qemu-devel] [PULL 00/50] Misc patches for 2019-01-21 Paolo Bonzini
2019-01-25 17:17 ` Paolo Bonzini [this message]
2019-01-25 17:17 ` [Qemu-devel] [PULL 16/50] vhost-user-test: create a temporary directory per TestServer Paolo Bonzini
2019-01-28 12:53 ` [Qemu-devel] [PULL 00/50] Misc patches for 2019-01-21 Peter Maydell
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=1548436676-31749-2-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).