Tuesday, June 28, 2016

Linux USB Gadget Application Testing

Developing a USB gadget application that runs on Linux?
Following a recent Ceph USB gateway project, I was looking at ways to test a Linux USB device without the need to fiddle with cables, or deal with slow embedded board boot times.

Ideally USB gadget testing could be performed by running the USB device code within a virtual machine, and attaching the VM's virtual USB device port to an emulated USB host controller on the hypervisor system.


I was unfortunately unable to find support for virtual USB device ports in QEMU, so I abandoned the above architecture, and discovered dummy_hcd.ko instead.


The dummy_hcd Linux kernel module is an excellent utility for USB device testing from within a standalone system or VM.



dummy_hcd.ko offers the following features:
  • Re-route USB device traffic back to the local system
    • Effectively providing device loopback functionality
  • USB high-speed and super-speed connection simulation
It can be enabled via the USB_DUMMY_HCD kernel config parameter. Once the module is loaded, no further configuration is required.

1 comment:

  1. Nice approach...I spent yesterday figuring this all out for myself only to stumble upon your post today! It is worth amplifying that dummy_hcd is both a combined USB Host Driver and USB Device Driver, so technically those two boxes in your diagram should really sit inside dummy_hcd.

    It also works with the testusb application and usbtest kernel driver (assuming you load g_zero gadget) so you can also easily create a test framework for USB.

    ReplyDelete

Comments are moderated due to spammer abuse.