-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Cmock functions are generated incorectlly in some cases #467
Comments
Its not a bug, its bad coding from your side. Rather then using ifdef-else clause use define for Secondly, you are mixing inline implementation of the functions with declaration. I would propose that you split declarations (in |
Maybe you are rigth, but the sample has been built on basic the zephyr spi.h file for
We can't change the zephyr source code. |
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: