-
Notifications
You must be signed in to change notification settings - Fork 163
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 to rcl functions #727
Changes from all 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 | ||||
---|---|---|---|---|---|---|
|
@@ -17,6 +17,7 @@ | |||||
#include "rcl/client.h" | ||||||
|
||||||
#include "rcl/rcl.h" | ||||||
#include "rcutils/testing/fault_injection.h" | ||||||
|
||||||
#include "test_msgs/srv/basic_types.h" | ||||||
|
||||||
|
@@ -277,3 +278,29 @@ TEST_F(TestClientFixture, test_client_bad_arguments) { | |||||
&client, &client_request, &sequence_number)) << rcl_get_error_string().str; | ||||||
EXPECT_EQ(24, sequence_number); | ||||||
} | ||||||
|
||||||
TEST_F(TestClientFixture, test_client_init_fini_maybe_fail) | ||||||
{ | ||||||
const rosidl_service_type_support_t * ts = ROSIDL_GET_SRV_TYPE_SUPPORT( | ||||||
test_msgs, srv, BasicTypes); | ||||||
constexpr char topic_name[] = "chatter"; | ||||||
rcl_client_options_t default_client_options = rcl_client_get_default_options(); | ||||||
|
||||||
RCUTILS_FAULT_INJECTION_TEST( | ||||||
{ | ||||||
rcl_client_t client = rcl_get_zero_initialized_client(); | ||||||
rcl_ret_t ret = rcl_client_init( | ||||||
&client, this->node_ptr, ts, topic_name, &default_client_options); | ||||||
if (RCL_RET_OK == ret) { | ||||||
EXPECT_TRUE(rcl_client_is_valid(&client)); | ||||||
ret = rcl_client_fini(&client, this->node_ptr); | ||||||
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 why not:
Suggested change
? 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. What happens in this scenario if 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. While there are few functions in |
||||||
if (RCL_RET_OK != ret) { | ||||||
// If fault injection caused fini to fail, we should try it again. | ||||||
EXPECT_EQ(RCL_RET_OK, rcl_client_fini(&client, this->node_ptr)); | ||||||
} | ||||||
} else { | ||||||
EXPECT_TRUE(rcl_error_is_set()); | ||||||
rcl_reset_error(); | ||||||
} | ||||||
}); | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
#include "rmw/rmw.h" | ||
#include "rmw/validate_full_topic_name.h" | ||
|
||
#include "rcutils/testing/fault_injection.h" | ||
#include "test_msgs/msg/basic_types.h" | ||
#include "test_msgs/msg/strings.h" | ||
#include "rosidl_runtime_c/string_functions.h" | ||
|
@@ -1065,3 +1066,30 @@ TEST_F(CLASSNAME(TestSubscriptionFixtureInit, RMW_IMPLEMENTATION), test_subscrip | |
EXPECT_EQ(NULL, rcl_subscription_get_options(&subscription_zero_init)); | ||
rcl_reset_error(); | ||
} | ||
|
||
TEST_F(CLASSNAME(TestSubscriptionFixture, RMW_IMPLEMENTATION), test_init_fini_maybe_fail) | ||
{ | ||
const rosidl_message_type_support_t * ts = | ||
ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, BasicTypes); | ||
constexpr char topic[] = "chatter"; | ||
rcl_subscription_options_t subscription_options = rcl_subscription_get_default_options(); | ||
rcl_subscription_t subscription = rcl_get_zero_initialized_subscription(); | ||
|
||
RCUTILS_FAULT_INJECTION_TEST( | ||
{ | ||
rcl_ret_t ret = rcl_subscription_init( | ||
&subscription, this->node_ptr, ts, topic, &subscription_options); | ||
|
||
if (RCL_RET_OK == ret) { | ||
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 same question and suggestion as above. 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. Resolved similarly. |
||
EXPECT_TRUE(rcl_subscription_is_valid(&subscription)); | ||
ret = rcl_subscription_fini(&subscription, this->node_ptr); | ||
if (RCL_RET_OK != ret) { | ||
// If fault injection caused fini to fail, we should try it again. | ||
EXPECT_EQ(RCL_RET_OK, rcl_subscription_fini(&subscription, this->node_ptr)); | ||
} | ||
} else { | ||
EXPECT_TRUE(rcl_error_is_set()); | ||
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 hmm, what if no error is injected within
rcl_client_init
but one makes it intorcl_client_fini
?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 added a second
rcl_client_fini
with an appropriate check for this case.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 will point out that coping with incidental fault injection this way can get cumbersome fast. That's why at some point I suggested disabling fault injection entirely for the duration of these post-call checks.
I won't block on this though.