Skip to content

Commit

Permalink
Add fault injection macros for use in other packages (#254)
Browse files Browse the repository at this point in the history
* Add fault injection macros for use in other packages

Signed-off-by: Stephen Brawner <[email protected]>

* cxx/c flags

Signed-off-by: Stephen Brawner <[email protected]>

* Address feedback

Signed-off-by: Stephen Brawner <[email protected]>

* lint cmake

Signed-off-by: Stephen Brawner <[email protected]>
  • Loading branch information
brawner authored Aug 31, 2020
1 parent 3db0cfa commit 518716c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions rmw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ add_library(${PROJECT_NAME} ${rmw_sources})
target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>")

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"
Expand Down
6 changes: 6 additions & 0 deletions rmw/src/names_and_types.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand All @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions rmw/src/topic_endpoint_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 518716c

Please sign in to comment.