cr / hx870

Python tools for the Standard Horizon HX870
GNU General Public License v3.0
21 stars 5 forks source link

Implement device simulator for testing #13

Open cr opened 5 years ago

cr commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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