You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If GPIO_BLA_BLA is defined then gpio_test function should be used in the source code.
If GPIO_BLA_BLA is NOT defined then gpio_test function should NOT be used in the source code.
The cmock functions are generated for all types in the header file regardless of macros. If we run unit test for modules which uses gpio driver, then cmock function is generated for gpio_test function even if GPIO_BLA_BLA is not defined.
Let's try to build it. Since GPIO_BLA_BLA is not defined then compiler replace the gpio_test string to the empty place (please see gpio.h file), as result we will get the following error:
If we comment out the "#define gpio_test" line in the gpio.h file than it is working.
Rather then using ifdef-else clause use define for WEAK and then once its defined __attribute (( weak ))__ and other time as weak or in unit test case as empty. You will have to add some strippables in this case (you could do it in yourcase as well).
Secondly, you are mixing inline implementation of the functions with declaration. I would propose that you split declarations (in gpio.h) and then put gpio_inline_impl.h for implementation/definition. Then you can conditionally include gpio_inline_impl.h with #ifndef TEST to enable the inline functions when not running in test mode and to get mocks.
If you're using Ceedling, you can enable preprocessing to preprocess your files before they get mocked. This solves most of these kinds of issues.
The root problem, that CMock doesn't fully parse C code with full preprocessing capabilities, etc, is a known issue and is one we mean to address. I apologize that it's still an issue after this long.
Sometimes developer use the macros to include/exclude the functions in the source code, like as:
gpio.h
If
GPIO_BLA_BLA
is defined thengpio_test
function should be used in the source code.If
GPIO_BLA_BLA
is NOT defined thengpio_test
function should NOT be used in the source code.The cmock functions are generated for all types in the header file regardless of macros. If we run unit test for modules which uses gpio driver, then cmock function is generated for
gpio_test
function even ifGPIO_BLA_BLA
is not defined.mock_gpio.h:
mock_gpio.c:
Let's try to build it. Since
GPIO_BLA_BLA
is not defined then compiler replace thegpio_test
string to the empty place (please see gpio.h file), as result we will get the following error:If we comment out the "#define gpio_test" line in the gpio.h file than it is working.
gpio.h
To fix it, CMock should add the GPIO_BLA_BLA to the mock_gpio.c: file, like as:
Or, CMock should not generate the cmock functions for
gpio_test
function ifGPIO_BLA_BLA
is not defined.All source files: src.zip
The text was updated successfully, but these errors were encountered: