By "late", I mean the serial device won't be configured by the kernel until full userspace is running. Here I'm doing this with a USB serial device, for which driver modules need to be loaded by the kernel. This is a regression test, because that didn't used to work, since serial consoles were only configured once at boot. Signed-off-by: Alyssa Ross <hi@alyssa.is> --- release/checks/integration/late-serial.c | 15 +++++++++++++++ release/checks/integration/lib.c | 16 ++++++++++------ release/checks/integration/lib.h | 4 ++++ release/checks/integration/meson.build | 9 ++++++--- 4 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 release/checks/integration/late-serial.c diff --git a/release/checks/integration/late-serial.c b/release/checks/integration/late-serial.c new file mode 100644 index 0000000..46f312a --- /dev/null +++ b/release/checks/integration/late-serial.c @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: EUPL-1.2+ +// SPDX-FileCopyrightText: 2025 Alyssa Ross <hi@alyssa.is> + +#include "lib.h" + +void test(struct config c) +{ + c.serial = (typeof(c.serial)) { + .optname = "-device", + .optval = "usb-serial,chardev=socket", + .console = "ttyUSB0", + }; + + start_qemu(c); +} diff --git a/release/checks/integration/lib.c b/release/checks/integration/lib.c index b0b4507..bc2b9dd 100644 --- a/release/checks/integration/lib.c +++ b/release/checks/integration/lib.c @@ -114,10 +114,12 @@ FILE *start_qemu(struct config c) "-drive", nullptr, "-drive", nullptr, "-drive", nullptr, + "-smbios", nullptr, "-m", "4G", "-nodefaults", "-machine", "virtualization=on", "-cpu", "max", + "-device", "qemu-xhci", "-device", "virtio-keyboard", "-device", "virtio-mouse", "-device", "virtio-gpu", @@ -125,19 +127,20 @@ FILE *start_qemu(struct config c) "-device", "e1000e,netdev=net0", "-monitor", "vc", "-vga", "none", - "-smbios", "type=11,value=io.systemd.stub.kernel-cmdline-extra=console=ttyS0", - "-serial", "unix:console", + "-chardev", "socket,id=socket,path=console", + c.serial.optname ? (char *)c.serial.optname : "-serial", + c.serial.optval ? (char *)c.serial.optval : "chardev:socket", nullptr, }; char **efi_arg = &args[2], **img_arg = &args[4], - **user_data_arg = &args[6]; + **user_data_arg = &args[6], **console_arg = &args[8]; if (!(arch = getenv("ARCH"))) { uname(&u); arch = u.machine; } - if (strcmp(arch, "x86_64")) - args[sizeof args / sizeof *args - 3] = nullptr; + if (!c.serial.console && !strcmp(arch, "x86_64")) + c.serial.console = "ttyS0"; console_listener = setup_unix("console"); @@ -153,7 +156,8 @@ FILE *start_qemu(struct config c) if (asprintf(efi_arg, "file=%s,format=raw,if=pflash,readonly=true", c.drives.efi) == -1 || asprintf(img_arg, "file=%s,format=raw,if=virtio,readonly=true", c.drives.img) == -1 || - asprintf(user_data_arg, "file=%s,format=raw,if=virtio,readonly=true", c.drives.user_data) == -1) { + asprintf(user_data_arg, "file=%s,format=raw,if=virtio,readonly=true", c.drives.user_data) == -1 || + asprintf(console_arg, "type=11,value=io.systemd.stub.kernel-cmdline-extra=%s%s", c.serial.console ? "console=" : "", c.serial.console) == -1) { perror("asprintf"); exit(EXIT_FAILURE); } diff --git a/release/checks/integration/lib.h b/release/checks/integration/lib.h index 959573d..743c906 100644 --- a/release/checks/integration/lib.h +++ b/release/checks/integration/lib.h @@ -9,6 +9,10 @@ struct config { struct { const char *efi, *img, *user_data; } drives; + + struct { + const char *optname, *optval, *console; + } serial; }; extern void test(struct config); diff --git a/release/checks/integration/meson.build b/release/checks/integration/meson.build index 7edc314..4a58cce 100644 --- a/release/checks/integration/meson.build +++ b/release/checks/integration/meson.build @@ -7,12 +7,15 @@ project('spectrum-integration-tests', 'c', add_project_arguments('-D_GNU_SOURCE', language : 'c') +run_qemu = find_program('../../../scripts/run-qemu.sh') + lib = static_library('spectrum-integration-test', 'lib.c') -test('networking', executable('networking', 'networking.c', link_with : lib), - args : [ - find_program('../../../scripts/run-qemu.sh'), +foreach test : ['networking', 'late-serial'] + test(test, executable(test, test + '.c', link_with : lib), args : [ + run_qemu, get_option('efi'), get_option('img'), get_option('user_data'), ]) +endforeach -- 2.49.0