From 458fe813450414f5fd9f319dd27e6508bbc46210 Mon Sep 17 00:00:00 2001 From: Zoltan Gyarmati Date: Fri, 9 Oct 2026 09:49:37 +0200 Subject: [PATCH] support/testing/tests/package/test_libusb_compat: new runtime test Signed-off-by: Zoltan Gyarmati Signed-off-by: Thomas Petazzoni --- DEVELOPERS | 2 + .../tests/package/test_libusb_compat.py | 58 +++++++++++++++++++ .../test_libusb_compat/linux-usb.fragment | 2 + 3 files changed, 62 insertions(+) create mode 100644 support/testing/tests/package/test_libusb_compat.py create mode 100644 support/testing/tests/package/test_libusb_compat/linux-usb.fragment diff --git a/DEVELOPERS b/DEVELOPERS index c703e50b14..dca5ecc5c0 100644 --- a/DEVELOPERS +++ b/DEVELOPERS @@ -3629,4 +3629,6 @@ F: package/quazip/ F: package/shapelib/ F: package/simple-mail/ F: package/tinc/ +F: support/testing/tests/package/test_libusb_compat.py +F: support/testing/tests/package/test_libusb_compat/ F: support/testing/tests/package/test_quazip.py diff --git a/support/testing/tests/package/test_libusb_compat.py b/support/testing/tests/package/test_libusb_compat.py new file mode 100644 index 0000000000..d0bb57d4cc --- /dev/null +++ b/support/testing/tests/package/test_libusb_compat.py @@ -0,0 +1,58 @@ +import os + +import infra.basetest + + +class TestLibusbCompat(infra.basetest.BRTest): + # enable USB 2.0 support so we can test the USB enumeration in qemu + linux_fragment = \ + infra.filepath("tests/package/test_libusb_compat/linux-usb.fragment") + config = \ + f""" + BR2_aarch64=y + BR2_TOOLCHAIN_EXTERNAL=y + BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0" + BR2_LINUX_KERNEL=y + BR2_LINUX_KERNEL_CUSTOM_VERSION=y + BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.1.73" + BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y + BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config" + BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="{linux_fragment}" + BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y + BR2_PACKAGE_LIBUSB=y + BR2_PACKAGE_LIBUSB_COMPAT=y + BR2_PACKAGE_LIBUSB_COMPAT_EXAMPLES=y + BR2_TARGET_ROOTFS_CPIO=y + BR2_TARGET_ROOTFS_CPIO_GZIP=y + # BR2_TARGET_ROOTFS_TAR is not set + """ + + examples_dir = "/usr/libexec/libusb-compat/examples" + + def test_run(self): + img = os.path.join(self.builddir, "images", "rootfs.cpio.gz") + kern = os.path.join(self.builddir, "images", "Image") + # We add a USB keyboard device for the test. + self.emulator.boot(arch="aarch64", + kernel=kern, + kernel_cmdline=["console=ttyAMA0"], + options=["-M", "virt", "-cpu", "cortex-a57", "-m", "256M", + "-initrd", img, + "-device", "usb-ehci,id=ehci", + "-device", "usb-kbd,bus=ehci.0"]) + self.emulator.login() + + # The lsusb example prints "idVendor:idProduct" for every + # device. We expect the Linux Foundation 2.0 root hub + # (1d6b:0002) and the QEMU USB keyboard (0627:0001). + output, exit_code = self.emulator.run(f"{self.examples_dir}/lsusb") + self.assertEqual(exit_code, 0) + self.assertIn("1d6b:0002", output) + self.assertIn("0627:0001", output) + + # The testlibusb example opens every device and prints its + # descriptors. The keyboard should show up as a HID + # (bInterfaceClass 3) device. + output, exit_code = self.emulator.run(f"{self.examples_dir}/testlibusb -v") + self.assertEqual(exit_code, 0) + self.assertIn("bInterfaceClass: 3", "\n".join(output)) diff --git a/support/testing/tests/package/test_libusb_compat/linux-usb.fragment b/support/testing/tests/package/test_libusb_compat/linux-usb.fragment new file mode 100644 index 0000000000..d9abd2821e --- /dev/null +++ b/support/testing/tests/package/test_libusb_compat/linux-usb.fragment @@ -0,0 +1,2 @@ +CONFIG_USB=y +CONFIG_USB_EHCI_HCD=y