test_usbutils.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import os
  2. import infra.basetest
  3. class TestUsbUtils(infra.basetest.BRTest):
  4. # A specific configuration is needed for testing usbutils, to
  5. # enable USB 2.0 support in the Kernel.
  6. linux_fragment = \
  7. infra.filepath("tests/package/test_usbutils/linux-usbutils.fragment")
  8. config = \
  9. f"""
  10. BR2_aarch64=y
  11. BR2_TOOLCHAIN_EXTERNAL=y
  12. BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
  13. BR2_LINUX_KERNEL=y
  14. BR2_LINUX_KERNEL_CUSTOM_VERSION=y
  15. BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.1.73"
  16. BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
  17. BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config"
  18. BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="{linux_fragment}"
  19. BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
  20. BR2_PACKAGE_EUDEV=y
  21. BR2_PACKAGE_USBUTILS=y
  22. BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_EUDEV=y
  23. BR2_TARGET_ROOTFS_CPIO=y
  24. BR2_TARGET_ROOTFS_CPIO_GZIP=y
  25. # BR2_TARGET_ROOTFS_TAR is not set
  26. """
  27. def test_run(self):
  28. img = os.path.join(self.builddir, "images", "rootfs.cpio.gz")
  29. kern = os.path.join(self.builddir, "images", "Image")
  30. # We add a USB keyboard and mouse devices for the test.
  31. self.emulator.boot(arch="aarch64",
  32. kernel=kern,
  33. kernel_cmdline=["console=ttyAMA0"],
  34. options=["-M", "virt", "-cpu", "cortex-a57", "-m", "256M",
  35. "-initrd", img,
  36. "-device", "usb-ehci,id=ehci",
  37. "-device", "usb-kbd,bus=ehci.0",
  38. "-device", "usb-mouse,bus=ehci.0"])
  39. self.emulator.login()
  40. # Check the program can execute. We also check the version
  41. # string to make sure we have the usbutils version. The
  42. # BusyBox lsusb ignores arguments.
  43. output, exit_code = self.emulator.run("lsusb --version")
  44. self.assertEqual(exit_code, 0)
  45. self.assertTrue(output[0].startswith("lsusb (usbutils)"))
  46. # Test few simple and common invocations
  47. self.assertRunOk("lsusb")
  48. self.assertRunOk("lsusb --tree")
  49. self.assertRunOk("lsusb --verbose")
  50. # 1d6b:0002 is Linux Foundation 2.0 root hub
  51. # it should be present. lsusb return an error if no device
  52. # is found.
  53. self.assertRunOk("lsusb -d 1d6b:0002")
  54. # we emulate a USB keyboard and mouse, so usbhid-dump should find them
  55. self.assertRunOk("usbhid-dump")