-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add Unity and CMock to NCS #519
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
Conversation
|
All checks are passing now. Review history of this comment for details about previous failed status. |
cd397ef to
fd404e3
Compare
|
@nordic-krch fantastic! Are there any requirements in terms of tooling for this, e.g. Ruby, Python modules? |
|
@lemrey, right. Ruby is of course required. In python no additional lib is needed. |
|
@SebastianBoe @tejlmand could you take a look as this is mainly cmake stuff and i'm newbie there. |
|
regex parsing of C? :( I'm concerned that we won't be able to regex parse the full language of CPP+CC, and that what we have here is just able to parse a subset of the language. What happens when the parsing fails, can we create mocks manually for the cases that are not covered? Sorry if this question doesn't make sense, I'm not familiar with mocking frameworks. |
scripts/unity/func_name_list.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you just need the func_names? Not the full prototype?
If so, maybe it would be possible to compile the header and then take the func names from the symbol table.
Then we don't need to regex parse unpreprocessed C code.
scripts/unity/func_name_list.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is not guaranteed to be closed, use 'with' instead of manually invoking close().
|
@SebastianBoe it is parsing header files mainly in search for function declarations and static inline functions. We need to handle following:
So in regexp we do not go beyond function declarations and we are focused on C since Cmock/Unity is C unit test framework. |
scripts/unity/header_prepare.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print() is best-practice
Sorry, by CPP, I meant C preprocessor. |
8ab1436 to
d4b088f
Compare
|
@SebastianBoe i've applied your comments. Regarding compiling header file: I'm not sure how to do that but imo, it can be later on improved if we find issues with using python to parse the header.
In case regexp is missing something and we find case which fails we need to improve regexp. |
What if it's impossible? e.g. if the prototype is constructed by the preprocessor? |
|
@SebastianBoe, worst case function won't be mocked. Header processed by python next goes to cmock ruby script which processes it in search for function prototypes. It will create mocks only for found prototypes. Python script can only improve. |
|
Okay, conceptually this makes sense then. I can review the CMake code when the PR is in PR-form and no longer an RFC. |
|
i've put RFC since there were some open items mentioned in the PR but i see no opinions so far and those open items can be fixed later (like changing west to use unity fork instead original) so removing RFC. |
I'd postpone this until necessary. |
SebastianBoe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass of review done, was not able to get through all of it today.
8046051 to
ca2b63d
Compare
6de177d to
0f52678
Compare
|
@ru-fu please not that i've just updated documentation and removed last paragraph. |
tejlmand
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found a minor thing in python scripts.
Zephyr is supporting python >= 3.4
ru-fu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a commit with doc update. Please check and squash if okay.
e7deb12 to
5388a26
Compare
|
@ru-fu thanks for review and changes. They look ok, i've squashed your commit. |
d7fcdd9 to
175a1bd
Compare
|
@tejlmand follow-up issue created. |
tejlmand
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good :)
|
@carlescufi i think we can merge it. Cmake experts are done, as well as the documentation. |
|
@nordic-krch very well, can you rebase on top of master? |
|
@carlescufi rebased. |
|
@nordic-krch still shows conflicted, probably someone has merged stuff in the meantime. |
Actions performed to add unity/cmock to ncs: - Add cmock (unity as submodule) repository to west list of projects - Add CMakeLists.txt file in nrf/tests/unity - Add Unity Kconfig file to nrf/tests/unity Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commis adds tests/unity/unity_test.cmake file which includes standard zephyr boilerplate and on top of that adds functions for creating mocks and test runner. Additionally, two helper python scrips are added. Scripts helps to handle: mocking static inline functions, mocking using --wrap linker feature, skipping syscalls used in zephyr API's. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Converted NRF_DIR to cache variable, in order to allow access to it from any location. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Created unity library which contains functions for cmock and runner generation. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Example shows how to: - mock a module (see CMakeLists.txt) - generate mock and test runner (see CMakeLists.txt) - use mock in the test (example_test.c) - override IS_ENABLED macro to runtime test compile time features (preincluded example_test.h) Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Added user guide which explains how to create and run unit test using Unity and CMock. Signed-off-by: Ruth Fuchss <ruth.fuchss@nordicsemi.no> Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
|
@carlescufi can you merge now? |
| @@ -0,0 +1,17 @@ | |||
| # Kconfig - Config options for logger sample app | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: the comment is a bit off.
This PR contains 3 commits:
Open items:
Please note that this is my first PR to NCS. Let me know if i did something wrong.
Please note that i'm total newbie to cmake so be patient in case of rookie mistakes.