RespiraWorks / Ventilator

Fully-featured ICU ventilator design, optimized for manufacture using commonly available components and free to license. Repository tracks all mechanical, electrical and systems design, software, requirements and regulatory documentation.
Apache License 2.0
130 stars 37 forks source link

On-device unit tests #472

Open jlebar opened 4 years ago

jlebar commented 4 years ago

Currently we can only run unit tests on host (i.e. your laptop). In pio test run -e native, "native" means, the machine which compiled the code.

We need the capability to run unit tests on the device as well.

Ideally we'd be able to run most or all of our unit tests on the device. But as a start, it would be helpful to have the capability of running some unit tests on device.

For example, we ought to have a unit test that checks that our clock only ever counts up. Obviously this test is only useful it it can run on the device itself. But because we can't run unit tests on device, I had to do it manually in https://github.com/RespiraWorks/VentilatorSoftware/pull/465#discussion_r437212802. We therefore have no regression check for this.

Some things this bug is not about

Code pointers

If you try to run tests on device (pio test -e stm32), you get a helpful error message

Error: Unknown Unit Test transport `None`. Please check a documentation how to create an own 'Test Transport':
- https://docs.platformio.org/page/plus/unit-testing.html

I think we need to write a test transport that uses the HAL debug serial API, defined in hal.h and debug.h. Seems somewhat straightforward.

The test itself unfortunately cannot be written using gunit, because there's no way (afaict) to redirect gunit's stdout to our custom test transport. The Unity framework should work.

(There was a period of time during which I thought we were going to need gmock, so I converted our tests to gunit. Turns out we don't need gmock, so it would be OK to slowly back.)

martukas commented 4 years ago

Sounds good. We definitely need this as well. If we had something like this, we could definitely add it to CI and already make use of the networked pizzas for this. We have a Jenkins server up and running already.

martukas commented 4 years ago

Tulasi is getting in touch with ST to see if they can provide help with this.

asmodai27 commented 3 years ago

There appears to be way to make this work for stm32: https://docs.platformio.org/en/latest/tutorials/ststm32/stm32cube_debugging_unit_testing.html#writing-unit-tests