L'Hexapod: Unit testing AVR assembly language

Previously published

This article was previously published on lhexapod.com as part of my journey of discovery into robotics and embedded assembly programming. A full index of these articles can be found here.

Way back at the beginning of this journey I mentioned the fact that I’d quite like to be able to use some of the development disciplines that I use in my day job during the development of the firmware for my hexapod. Now that I’ve actually written some non trivial assembly language for the AVR I find that I’m missing not having my usual unit tests to support my ongoing development and refactoring. This has been most noticeable just recently during the integration of the most complicated serial command of the new servo controller; the multiple move command.

I’m currently working on separating out the code that processes serial command messages from the code underlying support code. The idea being that I can then build the serial command processing code into a new AVR Studio project and ‘mock’ out the support code so that I can test the serial processing code. Once that’s done I should be able to write a suite of tests that can be run on the serial code to make sure that the commands do what they’re supposed to do. I’m lucky that the serial command code generally either calls other functions (which I can mock out by creating a testing version of the function and including the source for that rather than the source for the real function) or modifies data (which I can examine as part of the test to ensure that it has been modified in the correct way).

So far it’s going quite well. More once I have it working well enough to document and even more once I then use these new tests to fish out the bugs in the multiple move command!