From nobody Fri Nov 7 18:40:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.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 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548436889654942.248388792899; Fri, 25 Jan 2019 09:21:29 -0800 (PST) Received: from localhost ([127.0.0.1]:47986 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gn5AW-0002Zi-MY for importer@patchew.org; Fri, 25 Jan 2019 12:21:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33957) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gn57H-0000XL-6y for qemu-devel@nongnu.org; Fri, 25 Jan 2019 12:18:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gn57C-0006cj-MA for qemu-devel@nongnu.org; Fri, 25 Jan 2019 12:18:06 -0500 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:52387) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gn57C-0006bg-Fp for qemu-devel@nongnu.org; Fri, 25 Jan 2019 12:18:02 -0500 Received: by mail-wm1-x32d.google.com with SMTP id m1so7514648wml.2 for ; Fri, 25 Jan 2019 09:18:00 -0800 (PST) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id w12sm91534922wrr.23.2019.01.25.09.17.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Jan 2019 09:17:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xHXAwKhpFZ3ruqUcbu/7Yq7flgGf6oXCr4RM3ehqod4=; b=QmoVm+yhFyTbWDHAEAWiTvtuWLH/vNyO6vbU/PM6vqQhOskdIqLGVYoLczacfgT/lW 9ohjgaKRT6jVkVWu699qpFJkylNkdp4q/6bqiC7wkWoOER8sVo9rmQL/Fd7gFfh0mox6 xLmJtzpfmSN4xDcJRKUCVzsikdV2c2gg7oVP5Q7BLfraK0NKD9w7xezVzPujy1jIWBSJ gM6Ud38xAoPqr8lIhe+L5JpnJUVpq1debZe539nx8sXTruvlR/j/2UELKDb8eewuEf5o zZCSRUuxIY7wZekPCvRcCU9TaGOGHtFCTp2eLZZSmwcmQtmx+IGzCp9ki92EK6cGvgOA tl1Q== 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:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=xHXAwKhpFZ3ruqUcbu/7Yq7flgGf6oXCr4RM3ehqod4=; b=oMrOjuXwn7yBYCkXgPnpTTnJ2drpq86Xtr/pqRYwdlxhDjO4mCe7al41ALqHPDfVvQ 1F8ctzMDPR6Wtkq4PMuKa39QmiOZoDzcXsMZopKKqnydRibC9pzW0BBwhxbU5+mJ5vM7 Tb+FSYW7aQ9ItdQmP7ZWfn7h3AhMSNNSnjFUcQwIeC/J0TR8jiLMp2cAnElHUd1uw49q p/VO2Qh83vYKqIuM1XUWwmqbr1HC2nrr20OEtPPLvtY2rM9hT4cu0esHcmElNODRCVVP jSctN2zxiaSM7314I+ek8BDPFjqTVMc5dQt6t140BaEIGr0R/MwXlkVcBfeyrA9ZBleg INbQ== X-Gm-Message-State: AJcUukcaJ1SKXsz5meFH3JhfZNIfRJ9u20ENVtMlMQestPtUS+ncEQKE nV6Y0bnyxzuBsMA7Lki9X/gbMMAH X-Google-Smtp-Source: ALg8bN4n+Rzc6kGiQ7nwM03Ljb+T9JpPitSceVS+0DPcsqcqHQVLksY6/KnWmaWqUpyRGHSRmxNbRQ== X-Received: by 2002:a1c:27c6:: with SMTP id n189mr7534822wmn.108.1548436679224; Fri, 25 Jan 2019 09:17:59 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 25 Jan 2019 18:17:55 +0100 Message-Id: <1548436676-31749-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1548436676-31749-1-git-send-email-pbonzini@redhat.com> References: <1548436676-31749-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::32d Subject: [Qemu-devel] [PULL 14/50] 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This makes the tests more independent and removes the need to defer test_se= rver_free via an idle event source. Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Paolo Bonzini 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 =3D g_new0(TestServer, 1); + GMainContext *context =3D g_main_context_new(); + + server->loop =3D g_main_loop_new(context, FALSE); + g_main_context_unref(context); + + /* run the main loop thread so the chardev may operate */ + server->thread =3D g_thread_new(NULL, thread_function, server->loop); =20 server->socket_path =3D g_strdup_printf("%s/%s.sock", tmpfs, name); server->mig_path =3D 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"); } =20 -static gboolean _test_server_free(TestServer *server) +static void test_server_free(TestServer *server) { int i; =20 + /* 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); =20 for (i =3D 0; i < server->fds_num; i++) { @@ -563,13 +580,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) @@ -974,8 +984,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 @@ -997,10 +1005,6 @@ int main(int argc, char **argv) } #endif =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), @@ -1028,14 +1032,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 1.8.3.1