-
Notifications
You must be signed in to change notification settings - Fork 50
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 tests to construction/destruction APIs. #144
Changes from 2 commits
1bdb65b
7c8618d
7309204
ceac659
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 |
---|---|---|
|
@@ -14,12 +14,16 @@ | |
|
||
#include <gtest/gtest.h> | ||
|
||
#include "osrf_testing_tools_cpp/memory_tools/memory_tools.hpp" | ||
|
||
#include "rcutils/allocator.h" | ||
#include "rcutils/strdup.h" | ||
|
||
#include "rmw/error_handling.h" | ||
#include "rmw/rmw.h" | ||
|
||
#include "./testing_macros.hpp" | ||
|
||
|
||
#ifdef RMW_IMPLEMENTATION | ||
# define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX | ||
|
@@ -173,3 +177,41 @@ TEST_F( | |
ASSERT_NE(nullptr, node) << rmw_get_error_string().str; | ||
EXPECT_EQ(RMW_RET_OK, rmw_destroy_node(node)) << rmw_get_error_string().str; | ||
} | ||
|
||
TEST_F( | ||
CLASSNAME(TestNodeConstructionDestruction, RMW_IMPLEMENTATION), | ||
create_with_internal_errors) { | ||
RCUTILS_FAULT_INJECTION_TEST( | ||
{ | ||
constexpr char node_name[] = "my_node"; | ||
constexpr char node_namespace[] = "/my_ns"; | ||
rmw_node_t * node = rmw_create_node(&context, node_name, node_namespace); | ||
if (node) { | ||
RCUTILS_NO_FAULT_INJECTION( | ||
{ | ||
rmw_ret_t ret = rmw_destroy_node(node); | ||
EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; | ||
}); | ||
} else { | ||
rmw_reset_error(); | ||
} | ||
}); | ||
} | ||
|
||
TEST_F( | ||
CLASSNAME(TestNodeConstructionDestruction, RMW_IMPLEMENTATION), | ||
destroy_with_internal_errors) { | ||
RCUTILS_FAULT_INJECTION_TEST( | ||
{ | ||
constexpr char node_name[] = "my_node"; | ||
constexpr char node_namespace[] = "/my_ns"; | ||
int64_t count = rcutils_fault_injection_get_count(); | ||
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. Same here 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. See 7309204. |
||
rcutils_fault_injection_set_count(RCUTILS_FAULT_INJECTION_NEVER_FAIL); | ||
rmw_node_t * node = rmw_create_node(&context, node_name, node_namespace); | ||
ASSERT_NE(nullptr, node) << rmw_get_error_string().str; | ||
rcutils_fault_injection_set_count(count); | ||
if (RMW_RET_OK != rmw_destroy_node(node)) { | ||
rmw_reset_error(); | ||
} | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,10 @@ | |
#include <gtest/gtest.h> | ||
|
||
#include "osrf_testing_tools_cpp/memory_tools/gtest_quickstart.hpp" | ||
#include "osrf_testing_tools_cpp/scope_exit.hpp" | ||
|
||
#include "rcutils/allocator.h" | ||
#include "rcutils/macros.h" | ||
#include "rcutils/strdup.h" | ||
|
||
#include "rmw/rmw.h" | ||
|
@@ -82,6 +84,27 @@ TEST_F(CLASSNAME(TestPublisher, RMW_IMPLEMENTATION), create_and_destroy) { | |
EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; | ||
} | ||
|
||
TEST_F(CLASSNAME(TestPublisher, RMW_IMPLEMENTATION), create_with_internal_errors) { | ||
constexpr char topic_name[] = "/test"; | ||
const rosidl_message_type_support_t * ts = | ||
ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, BasicTypes); | ||
|
||
RCUTILS_FAULT_INJECTION_TEST( | ||
{ | ||
rmw_publisher_options_t options = rmw_get_default_publisher_options(); | ||
rmw_publisher_t * pub = | ||
rmw_create_publisher(node, ts, topic_name, &rmw_qos_profile_default, &options); | ||
if (pub) { | ||
int64_t count = rcutils_fault_injection_get_count(); | ||
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. Same 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. See 7309204. |
||
rcutils_fault_injection_set_count(RCUTILS_FAULT_INJECTION_NEVER_FAIL); | ||
EXPECT_EQ(RMW_RET_OK, rmw_destroy_publisher(node, pub)) << rmw_get_error_string().str; | ||
rcutils_fault_injection_set_count(count); | ||
} else { | ||
rmw_reset_error(); | ||
} | ||
}); | ||
} | ||
|
||
TEST_F(CLASSNAME(TestPublisher, RMW_IMPLEMENTATION), create_and_destroy_native) { | ||
rmw_publisher_options_t options = rmw_get_default_publisher_options(); | ||
constexpr char topic_name[] = "test"; | ||
|
@@ -185,6 +208,26 @@ TEST_F(CLASSNAME(TestPublisher, RMW_IMPLEMENTATION), destroy_with_bad_arguments) | |
rmw_reset_error(); | ||
} | ||
|
||
TEST_F(CLASSNAME(TestPublisher, RMW_IMPLEMENTATION), destroy_with_internal_errors) { | ||
constexpr char topic_name[] = "/test"; | ||
const rosidl_message_type_support_t * ts = | ||
ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, BasicTypes); | ||
|
||
RCUTILS_FAULT_INJECTION_TEST( | ||
{ | ||
int64_t count = rcutils_fault_injection_get_count(); | ||
rcutils_fault_injection_set_count(RCUTILS_FAULT_INJECTION_NEVER_FAIL); | ||
rmw_publisher_options_t options = rmw_get_default_publisher_options(); | ||
rmw_publisher_t * pub = | ||
rmw_create_publisher(node, ts, topic_name, &rmw_qos_profile_default, &options); | ||
ASSERT_NE(nullptr, pub) << rmw_get_error_string().str; | ||
rcutils_fault_injection_set_count(count); | ||
if (RMW_RET_OK != rmw_destroy_publisher(node, pub)) { | ||
rmw_reset_error(); | ||
} | ||
}); | ||
} | ||
|
||
TEST_F(CLASSNAME(TestPublisher, RMW_IMPLEMENTATION), get_actual_qos_from_system_defaults) { | ||
rmw_publisher_options_t options = rmw_get_default_publisher_options(); | ||
constexpr char topic_name[] = "/test"; | ||
|
@@ -405,6 +448,20 @@ TEST_F( | |
test_msgs__msg__BasicTypes__fini(&input_message); | ||
} | ||
|
||
TEST_F(CLASSNAME(TestPublisherUse, RMW_IMPLEMENTATION), publish_with_internal_errors) { | ||
test_msgs__msg__BasicTypes message{}; | ||
ASSERT_TRUE(test_msgs__msg__BasicTypes__init(&message)); | ||
rmw_publisher_allocation_t * null_allocation{nullptr}; // still a valid allocation | ||
|
||
RCUTILS_FAULT_INJECTION_TEST( | ||
{ | ||
rmw_ret_t ret = rmw_publish(pub, &message, null_allocation); | ||
if (RMW_RET_OK != ret) { | ||
rmw_reset_error(); | ||
} | ||
}); | ||
} | ||
|
||
TEST_F( | ||
CLASSNAME(TestPublisherUse, RMW_IMPLEMENTATION), | ||
publish_serialized_message_with_bad_arguments) { | ||
|
@@ -434,6 +491,33 @@ TEST_F( | |
RMW_RET_OK, rmw_serialized_message_fini(&serialized_message)) << rmw_get_error_string().str; | ||
} | ||
|
||
TEST_F(CLASSNAME(TestPublisherUse, RMW_IMPLEMENTATION), publish_serialized_with_internal_errors) { | ||
test_msgs__msg__BasicTypes message{}; | ||
ASSERT_TRUE(test_msgs__msg__BasicTypes__init(&message)); | ||
rcutils_allocator_t default_allocator = rcutils_get_default_allocator(); | ||
rmw_serialized_message_t serialized_message = rmw_get_zero_initialized_serialized_message(); | ||
rmw_ret_t ret = rmw_serialized_message_init(&serialized_message, 0lu, &default_allocator); | ||
ASSERT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; | ||
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( | ||
{ | ||
rmw_ret_t ret = rmw_serialized_message_fini(&serialized_message); | ||
EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; | ||
}); | ||
ret = rmw_serialize(&message, ts, &serialized_message); | ||
ASSERT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str; | ||
rmw_publisher_allocation_t * null_allocation{nullptr}; // still a valid allocation | ||
|
||
RCUTILS_FAULT_INJECTION_TEST( | ||
{ | ||
ret = rmw_publish_serialized_message( | ||
pub, &serialized_message, null_allocation); | ||
if (RMW_RET_OK != ret) { | ||
rmw_reset_error(); | ||
} | ||
}); | ||
} | ||
|
||
|
||
class CLASSNAME (TestPublisherUseLoan, RMW_IMPLEMENTATION) | ||
: public CLASSNAME(TestPublisherUse, RMW_IMPLEMENTATION) | ||
{ | ||
|
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 missing
RCUTILS_NO_FAULT_INJECTION
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.
Argh, thought I had covered them all. See 7309204.