Skip to content

Commit 7da70bf

Browse files
committed
Emulate a USB keyboard+mouse when starting QEMU
This previously triggered a panic in the purecap kernel, so adding those devices seems like a good idea for CI purposes.
1 parent ab7e14e commit 7da70bf

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

pycheribuild/boot_cheribsd/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ def boot_cheribsd(qemu_options: QemuOptions, qemu_command: typing.Optional[Path]
771771
qemu_args = qemu_options.get_commandline(qemu_command=qemu_command, kernel_file=kernel_image, disk_image=disk_image,
772772
bios_args=bios_args, user_network_args=user_network_args,
773773
write_disk_image_changes=write_disk_image_changes,
774-
add_network_device=True,
774+
add_network_device=True, add_usb_input=True,
775775
trap_on_unrepresentable=trap_on_unrepresentable, # For debugging
776776
add_virtio_rng=True # faster entropy gathering
777777
)

pycheribuild/config/chericonfig.py

+2
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ def __init__(self, loader, action_class):
322322
self.run_under_gdb = loader.add_bool_option("run-under-gdb", group=loader.run_group,
323323
help="Run tests/benchmarks under GDB. Note: currently most "
324324
"targets ignore this flag.")
325+
self.emulate_usb_input_devices = loader.add_bool_option("emulate-usb-input-devices", group=loader.run_group,
326+
default=True, help="Emulate USB keyboard+mouse in QEMU")
325327

326328
# Test options:
327329
self.test_ssh_key = loader.add_path_option("test-ssh-key", default=None, group=loader.tests_group,

pycheribuild/projects/run_qemu.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,8 @@ def add_smb_or_9p_dir(directory, target, share_name=None, readonly=False):
308308
user_network_args=user_network_options,
309309
trap_on_unrepresentable=self.config.trap_on_unrepresentable,
310310
debugger_on_cheri_trap=self.config.debugger_on_cheri_trap,
311-
add_virtio_rng=self._add_virtio_rng)
311+
add_virtio_rng=self._add_virtio_rng,
312+
add_usb_input=self.config.emulate_usb_input_devices)
312313
qemu_command += self._project_specific_options + self._after_disk_options + monitor_options
313314
qemu_command += logfile_options + self.extra_qemu_options + virtfs_args
314315
self.info("About to run QEMU with image", self.disk_image, "and loader/kernel", qemu_loader_or_kernel)

pycheribuild/qemu_utils.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def get_qemu_binary(self) -> "typing.Optional[Path]":
154154

155155
def get_commandline(self, *, qemu_command=None, kernel_file: Path = None, disk_image: Path = None,
156156
disk_image_format: str = "raw", user_network_args: str = "", add_network_device=True,
157-
bios_args: "typing.List[str]" = None, trap_on_unrepresentable=False,
157+
bios_args: "typing.List[str]" = None, trap_on_unrepresentable=False, add_usb_input: bool,
158158
debugger_on_cheri_trap=False, add_virtio_rng=False, write_disk_image_changes=True,
159159
gui_options: "typing.List[str]" = None) -> "typing.List[str]":
160160
if qemu_command is None:
@@ -185,6 +185,10 @@ def get_commandline(self, *, qemu_command=None, kernel_file: Path = None, disk_i
185185
result.extend(self.user_network_args(user_network_args))
186186
if add_virtio_rng:
187187
result.extend(["-device", "virtio-rng-pci"])
188+
if add_usb_input:
189+
# Add USB input devices instead of the default PS/2. This ensures that the USB kernel setup logic
190+
# in CheriBSD is tested during CI runs.
191+
result.extend(["-device", "qemu-xhci", "-device", "usb-mouse", "-device", "usb-kbd"])
188192
return result
189193

190194

0 commit comments

Comments
 (0)