UT test framework support
When we create unit test, we'd like to build them as native executables and run them in a Linux box/win box other than on the target board.
Current Sphere SDK header file folder is a mix of system header and app headers(applibs, azureiot etc), which makes it very difficult to build with native tool chain.
For example. I try to unit test a sphere module, myuart.c which use UARTopen and Log_Debug. Then the include will look like below
To build it, I need to add Sphere SDK folder to include path, so it can find uart.h and log.h.
gcc my_uart.c -I <Sphere SDK INC>
Since native toolschain system header will be include by default and we are include another set of system header. Having two set of system header in include path cause conflict. (e.g. stdio.h in SDK folder will be used, but we want to native one)
This will cause some weird issue, like smash stack, segment fault etc.
It will be much easier if you can separate Sphere app heads and Sphere system header. So we can do this
gcc my_uart.c -I <Sphere App Inc>
We notice that Azure IoT and Azure Shared Utility is using umock-c as the mock tools, but umock-c require all the function need to be mocked be declared with MOCKABLE_FUNCTION macro which Sphere SDK doesn't. This prevent us from using it.
I end up using Unity and cmock for the unit test and some hack to workaround the two set system header issues.
António Sérgio Azevedo commented
I noticed that this feedback entry was posted before the following CMake sample: https://github.com/Azure/azure-sphere-samples/tree/master/Samples/CMakeSample
Can it help answering some of your questions?
Daniel Schwartz commented
Playing around, I see that I can wrap the Azure Sphere API in C++ classes that are build on abstract interfaces. That allows me to inject mock APIs in my code and make it testable.
I remain unsure about the test runner and test framework to use. Azure Sphere is ARM code, so I can't run the tests on my windows box. And I believe the Azure Sphere SDK won't allow for running tests on target, either. So do I run them on a Raspberry Pi remotely? Do I add a x86 build configuration and run them in Linux on Win 10? Insights would be appreciated - Thanks!
Daniel Schwartz commented
Hello Azure Sphere Team, do you have guidance on how to go about unit testing with Azure Sphere? It would be very nice to be able to write c++ code and thus have interfaces and injection of dependencies and mocks based on abstractions. Is C++ on the road map?
Thank you for the feedback. This request is on our backlog. We will provide updates as we make progress on this feature.