Wallacoloo / printipi

3d printing directly through the Raspberry Pi's GPIO pins
MIT License
141 stars 43 forks source link

Add a way to test IO in the automated testsuite #68

Closed Wallacoloo closed 9 years ago

Wallacoloo commented 9 years ago

Currently, when you do something complicated that should eventually lead to an IoPin write, it's very difficult to tell if it actually resulted in one. There are a few possible solutions to this:

Note: in general, there's not always a way to actually verify that a pin IS set, without configuring another input to be directly connected to it. This is because the pin can be set by a peripheral other than the CPU (e.g. DMA). On the Raspberry Pi though, the GPLEV register will read the value of an input OR an output.

Also, although it may only be possible to generically test IO propagation through to the point where the platform-specific HardwareScheduler takes hold of it, platform-specific testing could be employed to test that any OutputEvent reaching the HardwareScheduler is handled correctly. So, option 2 (the onOutputEventProcessed callback) is perhaps the best option.

Wallacoloo commented 9 years ago

In the spirit of unit testing, it may be best to NOT have something like a Servo verify that the IoPins are actually set. Rather, the servo verifies that it exposes the correct information to the State, and then the State verifies that it processes that information correctly and sends the right bits to the Scheduler, and so on (this isn't to say that IO doesn't need to be tested, just that it should only be tested by the relevant classes).