-
Notifications
You must be signed in to change notification settings - Fork 167
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
Add fault injection macros and unit tests to rcl_action #730
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -965,3 +965,70 @@ TEST_F(TestActionServerCancelPolicy, test_action_process_cancel_request_by_time_ | |
EXPECT_TRUE(uuidcmp(goal_info_out->goal_id.uuid, cancel_request.goal_info.goal_id.uuid)); | ||
EXPECT_EQ(RCL_RET_OK, rcl_action_cancel_response_fini(&cancel_response)); | ||
} | ||
|
||
TEST_F(TestActionServer, action_server_init_fini_maybe_fail) | ||
{ | ||
rcl_allocator_t allocator = rcl_get_default_allocator(); | ||
rcl_init_options_t init_options = rcl_get_zero_initialized_init_options(); | ||
rcl_ret_t ret = rcl_init_options_init(&init_options, allocator); | ||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @brawner missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. |
||
rcl_context_t context = rcl_get_zero_initialized_context(); | ||
ret = rcl_init(0, nullptr, &init_options, &context); | ||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @brawner missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. |
||
|
||
rcl_node_t node = rcl_get_zero_initialized_node(); | ||
rcl_node_options_t node_options = rcl_node_get_default_options(); | ||
ret = rcl_node_init(&node, "test_action_server_node", "", &context, &node_options); | ||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @brawner missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. |
||
rcl_clock_t clock; | ||
ret = rcl_clock_init(RCL_STEADY_TIME, &clock, &allocator); | ||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; | ||
const rosidl_action_type_support_t * ts = ROSIDL_GET_ACTION_TYPE_SUPPORT(test_msgs, Fibonacci); | ||
const rcl_action_server_options_t options = rcl_action_server_get_default_options(); | ||
constexpr char action_name[] = "test_action_server_name"; | ||
|
||
RCUTILS_FAULT_INJECTION_TEST( | ||
{ | ||
rcl_action_server_t action_server = rcl_action_get_zero_initialized_server(); | ||
rcl_ret_t ret = rcl_action_server_init( | ||
&action_server, &node, &clock, ts, action_name, &options); | ||
|
||
if (RCL_RET_OK == ret) { | ||
ret = rcl_action_server_fini(&action_server, &node); | ||
} | ||
}); | ||
} | ||
|
||
TEST_F(TestActionServerCancelPolicy, test_action_process_cancel_request_maybe_fail) | ||
{ | ||
// Request to cancel all goals | ||
rcl_action_cancel_request_t cancel_request = rcl_action_get_zero_initialized_cancel_request(); | ||
cancel_request.goal_info.stamp.sec = 0; | ||
cancel_request.goal_info.stamp.nanosec = 0u; | ||
rcl_action_cancel_response_t cancel_response = rcl_action_get_zero_initialized_cancel_response(); | ||
|
||
RCUTILS_FAULT_INJECTION_TEST( | ||
{ | ||
rcl_ret_t ret = rcl_action_process_cancel_request( | ||
&this->action_server, &cancel_request, &cancel_response); | ||
// Regardless of return, fini should be able to succeed | ||
(void)ret; | ||
Blast545 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
EXPECT_EQ(RCL_RET_OK, rcl_action_cancel_response_fini(&cancel_response)); | ||
}); | ||
} | ||
|
||
TEST_F(TestActionServerCancelPolicy, test_action_expire_goals_maybe_fail) | ||
{ | ||
const size_t capacity = 10u; | ||
rcl_action_goal_info_t expired_goals[10u]; | ||
size_t num_expired = 42u; | ||
|
||
RCUTILS_FAULT_INJECTION_TEST( | ||
{ | ||
rcl_ret_t ret = rcl_action_expire_goals( | ||
&this->action_server, expired_goals, capacity, &num_expired); | ||
if (RCL_RET_OK != ret) { | ||
rcl_reset_error(); | ||
} | ||
}); | ||
} |
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.
@brawner meta: should this be outside the loop?
We haven't agreed on this, but I think it'd be good to minimize the overlap between fault injection tests. It's an expensive test and the more stuff we add the harder it is to track it down. WDYT?
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.
Seems reasonable. Moved non rcl_action code outside of this macro loop.
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.
Uh, I don't see it here. Refreshing Github's UI won't do either 🤔
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.
Hmm, phantom code change I see. Fixed again