Join GitHub today
Add Support for local ("PC") unit tests #519
For CI and testing reasons I would really like to run unit tests. For performance reasons these should run on the local machine (PC), and not on the device (in contrast to #408).
I managed to hack together an
Adding multiple test files does NOT work, bc the compilation of 'program' lumps together every testfile in one executable and the linker fails with duplicate symbols.
If someone with SCons skills can help me, we could extend
Reviewing this, you seem to be wanting an x86-only test run situation. That seems fully feasible.
I do it with a distinct directory (test, alongside src) and custom makefiles that travis picks up, then use Catch.hpp unit test framework because it's light and easy with C++
I bet the same approach can work with pio+scons, however my scons skills are too nub-ish to make further recommendations
note: there is also a test.pio folder, but that is not automated testing and not relevant to our discussion, so ignore it
Is there any indication wether the testing configuration can handle using or emulating the same types as the target platform? Or is that just common, and independent of the target??
i.e. some variables I want to be uint8_t, and other uint32_t. Will the unit test compilation be able to ensure correctly sized integers/floats?
I can't resist to promote Simba in this thread since it has the host PC test execution functionality already in place. I'm not saying you should use Simba, but instead I'm giving an example of how I work developing for embedded devices.
When I started the development of Simba RTOS I compiled and tested everything on my Linux PC. After all, the big job was to set the interfaces, not to execute the binary on an embedded device. Executing the binary on my Linux PC gave the possibility to use Linux tools, for example gdb, gprof, code coverage, etc. Very useful indeed!
Even today I usually implement and test everything on my Linux PC. When I'm satisfied I cross-compile the code and upload the binary to the embedded deivce.
Of course, certain functionality requires the embedded device, but a surprisingly big part does not.
Here is an example of how to build and run for two boards, linux and arduino_due:
The output from the test suite today is rather big, but if you have a PC with lots of RAM you can open it here: https://travis-ci.org/eerimoq/simba
Code coverage (press "src" at the bottom of the page): https://codecov.io/gh/eerimoq/simba
Simba project page on GitHub: https://github.com/eerimoq/simba