Skip to content

Commit 5ddbdab

Browse files
brawnerahcorde
authored andcommitted
Add fault injection macros for use in other packages (#254)
* 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]>
1 parent 528953f commit 5ddbdab

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

rmw/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ add_library(${PROJECT_NAME} ${rmw_sources})
4747
target_include_directories(${PROJECT_NAME} PUBLIC
4848
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
4949
"$<INSTALL_INTERFACE:include>")
50+
51+
if(BUILD_TESTING AND NOT RCUTILS_DISABLE_FAULT_INJECTION)
52+
target_compile_definitions(${PROJECT_NAME} PUBLIC RCUTILS_ENABLE_FAULT_INJECTION)
53+
endif()
54+
5055
ament_target_dependencies(${PROJECT_NAME}
5156
"rcutils"
5257
"rosidl_runtime_c"

rmw/src/names_and_types.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "rmw/names_and_types.h"
1616

1717
#include "rcutils/logging_macros.h"
18+
#include "rcutils/macros.h"
1819
#include "rcutils/types/string_array.h"
1920
#include "rmw/error_handling.h"
2021
#include "rmw/convert_rcutils_ret_to_rmw_ret.h"
@@ -34,6 +35,8 @@ rmw_get_zero_initialized_names_and_types(void)
3435
rmw_ret_t
3536
rmw_names_and_types_check_zero(rmw_names_and_types_t * names_and_types)
3637
{
38+
RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_INVALID_ARGUMENT);
39+
3740
if (!names_and_types) {
3841
RMW_SET_ERROR_MSG("names_and_types is null");
3942
return RMW_RET_INVALID_ARGUMENT;
@@ -55,6 +58,9 @@ rmw_names_and_types_init(
5558
size_t size,
5659
rcutils_allocator_t * allocator)
5760
{
61+
RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_INVALID_ARGUMENT);
62+
RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_BAD_ALLOC);
63+
5864
if (!allocator) {
5965
RMW_SET_ERROR_MSG("allocator is null");
6066
return RMW_RET_INVALID_ARGUMENT;

rmw/src/topic_endpoint_info.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "rmw/topic_endpoint_info.h"
1616

17+
#include "rcutils/macros.h"
1718
#include "rcutils/strdup.h"
1819
#include "rmw/error_handling.h"
1920
#include "rmw/types.h"
@@ -71,6 +72,8 @@ rmw_topic_endpoint_info_fini(
7172
rmw_topic_endpoint_info_t * topic_endpoint_info,
7273
rcutils_allocator_t * allocator)
7374
{
75+
RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_INVALID_ARGUMENT);
76+
7477
if (!topic_endpoint_info) {
7578
RMW_SET_ERROR_MSG("topic_endpoint_info is null");
7679
return RMW_RET_INVALID_ARGUMENT;
@@ -105,6 +108,9 @@ _rmw_topic_endpoint_info_copy_str(
105108
const char * str,
106109
rcutils_allocator_t * allocator)
107110
{
111+
RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_INVALID_ARGUMENT);
112+
RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_BAD_ALLOC);
113+
108114
if (!str) {
109115
RMW_SET_ERROR_MSG("str is null");
110116
return RMW_RET_INVALID_ARGUMENT;
@@ -134,6 +140,8 @@ rmw_topic_endpoint_info_set_topic_type(
134140
const char * topic_type,
135141
rcutils_allocator_t * allocator)
136142
{
143+
RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_INVALID_ARGUMENT);
144+
137145
if (!topic_endpoint_info) {
138146
RMW_SET_ERROR_MSG("topic_endpoint_info is null");
139147
return RMW_RET_INVALID_ARGUMENT;
@@ -147,6 +155,8 @@ rmw_topic_endpoint_info_set_node_name(
147155
const char * node_name,
148156
rcutils_allocator_t * allocator)
149157
{
158+
RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_INVALID_ARGUMENT);
159+
150160
if (!topic_endpoint_info) {
151161
RMW_SET_ERROR_MSG("topic_endpoint_info is null");
152162
return RMW_RET_INVALID_ARGUMENT;
@@ -160,6 +170,8 @@ rmw_topic_endpoint_info_set_node_namespace(
160170
const char * node_namespace,
161171
rcutils_allocator_t * allocator)
162172
{
173+
RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_INVALID_ARGUMENT);
174+
163175
if (!topic_endpoint_info) {
164176
RMW_SET_ERROR_MSG("topic_endpoint_info is null");
165177
return RMW_RET_INVALID_ARGUMENT;
@@ -175,6 +187,8 @@ rmw_topic_endpoint_info_set_endpoint_type(
175187
rmw_topic_endpoint_info_t * topic_endpoint_info,
176188
rmw_endpoint_type_t type)
177189
{
190+
RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_INVALID_ARGUMENT);
191+
178192
if (!topic_endpoint_info) {
179193
RMW_SET_ERROR_MSG("topic_endpoint_info is null");
180194
return RMW_RET_INVALID_ARGUMENT;
@@ -191,6 +205,8 @@ rmw_topic_endpoint_info_set_gid(
191205
const uint8_t gid[],
192206
size_t size)
193207
{
208+
RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_INVALID_ARGUMENT);
209+
194210
if (!topic_endpoint_info) {
195211
RMW_SET_ERROR_MSG("topic_endpoint_info is null");
196212
return RMW_RET_INVALID_ARGUMENT;
@@ -209,6 +225,8 @@ rmw_topic_endpoint_info_set_qos_profile(
209225
rmw_topic_endpoint_info_t * topic_endpoint_info,
210226
const rmw_qos_profile_t * qos_profile)
211227
{
228+
RCUTILS_CAN_RETURN_WITH_ERROR_OF(RMW_RET_INVALID_ARGUMENT);
229+
212230
if (!topic_endpoint_info) {
213231
RMW_SET_ERROR_MSG("topic_endpoint_info is null");
214232
return RMW_RET_INVALID_ARGUMENT;

0 commit comments

Comments
 (0)