Skip to content
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

Allow the combination of use_test_preprocessor and CMock's treat_inlines #421

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

M-Bab
Copy link

@M-Bab M-Bab commented Jan 12, 2023

I expect this combination to be pretty common especially in embedded unit testing. Often the preprocessor is needed because the vendor headers alone are too complex and tricky to be parsed correctly without preprocessing (NXP, STM, ...). Not to mention the own developed header files.

On the other hand you want to mock the evil inline functions that try to directly manipulate non existing registers. Even if you fake-map the registers into the host runner RAM you still have no control if the inline function was called or not. You gain a more fine grained control over your tests if the inline functions are mocked.

Unfortunately the combination of preprocessor and treat_inlines creates a copy of the original header in the include path which is stripped of all macros (=preprocessed). When the following GCC build of unit test itself is in anyway dependent on these macros the build will fail. This MR allows the specific mechanism of removing the static/inline keywords for the header copy to operate on the original file instead of the preprocessed file. While other operations of CMock run on the preprocessed file so there is no change in behaviour there.

I am not particular happy about this pull request concerning the code quality itself. It was my first touch with ruby/rake ever and I am just glad I achieved the level "works for us". Probably the tests need to be fixed. Probably there is a better or complete different way to resolve this. I just wanted to provide this to give an idea how it works. But I am also ready and willing to improve it, if you have some suggestions.

For more information compare the issue ThrowTheSwitch/Ceedling#706

This PR is dependent on this PR: ThrowTheSwitch/Ceedling#728

…e CMock parse function.

This allows the treat_inlines to operate on the original header instead of the preprocessed
header which is crucial to get a correct copy of the original header (with the keywords static/inline stripped).

This needs the appropriate ceedling version to work. CMock called directly will continue
to work since an illegal path is provided (""). No error is triggered, if the treat_inlines feature is deactivated.
Copy link
Member

@mvandervoord mvandervoord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you retarget this PR to the branch cmock_2_6_rc instead? This is a good starting point. I'll need to backfill some tests and tweak some details. :)

else
''
end
if @treat_inlines == :include
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "Ruby Way" of doing this same thing would be to have a single line which is like raise "Blah" if orig_file.nil? In this case, however, I think if an original file isn't provided, there's no reason it shouldn't just go with the specified source instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants