All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zijun Hu <zijun.hu@oss.qualcomm.com>
To: Linux Bluetooth <linux-bluetooth@vger.kernel.org>
Cc: Marcel Holtmann <marcel@holtmann.org>,
	Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
	Zijun Hu <zijun_hu@icloud.com>
Subject: [PATCH bluez 3/3] tools/test-runner: Allow suppressing noisy bluetoothd debug output
Date: Sun, 22 Nov 2026 02:34:22 -0800	[thread overview]
Message-ID: <20261122-tr_arm64-v1-3-4eccf35daeca@oss.qualcomm.com> (raw)
In-Reply-To: <20261122-tr_arm64-v1-0-4eccf35daeca@oss.qualcomm.com>

test-runner always starts bluetoothd with -d, which floods the console
with debug output when only the test output is of interest.

Add an optional bluetoothd run mode to -d, e.g. -d2:
- 1: --nodetach -d [-f src/main.conf] (default)
- 2: --nodetach [-f src/main.conf]

Also make supporting other run modes easier in the future.

Existing usage in doc/test-runner.rst still works since -d without a
mode behaves as before.

Assisted-by: Claude:claude-opus-5-5
---
 doc/test-runner.rst | 16 ++++++++++++-
 tools/test-runner.c | 65 +++++++++++++++++++++++++++++++++++++++--------------
 2 files changed, 63 insertions(+), 18 deletions(-)

diff --git a/doc/test-runner.rst b/doc/test-runner.rst
index 4ff9d1b02c1b..b9dc4f1f45a1 100644
--- a/doc/test-runner.rst
+++ b/doc/test-runner.rst
@@ -12,17 +12,20 @@ it launches a virtual machine using qemu(1) with the host filesystem mounted
 read-only inside the guest.
 
 OPTIONS
 =======
 
 :-a:--auto: Find tests and run them
 :-b/--dbus: Start D-Bus system daemon
 :-s/--dbus-session: Start D-Bus session daemon
-:-d/--daemon: Start bluetoothd
+:-d/--daemon[=mode]: Start bluetoothd, mode (default 1):
+
+    | 1: --nodetach -d [-f src/main.conf]
+    | 2: --nodetach [-f src/main.conf]
 :-m/--monitor: Start btmon
 :-l/--emulator[=num]: Start btvirt
 :-A/-audio[=path]: Start audio server
 :-u/--unix[=path]: Provide serial device
 :-U/--usb=<qemu_args>: Provide USB device
 :-P/--pcie=<qemu_args>: Provide PCIe device
 :-q/--qemu=<path>: QEMU binary
 :-H/--qemu-host-cpu: Use host CPU (requires KVM support)
@@ -359,16 +362,27 @@ Running bluetoothctl with emulated controller and audio support
 Running shell with host controller using btproxy
 ------------------------------------------------
 
 .. code-block::
 
 	$ tools/btproxy -u [1]
 	$ tools/test-runner -u -d -k /pathto/bzImage -- /bin/bash [2]
 
+Running bluetoothctl with host controller using btproxy for normal output
+--------------------------------------------------------------------------
+
+With -d2, bluetoothd is started without -d, so the bluetoothctl console
+is not flooded with debug output:
+
+.. code-block::
+
+	$ tools/btproxy -u [1]
+	$ tools/test-runner -u -d2 -k /pathto/bzImage -- client/bluetoothctl [2]
+
 Running shell with host controller USB-passthrough
 --------------------------------------------------
 
 In addition the above kernel config option the following is required:
 
 .. code-block::
 
 	CONFIG_USB=y
diff --git a/tools/test-runner.c b/tools/test-runner.c
index a2105977c1ee..bcfa4b2971ff 100644
--- a/tools/test-runner.c
+++ b/tools/test-runner.c
@@ -50,25 +50,26 @@
 #endif
 
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 
 #define _cleanup_(f) __attribute__((cleanup(f)))
 
 #define CMDLINE_MAX (2048 * 10)
 #define EXTRA_OPT_MAX 64
+#define DAEMON_MODE_MAX 3
 
 static const char *own_binary;
 static char **test_argv;
 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 unsigned int start_daemon;
 static bool start_monitor = false;
 static bool qemu_host_cpu = false;
 /* Simulated time with User Mode Linux: -1 if supported by the kernel */
 static int time_travel = -1;
 static int num_devs = 0;
 static int num_emulator = 0;
 static const char *device_path = "/tmp/bt-server-bredr";
 static const char *qemu_binary = NULL;
@@ -1578,17 +1579,17 @@ static const char *daemon_table[] = {
 	"/usr/sbin/bluetoothd",
 	"/usr/libexec/bluetooth/bluetoothd",
 	NULL
 };
 
 static pid_t start_bluetooth_daemon(const char *home)
 {
 	const char *daemon = NULL;
-	char *argv[6], *envp[2];
+	char *argv[6] = { NULL }, *envp[2];
 	pid_t pid;
 	struct stat st;
 	int i;
 
 	if (chdir(home + 5) < 0) {
 		perror("Failed to change home directory for daemon");
 		return -1;
 	}
@@ -1603,25 +1604,40 @@ static pid_t start_bluetooth_daemon(const char *home)
 
 	if (!daemon) {
 		fprintf(stderr, "Failed to locate Bluetooth daemon binary\n");
 		return -1;
 	}
 
 	printf("Using Bluetooth daemon %s\n", daemon);
 
-	argv[0] = (char *) daemon;
-	argv[1] = "--nodetach";
-	argv[2] = "-d";
-	argv[3] = NULL;
+	i = 0;
+	argv[i++] = (char *) daemon;
 
-	if (!stat("src/main.conf", &st)) {
-		argv[3] = "-f";
-		argv[4] = "src/main.conf";
-		argv[5] = NULL;
+	switch (start_daemon) {
+	case 1:
+		argv[i++] = "--nodetach";
+		argv[i++] = "-d";
+
+		if (!stat("src/main.conf", &st)) {
+			argv[i++] = "-f";
+			argv[i++] = "src/main.conf";
+		}
+		break;
+	case 2:
+		argv[i++] = "--nodetach";
+
+		if (!stat("src/main.conf", &st)) {
+			argv[i++] = "-f";
+			argv[i++] = "src/main.conf";
+		}
+		break;
+	default:
+		fprintf(stderr, "Invalid daemon mode %u\n", start_daemon);
+		return -1;
 	}
 
 	envp[0] = "DBUS_SYSTEM_BUS_ADDRESS=unix:path=/run/dbus/system_bus_socket";
 	envp[1] = NULL;
 
 	printf("Starting Bluetooth daemon\n");
 
 	pid = fork();
@@ -2165,20 +2181,21 @@ static void run_tests(void)
 	}
 
 	ptr = strstr(cmdline, "TESTDBUSSESSION=1");
 	if (ptr) {
 		printf("D-Bus session daemon requested\n");
 		start_dbus_session = true;
 	}
 
-	ptr = strstr(cmdline, "TESTDAEMON=1");
+	ptr = strstr(cmdline, "TESTDAEMON=");
 	if (ptr) {
-		printf("bluetoothd requested\n");
-		start_daemon = true;
+		start_daemon = strtoul(ptr + 11, NULL, 0);
+		if (start_daemon)
+			printf("bluetoothd mode %u requested\n", start_daemon);
 	}
 
 	ptr = strstr(cmdline, "TESTMONITOR=1");
 	if (ptr) {
 		printf("Monitor requested\n");
 		start_monitor = true;
 	}
 
@@ -2218,17 +2235,19 @@ static void usage(void)
 {
 	printf("test-runner - Automated test execution utility\n"
 		"Usage:\n");
 	printf("\ttest-runner [options] [--] <command> [args]\n");
 	printf("Options:\n"
 		"\t-a, --all,--auto       Find tests and run them\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-d, --daemon[=mode]    Start bluetoothd, mode (default 1):\n"
+		"\t                       1: --nodetach -d [-f src/main.conf]\n"
+		"\t                       2: --nodetach [-f src/main.conf]\n"
 		"\t-m, --monitor          Start btmon\n"
 		"\t-l, --emulator[=num]   Start btvirt\n"
 		"\t-A, --audio[=path]     Start audio server\n"
 		"\t-u, --unix[=path]      Provide serial device\n"
 		"\t-U, --usb <qemu_args>  Provide USB device\n"
 		"\t-P, --pcie <qemu_args> Provide PCIe device\n"
 		"\t-q, --qemu <path>      QEMU binary\n"
 		"\t-H, --qemu-host-cpu    Use host CPU (requires KVM support)\n"
@@ -2247,17 +2266,17 @@ static void usage(void)
 }
 
 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",    optional_argument, NULL, 'u' },
-	{ "daemon",  no_argument,       NULL, 'd' },
+	{ "daemon",  optional_argument, NULL, 'd' },
 	{ "emulator", no_argument,      NULL, 'l' },
 	{ "monitor", no_argument,       NULL, 'm' },
 	{ "qemu",    required_argument, NULL, 'q' },
 	{ "qemu-host-cpu", no_argument, NULL, 'H' },
 	{ "kernel",  required_argument, NULL, 'k' },
 	{ "audio",   optional_argument, NULL, 'A' },
 	{ "usb",     required_argument, NULL, 'U' },
 	{ "pcie",    required_argument, NULL, 'P' },
@@ -2288,17 +2307,17 @@ int main(int argc, char *argv[])
 			reboot(RB_AUTOBOOT);
 		return EXIT_SUCCESS;
 	}
 
 	for (;;) {
 		int opt;
 
 		opt = getopt_long(argc, argv,
-				"au::bdsl::mq:Hk:A::U:P:o:F::TRvh",
+				"au::bd::sl::mq:Hk:A::U:P:o:F::TRvh",
 				main_options, NULL);
 		if (opt < 0)
 			break;
 
 		switch (opt) {
 		case 'a':
 			run_auto = true;
 			break;
@@ -2310,17 +2329,29 @@ 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;
+			start_daemon = 1;
+			if (optarg) {
+				char *endptr;
+
+				start_daemon = strtoul(optarg, &endptr, 0);
+				if (start_daemon >= DAEMON_MODE_MAX ||
+								*endptr) {
+					fprintf(stderr,
+						"Invalid daemon mode %s\n",
+						optarg);
+					return EXIT_FAILURE;
+				}
+			}
 			break;
 		case 'l':
 			num_emulator = optarg ? atoi(optarg) : 1;
 			break;
 		case 'm':
 			start_monitor = true;
 			break;
 		case 'q':

-- 
2.34.1


      parent reply	other threads:[~2026-11-22 10:34 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 10:34 [PATCH bluez 0/3] tools/test-runner: Add arm64 host support Zijun Hu
2026-11-22 10:34 ` [PATCH bluez 1/3] doc/test-runner: s/CONFIG_BT_HCIBTINTEL_PCIE/CONFIG_BT_INTEL_PCIE/ Zijun Hu
2026-11-22 18:56   ` tools/test-runner: Add arm64 host support bluez.test.bot
2026-11-25  8:59   ` [PATCH bluez 1/3] doc/test-runner: s/CONFIG_BT_HCIBTINTEL_PCIE/CONFIG_BT_INTEL_PCIE/ Bastien Nocera
2026-11-25 10:43     ` Zijun Hu
2026-11-25 11:06       ` Bastien Nocera
2026-11-22 10:34 ` [PATCH bluez 2/3] tools/test-runner: Support running on arm64 hosts Zijun Hu
2026-11-22 16:24   ` Pauli Virtanen
2026-11-23  1:04     ` Zijun Hu
2026-11-23 14:45       ` Luiz Augusto von Dentz
2026-11-24  2:57         ` Zijun Hu
2026-11-24 15:20           ` Luiz Augusto von Dentz
2026-11-25  7:11             ` Zijun Hu
2026-11-25  9:04   ` Bastien Nocera
2026-11-25 10:46     ` Zijun Hu
2026-11-25 11:07       ` Bastien Nocera
2026-11-22 10:34 ` Zijun Hu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261122-tr_arm64-v1-3-4eccf35daeca@oss.qualcomm.com \
    --to=zijun.hu@oss.qualcomm.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    --cc=zijun_hu@icloud.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.