linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ v2 0/3] test-runner: Add support for audio daemons
@ 2022-06-10  7:28 Frédéric Danis
  2022-06-10  7:28 ` [PATCH BlueZ v2 1/3] test-runner: Add DBus session support Frédéric Danis
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Frédéric Danis @ 2022-06-10  7:28 UTC (permalink / raw)
  To: linux-bluetooth

Those patches add DBus session and an audio card so it should be possible
to start an audio daemon like PipeWire in the VM.

Frédéric Danis (3):
  test-runner: Add DBus session support
  test-runner: Add audio card support
  test-runner: Add udevd and trigger events

 doc/test-runner.txt |   5 ++
 tools/test-runner.c | 197 +++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 189 insertions(+), 13 deletions(-)

Since v1:
- Fix checkpatch errors

-- 
2.25.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH BlueZ v2 1/3] test-runner: Add DBus session support
  2022-06-10  7:28 [PATCH BlueZ v2 0/3] test-runner: Add support for audio daemons Frédéric Danis
@ 2022-06-10  7:28 ` Frédéric Danis
  2022-06-10  9:51   ` test-runner: Add support for audio daemons bluez.test.bot
  2022-06-10  7:28 ` [PATCH BlueZ v2 2/3] test-runner: Add audio card support Frédéric Danis
  2022-06-10  7:28 ` [PATCH BlueZ v2 3/3] test-runner: Add udevd and trigger events Frédéric Danis
  2 siblings, 1 reply; 7+ messages in thread
From: Frédéric Danis @ 2022-06-10  7:28 UTC (permalink / raw)
  To: linux-bluetooth

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("<!DOCTYPE busconfig PUBLIC "
+		"\"-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN\" "
+		"\"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd\">\n", fp);
+	fputs("<busconfig>\n", fp);
+	fputs("<type>session</type>\n", fp);
+	fputs("<listen>unix:path=/run/user/0/bus</listen>\n", fp);
+	fputs("<policy context=\"default\">\n", fp);
+	fputs("<allow user=\"*\"/>\n", fp);
+	fputs("<allow own=\"*\"/>\n", fp);
+	fputs("<allow send_type=\"method_call\"/>\n", fp);
+	fputs("<allow send_type=\"signal\"/>\n", fp);
+	fputs("<allow send_type=\"method_return\"/>\n", fp);
+	fputs("<allow send_type=\"error\"/>\n", fp);
+	fputs("<allow receive_type=\"method_call\"/>\n", fp);
+	fputs("<allow receive_type=\"signal\"/>\n", fp);
+	fputs("<allow receive_type=\"method_return\"/>\n", fp);
+	fputs("<allow receive_type=\"error\"/>\n", fp);
+	fputs("</policy>\n", fp);
+	fputs("</busconfig>\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] [--] <command> [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;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH BlueZ v2 2/3] test-runner: Add audio card support
  2022-06-10  7:28 [PATCH BlueZ v2 0/3] test-runner: Add support for audio daemons Frédéric Danis
  2022-06-10  7:28 ` [PATCH BlueZ v2 1/3] test-runner: Add DBus session support Frédéric Danis
@ 2022-06-10  7:28 ` Frédéric Danis
  2022-06-10 15:48   ` Luiz Augusto von Dentz
  2022-06-10  7:28 ` [PATCH BlueZ v2 3/3] test-runner: Add udevd and trigger events Frédéric Danis
  2 siblings, 1 reply; 7+ messages in thread
From: Frédéric Danis @ 2022-06-10  7:28 UTC (permalink / raw)
  To: linux-bluetooth

With this commit audio daemons can detect an audio card with output and
input, allowing to test interaction between BlueZ and the audio daemon.
---
 doc/test-runner.txt |  5 +++++
 tools/test-runner.c | 23 ++++++++++++++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

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.
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 <path>      QEMU binary\n"
 		"\t-k, --kernel <image>   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;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH BlueZ v2 3/3] test-runner: Add udevd and trigger events
  2022-06-10  7:28 [PATCH BlueZ v2 0/3] test-runner: Add support for audio daemons Frédéric Danis
  2022-06-10  7:28 ` [PATCH BlueZ v2 1/3] test-runner: Add DBus session support Frédéric Danis
  2022-06-10  7:28 ` [PATCH BlueZ v2 2/3] test-runner: Add audio card support Frédéric Danis
@ 2022-06-10  7:28 ` Frédéric Danis
  2022-06-10 15:50   ` Luiz Augusto von Dentz
  2 siblings, 1 reply; 7+ messages in thread
From: Frédéric Danis @ 2022-06-10  7:28 UTC (permalink / raw)
  To: linux-bluetooth

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..e79e3b6e9 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 "
+				"AUDIO_SUPPORT=%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, "AUDIO_SUPPORT=1");
+	if (ptr) {
+		printf("Audio support requested\n");
+		audio_support = true;
+	}
+
 	ptr = strstr(cmdline, "TESTHOME=");
 	if (ptr) {
 		home = ptr + 4;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* RE: test-runner: Add support for audio daemons
  2022-06-10  7:28 ` [PATCH BlueZ v2 1/3] test-runner: Add DBus session support Frédéric Danis
@ 2022-06-10  9:51   ` bluez.test.bot
  0 siblings, 0 replies; 7+ messages in thread
From: bluez.test.bot @ 2022-06-10  9:51 UTC (permalink / raw)
  To: linux-bluetooth, frederic.danis

[-- Attachment #1: Type: text/plain, Size: 998 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=649137

---Test result---

Test Summary:
CheckPatch                    PASS      4.38 seconds
GitLint                       PASS      2.91 seconds
Prep - Setup ELL              PASS      41.65 seconds
Build - Prep                  PASS      0.64 seconds
Build - Configure             PASS      8.71 seconds
Build - Make                  PASS      1343.82 seconds
Make Check                    PASS      11.11 seconds
Make Check w/Valgrind         PASS      414.74 seconds
Make Distcheck                PASS      226.88 seconds
Build w/ext ELL - Configure   PASS      8.37 seconds
Build w/ext ELL - Make        PASS      1356.48 seconds
Incremental Build with patchesPASS      4265.16 seconds



---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH BlueZ v2 2/3] test-runner: Add audio card support
  2022-06-10  7:28 ` [PATCH BlueZ v2 2/3] test-runner: Add audio card support Frédéric Danis
@ 2022-06-10 15:48   ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2022-06-10 15:48 UTC (permalink / raw)
  To: Frédéric Danis; +Cc: linux-bluetooth

Hi Frédéric,

On Fri, Jun 10, 2022 at 12:30 AM Frédéric Danis
<frederic.danis@collabora.com> wrote:
>
> With this commit audio daemons can detect an audio card with output and
> input, allowing to test interaction between BlueZ and the audio daemon.
> ---
>  doc/test-runner.txt |  5 +++++
>  tools/test-runner.c | 23 ++++++++++++++++++++++-
>  2 files changed, 27 insertions(+), 1 deletion(-)
>
> 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

Lets have this as a separate patch.

>  These options should be installed as .config in the kernel source directory
>  followed by this command.
> 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 <path>      QEMU binary\n"
>                 "\t-k, --kernel <image>   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;
> --
> 2.25.1
>


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH BlueZ v2 3/3] test-runner: Add udevd and trigger events
  2022-06-10  7:28 ` [PATCH BlueZ v2 3/3] test-runner: Add udevd and trigger events Frédéric Danis
@ 2022-06-10 15:50   ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2022-06-10 15:50 UTC (permalink / raw)
  To: Frédéric Danis; +Cc: linux-bluetooth

Hi Frédéric,

On Fri, Jun 10, 2022 at 12:30 AM Frédéric Danis
<frederic.danis@collabora.com> wrote:
>
> 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..e79e3b6e9 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 "
> +                               "AUDIO_SUPPORT=%u "

Lets name these TESTAUDIO instead of AUDIO_SUPPORT so it is consistent
with the other parameters like it.

>                                 "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, "AUDIO_SUPPORT=1");
> +       if (ptr) {
> +               printf("Audio support requested\n");
> +               audio_support = true;
> +       }
> +
>         ptr = strstr(cmdline, "TESTHOME=");
>         if (ptr) {
>                 home = ptr + 4;
> --
> 2.25.1
>


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-06-10 15:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-10  7:28 [PATCH BlueZ v2 0/3] test-runner: Add support for audio daemons Frédéric Danis
2022-06-10  7:28 ` [PATCH BlueZ v2 1/3] test-runner: Add DBus session support Frédéric Danis
2022-06-10  9:51   ` test-runner: Add support for audio daemons bluez.test.bot
2022-06-10  7:28 ` [PATCH BlueZ v2 2/3] test-runner: Add audio card support Frédéric Danis
2022-06-10 15:48   ` Luiz Augusto von Dentz
2022-06-10  7:28 ` [PATCH BlueZ v2 3/3] test-runner: Add udevd and trigger events Frédéric Danis
2022-06-10 15:50   ` Luiz Augusto von Dentz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).