diff mbox series

[1/1] support/testing: add usbutils runtime test

Message ID 20240124222523.16703-1-ju.o@free.fr
State Accepted
Headers show
Series [1/1] support/testing: add usbutils runtime test | expand

Commit Message

Julien Olivain Jan. 24, 2024, 10:25 p.m. UTC
Signed-off-by: Julien Olivain <ju.o@free.fr>
---
Patch tested on branch master at commit 7a59c3a with commands:

    make check-package
    ...
    0 warnings generated

    support/testing/run-tests \
        -d dl -o output_folder \
        tests.package.test_usbutils
    ...
    OK
---
 DEVELOPERS                                    |  2 +
 .../testing/tests/package/test_usbutils.py    | 60 +++++++++++++++++++
 .../test_usbutils/linux-usbutils.fragment     |  2 +
 3 files changed, 64 insertions(+)
 create mode 100644 support/testing/tests/package/test_usbutils.py
 create mode 100644 support/testing/tests/package/test_usbutils/linux-usbutils.fragment

Comments

Peter Korsgaard Feb. 5, 2024, 10:19 p.m. UTC | #1
>>>>> "Julien" == Julien Olivain <ju.o@free.fr> writes:

 > Signed-off-by: Julien Olivain <ju.o@free.fr>
 > ---
 > Patch tested on branch master at commit 7a59c3a with commands:

 >     make check-package
 >     ...
 >     0 warnings generated

 >     support/testing/run-tests \
 >         -d dl -o output_folder \
 >         tests.package.test_usbutils
 >     ...
 >     OK
 > ---
 >  DEVELOPERS                                    |  2 +
 >  .../testing/tests/package/test_usbutils.py    | 60 +++++++++++++++++++
 >  .../test_usbutils/linux-usbutils.fragment     |  2 +
 >  3 files changed, 64 insertions(+)
 >  create mode 100644 support/testing/tests/package/test_usbutils.py
 >  create mode 100644 support/testing/tests/package/test_usbutils/linux-usbutils.fragment

 > diff --git a/DEVELOPERS b/DEVELOPERS
 > index f5b04937b6..5a5ce47d73 100644
 > --- a/DEVELOPERS
 > +++ b/DEVELOPERS
 > @@ -1814,6 +1814,8 @@ F:	support/testing/tests/package/test_screen.py
 >  F:	support/testing/tests/package/test_stress_ng.py
 >  F:	support/testing/tests/package/test_tcl.py
 >  F:	support/testing/tests/package/test_tcl/
 > +F:	support/testing/tests/package/test_usbutils.py
 > +F:	support/testing/tests/package/test_usbutils/
 >  F:	support/testing/tests/package/test_weston.py
 >  F:	support/testing/tests/package/test_weston/
 >  F:	support/testing/tests/package/test_xz.py
 > diff --git a/support/testing/tests/package/test_usbutils.py b/support/testing/tests/package/test_usbutils.py
 > new file mode 100644
 > index 0000000000..9a5484d5e6
 > --- /dev/null
 > +++ b/support/testing/tests/package/test_usbutils.py
 > @@ -0,0 +1,60 @@
 > +import os
 > +
 > +import infra.basetest
 > +
 > +
 > +class TestUsbUtils(infra.basetest.BRTest):
 > +    # A specific configuration is needed for testing usbutils, to
 > +    # enable USB 2.0 support in the Kernel.
 > +    linux_fragment = \
 > +        infra.filepath("tests/package/test_usbutils/linux-usbutils.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_EUDEV=y
 > +        BR2_PACKAGE_USBUTILS=y
 > +        BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_EUDEV=y
 > +        BR2_TARGET_ROOTFS_CPIO=y
 > +        BR2_TARGET_ROOTFS_CPIO_GZIP=y
 > +        # BR2_TARGET_ROOTFS_TAR is not set
 > +        """
 > +
 > +    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 and mouse devices 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",
 > +                                    "-device", "usb-mouse,bus=ehci.0"])
 > +        self.emulator.login()
 > +
 > +        # Check the program can execute. We also check the version
 > +        # string to make sure we have the usbutils version. The
 > +        # BusyBox lsusb ignores arguments.
 > +        output, exit_code = self.emulator.run("lsusb --version")
 > +        self.assertEqual(exit_code, 0)
 > +        self.assertTrue(output[0].startswith("lsusb (usbutils)"))
 > +
 > +        # Test few simple and common invocations
 > +        self.assertRunOk("lsusb")
 > +        self.assertRunOk("lsusb --tree")
 > +        self.assertRunOk("lsusb --verbose")
 > +        # 1d6b:0002 is Linux Foundation 2.0 root hub
 > +        # it should be present. lsusb return an error if no device
 > +        # is found.
 > +        self.assertRunOk("lsusb -d 1d6b:0002")
 > +        self.assertRunOk("usbhid-dump")

It was not directly obvious why this would not fail until I noticed that
you configure qemu to emulate a USB keyboard and a mouse, so I added a
comment about this and applied - Thanks.
diff mbox series

Patch

diff --git a/DEVELOPERS b/DEVELOPERS
index f5b04937b6..5a5ce47d73 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1814,6 +1814,8 @@  F:	support/testing/tests/package/test_screen.py
 F:	support/testing/tests/package/test_stress_ng.py
 F:	support/testing/tests/package/test_tcl.py
 F:	support/testing/tests/package/test_tcl/
+F:	support/testing/tests/package/test_usbutils.py
+F:	support/testing/tests/package/test_usbutils/
 F:	support/testing/tests/package/test_weston.py
 F:	support/testing/tests/package/test_weston/
 F:	support/testing/tests/package/test_xz.py
diff --git a/support/testing/tests/package/test_usbutils.py b/support/testing/tests/package/test_usbutils.py
new file mode 100644
index 0000000000..9a5484d5e6
--- /dev/null
+++ b/support/testing/tests/package/test_usbutils.py
@@ -0,0 +1,60 @@ 
+import os
+
+import infra.basetest
+
+
+class TestUsbUtils(infra.basetest.BRTest):
+    # A specific configuration is needed for testing usbutils, to
+    # enable USB 2.0 support in the Kernel.
+    linux_fragment = \
+        infra.filepath("tests/package/test_usbutils/linux-usbutils.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_EUDEV=y
+        BR2_PACKAGE_USBUTILS=y
+        BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_EUDEV=y
+        BR2_TARGET_ROOTFS_CPIO=y
+        BR2_TARGET_ROOTFS_CPIO_GZIP=y
+        # BR2_TARGET_ROOTFS_TAR is not set
+        """
+
+    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 and mouse devices 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",
+                                    "-device", "usb-mouse,bus=ehci.0"])
+        self.emulator.login()
+
+        # Check the program can execute. We also check the version
+        # string to make sure we have the usbutils version. The
+        # BusyBox lsusb ignores arguments.
+        output, exit_code = self.emulator.run("lsusb --version")
+        self.assertEqual(exit_code, 0)
+        self.assertTrue(output[0].startswith("lsusb (usbutils)"))
+
+        # Test few simple and common invocations
+        self.assertRunOk("lsusb")
+        self.assertRunOk("lsusb --tree")
+        self.assertRunOk("lsusb --verbose")
+        # 1d6b:0002 is Linux Foundation 2.0 root hub
+        # it should be present. lsusb return an error if no device
+        # is found.
+        self.assertRunOk("lsusb -d 1d6b:0002")
+        self.assertRunOk("usbhid-dump")
diff --git a/support/testing/tests/package/test_usbutils/linux-usbutils.fragment b/support/testing/tests/package/test_usbutils/linux-usbutils.fragment
new file mode 100644
index 0000000000..d9abd2821e
--- /dev/null
+++ b/support/testing/tests/package/test_usbutils/linux-usbutils.fragment
@@ -0,0 +1,2 @@ 
+CONFIG_USB=y
+CONFIG_USB_EHCI_HCD=y