-
Notifications
You must be signed in to change notification settings - Fork 250
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
Issue with mocking header inline functions and defines #868
Comments
Are you in a position to try the preview release candidate? (You'd need to download the gem from releases and then install it using The second version of the problem above is caused by having the mocked version of the function AND the original version of the function both existing when we attempt to link. The release candidate solves this by cloning the header file and removing the inline version so that it can be linked properly during tests. |
I am currently using a snapshot 0.32.0-164e950. Do you have any advised snapshot to get or just the latest one? I might try this over the weekend if I don't have time in the meantime. |
Ah. If you're already using a release candidate, that suggests that we likely still have a problem in this area. I'll add this to our priority list! Thanks! |
let me know if you need details to replicate the issue or for me to try anything. thank you |
Hello, I've tried this with snapshot 0.32.0-9b8d8a9. I created a new project and attempted to mock one of the LL headers from ST. I wanted to add my project.yml to the post but it unformats everything. I get an issue with the include:
Other than that I can see looking at the mock files that it does create the function prototypes and the typedefs. But it doesn't include the defines. |
@LuisAfonso95 If you are able please do provide your configuration. You can use the code block feature of the Github comment editor to preserve the formatting. Or, you can use Markdown formatting directly by surrounding your configuration file text with |
Hello, This is what I tried in this last one:
|
You have include path error, because I assume you would like to run this on x86_64 architecture, but CMSIS from ARM has few guards against compiling for wrong architecture. So after you fix your include, you will also have to create mock for the chip (replace hardcoded addresses as variables):
volatile USART_TypeDef usart0_base; /* Create global variable instead of the fixed base address */
#define USART0_BASE (&usart0_base) /**< USART0 base address */
volatile USART_TypeDef usart1_base; /* Create global variable instead of the fixed base address */
#define USART1_BASE (&usart1_base) /**< USART1 base address */ |
The issue only occurs in the mock with that specific snapshot. The path seems to be correct. I do have mock registers, this one was just a quick test of the new snapshot to see if it could mock the header inline functions. |
I believe pull request #728 seems like it does exactly what I need. Might try to pull and build it to see if it works. |
Yeah that sounds very familiar. Have you been successful with my modified version of Ceedling @lafonso-gnrc ? I think the fastest way to get it installed is the following:
|
This bug was fixed as of a prerelease of Ceedling 1.0.0 from two or three weeks ago. CMock's |
Hello, I have tried this with pre-release 1.0.0-95edb5b. I have I have defines from ST's LL like the following that don-t appear in the generated header.
|
@lafonso-gnrc They will always be removed in the copied header. The question is: Does it work though or does it not work? And if it doesn't work is it due to missing defines? And did you ever tried my fix with the above description? #868 (comment) - even if it is only as a cross-check? |
@M-Bab oh it's a fully separate branch, not a pre-release. I got to try that at some point. Just been very busy, completely lost that detail. To answer your question, it doesn't work at all because those defines are necessary for the test and code to compile |
@lafonso-gnrc Let me first explain how Preprocessing a mockable header simply means running it through the GCC preprocessor to expand all macros and conditional preprocessor statements to arrive at nothing but C code. From this, CMock can then extract the function signatures and types it needs. In the case of handling So, in a complicated project it goes like this: In previous versions of Ceedling and CMock various complexities and bugs were preventing the intended behavior above from working properly. This has been fixed. Generally speaking, it's just practically impossible to preserve an arbitrary set of macros through preprocessing. If you have hidden function signatures in header files, you gotta reveal them with preprocessing. Similarly, if you have conditionals around (not in) your test cases, you need preprocessing as well. I think what is happening is that your Macros can get quite complicated particularly when it comes to providing access to bit flags, memory mapped registers, etc. I suspect that's where your need is here, but, of course, I can't say. I gather you need them in your test cases, but, again, I'm guessing. I may be oversimplifying the problem / misunderstanding with this suggestion, but an approach that might work is this:
If you do have complex test files with We just recently expanded and clarified the documentation on Ceedling's preprocessing features. I'd suggest looking in CeedlingPacket to digest this. If I'm not understanding your problem please come on back here with more details. I can't guarantee it, but with a little effort your problem may be solvable. |
We also had a chance to test it and can unfortunately confirm it is not working as expected. Your explanation above @mkarlesky also shows you chose intentionally the opposite approach of my pull request. Your argument in the combined usage of treat_inlines and use_preprocessor:
My approach was:
I know see what you aimed for but I am still confused because CMock has already a very flexible configuration to help it find all the inline keywords: We actually had to extend this parameter well to grep all the inline functions:
But in the end it worked very well and without any hacks or helper headers for the whole Microcontroller HALs. |
It also feels like the new configuration feature |
Hello,
I'm trying to unit test a piece of software that will use some embedded libraries for a microcontroller.
Said libraries have quite a few inline functions in the header.
I tried using the CMock option
:treat_inlines: :include
and I do haveuse_test_preprocessor: TRUE
. This does not work because all the defines get erased.With
use_test_preprocessor: FALSE
the problem I have is that I get the following errors:Any advice on how to proceed? Am I missing some option?
The text was updated successfully, but these errors were encountered: