-
Notifications
You must be signed in to change notification settings - Fork 166
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
Action goal state machine tests #311
Conversation
}, | ||
}; | ||
static rcl_action_goal_event_handler | ||
_goal_state_transition_map[GOAL_STATE_NUM_STATES][GOAL_EVENT_NUM_EVENTS]; |
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.
@jacobperron just out of curiosity, what was wrong about the previous direct initialization?
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.
When the direct initialization gets included in C++ (e.g. gtest), then gcc complains about a sparsely populated 2d array. But we might be able to use null pointers in the direct initialization instead of this init function.
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.
Moving the direct initialization to the C file got rid of the compiler warnings :)
_goal_state_transition_map[GOAL_STATE_NUM_STATES][GOAL_EVENT_NUM_EVENTS]; | ||
|
||
static inline void | ||
rcl_action_goal_transition_map_init() |
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.
@jacobperron Why are we using static linkage for these? Why not defining them on goal_state_machine.c ?
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.
Yeah, agreed; for a large function like this, making it static inline is bloating the downstream users for not a lot of reason. This is probably better as a function inside a C file.
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.
In retrospect, I think all of these static functions and the transition map can be moved to a C file.
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.
+1, you should move as much out of the public interface as is possible/reasonable.
{ | ||
// Only run this function once | ||
static bool _is_goal_state_transition_map_init = false; | ||
if (_is_goal_state_transition_map_init) { |
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.
If this could be called from multiple threads, there is a TOCTTOU bug here; thread 1 could have read the state of _is_goal_state_transition_map_init
as false then been swapped out, then thread 2 could read the state of _is_goal_state_transition_map
as false, and do the initialization. Then when thread 1 wakes back up, it still thinks that it needs to do the initialization, and does it again.
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.
Moving the initialization to the C file let me do a direct initialization, so I believe this issue goes away.
#315 should fix the unstable windows build. I'll rebase once it's merged. |
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.
LGTM
} | ||
|
||
// Transition map | ||
rcl_action_goal_event_handler |
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.
@jacobperron nit: this one could be static
.
Along with unit tests: - Fix buggy if-conditions in transition functions. - Populate transition map in function for compatibility with cpp code (e.g. gtest). - Move rcl_action_transition_goal_state implementation to .c file and build rcl_action library
b63275b
to
6a8750e
Compare
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.
LGTM!
Connects to #306.
As a follow up, we might consider replacing the hard-coded transition map with the more general one in rcl_lifecycle. This would involve moving the general transition map to a common package like rcutils.