From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48649) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a21X7-0008GT-L0 for qemu-devel@nongnu.org; Thu, 26 Nov 2015 13:44:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a21X4-0002uT-EG for qemu-devel@nongnu.org; Thu, 26 Nov 2015 13:44:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58623) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a21X4-0002uH-7T for qemu-devel@nongnu.org; Thu, 26 Nov 2015 13:44:38 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id BF06991349 for ; Thu, 26 Nov 2015 18:44:37 +0000 (UTC) Date: Thu, 26 Nov 2015 20:44:34 +0200 From: "Michael S. Tsirkin" Message-ID: <20151126204402-mutt-send-email-mst@redhat.com> References: <1448562655-19656-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1448562655-19656-1-git-send-email-marcandre.lureau@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] tests: fix vhost-user-test race List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: marcandre.lureau@redhat.com Cc: qemu-devel@nongnu.org On Thu, Nov 26, 2015 at 07:30:55PM +0100, marcandre.lureau@redhat.com wro= te: > From: Marc-Andr=E9 Lureau >=20 > vhost-user-tests uses a helper thread to dispatch the vhost-user server= s > sources. However the CharDriverState is not thread-safe. Therefore, whe= n > it's given to the thread, it shouldn't be maniuplated concurrently. >=20 > We dispatch cleaning the server in an idle source. By the end of the > test, we ensure not to leave anything behind by joining the thread and > finishing the sources dispatch. >=20 > Signed-off-by: Marc-Andr=E9 Lureau Reviewed-by: Michael S. Tsirkin Let's hope this fixes travis errors too. > --- > tests/vhost-user-test.c | 26 +++++++++++++++++++++----- > 1 file changed, 21 insertions(+), 5 deletions(-) >=20 > diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c > index e4c36af..261f4b7 100644 > --- a/tests/vhost-user-test.c > +++ b/tests/vhost-user-test.c > @@ -216,8 +216,7 @@ static void read_guest_mem(TestServer *s) > =20 > static void *thread_function(void *data) > { > - GMainLoop *loop; > - loop =3D g_main_loop_new(NULL, FALSE); > + GMainLoop *loop =3D data; > g_main_loop_run(loop); > return NULL; > } > @@ -389,7 +388,7 @@ static TestServer *test_server_new(const gchar *nam= e) > g_strdup_printf(QEMU_CMD extra, (mem), (mem), (root), (s)->chr_nam= e, \ > (s)->socket_path, (s)->chr_name, ##__VA_ARGS__) > =20 > -static void test_server_free(TestServer *server) > +static gboolean _test_server_free(TestServer *server) > { > int i; > =20 > @@ -406,9 +405,15 @@ static void test_server_free(TestServer *server) > unlink(server->socket_path); > g_free(server->socket_path); > =20 > - > g_free(server->chr_name); > g_free(server); > + > + return FALSE; > +} > + > +static void test_server_free(TestServer *server) > +{ > + g_idle_add((GSourceFunc)_test_server_free, server); > } > =20 > static void wait_for_log_fd(TestServer *s) > @@ -590,6 +595,8 @@ int main(int argc, char **argv) > char *qemu_cmd =3D NULL; > int ret; > char template[] =3D "/tmp/vhost-test-XXXXXX"; > + GMainLoop *loop; > + GThread *thread; > =20 > g_test_init(&argc, &argv, NULL); > =20 > @@ -612,8 +619,9 @@ int main(int argc, char **argv) > =20 > server =3D test_server_new("test"); > =20 > + loop =3D g_main_loop_new(NULL, FALSE); > /* run the main loop thread so the chardev may operate */ > - g_thread_new(NULL, thread_function, NULL); > + thread =3D g_thread_new(NULL, thread_function, loop); > =20 > qemu_cmd =3D GET_QEMU_CMD(server); > =20 > @@ -632,6 +640,14 @@ int main(int argc, char **argv) > /* cleanup */ > test_server_free(server); > =20 > + /* 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 =3D rmdir(tmpfs); > if (ret !=3D 0) { > g_test_message("unable to rmdir: path (%s): %s\n", > --=20 > 2.5.0