-
Notifications
You must be signed in to change notification settings - Fork 21
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
Output expected value on assertion #350
base: main
Are you sure you want to change the base?
Conversation
…ification/more detailed printouts, and change currently existing assertions to match.
Add error codes that break up some larger conditions so that the expected values can be logged appropriately
84e5e92
to
7c68007
Compare
FOREVER \ | ||
{ \ | ||
Ros_Debug_BroadcastMsg("MotoROS2 Assertion Failure: %s (subcode: %d)", motoRos_error_handling_assert_msg, subCodeOnFailure); \ | ||
Ros_Debug_BroadcastMsg("Actual: %s == %d", actualName, (actual)); \ |
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 we really need two specialised versions for this?
I'm sort-of hoping/expecting we can use token pasting / concatenation and just build the expected vs actual string part of the msg using the pre-processor. I don't know whether that's true though, I expect you've tried.
char motoRos_error_handling_assert_msg[ERROR_MSG_MAX_SIZE] = {0}; \ | ||
snprintf(motoRos_error_handling_assert_msg, ERROR_MSG_MAX_SIZE, msgFmtOnFailure, ##__VA_ARGS__); \ | ||
Ros_Controller_SetIOState(IO_FEEDBACK_FAILURE, TRUE); \ | ||
Ros_Controller_SetIOState(IO_FEEDBACK_INITIALIZATION_DONE, FALSE); \ | ||
mpSetAlarm(ALARM_ASSERTION_FAIL, motoRos_error_handling_assert_msg, subCodeOnFailure); \ |
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'm wondering whether this is what we'd want to do. With the current implementation, we'd be adding both mpSetAlarm(..)
and IO state management code to all call-sites of this macro.
It'd be invisible -- because it's part of the macro body -- but it would still be there. At the very least it increases binary size, but it also seems like we should be able to call a function to which we delegate this responsibility -- didn't we have that before?
|
||
#define motoRos_ASSERT_GENERIC_COMPARISON_INT_MESSAGE(actual, benchmark, subCodeOnFailure, actualName, benchmarkName, op, msgFmtOnFailure, ...) \ | ||
do { \ | ||
if (!((actual) op (benchmark))) \ |
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 is a nice use of token pasting / concatenation, but I might suggest keeping the actual 'ops' (ie: the conditionals) in the macros that call this one.
That would both make those macros easier to read (as we just see them doing something like if (!(x > y)) assert(my_msg)
) and it would reduce the responsibilities of this macro (as it now only needs to log the message and raise an alarm (but see my other comment about this)).
Less responsibilities would simplify the code (less nesting), which is always good I feel.
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 can't immediately find it, but isn't it possible to simplify things a bit by considering the conditional expression a token and evaluate it both as an actual expression as well as use it as part of the message?
So we could end up with something like: motoRos_Assert(x < y, "my message if not true", ...)
and x < y
would end up in the message as well, despite being an expression. That would reduce the need for specialised macros, while still getting us what we're after.
Edit: something like this:
#define ASSERT_WITH_MSG_(EXPR, msg) \
{ \
if (!(EXPR)) \
{ \
printf("ERROR: %s: '%s'", msg, #EXPR ); \
} \
} while (0)
For ASSERT_WITH_MSG_(1 < 1, "not smaller than")
this prints:
ERROR: not smaller than: '1 < 1'
Edit 2: see frameworks like nemequ/munit fi, which do something similar (here fi).
Edit 3: ah, but for expressions which reference variables you'd only get the name, not the value: ASSERT_WITH_MSG_(some_struct.field0 < 3, "...")
only prints:
ERROR: ...: 'some_struct.field0 < 3'
In reference to #268.
I am going to make this a draft because I definitely want feedback and expect that I will have to make changes.
The second most recent commit (as of now), 6668a4d had a function for each assertion, but there was a lot of code duplication. 7c68007 changed that by using more macros.