From nobody Thu Nov 6 18:20:03 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1542292638079687.0779740974907; Thu, 15 Nov 2018 06:37:18 -0800 (PST) Received: from localhost ([::1]:39213 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIlg-000657-Ql for importer@patchew.org; Thu, 15 Nov 2018 09:37:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34961) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIgY-0002SV-Sm for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:32:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNIgU-00045J-TC for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:31:58 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:37210) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gNIgU-0003x7-MT for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:31:54 -0500 Received: by mail-wr1-x441.google.com with SMTP id j10so7230789wru.4 for ; Thu, 15 Nov 2018 06:31:36 -0800 (PST) Received: from localhost.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id x194-v6sm55262620wmd.41.2018.11.15.06.31.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 15 Nov 2018 06:31:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8ybSngDbAsnKU74wJybZnE/Dejvufdpkcaf4Hf4ar/s=; b=I3T0+30/6sB4lC/C71KizYZkJE76DU5YEQnay34EsIwuY89DuSXnQMmiZ6u48ZWGlc /CuPr7Ft76lb13hCbkWECbSdYi5rBDOfs/HnUbo/WjD/buTDAHYsuEfYD54BsoBbQb+E rG1UHsBzp6MihWMroG9JQTAqz61CfHfwpdnkVGTVs/bfxHkCB8sn28f5dptiI7BA0kdN sC+QWwv87n31dIgIglv1wDGgwFZ6XRtpe85aM2G2Ykz7u10bm0dMjPnP2TpKG1LNXXDG 0q+xTl0W1iXqOdTnZJ8nAOPZ72+UlFly3XnnjOVH78Lw/5blO9k28k1EgidIoogqxg+o EleQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=8ybSngDbAsnKU74wJybZnE/Dejvufdpkcaf4Hf4ar/s=; b=f2wRA7xzFwuo2soam5fmH4O3o1u/j+++82Mtelze3Fx0pKGCatM2uCqdrb8juYHR19 V2r2E3yNkUykus7jdleD1usi9OCl+Myq14uVWhiPIWhgjV0JrV0XFJxykZy/9ep8kvwI LGSYkrrLmOM0qu6yhelp+RupbR6PBE3GXTONqjY8P8jkUPC9Ng29XX6Z9CGa/BtRwo17 aBYZb9x/7AOOrPd+JkcBIky690ILxcE/iqG2mSOIjEQrAIqSGbcxHw8t1UpqUK9dqEEb gFrY+LqRisKtBATN+oxsZlETxa5hwyw2Qdaha8yFSl9RJhdndbjYzJYE0vhrAXBs6ZC0 0iGg== X-Gm-Message-State: AGRZ1gIGCHkagUIMfN6hhTI88YnRYBoKbl+p9MWscYPuLfRMcAyRW0vc JAvmulhc5EurV3+3YeHfOo8Ra5YP X-Google-Smtp-Source: AJdET5eYG6UqXzfzCZ7/9RcNzTG/imVB307/T0F8ZGMaRRihPyFuu2jQ/VXUpaDiqSaeJTVHkzQ5jg== X-Received: by 2002:a05:6000:1091:: with SMTP id y17mr5909856wrw.226.1542292295072; Thu, 15 Nov 2018 06:31:35 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 15:31:22 +0100 Message-Id: <20181115143124.19234-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181115143124.19234-1-pbonzini@redhat.com> References: <20181115143124.19234-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [PATCH 08/10] vhost-user-test: create a main loop per TestServer X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , jasowang@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This makes the tests more independent and removes the need to defer test_se= rver_free via an idle event source. Signed-off-by: Paolo Bonzini Reviewed-by: Marc-Andr=C3=A9 Lureau --- tests/vhost-user-test.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c index c3a8af3d85..93d5157b13 100644 --- a/tests/vhost-user-test.c +++ b/tests/vhost-user-test.c @@ -143,6 +143,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; @@ -490,6 +492,10 @@ static TestServer *test_server_new(const gchar *name) { TestServer *server =3D g_new0(TestServer, 1); =20 + server->loop =3D g_main_loop_new(NULL, FALSE); + /* run the main loop thread so the chardev may operate */ + server->thread =3D g_thread_new(NULL, thread_function, server->loop); + server->socket_path =3D g_strdup_printf("%s/%s.sock", tmpfs, name); server->mig_path =3D g_strdup_printf("%s/%s.mig", tmpfs, name); server->chr_name =3D g_strdup_printf("chr-%s", name); @@ -533,9 +539,18 @@ static void test_server_listen(TestServer *server) test_server_create_chr(server, ",server,nowait"); } =20 -static gboolean _test_server_free(TestServer *server) +static void test_server_free(TestServer *server) { int i; + int ret; + + /* 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); =20 qemu_chr_fe_deinit(&server->chr, true); =20 @@ -558,13 +573,6 @@ static gboolean _test_server_free(TestServer *server) qpci_free_pc(server->bus); =20 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) @@ -969,8 +977,6 @@ int main(int argc, char **argv) const char *hugefs; int ret; char template[] =3D "/tmp/vhost-test-XXXXXX"; - GMainLoop *loop; - GThread *thread; =20 g_test_init(&argc, &argv, NULL); =20 @@ -991,10 +997,6 @@ int main(int argc, char **argv) root =3D tmpfs; } =20 - loop =3D g_main_loop_new(NULL, FALSE); - /* run the main loop thread so the chardev may operate */ - thread =3D 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), @@ -1022,14 +1024,6 @@ int main(int argc, char **argv) =20 /* cleanup */ =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.19.1