From: Luiz Augusto von Dentz <luiz.von.dentz@xxxxxxxxx> This adds option to use a host controller plugged over USB: > tools/test-runner -U "usb-host,vendorid=0x8087,productid=0x0036"... -- /bin/bash > dmesg [ 1.046214] usb 1-1: new full-speed USB device number 2 using xhci_hcd [ 1.192623] Bluetooth: hci0: Firmware timestamp 2025.18 buildtype 2 build 82364 [ 1.192638] Bluetooth: hci0: Firmware SHA1: 0xa66e016b [ 1.197362] Bluetooth: hci0: Fseq status: Success (0x00) [ 1.197368] Bluetooth: hci0: Fseq executed: 00.00.04.196 [ 1.197371] Bluetooth: hci0: Fseq BT Top: 00.00.04.197 > lsusb Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 002: ID 8087:0036 Intel Corp. BE200 Bluetooth Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub --- tools/test-runner.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tools/test-runner.c b/tools/test-runner.c index 7c9386d2c3d3..ae4e653e3502 100644 --- a/tools/test-runner.c +++ b/tools/test-runner.c @@ -57,6 +57,7 @@ static int num_devs = 0; static const char *qemu_binary = NULL; static const char *kernel_image = NULL; static char *audio_server; +static char *usb_dev; static const char *qemu_table[] = { "qemu-system-x86_64", @@ -288,7 +289,8 @@ static void start_qemu(void) testargs); argv = alloca(sizeof(qemu_argv) + - (sizeof(char *) * (6 + (num_devs * 4)))); + (sizeof(char *) * (6 + (num_devs * 4))) + + (sizeof(char *) * (usb_dev ? 4 : 0))); memcpy(argv, qemu_argv, sizeof(qemu_argv)); pos = (sizeof(qemu_argv) / sizeof(char *)) - 1; @@ -326,6 +328,13 @@ static void start_qemu(void) argv[pos++] = serdev; } + if (usb_dev) { + argv[pos++] = "-device"; + argv[pos++] = "qemu-xhci"; + argv[pos++] = "-device"; + argv[pos++] = usb_dev; + } + argv[pos] = NULL; execve(argv[0], argv, qemu_envp); @@ -1183,6 +1192,7 @@ static void usage(void) "\t-l, --emulator 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-q, --qemu <path> QEMU binary\n" "\t-H, --qemu-host-cpu Use host CPU (requires KVM support)\n" "\t-k, --kernel <image> Kernel image (bzImage)\n" @@ -1202,6 +1212,7 @@ static const struct option main_options[] = { { "qemu-host-cpu", no_argument, NULL, 'H' }, { "kernel", required_argument, NULL, 'k' }, { "audio", optional_argument, NULL, 'A' }, + { "usb", required_argument, NULL, 'U' }, { "version", no_argument, NULL, 'v' }, { "help", no_argument, NULL, 'h' }, { } @@ -1221,8 +1232,8 @@ int main(int argc, char *argv[]) for (;;) { int opt; - opt = getopt_long(argc, argv, "aubdslmq:Hk:A::vh", main_options, - NULL); + opt = getopt_long(argc, argv, "aubdslmq:Hk:A::U:vh", + main_options, NULL); if (opt < 0) break; @@ -1261,6 +1272,9 @@ int main(int argc, char *argv[]) case 'A': audio_server = optarg ? optarg : "/usr/bin/pipewire"; break; + case 'U': + usb_dev = optarg; + break; case 'v': printf("%s\n", VERSION); return EXIT_SUCCESS; -- 2.49.0