smf: add compile check for ancestors.#102050
smf: add compile check for ancestors.#102050laughing-imp wants to merge 1 commit intozephyrproject-rtos:mainfrom
Conversation
|
Hello @laughing-imp, and thank you very much for your first pull request to the Zephyr project! |
86619e8 to
406bf49
Compare
Throw an error if ancestors are disabled but a parent is given Signed-off-by: Brandon Allen <allen@lunarmed.ca>
406bf49 to
f0f7fab
Compare
|
Please add a description to the pull request. Also, would it make sense to do the same thing for |
|
|
I didnt think this through. Build asserts cant be used here because from this diff (a test with ancestors disabled) diff --git a/tests/lib/smf/src/test_lib_flat_smf.c b/tests/lib/smf/src/test_lib_flat_smf.c
index 72190cb6822..de924f2ed73 100644
--- a/tests/lib/smf/src/test_lib_flat_smf.c
+++ b/tests/lib/smf/src/test_lib_flat_smf.c
@@ -253,7 +253,7 @@ static void state_d_exit(void *obj)
static const struct smf_state test_states[] = {
[STATE_A] = SMF_CREATE_STATE(state_a_entry, state_a_run, state_a_exit, NULL, NULL),
- [STATE_B] = SMF_CREATE_STATE(state_b_entry, state_b_run, state_b_exit, NULL, NULL),
+ [STATE_B] = SMF_CREATE_STATE(state_b_entry, state_b_run, state_b_exit, &test_states[STATE_A], NULL),
[STATE_C] = SMF_CREATE_STATE(state_c_entry, state_c_run, state_c_exit, NULL, NULL),
[STATE_D] = SMF_CREATE_STATE(state_d_entry, state_d_run, state_d_exit, NULL, NULL),
};
(END)it generates this error In file included from /Users/brandonallen/work/tms-fw/zephyr/tests/lib/smf/src/test_lib_flat_smf.c:8:
/Users/brandonallen/work/tms-fw/zephyr/include/zephyr/smf.h:52:30: error: negative width in bit-field 'PARENT_SET_BUT_CONFIG_SMF_ANCESTOR_SUPPORT_DISABLED'
52 | _parent, PARENT_SET_BUT_CONFIG_SMF_ANCESTOR_SUPPORT_DISABLED) + \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/brandonallen/work/tms-fw/zephyr/include/zephyr/smf.h:28:30: note: in definition of macro 'SMF_VALIDATE_NON_NULL'
28 | (sizeof(struct { int _err_msg: (IS_ENABLED(_conf) || ((_val) == NULL) ? 1 : -1); }) * 0)
| ^~~~~~~~
/Users/brandonallen/work/tms-fw/zephyr/tests/lib/smf/src/test_lib_flat_smf.c:256:21: note: in expansion of macro 'SMF_CREATE_STATE'
256 | [STATE_B] = SMF_CREATE_STATE(state_b_entry, state_b_run, state_b_exit, &test_states[STATE_A], NULL),
| ^~~~~~~~~~~~~~~~
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /opt/homebrew/bin/cmake --build /Users/brandonallen/work/tms-fw/zephyr/buildWould you accept something like this? |
|
The error message seems clear enough, but it makes the code pretty ugly and convoluted. I'd like to hear what the rest think about it. |
|
Hi @laughing-imp, I agree with @glenn-andrews and it does look a bit messy. Also on Zephyr's documentation page, it is stated:
URL: https://docs.zephyrproject.org/latest/services/smf/index.html If you can find a way to make it more aesthetic, it will be reviewed. |
|
@laughing-imp if you want there is a suggestion by @glenn-andrews about how to improve the code. |
vlad-kulikov
left a comment
There was a problem hiding this comment.
It does create a build time error in the correct scenarios but the error is syntax related and would not be clear to someone.
As stated by @laughing-imp



currently in SMF when
CONFIG_SMF_ANCESTOR_SUPPORTorCONFIG_SMF_INITIAL_TRANSITIONis disabled the value assigned to the member silently gets dropped when using theSMF_CREATE_STATE()macro. The goal of this PR is to add a clear compile time error which instructs the developer that this is happening when they are providing a non null value to the disabled member.I spent time debugging what I assumed to be bad application level logic but it turned out that I forgot to enable ancestors; maybe this change could save someone else some time aswell.