From patchwork Fri Jun 10 16:38:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Danis?= X-Patchwork-Id: 581169 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DD34C43334 for ; Fri, 10 Jun 2022 16:38:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349768AbiFJQil (ORCPT ); Fri, 10 Jun 2022 12:38:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349832AbiFJQih (ORCPT ); Fri, 10 Jun 2022 12:38:37 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 504EF580C0 for ; Fri, 10 Jun 2022 09:38:31 -0700 (PDT) Received: from localhost.localdomain (67.227.121.78.rev.sfr.net [78.121.227.67]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: fdanis) by madras.collabora.co.uk (Postfix) with ESMTPSA id 110856601723 for ; Fri, 10 Jun 2022 17:38:30 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1654879110; bh=Lc7PC9+oSIwJ7vQ2nt3r75oW/nmzfWTl+CMq2453Qj0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Ww38OQH6raGihlnus5obeMIHICINHePSfAnfgVJZUL1fzKZNAdfiVK2UIrMDD1QNd Obu6URxCsbwbBSd5eVWX5N2guRGhfsDNx0i2lBDtSc+2oFPZGdFcsrCOb3A9l5e/Kv G3CfulsTnyWlgwZAkxPbpa2I7Vft9aJ9pl20OGDQK+4RH4RzSO9PGk0ddxv4+rweet M/P90JKLEhNdfc5soMV3Uo2+ykPNQYJbpgAp7h/ErktFsq8fkxlLr9vQjP5mfvLdkF fRBgFaIbVO7RpxJySSnEdIRRer+54qrIfPIbubCrnSpqMkz5aewlCRQdrSiYJ0yBgh NJVY8Y6MnfJHg== From: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Danis?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v3 1/4] test-runner: Add DBus session support Date: Fri, 10 Jun 2022 18:38:17 +0200 Message-Id: <20220610163820.79105-2-frederic.danis@collabora.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220610163820.79105-1-frederic.danis@collabora.com> References: <20220610163820.79105-1-frederic.danis@collabora.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Audio daemons requests access to DBus session to start --- tools/test-runner.c | 97 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 85 insertions(+), 12 deletions(-) diff --git a/tools/test-runner.c b/tools/test-runner.c index 945a16a77..9fc8e7b33 100644 --- a/tools/test-runner.c +++ b/tools/test-runner.c @@ -47,6 +47,7 @@ static int test_argc; static bool run_auto = false; static bool start_dbus = false; +static bool start_dbus_session; static bool start_daemon = false; static bool start_emulator = false; static bool start_monitor = false; @@ -251,9 +252,11 @@ static void start_qemu(void) "acpi=off pci=noacpi noapic quiet ro init=%s " "bluetooth.enable_ecred=1" "TESTHOME=%s TESTDBUS=%u TESTDAEMON=%u " + "TESTDBUSSESSION=%u XDG_RUNTIME_DIR=/run/user/0 " "TESTMONITOR=%u TESTEMULATOR=%u TESTDEVS=%d " "TESTAUTO=%u TESTARGS=\'%s\'", initcmd, cwd, start_dbus, start_daemon, + start_dbus_session, start_monitor, start_emulator, num_devs, run_auto, testargs); @@ -420,19 +423,63 @@ static void create_dbus_system_conf(void) mkdir("/run/dbus", 0755); } -static pid_t start_dbus_daemon(void) +static void create_dbus_session_conf(void) +{ + FILE *fp; + + fp = fopen("/etc/dbus-1/session.conf", "we"); + if (!fp) + return; + + fputs("\n", fp); + fputs("\n", fp); + fputs("session\n", fp); + fputs("unix:path=/run/user/0/bus\n", fp); + fputs("\n", fp); + fputs("\n", fp); + fputs("\n", fp); + fputs("\n", fp); + fputs("\n", fp); + fputs("\n", fp); + fputs("\n", fp); + fputs("\n", fp); + fputs("\n", fp); + fputs("\n", fp); + fputs("\n", fp); + fputs("\n", fp); + fputs("\n", fp); + + fclose(fp); + + if (symlink("/etc/dbus-1/session.conf", + "/usr/share/dbus-1/session.conf") < 0) + perror("Failed to create session.conf symlink"); + + mkdir("/run/user", 0755); + mkdir("/run/user/0", 0755); +} + +static pid_t start_dbus_daemon(bool session) { char *argv[3], *envp[1]; pid_t pid; int i; + char *bus_type = session ? "session" : "system"; + char *socket_path = session ? + "/run/user/0/bus" : "/run/dbus/system_bus_socket"; argv[0] = "/usr/bin/dbus-daemon"; - argv[1] = "--system"; + if (session) + argv[1] = "--session"; + else + argv[1] = "--system"; argv[2] = NULL; envp[0] = NULL; - printf("Starting D-Bus daemon\n"); + printf("Starting D-Bus %s daemon\n", bus_type); pid = fork(); if (pid < 0) { @@ -445,13 +492,13 @@ static pid_t start_dbus_daemon(void) exit(EXIT_SUCCESS); } - printf("D-Bus daemon process %d created\n", pid); + printf("D-Bus %s daemon process %d created\n", bus_type, pid); for (i = 0; i < 20; i++) { struct stat st; - if (!stat("/run/dbus/system_bus_socket", &st)) { - printf("Found D-Bus daemon socket\n"); + if (!stat(socket_path, &st)) { + printf("Found D-Bus %s daemon socket\n", bus_type); return pid; } @@ -666,7 +713,8 @@ static void run_command(char *cmdname, char *home) char *argv[9], *envp[3]; int pos = 0, idx = 0; int serial_fd; - pid_t pid, dbus_pid, daemon_pid, monitor_pid, emulator_pid; + pid_t pid, dbus_pid, daemon_pid, monitor_pid, emulator_pid, + dbus_session_pid; if (num_devs) { const char *node = "/dev/ttyS1"; @@ -684,10 +732,16 @@ static void run_command(char *cmdname, char *home) if (start_dbus) { create_dbus_system_conf(); - dbus_pid = start_dbus_daemon(); + dbus_pid = start_dbus_daemon(false); } else dbus_pid = -1; + if (start_dbus_session) { + create_dbus_session_conf(); + dbus_session_pid = start_dbus_daemon(true); + } else + dbus_session_pid = -1; + if (start_daemon) daemon_pid = start_bluetooth_daemon(home); else @@ -780,7 +834,12 @@ start_next: printf("Process %d continued\n", corpse); if (corpse == dbus_pid) { - printf("D-Bus daemon terminated\n"); + printf("D-Bus system daemon terminated\n"); + dbus_pid = -1; + } + + if (corpse == dbus_session_pid) { + printf("D-Bus session daemon terminated\n"); dbus_pid = -1; } @@ -814,6 +873,9 @@ start_next: if (dbus_pid > 0) kill(dbus_pid, SIGTERM); + if (dbus_session_pid > 0) + kill(dbus_session_pid, SIGTERM); + if (emulator_pid > 0) kill(dbus_pid, SIGTERM); @@ -874,10 +936,16 @@ static void run_tests(void) ptr = strstr(cmdline, "TESTDBUS=1"); if (ptr) { - printf("D-Bus daemon requested\n"); + printf("D-Bus system daemon requested\n"); start_dbus = true; } + ptr = strstr(cmdline, "TESTDBUSSESSION=1"); + if (ptr) { + printf("D-Bus session daemon requested\n"); + start_dbus_session = true; + } + ptr = strstr(cmdline, "TESTDAEMON=1"); if (ptr) { printf("bluetoothd requested\n"); @@ -914,7 +982,8 @@ static void usage(void) printf("\ttest-runner [options] [--] [args]\n"); printf("Options:\n" "\t-a, --auto Find tests and run them\n" - "\t-b, --dbus Start D-Bus daemon\n" + "\t-b, --dbus Start D-Bus system daemon\n" + "\t-s, --dbus-session Start D-Bus session daemon\n" "\t-d, --daemon Start bluetoothd\n" "\t-m, --monitor Start btmon\n" "\t-l, --emulator Start btvirt\n" @@ -928,6 +997,7 @@ static const struct option main_options[] = { { "all", no_argument, NULL, 'a' }, { "auto", no_argument, NULL, 'a' }, { "dbus", no_argument, NULL, 'b' }, + { "dbus-session", no_argument, NULL, 's' }, { "unix", no_argument, NULL, 'u' }, { "daemon", no_argument, NULL, 'd' }, { "emulator", no_argument, NULL, 'l' }, @@ -953,7 +1023,7 @@ int main(int argc, char *argv[]) for (;;) { int opt; - opt = getopt_long(argc, argv, "aubdlmq:k:vh", main_options, + opt = getopt_long(argc, argv, "aubdslmq:k:vh", main_options, NULL); if (opt < 0) break; @@ -968,6 +1038,9 @@ int main(int argc, char *argv[]) case 'b': start_dbus = true; break; + case 's': + start_dbus_session = true; + break; case 'd': start_dbus = true; start_daemon = true; From patchwork Fri Jun 10 16:38:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Danis?= X-Patchwork-Id: 581168 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F33EC43334 for ; Fri, 10 Jun 2022 16:38:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349751AbiFJQin (ORCPT ); Fri, 10 Jun 2022 12:38:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349835AbiFJQih (ORCPT ); Fri, 10 Jun 2022 12:38:37 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5063E5932E for ; Fri, 10 Jun 2022 09:38:31 -0700 (PDT) Received: from localhost.localdomain (67.227.121.78.rev.sfr.net [78.121.227.67]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: fdanis) by madras.collabora.co.uk (Postfix) with ESMTPSA id 485D46601724 for ; Fri, 10 Jun 2022 17:38:30 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1654879110; bh=TYvfHpLsV7jiR7wDzcPhKTa6mm+IINJaaS2N4SEONZk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=N+0Ft4mZcptdzYRn5+BhECekLeSbamM7ZTFjdBbAti4EVw60q/188IBvCQ9QREsET Ralw7auDHDy9hAL86KV4dHN66gtHEio292QalrQb2sB2eZri+ZRQDQL6yF72G6SYgw zrm6PrUpo3dPf3RFiafv+wmxRvAk4hrdV1dz/YNnCruarGbZYcJsYC9WDSbDOBThod 48Ri8m7gUJ5XDUIS0BTGIGRT3Jlt4zTGO9ylcb7ye44BHiF73dE3pSU8nc/cDQJTUq M6/e9i9RQ+WXluBoLCNvC8VXwCFjx2eEQCKW/iYv8U0jqmyKyKxWvkzc3zfak80aJm L39kXwrf0/oTQ== From: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Danis?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v3 2/4] doc/test-runner: Add audio config options Date: Fri, 10 Jun 2022 18:38:18 +0200 Message-Id: <20220610163820.79105-3-frederic.danis@collabora.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220610163820.79105-1-frederic.danis@collabora.com> References: <20220610163820.79105-1-frederic.danis@collabora.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org List the build options for an AC97 audio card necessary for test with audio daemon. --- doc/test-runner.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/test-runner.txt b/doc/test-runner.txt index 683c622a2..019c23188 100644 --- a/doc/test-runner.txt +++ b/doc/test-runner.txt @@ -54,6 +54,11 @@ For Bluetooth functionality: CONFIG_UHID=y +For Audio functionality: + CONFIG_SYSVIPC=y + CONFIG_SOUND=y + CONFIG_SND=y + CONFIG_SND_INTEL8X0=y These options should be installed as .config in the kernel source directory followed by this command. From patchwork Fri Jun 10 16:38:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Danis?= X-Patchwork-Id: 581170 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5781CC43334 for ; Fri, 10 Jun 2022 16:38:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349654AbiFJQik (ORCPT ); Fri, 10 Jun 2022 12:38:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349818AbiFJQif (ORCPT ); Fri, 10 Jun 2022 12:38:35 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50439579A9 for ; Fri, 10 Jun 2022 09:38:31 -0700 (PDT) Received: from localhost.localdomain (67.227.121.78.rev.sfr.net [78.121.227.67]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: fdanis) by madras.collabora.co.uk (Postfix) with ESMTPSA id 8AD5B6601726 for ; Fri, 10 Jun 2022 17:38:30 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1654879110; bh=Ennfx6R5it+STbujT8TaTPJ+N0XXO/K1XoxzAwfznz4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=NKu99Ne6N6x9F32KvinAmUQYDoSDMHG2CpdCMAL357dkZajHj4m4S2MdHWdvXYhpV dn0+tRawx0hELRRdC5d2AjCJfHFUGbSLwLZVeIsD92K2BVricjXDu59D1dCF18AWW1 8LFevIzb0s/9IJeaAnfWIL2FTZGr3r1e5TQ70RL7x2skc0QMmTZCMNhgYlSv4pSUFb 0AK3f8YO3o+2wu37pKN685HjA98WflXWpVkSDoeA4y0iYR1X/zVUSFzUnH2pUeJW/d YRSZDti9qf01HYtop+LPS7GdmpnD1AtIRusRpToPAH5UYgY8W+TSzjIPqnlFUOvfQj zvf5Np/3u6R8w== From: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Danis?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v3 3/4] test-runner: Add audio card support Date: Fri, 10 Jun 2022 18:38:19 +0200 Message-Id: <20220610163820.79105-4-frederic.danis@collabora.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220610163820.79105-1-frederic.danis@collabora.com> References: <20220610163820.79105-1-frederic.danis@collabora.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org With this commit audio daemons can detect an audio card with output and input, allowing to test interaction between BlueZ and the audio daemon. --- tools/test-runner.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tools/test-runner.c b/tools/test-runner.c index 9fc8e7b33..bbbca5b5d 100644 --- a/tools/test-runner.c +++ b/tools/test-runner.c @@ -54,6 +54,7 @@ static bool start_monitor = false; static int num_devs = 0; static const char *qemu_binary = NULL; static const char *kernel_image = NULL; +static bool audio_support; static const char *qemu_table[] = { "qemu-system-x86_64", @@ -261,6 +262,7 @@ static void start_qemu(void) run_auto, testargs); argv = alloca(sizeof(qemu_argv) + + (audio_support ? 4 : 0) + (sizeof(char *) * (4 + (num_devs * 4)))); memcpy(argv, qemu_argv, sizeof(qemu_argv)); @@ -268,6 +270,20 @@ static void start_qemu(void) argv[0] = (char *) qemu_binary; + if (audio_support) { + char *xdg_runtime_dir, *audiodev; + + xdg_runtime_dir = getenv("XDG_RUNTIME_DIR"); + audiodev = alloca(40 + strlen(xdg_runtime_dir)); + sprintf(audiodev, "id=audio,driver=pa,server=%s/pulse/native", + xdg_runtime_dir); + + argv[pos++] = "-audiodev"; + argv[pos++] = audiodev; + argv[pos++] = "-device"; + argv[pos++] = "AC97,audiodev=audio"; + } + argv[pos++] = "-kernel"; argv[pos++] = (char *) kernel_image; argv[pos++] = "-append"; @@ -990,6 +1006,7 @@ static void usage(void) "\t-u, --unix [path] Provide serial device\n" "\t-q, --qemu QEMU binary\n" "\t-k, --kernel Kernel image (bzImage)\n" + "\t-A, --audio Add audio support\n" "\t-h, --help Show help options\n"); } @@ -1004,6 +1021,7 @@ static const struct option main_options[] = { { "monitor", no_argument, NULL, 'm' }, { "qemu", required_argument, NULL, 'q' }, { "kernel", required_argument, NULL, 'k' }, + { "audio", no_argument, NULL, 'A' }, { "version", no_argument, NULL, 'v' }, { "help", no_argument, NULL, 'h' }, { } @@ -1023,7 +1041,7 @@ int main(int argc, char *argv[]) for (;;) { int opt; - opt = getopt_long(argc, argv, "aubdslmq:k:vh", main_options, + opt = getopt_long(argc, argv, "aubdslmq:k:Avh", main_options, NULL); if (opt < 0) break; @@ -1057,6 +1075,9 @@ int main(int argc, char *argv[]) case 'k': kernel_image = optarg; break; + case 'A': + audio_support = true; + break; case 'v': printf("%s\n", VERSION); return EXIT_SUCCESS; From patchwork Fri Jun 10 16:38:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Danis?= X-Patchwork-Id: 580762 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 945D1C433EF for ; Fri, 10 Jun 2022 16:38:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349711AbiFJQil (ORCPT ); Fri, 10 Jun 2022 12:38:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349821AbiFJQif (ORCPT ); Fri, 10 Jun 2022 12:38:35 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 505C9590B8 for ; Fri, 10 Jun 2022 09:38:32 -0700 (PDT) Received: from localhost.localdomain (67.227.121.78.rev.sfr.net [78.121.227.67]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: fdanis) by madras.collabora.co.uk (Postfix) with ESMTPSA id C41956601729 for ; Fri, 10 Jun 2022 17:38:30 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1654879110; bh=sqnOq4Kb0YQFa5LgrYACY18LAxQmcVnx5NOTJut+DIQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=HMeYvbWHOkzzh2gI2agin4wT+MNBDvJ1XfJJ88MdKLJgSw4bvkQ1EQcmzTlSwrMGw 4QN02su/AWKxOIJwp2xfJkwYGZBwcJ4pqRdzQQgpnLE3FtXYG9QYaLMS2RdODcKkot ZlW0uOeiGI9E0RUnn9Y5byP8t8sstVtswoNRDl32k6T5S4gpWOOCivsJrseAUbeOtT BenL9Kk0XL3rt8A//rID3v52V8ToFeJXojFMwdWR7pCrK9EZAXPMl+qVGVrvsM/iGb CB69eh4fkhk3KmTZgSBMLKD3aDfYdA44rCBERxbOApA77GwtD8JnTHvgsij1+XQRIA dEXCP6aHn8SfQ== From: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Danis?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v3 4/4] test-runner: Add udevd and trigger events Date: Fri, 10 Jun 2022 18:38:20 +0200 Message-Id: <20220610163820.79105-5-frederic.danis@collabora.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220610163820.79105-1-frederic.danis@collabora.com> References: <20220610163820.79105-1-frederic.danis@collabora.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Kernel events should have been managed so the audio card is accessible from PipeWire --- tools/test-runner.c | 83 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 3 deletions(-) diff --git a/tools/test-runner.c b/tools/test-runner.c index bbbca5b5d..49fc21325 100644 --- a/tools/test-runner.c +++ b/tools/test-runner.c @@ -251,13 +251,14 @@ static void start_qemu(void) "rootfstype=9p " "rootflags=trans=virtio,version=9p2000.L " "acpi=off pci=noacpi noapic quiet ro init=%s " - "bluetooth.enable_ecred=1" + "bluetooth.enable_ecred=1 " "TESTHOME=%s TESTDBUS=%u TESTDAEMON=%u " "TESTDBUSSESSION=%u XDG_RUNTIME_DIR=/run/user/0 " + "TESTAUDIO=%u " "TESTMONITOR=%u TESTEMULATOR=%u TESTDEVS=%d " "TESTAUTO=%u TESTARGS=\'%s\'", initcmd, cwd, start_dbus, start_daemon, - start_dbus_session, + start_dbus_session, audio_support, start_monitor, start_emulator, num_devs, run_auto, testargs); @@ -724,13 +725,70 @@ static pid_t start_btvirt(const char *home) return pid; } +static void trigger_udev(void) +{ + char *argv[3], *envp[1]; + pid_t pid; + + argv[0] = "/bin/udevadm"; + argv[1] = "trigger"; + argv[2] = NULL; + + envp[0] = NULL; + + printf("Triggering udev events\n"); + + pid = fork(); + if (pid < 0) { + perror("Failed to fork new process"); + return; + } + + if (pid == 0) { + execve(argv[0], argv, envp); + exit(EXIT_SUCCESS); + } + + printf("udev trigger process %d created\n", pid); +} + +static pid_t start_udevd(void) +{ + char *argv[2], *envp[1]; + pid_t pid; + + argv[0] = "/lib/systemd/systemd-udevd"; + argv[1] = NULL; + + envp[0] = NULL; + + printf("Starting udevd daemon\n"); + + pid = fork(); + if (pid < 0) { + perror("Failed to fork new process"); + return -1; + } + + if (pid == 0) { + execve(argv[0], argv, envp); + exit(EXIT_SUCCESS); + } + + printf("udevd daemon process %d created\n", pid); + + trigger_udev(); + + return pid; +} + static void run_command(char *cmdname, char *home) { char *argv[9], *envp[3]; int pos = 0, idx = 0; int serial_fd; pid_t pid, dbus_pid, daemon_pid, monitor_pid, emulator_pid, - dbus_session_pid; + dbus_session_pid, udevd_pid; if (num_devs) { const char *node = "/dev/ttyS1"; @@ -746,6 +804,11 @@ static void run_command(char *cmdname, char *home) } else serial_fd = -1; + if (audio_support) + udevd_pid = start_udevd(); + else + udevd_pid = -1; + if (start_dbus) { create_dbus_system_conf(); dbus_pid = start_dbus_daemon(false); @@ -874,6 +937,11 @@ start_next: monitor_pid = -1; } + if (corpse == udevd_pid) { + printf("udevd terminated\n"); + udevd_pid = -1; + } + if (corpse == pid) break; } @@ -898,6 +966,9 @@ start_next: if (monitor_pid > 0) kill(monitor_pid, SIGTERM); + if (udevd_pid > 0) + kill(udevd_pid, SIGTERM); + if (serial_fd >= 0) { close(serial_fd); serial_fd = -1; @@ -980,6 +1051,12 @@ static void run_tests(void) start_emulator = true; } + ptr = strstr(cmdline, "TESTAUDIO=1"); + if (ptr) { + printf("Audio support requested\n"); + audio_support = true; + } + ptr = strstr(cmdline, "TESTHOME="); if (ptr) { home = ptr + 4;