libopencm3/tests/gadget-zero/README.md

1.9 KiB

This project, inspired by usbtest and the linux usb gadget zero driver is used for regression testing changes to the libopencm3 usb stack.

The firmware itself is meant to be portable to any supported hardware, and then identical unit test code is run against all platforms. This project can and should be built for multiple devices.

Requirements:

  • pyusb for running the tests.
  • openocd >= 0.9 for automated flashing of specific boards
  • python3 for running the tests at the command line.

Example using virtual environments

pyvenv .env  # ensures a python3 virtual env
. .env/bin/activate
pip install pyusb

You will need to modify the openocd config files, as they contain specific serial numbers of programming hardware. You should set these up for the set of available boards at your disposal.

Tests marked as @unittest.skip are either for functionality that is known to be broken, and are awaiting code fixes, or are long running performance tests

Running the tests

Below is an example of running the full suite of tests from the command line. The argument specifies the serial number to look for in the usb gadget, if you have more than one. No argument will the tests against all gadget-zero's found.

$ python test_gadget0.py
Running tests for DUT:  stm32f072disco
.........ss................
----------------------------------------------------------------------
Ran 27 tests in 0.388s

OK (skipped=2)

You can also run individual tests, or individual sets of tests, see the unittest documentation for more information.

Many development environments, such as PyCharm can also be used to edit and run the tests, in whole or individually, with a nice visual test runner.