* [PATCH bluez] tools/test-runner: Add optional log path to -d for QEMU
@ 2026-12-05 6:24 Zijun Hu
2026-12-05 14:49 ` [bluez] " bluez.test.bot
0 siblings, 1 reply; 2+ messages in thread
From: Zijun Hu @ 2026-12-05 6:24 UTC (permalink / raw)
To: Linux Bluetooth; +Cc: Marcel Holtmann, Luiz Augusto von Dentz, Zijun Hu
Issue:
When running:
tools/test-runner -u -d -k /path/to/bzImage -- client/bluetoothctl
bluetoothd debug level logs flood the console and bury the
bluetoothctl output the user is interested in. For example, this
causes difficulty finding a specific device in the scan results.
Why:
test-runner always starts bluetoothd with "--nodetach -d": -d
enables bluetoothd's debug level logs, and --nodetach sends them to
stderr on the console, where they mix with the bluetoothctl output.
Fix by:
Make test-runner's -d take an optional log path, -d[log_path]. If
given, redirect bluetoothd's stdout and stderr to the host file
through a virtio-serial port.
Plain -d keeps the current behavior. With QEMU, use -d<log_path> to
redirect the logs to a host file or -d/dev/null to discard them:
tools/test-runner -u -d/tmp/vm_btd.log -k /path/to/bzImage \
-- client/bluetoothctl
Advantages:
- Keeps the full bluetoothd logs for later analysis
Assisted-by: Codex:gpt-5
---
This is an alternative solution for:
tools/test-runner: Add optional mode parameter to -d
https://lore.kernel.org/all/20261204-tr_mode-v4-1-320f800a9063@oss.qualcomm.com
which uses a mode parameter to control how to start bluetoothd, e.g.
-d2 starts it without debug level logs.
---
doc/test-runner.rst | 17 +++++++-
tools/test-runner.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 122 insertions(+), 8 deletions(-)
diff --git a/doc/test-runner.rst b/doc/test-runner.rst
index 7ffcff72a2a5..4a6782dd5964 100644
--- a/doc/test-runner.rst
+++ b/doc/test-runner.rst
@@ -12,17 +12,18 @@ 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[=log_path]: Start bluetoothd, optionally save its logs
+ to a host file with QEMU
:-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)
@@ -150,17 +151,17 @@ When ``-k`` is a User Mode Linux (UML) binary, recognized by its
with the host filesystem mounted as root through hostfs, and powers it off
at the end since rebooting UML starts it again. The kernel needs
``CONFIG_HOSTFS``, and ``CONFIG_VIRTIO_UML`` for virtio devices.
``-o`` then adds kernel parameters, which is how UML attaches devices served
from the host, e.g. ``virtio_uml.device=<socket>:40`` for a virtio
Bluetooth controller, or joins an external simulated clock with
``time-travel=ext:<socket>``. See `virtio.rst <virtio.rst>`_. ``-u``,
-``-U``, ``-P``, ``-q`` and ``-H`` need QEMU.
+``-U``, ``-P``, ``-q``, ``-H`` and ``-d<log_path>`` need QEMU.
If the kernel has ``CONFIG_UML_TIME_TRAVEL_SUPPORT``, test-runner starts
**btvirt(1)** ``--time`` as time travel calendar and runs the guest on its
simulated clock: time only advances when the guest waits, so it skips idle
time and timeouts take no real time, while the guest sees the same timings
on every run. ``-R`` runs the guest on real time instead, and ``-T`` fails if
the kernel has no time travel support. A ``time-travel`` kernel parameter
given with ``-o``, e.g. to join the calendar of other guests, replaces the
@@ -360,16 +361,28 @@ 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 a clearer console
+--------------------------------------------
+
+To get a clearer bluetoothctl console, use ``-d<log_path>`` to redirect
+bluetoothd logs to a host file, or ``-d/dev/null`` to discard them:
+
+.. code-block::
+
+ $ tools/btproxy -u [1]
+ $ tools/test-runner -u -d/tmp/vm_btd.log -k /path/to/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 1af9fa700d81..afdce2b0ba1a 100644
--- a/tools/test-runner.c
+++ b/tools/test-runner.c
@@ -50,16 +50,20 @@
#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_LOG_VPORT_NAME "bluetoothd.log"
+
+static bool daemon_log;
+static const char *daemon_log_path;
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;
@@ -963,23 +967,25 @@ static int start_qemu(void)
*/
noacpi = pcie_dev ? "" : "acpi=off pci=noacpi noapic";
#endif
snprintf(cmdline, sizeof(cmdline),
"console=hvc0 %s "
"no_hash_pointers=1 %s %s quiet ro init=%s "
"TESTHOME=%s TESTDBUS=%u TESTDAEMON=%u "
+ "DAEMONLOG=%u "
"TESTDBUSSESSION=%u XDG_RUNTIME_DIR=/run/user/0 "
"TESTMONITOR=%u TESTEMULATOR=%u TESTDEVS=%d "
"TESTAUTO=%u TESTAUDIO='%s' TESTARGS=\'%s\'",
earlycon,
fscmdline,
noacpi,
initcmd, cwd, start_dbus, start_daemon,
+ daemon_log,
start_dbus_session,
start_monitor, num_emulator, num_devs,
run_auto, audio_server ? audio_server : "",
testargs);
/* Make sure qemu_binary is not null */
if (!qemu_binary) {
fprintf(stderr, "No QEMU binary is set\n");
@@ -1018,16 +1024,25 @@ static int start_qemu(void)
for (i = 0; i < num_devs; i++) {
strv_append(&argv, "-chardev");
strv_append(&argv, "socket,path=%s,id=bt%d", device_path, i);
strv_append(&argv, "-device");
strv_append(&argv, "virtconsole,chardev=bt%d,name=bt.%d", i, i);
}
+ if (daemon_log) {
+ strv_append(&argv, "-chardev");
+ strv_append(&argv, "file,id=bluetoothd-log,path=%s",
+ daemon_log_path);
+ strv_append(&argv, "-device");
+ strv_append(&argv, "virtserialport,chardev=bluetoothd-log,"
+ "name=" DAEMON_LOG_VPORT_NAME);
+ }
+
if (usb_dev) {
strv_append(&argv, "-device");
strv_append(&argv, "qemu-xhci");
strv_append(&argv, "-device");
strv_append(&argv, "%s", usb_dev);
}
if (pcie_dev) {
@@ -1575,16 +1590,65 @@ static pid_t start_dbus_daemon(bool session)
static const char *daemon_table[] = {
"bluetoothd",
"src/bluetoothd",
"/usr/sbin/bluetoothd",
"/usr/libexec/bluetooth/bluetoothd",
NULL
};
+/* Find the virtio port by name */
+static int open_vport_by_name(const char *port_name)
+{
+ /* Allow 32 bytes for the path and 256 for d_name. */
+ char name_path[32 + 256];
+ ssize_t name_len, len;
+ struct dirent *entry;
+ int name_fd;
+ DIR *dir;
+
+ dir = opendir("/sys/class/virtio-ports");
+ if (!dir)
+ return -1;
+
+ name_len = strlen(port_name);
+
+ while ((entry = readdir(dir))) {
+ if (strncmp(entry->d_name, "vport", 5))
+ continue;
+
+ snprintf(name_path, sizeof(name_path),
+ "/sys/class/virtio-ports/%s/name", entry->d_name);
+
+ name_fd = open(name_path, O_RDONLY);
+ if (name_fd < 0)
+ continue;
+
+ len = read(name_fd, name_path, sizeof(name_path));
+ close(name_fd);
+
+ if (len < name_len)
+ continue;
+
+ if (strncmp(name_path, port_name, name_len))
+ continue;
+
+ snprintf(name_path, sizeof(name_path), "/dev/%s",
+ entry->d_name);
+
+ closedir(dir);
+ return open(name_path, O_WRONLY);
+ }
+
+ closedir(dir);
+ errno = ENOENT;
+
+ return -1;
+}
+
static pid_t start_bluetooth_daemon(const char *home)
{
const char *daemon = NULL;
char *argv[6], *envp[2];
pid_t pid;
struct stat st;
int i;
@@ -1626,16 +1690,36 @@ static pid_t start_bluetooth_daemon(const char *home)
pid = fork();
if (pid < 0) {
perror("Failed to fork new process");
return -1;
}
if (pid == 0) {
+ if (daemon_log) {
+ int log_fd;
+
+ log_fd = open_vport_by_name(DAEMON_LOG_VPORT_NAME);
+ if (log_fd < 0) {
+ perror("Failed to open daemon log vport");
+ _exit(EXIT_FAILURE);
+ }
+
+ if (dup2(log_fd, STDOUT_FILENO) < 0 ||
+ dup2(log_fd, STDERR_FILENO) < 0) {
+ perror("Failed to redirect daemon log");
+ _exit(EXIT_FAILURE);
+ }
+
+ if (log_fd != STDOUT_FILENO &&
+ log_fd != STDERR_FILENO)
+ close(log_fd);
+ }
+
execve(argv[0], argv, envp);
exit(EXIT_SUCCESS);
}
printf("Bluetooth daemon process %d created\n", pid);
return pid;
}
@@ -2173,16 +2257,20 @@ static void run_tests(void)
}
ptr = strstr(cmdline, "TESTDAEMON=1");
if (ptr) {
printf("bluetoothd requested\n");
start_daemon = true;
}
+ ptr = strstr(cmdline, "DAEMONLOG=1");
+ if (ptr)
+ daemon_log = true;
+
ptr = strstr(cmdline, "TESTMONITOR=1");
if (ptr) {
printf("Monitor requested\n");
start_monitor = true;
}
ptr = strstr(cmdline, "TESTEMULATOR=");
if (ptr) {
@@ -2220,17 +2308,17 @@ 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[=log_path] Start bluetoothd and log to a host file\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"
@@ -2249,17 +2337,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' },
@@ -2290,17 +2378,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;
@@ -2313,16 +2401,29 @@ int main(int argc, char *argv[])
start_dbus = true;
break;
case 's':
start_dbus_session = true;
break;
case 'd':
start_dbus = true;
start_daemon = true;
+ if (optarg) {
+ /* Commas separate QEMU chardev options. */
+ if (strchr(optarg, ',')) {
+ fprintf(stderr, "Unexpected ',' in "
+ "daemon log path "
+ "'%s'\n", optarg);
+ return EXIT_FAILURE;
+ }
+
+ daemon_log_path = optarg;
+ daemon_log = true;
+ }
+
break;
case 'l':
num_emulator = optarg ? atoi(optarg) : 1;
break;
case 'm':
start_monitor = true;
break;
case 'q':
@@ -2399,19 +2500,19 @@ int main(int argc, char *argv[])
fprintf(stderr, "No kernel image found\n");
return EXIT_FAILURE;
}
kernel_image = kernel_path;
if (is_uml_kernel(kernel_image)) {
if (num_devs || usb_dev || pcie_dev || qemu_binary ||
- qemu_host_cpu) {
- fprintf(stderr, "-u, -U, -P, -q and -H need QEMU, not "
- "User Mode Linux\n");
+ qemu_host_cpu || daemon_log) {
+ fprintf(stderr, "-u, -U, -P, -q, -H and -d<log_path> "
+ "need QEMU, not User Mode Linux\n");
return EXIT_FAILURE;
}
if (time_travel && !uml_has_time_travel()) {
if (time_travel > 0) {
fprintf(stderr, "%s has no time travel support "
"(CONFIG_UML_TIME_TRAVEL_SUPPORT)\n",
kernel_image);
---
base-commit: 96e805a6b6bb052d4d2e3d73dc2b703f298b0349
change-id: 20261204-tr_vs-50f984d254cc
Best regards,
--
Zijun Hu <zijun.hu@oss.qualcomm.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* RE: [bluez] tools/test-runner: Add optional log path to -d for QEMU
2026-12-05 6:24 [PATCH bluez] tools/test-runner: Add optional log path to -d for QEMU Zijun Hu
@ 2026-12-05 14:49 ` bluez.test.bot
0 siblings, 0 replies; 2+ messages in thread
From: bluez.test.bot @ 2026-12-05 14:49 UTC (permalink / raw)
To: linux-bluetooth, zijun.hu
[-- Attachment #1: Type: text/plain, Size: 1218 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/series/1232683/
---Test result---
Test Summary:
CheckPatch PASS 0.48 seconds
GitLint FAIL 0.24 seconds
BuildEll PASS 20.07 seconds
BluezMake PASS 311.92 seconds
MakeCheck PASS 14.50 seconds
MakeDistcheck PASS 147.18 seconds
CheckValgrind PASS 353.62 seconds
CheckSmatch PASS 317.16 seconds
bluezmakeextell PASS 100.93 seconds
TestFunctional PASS 1223.75 seconds
IncrementalBuild PASS 314.33 seconds
ScanBuild PASS 1197.50 seconds
Details
##############################
Test: GitLint - FAIL
Desc: Run gitlint
Output:
[bluez] tools/test-runner: Add optional log path to -d for QEMU
50: B2 Line has trailing whitespace: "-- "
https://github.com/bluez/bluez/pull/2985
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-05 14:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 6:24 [PATCH bluez] tools/test-runner: Add optional log path to -d for QEMU Zijun Hu
2026-12-05 14:49 ` [bluez] " bluez.test.bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox