-
Notifications
You must be signed in to change notification settings - Fork 276
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
static inline functions result in incorrectly generated mocks #342
Comments
Potentially related to #313 and Ceedling/issues/541 |
@mvandervoord any chance you might be able to look at this? Thought upgrading to 2.5.2 (which has fix for #313) would fix, but seems it wasn't related. Let me know any other info I can provide to help. Right now I'm running
|
Is it possible you can send me the header file you are attempting to mock? (If you're not comfortable posting it here, you are welcome to send it to me directly). |
Whoops sorry it wasn't clearer in my original post. It's nrfx_rtc.h |
If you define 'SUPPRESS_STATIC_INLINE' the sdk will remove the definitions, however it still has the prototypes with static inline defined. |
@mvandervoord any more info I can provide to be helpful? |
@mvandervoord I've managed to replicate this issue on a completely different project with a completely different SDK. The treatment of static inlines functions seems to be completely broken. Do you have enough information to deal with this? |
You should use Also post a content of I still don't think this has anything to do with the static inline since mocks are created (look at file: mock_nrfx_rtc.c).That file that you pasted also has no direct memory access (quick glance), so maybe you are doing that in your test file or something that is not mocked? So problem with mocks could be if there is something strange in mock_nrfx_rtc.c. |
@Letme thats good info re: Re: the segfault, yes that is when I manually edited the autogenerated mocks to try and massage it into working...I wouldn't put too much credence in that |
the relative path issue is unfortunately at the core of the problem |
@Letme why do you think the relative path issues are a "good luck" type of thing? Isn't that part of the core functionality of how all of this should work, and it's broken? The handling of static inline functions right now is wrong. I'm trying to dig through the ruby code to figure out where and why, but I don't know ruby so am a bit lost. It looks like @laurensmiers wrote a lot of the code for the static inline functions...hopefully it isn't inappropriate to ping you on this. As an example with a completely different SDK (an NXP chip this time): given the following source layout:
and the following project include paths and inline configuration
Unit tests for I can't fix this by adding the root of my project to the include path, as the include string to the compiler invocation is too long and ceedling crashes. |
Here is a git repo containing a bare-minimum reproduction of the bug, with only three files and one test. https://github.com/bigbrett/cmock-bug-repro Clone the repo and run |
As an easy answer: The core of unit testing is to swap paths, so if you have I went a bit through your example and I see the issue where gcc
I also moved the test file around different subfolders and that makes no effect, so its purely something to do with preprocessor and adding includes. I think somehow that relative path is added to the file, while it is skipped for non-inline parser. Same as you, my Ruby knowledge is basically non-existent, so all you can do is wait... |
Hi @bigbrett, Thanks for the example. This explains why the adding of the root-directory to the include paths in your example works. The include in the original header expects the root of the project to be in the include-path, so the generated header just has the same assumptions/requirements. |
@laurensmiers thanks for responding!
Hmmm except that isn't quite true... the include in the original header is not a path relative from project root (e.g. it doesn't expect the root of the project to be in the include-path, as you claimed). That is why I think this is a bug. Unless I am misunderstanding you? The include in the original header is |
Oh damn, sorry completely missed that part.... Will read @Letme 's comment a bit more in detail cause the rabbit hole seems to be deeper than I thought. Some quick observations: cmock seems to receive the header with already a full relative path iso I know the testprocessor setting runs the test files and headers through the gcc preprocessor and hands these outputs to ceedling/cmock to be parsed (so cmock doesn't know about the original include here actually...), but I wouldn't expect him to change paths like this (but again, this may be due to my lack of knowledge) EDIT: |
@laurensmiers ok, so we figured that preprocessor is the problem for the inlines as it adds something too much I assume. Maybe a solution would be to check the output of the preprocessor to see if the other non-inline parser skips something. Because I know you are dealing with includes and maybe when |
interesting....so this could be a ceedling pre-processor bug? @laurensmiers Should I file an issue in the ceedling repo? Unfortunately, I'm not able to turn off |
Hi! |
Why would you still want relative paths even in the preprocessed header? Tests include |
I agree, I don't think relative paths should ever be a thing. Explicit includes in the original source files should not be changed, period, right? It should be up to the developer to setup the correct include paths in |
@Letme I think the linker has nothing to do with this. It is preprocessor job. |
If anybody interested I updated my branch. Now I'm trying to cheat compiler to use generated header with the highest priority by the |
@CezaryGapinski I'm interested! Let me know when you are ready and I can test |
@bigbrett Great! Please test as it is and we will see. I I don't have any more clever idea at this moment. I tested it on my more complex project and it works, but I'm curious if it help you. |
@CezaryGapinski I'm not able to get it to succeed on the test repo I provided. Very possible I'm doing something wrong though. Do I need to tweak the |
@bigbrett Please go to vendor folder in your project and remove ceedling folder. git clone --branch static-inline-headers --recursive https://github.com/CezaryGapinski/ceedling.git Next try to run Clobbering all generated files...
(For large projects, this task may take a long time to complete)
Test 'test_proto_flash.c'
-------------------------
Generating include list for fsl_flexspi.h...
Creating mock for fsl_flexspi...
Creating mock for fsl_flexspi...
Generating include list for proto_flash.c...
Generating runner for test_proto_flash.c...
Compiling test_proto_flash_runner.c...
Compiling test_proto_flash.c...
Compiling mock_fsl_flexspi.c...
Compiling unity.c...
Compiling proto_flash.c...
common/proto/proto_flash.c: In function ‘proto_flash_init’:
common/proto/proto_flash.c:5:20: warning: passing argument 1 of ‘FLEXSPI_SoftwareReset’ makes pointer from integer without a cast [-Wint-conversion]
5 | #define FLASH_ADDR (0xFEEDBEEF)
| ^~~~~~~~~~~~
| |
| unsigned int
common/proto/proto_flash.c:9:27: note: in expansion of macro ‘FLASH_ADDR’
9 | FLEXSPI_SoftwareReset(FLASH_ADDR);
| ^~~~~~~~~~
In file included from <command-line>:
./build/test/mocks/fsl_flexspi.h:9:35: note: expected ‘void *’ but argument is of type ‘unsigned int’
9 | void FLEXSPI_SoftwareReset(void * addr);
| ~~~~~~~^~~~
Compiling cmock.c...
Linking test_proto_flash.out...
Running test_proto_flash.out...
--------------------
OVERALL TEST SUMMARY
--------------------
TESTED: 1
PASSED: 1
FAILED: 0
IGNORED: 0 Of course there is a warning but I think you should change |
@bigbrett Did you ever solve your second issue? |
Please check if this is the problem described here: ThrowTheSwitch/Ceedling#706 (comment) |
When I try to mock driver functions from a file in the NRF5 SDK that contain
static inline
functions the generated mocks seem broken.For example, lets have a module in my app called
timekeeper.c
that depends upon nrfx_rtc.h (which should be mocked).The two errors I can see in the generated mocks are:
project.yml
. Therefore it results in the file not being able to be discovered?static inline
innrfx_rtc.h
by using:cmock: :treat_inlines: :include
inproject.yml
, the output atbuild/test/mocks/nrf_rtc.h
contains TWO different definitions for each original instance ofstatic inline
functions... one that isstatic inline
and one that is not...e.g.That is about as deep as I am able to trace things down. When I manually edit the generated files to have the correct include path, it chokes on the two different definitions. When I try and manually remove one of the definitions just to see what would happen, the test never executes
The text was updated successfully, but these errors were encountered: