Browse Source

tests: gadget-zero: add xunit reporting

This is intended to help produce CI reporting on PRs and regression
testing.
pull/1251/head
Karl Palsson 4 years ago
parent
commit
0bb9d882cc
  1. 3
      tests/gadget-zero/README.md
  2. 54
      tests/gadget-zero/test_gadget0.py

3
tests/gadget-zero/README.md

@ -10,6 +10,7 @@ should be built for multiple devices.
* [pyusb](https://walac.github.io/pyusb/) for running the tests.
* [OpenOCD](http://openocd.org/) >= 0.9 for automated flashing of specific boards
* python3 for running the tests at the command line.
* unittest-xml-reporting, only if running in CI mode. XX
### Building the device firmware
There are Makefile.xxxxx files for all the currently tested targets.
@ -61,7 +62,7 @@ OK (skipped=2)
To be even more brutal, run this in a shell loop.
```
$ while true; do python test_gadget0.py stm32f072disco; done
$ while true; do python test_gadget0.py -d stm32f072disco; done
```
You can also run individual tests, or individual sets of tests, see the [unittest documentation](https://docs.python.org/3/library/unittest.html) for more information.

54
tests/gadget-zero/test_gadget0.py

@ -1,3 +1,14 @@
#!/usr/bin/env python3
"""
Tests for the libopencm3 USB stack. Uses pyusb to make a variety of transfers, both legal and illegal to
exercise as many paths of the stack as possible for consistency and functionality.
By default, will attempt to run the test suite against any detected compatible firmware, based on a fixed
VID:PID pair defined in the firmware. Can also be told to test just a single device
Requires pyusb. unittest-xml-reporting also required for xUnit reports
"""
import argparse
import array
import datetime
import random
@ -13,8 +24,9 @@ PRODUCT_ID=0xcafe
# you only need to worry about these if you are trying to explicitly test
# a single target. Normally, the test will autofind the attached target
DUT_SERIAL=None
#DUT_SERIAL = "stm32f429i-disco"
DUT_SERIAL = "stm32f4disco"
#DUT_SERIAL = "stm32f4disco"
#DUT_SERIAL = "stm32f103-generic"
#DUT_SERIAL = "stm32l1-generic"
#DUT_SERIAL = "stm32f072disco"
@ -494,15 +506,43 @@ class TestUnaligned(unittest.TestCase):
self.do_readwrite()
def run_ci_test(dut):
# Avoids the import for non-CI users!
import xmlrunner
print("Running tests for DUT: ", dut)
with open("TEST-%s.xml" % dut, 'wb') as output:
unittest.main(exit=False, testRunner=xmlrunner.XMLTestRunner(output=output))
def run_user_test(dut):
print("Running tests for DUT: ", dut)
unittest.main(exit=False, argv=[__file__])
def get_parser():
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-d", "--dut", help="Specify a particular DUT serial to test")
parser.add_argument("-X", "--xunit", help="Write xml 'junit' style outputs, intended for CI use", action="store_true")
parser.add_argument("-l", "--list", help="List all detected matching devices, but don't run any tests", action="store_true")
return parser
print("about to do... something? either main, or fall off")
if __name__ == "__main__":
if len(sys.argv) > 1:
DUT_SERIAL = sys.argv.pop()
print("Running tests for DUT: ", DUT_SERIAL)
unittest.main()
print("running our own main")
p = get_parser()
opts = p.parse_args()
runner = run_user_test
if opts.xunit:
runner = run_ci_test
if opts.dut:
runner(opts.dut)
else:
# scan for available and try them all!
devs = usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID, find_all=True)
for dev in devs:
DUT_SERIAL = dev.serial_number
print("Running tests for DUT: ", DUT_SERIAL)
unittest.main(exit=False)
if opts.list:
print("Detected %s on bus:port-address: %s:%s-%s" % (DUT_SERIAL, dev.bus, '.'.join(map(str,dev.port_numbers)), dev.address))
else:
runner(DUT_SERIAL)
print("fell off the end of the file")

Loading…
Cancel
Save