From 08568668a0f8c833b081057a7d92d31fe4bfe64a Mon Sep 17 00:00:00 2001 From: Stephen Brawner Date: Wed, 22 Jul 2020 16:55:56 -0700 Subject: [PATCH 1/4] Add fault injection macros for use in other packages Signed-off-by: Stephen Brawner --- rmw/src/names_and_types.c | 6 ++++++ rmw/src/topic_endpoint_info.c | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) 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..305152b8 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,8 @@ _rmw_topic_endpoint_info_copy_str( const char * str, rcutils_allocator_t * allocator) { + RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_INVALID_ARGUMENT); + if (!str) { RMW_SET_ERROR_MSG("str is null"); return RMW_RET_INVALID_ARGUMENT; @@ -134,6 +139,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 +154,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 +169,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 +186,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 +204,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 +224,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; From 743064d365e32bfded464634d56a34bd8e059222 Mon Sep 17 00:00:00 2001 From: Stephen Brawner Date: Fri, 7 Aug 2020 15:37:36 -0700 Subject: [PATCH 2/4] cxx/c flags Signed-off-by: Stephen Brawner --- rmw/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rmw/CMakeLists.txt b/rmw/CMakeLists.txt index 2dbffe2c..d6754613 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" From ba7ff3555aa133a6aedcc72ad4216fe1b7fbd7a1 Mon Sep 17 00:00:00 2001 From: Stephen Brawner Date: Thu, 27 Aug 2020 16:29:06 -0700 Subject: [PATCH 3/4] Address feedback Signed-off-by: Stephen Brawner --- rmw/src/topic_endpoint_info.c | 1 + 1 file changed, 1 insertion(+) diff --git a/rmw/src/topic_endpoint_info.c b/rmw/src/topic_endpoint_info.c index 305152b8..5f6719ca 100644 --- a/rmw/src/topic_endpoint_info.c +++ b/rmw/src/topic_endpoint_info.c @@ -109,6 +109,7 @@ _rmw_topic_endpoint_info_copy_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"); From 3f8c2e47de1a8897d682149134bb5052abd8f5e5 Mon Sep 17 00:00:00 2001 From: Stephen Brawner Date: Mon, 31 Aug 2020 11:41:01 -0700 Subject: [PATCH 4/4] lint cmake Signed-off-by: Stephen Brawner --- rmw/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rmw/CMakeLists.txt b/rmw/CMakeLists.txt index d6754613..23c94572 100644 --- a/rmw/CMakeLists.txt +++ b/rmw/CMakeLists.txt @@ -48,7 +48,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC "$" "$") -if (BUILD_TESTING AND NOT RCUTILS_DISABLE_FAULT_INJECTION) +if(BUILD_TESTING AND NOT RCUTILS_DISABLE_FAULT_INJECTION) target_compile_definitions(${PROJECT_NAME} PUBLIC RCUTILS_ENABLE_FAULT_INJECTION) endif()