USB endurance testing

From RidgeRun Developer Wiki


Plug unplug USB endurance testing

Ever need to track down a software error that can only be reproduced by plugging in a USB cable, waiting, unplugging the cable, waiting some more, then repeating the plug / unplug hundreds of times? Here is a trick I use to automate the testing.

The trick is "cut" the 5v signal to the USB device to cause the host computer to detect an unplug event, and then let the 5v signal go to the device to cause the host computer to detect a plug event. This works because the USB spec (section 7.1.5) says:

  • Full-speed and low-speed devices are differentiated by the position of the pull-up resistor... Full-speed devices are terminated ... with the pull-up resistor on the D+ line.

This means if the 5v is cut, the pull up resistor no long causes D+ line to go high, so the host computer detects the device was unplugged.

Test hardware

USB breakout extension cable
USB breakout extension cable

First I start by making what I call a USB breakout extension cable. By extension cable I mean it has a male type A connector on one end and a female type A connector on the other end. Here is an example USB extension cable:

To make it a breakout cable, I cut the cable in half, and put a small protoboard with inline pins allowing access to the signals. I used a 5 pins with a jumper being installed to connect the 5v line together. I can remove the 5v jumper and put in a current meter if I like. For endurance testing, I connect those two pins to a relay. The other 3 signals (GND, D+ and D-) are just wired straight though with each signal also going to the header.

Here is an example breakout cable that uses switches instead of pins:

Next I got a relay with 100v coil that was easy to hook up. I used one I found online in 60 seconds of searching, with hundreds of other options being available.

I simply connect the relay closure switch to the 5v wires in the USB breakout extension cable. This way, when the relay is activated, the 5v is turned on, which is the same as plugging in a USB device.

Now you need a way for a computer to turn on and off a 110v outlet. My favorite is X10. I use the following:

I plug the USB PC transceiver in my development workstation, the wireless transceiver module in a convenient outlet near my computer, and if the unit-under-test is not near the transceiver module, then I use the appliance module to drive the relay. Otherwise, I just plug the relay into the wireless transceiver module.

If you have a lower cost approach, please let me know (inquiries@ridgerun.com).

Test software

I use the CM19aDriver.py module by Andrew Cuddon. I like Andrew's approach as it doesn't require a special kernel driver.

I have the pppliance module code set to E 3, so my endurance test consists of:

while sleep 10 ; do sudo python CM19aDriver.py E 3 ON ; sleep 15 ; sudo python CM19aDriver.py E 3 OFF ; done

This will wait 10 seconds, close the relay causing the computer to recognize the USB device has been plugged in. Then it waits for 15 seconds to let the computer interact with the device, followed by turning off the release which effectively causes the computer to detect the device has been unplugged.