From 6705b728fe85d71f8c11b1d30162455a817c58c0 Mon Sep 17 00:00:00 2001 From: brawner Date: Mon, 31 Aug 2020 12:52:17 -0700 Subject: [PATCH] Add fault injection macros for use in other packages (#254) * Add fault injection macros for use in other packages Signed-off-by: Stephen Brawner * cxx/c flags Signed-off-by: Stephen Brawner * Address feedback Signed-off-by: Stephen Brawner * lint cmake Signed-off-by: Stephen Brawner --- rmw/CMakeLists.txt | 5 +++++ rmw/src/names_and_types.c | 6 ++++++ rmw/src/topic_endpoint_info.c | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/rmw/CMakeLists.txt b/rmw/CMakeLists.txt index 9873ec28..d8d6b58e 100644 --- a/rmw/CMakeLists.txt +++ b/rmw/CMakeLists.txt @@ -47,6 +47,11 @@ add_library(${PROJECT_NAME} ${rmw_sources}) target_include_directories(${PROJECT_NAME} PUBLIC "$" "$") + +if(BUILD_TESTING AND NOT RCUTILS_DISABLE_FAULT_INJECTION) + target_compile_definitions(${PROJECT_NAME} PUBLIC RCUTILS_ENABLE_FAULT_INJECTION) +endif() + ament_target_dependencies(${PROJECT_NAME} "rcutils" "rosidl_runtime_c" diff --git a/rmw/src/names_and_types.c b/rmw/src/names_and_types.c index f4fa80c6..9baf512d 100644 --- a/rmw/src/names_and_types.c +++ b/rmw/src/names_and_types.c @@ -15,6 +15,7 @@ #include "rmw/names_and_types.h" #include "rcutils/logging_macros.h" +#include "rcutils/macros.h" #include "rcutils/types/string_array.h" #include "rmw/error_handling.h" #include "rmw/convert_rcutils_ret_to_rmw_ret.h" @@ -34,6 +35,8 @@ rmw_get_zero_initialized_names_and_types(void) rmw_ret_t rmw_names_and_types_check_zero(rmw_names_and_types_t * names_and_types) { + RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_INVALID_ARGUMENT); + if (!names_and_types) { RMW_SET_ERROR_MSG("names_and_types is null"); return RMW_RET_INVALID_ARGUMENT; @@ -55,6 +58,9 @@ rmw_names_and_types_init( size_t size, rcutils_allocator_t * allocator) { + RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_INVALID_ARGUMENT); + RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_BAD_ALLOC); + if (!allocator) { RMW_SET_ERROR_MSG("allocator is null"); return RMW_RET_INVALID_ARGUMENT; diff --git a/rmw/src/topic_endpoint_info.c b/rmw/src/topic_endpoint_info.c index ee8cc4cd..5f6719ca 100644 --- a/rmw/src/topic_endpoint_info.c +++ b/rmw/src/topic_endpoint_info.c @@ -14,6 +14,7 @@ #include "rmw/topic_endpoint_info.h" +#include "rcutils/macros.h" #include "rcutils/strdup.h" #include "rmw/error_handling.h" #include "rmw/types.h" @@ -71,6 +72,8 @@ rmw_topic_endpoint_info_fini( rmw_topic_endpoint_info_t * topic_endpoint_info, rcutils_allocator_t * allocator) { + RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_INVALID_ARGUMENT); + if (!topic_endpoint_info) { RMW_SET_ERROR_MSG("topic_endpoint_info is null"); return RMW_RET_INVALID_ARGUMENT; @@ -105,6 +108,9 @@ _rmw_topic_endpoint_info_copy_str( const char * str, rcutils_allocator_t * allocator) { + RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_INVALID_ARGUMENT); + RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_BAD_ALLOC); + if (!str) { RMW_SET_ERROR_MSG("str is null"); return RMW_RET_INVALID_ARGUMENT; @@ -134,6 +140,8 @@ rmw_topic_endpoint_info_set_topic_type( const char * topic_type, rcutils_allocator_t * allocator) { + RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_INVALID_ARGUMENT); + if (!topic_endpoint_info) { RMW_SET_ERROR_MSG("topic_endpoint_info is null"); return RMW_RET_INVALID_ARGUMENT; @@ -147,6 +155,8 @@ rmw_topic_endpoint_info_set_node_name( const char * node_name, rcutils_allocator_t * allocator) { + RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_INVALID_ARGUMENT); + if (!topic_endpoint_info) { RMW_SET_ERROR_MSG("topic_endpoint_info is null"); return RMW_RET_INVALID_ARGUMENT; @@ -160,6 +170,8 @@ rmw_topic_endpoint_info_set_node_namespace( const char * node_namespace, rcutils_allocator_t * allocator) { + RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_INVALID_ARGUMENT); + if (!topic_endpoint_info) { RMW_SET_ERROR_MSG("topic_endpoint_info is null"); return RMW_RET_INVALID_ARGUMENT; @@ -175,6 +187,8 @@ rmw_topic_endpoint_info_set_endpoint_type( rmw_topic_endpoint_info_t * topic_endpoint_info, rmw_endpoint_type_t type) { + RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_INVALID_ARGUMENT); + if (!topic_endpoint_info) { RMW_SET_ERROR_MSG("topic_endpoint_info is null"); return RMW_RET_INVALID_ARGUMENT; @@ -191,6 +205,8 @@ rmw_topic_endpoint_info_set_gid( const uint8_t gid[], size_t size) { + RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_INVALID_ARGUMENT); + if (!topic_endpoint_info) { RMW_SET_ERROR_MSG("topic_endpoint_info is null"); return RMW_RET_INVALID_ARGUMENT; @@ -209,6 +225,8 @@ rmw_topic_endpoint_info_set_qos_profile( rmw_topic_endpoint_info_t * topic_endpoint_info, const rmw_qos_profile_t * qos_profile) { + RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_INVALID_ARGUMENT); + if (!topic_endpoint_info) { RMW_SET_ERROR_MSG("topic_endpoint_info is null"); return RMW_RET_INVALID_ARGUMENT;