hx870 icon indicating copy to clipboard operation
hx870 copied to clipboard

Implement device simulator for testing

Open cr opened this issue 5 years ago • 4 comments

The device protocol is sufficiently well-understood by now that we can write a protocol-level HX device emulator to run implementation tests against.

This should be a good weekend's day of work.

cr avatar Apr 11 '19 08:04 cr

The ultimate goal should be to mock low-level reads and writes in the serial module to enable full-stack testing of our code, but that would take some major figuring unless someone's experienced with mocking that module in particular already.

A more achievable first step for noobs like us would be to implement an hxtool.tty.GenericHXTTYSimulator shim as replacement for hxtool.tty.GenericHXTTY in tests.

We maaaay even be able to hot-patch hxtool.tty.GenericHXTTY functions in memory, but that requires some investigation and playfulness.

cr avatar Apr 11 '19 08:04 cr

The simulator should also be exposed as a hidden model that automatically shows up in the device enumeration if activated by a global --simulator argument, for example.

cr avatar Apr 11 '19 08:04 cr

Found a neat way to implement the simulator as a virtual pseudo device that Python's serial module can talk to in place of a regular serial device. Implemented a stub (see hxtool --simulator devices) and a test harness for it. So far the simulator will make hxtool throw ProtocolError on any config write attempt, but at least the current architecture is paving the way for a more complete implementation.

cr avatar Apr 11 '19 19:04 cr

The simulator, even in its current, incomplete state, already enables a number of module and integration tests.

cr avatar Apr 11 '19 19:04 cr