From nobody Fri Nov 7 14:41:20 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 1548094519004618.2522579130429; Mon, 21 Jan 2019 10:15:19 -0800 (PST) Received: from localhost ([127.0.0.1]:57448 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gle6M-0002sw-Sb for importer@patchew.org; Mon, 21 Jan 2019 13:15:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51613) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gldy4-0004JD-Ca for qemu-devel@nongnu.org; Mon, 21 Jan 2019 13:06:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gldy2-00045J-S3 for qemu-devel@nongnu.org; Mon, 21 Jan 2019 13:06:40 -0500 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]:36530) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gldy2-00044F-K1 for qemu-devel@nongnu.org; Mon, 21 Jan 2019 13:06:38 -0500 Received: by mail-wr1-x434.google.com with SMTP id u4so24487851wrp.3 for ; Mon, 21 Jan 2019 10:06:38 -0800 (PST) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id 133sm56197732wme.9.2019.01.21.10.06.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jan 2019 10:06:36 -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=+t2irpjmhtcOA+IpPkHHqnKejDaOBA3vkIHxf/Jnv/A=; b=TMBS+IxAEsX4noBZIJYIxvO/9xMrqCeWzKLcZf44HXAq3ldkjppICxUojDQTsb5PMg ZvTiG03EiKmhg3onePWn1NtEGoVCYDYHMURmOsehMeh79KxMyDDbioOp0F1LcVAh+VtR ai+cRl3JmiDeEecH3yxSmuJKveIYsQwwIE/cmbE7HVh+ix8HgLysIsaaIU2txvJmjJmq kRtkyq73qetulkCouMorprxVuba0a36IpwZqAr4N1UcMVgDYaZvH3YeH4IjaQo0QZSJB GPp7/ETdXWZyWLPbhI+nWO1EbFZNf73MqEhJKNlmQ3e41Xkg3H6pTal3UHEkeMI5ZGMl BjCA== 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=+t2irpjmhtcOA+IpPkHHqnKejDaOBA3vkIHxf/Jnv/A=; b=LAZXkWfC7e8hrsyKquzBbWw2mgUrWipTaWzPYChwhDGYnonaHQWLUBVCCevIyzKueS CYAJphiFKk9A7hYtYXGPxBVp3uImzBSgeQMOC9CRydbq2N8Vchzb4xKQWSZ0WXvNuCcQ ChVyDw1eEZNvxV/l2N6lfQC4emXExQEuBdgYfzohlGqdSDd5U0Li2GY5Z1nbHO8Mn60r 43iYIHTY+8a4+BlH9L2f6tfWHV9oZw5Hc+3xmUcVu5ytEsWak3fnOo5KC9pdam2Zgiz8 lFGBgaTIZAkwX/owhxVPgmAfSH7UtjS8h/ImDdOBsYr4TslWHry2ImZNpQh70A6+pYLU m6jg== X-Gm-Message-State: AJcUukdQOH+Bz3b0Qag7wo7HCjA8cB08CWrRnvOZCXWmjNtnjUiYXKkJ vEwybQ6qZTyspvPA5ahiYW9WsWth X-Google-Smtp-Source: ALg8bN6oZ3yhbQyA0dHbeB7bSRLua5p4rLWcQ7cLFAgkPDE89Cr3h7vvXohDayfNG619vslvNS9kgQ== X-Received: by 2002:a5d:6988:: with SMTP id g8mr27995487wru.33.1548093997141; Mon, 21 Jan 2019 10:06:37 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 21 Jan 2019 19:05:45 +0100 Message-Id: <1548093980-43088-15-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1548093980-43088-1-git-send-email-pbonzini@redhat.com> References: <1548093980-43088-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::434 Subject: [Qemu-devel] [PULL 14/49] 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 | 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 =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); @@ -538,10 +544,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 +577,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 +981,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 +1002,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 +1029,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