This directory contains the test code and other requirements in order to run the hardware integration tests for the Timely Reference.

The Docker image uses SEGGER's JLink software tools, and requires accepting their [license](https://www.segger.com/downloads/jlink/JLink_Linux_x86_64.deb). This may be swapped out for [OpenOCD](https://sourceforge.net/p/openocd/code/ci/master/tree/) in the future.

Of course, the tools can also be installed directly into the host- Docker provides a (more) consistent runtime environment and forces documentation of setup steps.

### Hardware Requirements

Current:

- STMicroelectronics [Nucleo-L412-RB-P](https://www.st.com/en/evaluation-tools/nucleo-l412rb-p.html)
- SEGGER [J-Link](https://www.segger.com/products/debug-probes/j-link/) (Any model should do)
- FTDI [FT232R USB-Serial Breakout](https://www.ftdichip.com/Products/ICs/FT232R.htm). Tested with [this one from Amazon](https://www.amazon.com/gp/product/B075N82CDL)
- Sigrok-supported [FX2 logic analyzer](https://sigrok.org/wiki/Fx2lafw#Cypress_FX2_vs._FX2LP). Tested with [Lcsoft Mini Board](https://sigrok.org/wiki/Lcsoft_Mini_Board) and another no-name board. Other Sigrok-supported could be supported easily.

The current hardware detection mechanisms may fail if more than one these devices is connected.

### Execution

First, build the docker image. Depending on your execution environment, you may need to escalate privileges in order to run `docker`.

```
cd <project-root>
docker build -t tr-test test/
```

Then, execute the tests. The tests require access to the USB hardware components, so their files need to be volume-mounted in, and the container must be given privilege in order to access the devices.

```
docker run --privileged -it -v /dev/bus/usb:/dev/bus/usb -v $(pwd):/build-dir tr-test /build-dir/test/src/tr_test/test.py
```

The tests also accept other arguments accepted by [pytest](https://docs.pytest.org/en/latest/usage.html).
