This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

[UNIT TEST] Unity / CMock - cmock_handle()/native_posix still returns errors

Hello,

I've been working with unit tests lately, and got the example unity project to run (from here). Now I encounter some issues when integrating it into another Zephyr application (currently the blinky example to understand the procedure). As mentioned in the guide, cmock_handle() can be called in CMakeLists.txt to mock zephyr include headers. For instance, the blinky example consists of main.c which includes <zephyr.h>, <device.h>, <devicetree.h> and <drivers/gpio.h>. From my understanding, it is possible to run unit tests on the functions inside main.c when these include headers have been mocked, i.e., 

Fullscreen
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

However, running the project with native_posix still gives undefined devicetree macros, redefinitions and unknown config variables (CONFIG_GPIO=y and necessary modules are enabled). The mocked header files are included in the test files, where the working unity test example has been used as a base. Initially, CppUTest was used, but as it seemed more work to create the mocks and stubs, Unity / CMock has been used instead. When including CONFIG_GPIO=y, building the project yields an error saying (which may come from native posix board?):

Fullscreen
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Maybe it depends on the use case? Because the blinky example calls the "device_get_binding()" function and sets a certain pin, which is highly hardware related....

Have I misinterpreted the way of doing this?

Thanks in advance,

EivindTH