Skip to content

Commit c9d722a

Browse files
committed
Mock system calls in rcutils API implementation.
Signed-off-by: Michel Hidalgo <[email protected]>
1 parent eabfb01 commit c9d722a

File tree

10 files changed

+555
-25
lines changed

10 files changed

+555
-25
lines changed

CMakeLists.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ if(BUILD_TESTING)
181181
osrf_testing_tools_cpp::memory_tools LIBRARY_PRELOAD_ENVIRONMENT_IS_AVAILABLE)
182182

183183
ament_add_gtest(test_logging test/test_logging.cpp)
184-
target_link_libraries(test_logging ${PROJECT_NAME} osrf_testing_tools_cpp::memory_tools)
184+
target_link_libraries(test_logging ${PROJECT_NAME} mimick osrf_testing_tools_cpp::memory_tools)
185185

186186
add_executable(test_logging_long_messages test/test_logging_long_messages.cpp)
187187
target_link_libraries(test_logging_long_messages ${PROJECT_NAME})
@@ -234,7 +234,7 @@ if(BUILD_TESTING)
234234
test/test_char_array.cpp
235235
)
236236
if(TARGET test_char_array)
237-
target_link_libraries(test_char_array ${PROJECT_NAME})
237+
target_link_libraries(test_char_array ${PROJECT_NAME} mimick)
238238
endif()
239239

240240
# Can't use C++ with stdatomic_helper.h
@@ -275,7 +275,7 @@ if(BUILD_TESTING)
275275
test/test_split.cpp
276276
)
277277
if(TARGET test_split)
278-
target_link_libraries(test_split ${PROJECT_NAME})
278+
target_link_libraries(test_split ${PROJECT_NAME} mimick)
279279
endif()
280280

281281
rcutils_custom_add_gtest(test_find
@@ -322,7 +322,7 @@ if(BUILD_TESTING)
322322
)
323323
if(TARGET test_filesystem)
324324
ament_target_dependencies(test_filesystem "osrf_testing_tools_cpp")
325-
target_link_libraries(test_filesystem ${PROJECT_NAME})
325+
target_link_libraries(test_filesystem ${PROJECT_NAME} mimick)
326326
target_compile_definitions(test_filesystem PRIVATE BUILD_DIR="${CMAKE_CURRENT_BINARY_DIR}")
327327
endif()
328328

@@ -337,7 +337,7 @@ if(BUILD_TESTING)
337337
test/test_format_string.cpp
338338
)
339339
if(TARGET test_format_string)
340-
target_link_libraries(test_format_string ${PROJECT_NAME})
340+
target_link_libraries(test_format_string ${PROJECT_NAME} mimick)
341341
endif()
342342

343343
rcutils_custom_add_gtest(test_string_map
@@ -375,14 +375,14 @@ if(BUILD_TESTING)
375375
# which is appropriate when building the dll but not consuming it.
376376
target_compile_definitions(dummy_shared_library PRIVATE "DUMMY_SHARED_LIBRARY_BUILDING_DLL")
377377
endif()
378-
target_link_libraries(test_shared_library ${PROJECT_NAME})
378+
target_link_libraries(test_shared_library ${PROJECT_NAME} mimick)
379379
endif()
380380

381381
rcutils_custom_add_gtest(test_time
382382
test/test_time.cpp
383383
ENV ${memory_tools_test_env_vars})
384384
if(TARGET test_time)
385-
target_link_libraries(test_time ${PROJECT_NAME} osrf_testing_tools_cpp::memory_tools)
385+
target_link_libraries(test_time ${PROJECT_NAME} mimick osrf_testing_tools_cpp::memory_tools)
386386
endif()
387387

388388
rcutils_custom_add_gtest(test_snprintf
@@ -436,7 +436,7 @@ if(BUILD_TESTING)
436436
RCUTILS_COLORIZED_OUTPUT=1
437437
)
438438
if(TARGET test_logging_custom_env)
439-
target_link_libraries(test_logging_custom_env ${PROJECT_NAME} osrf_testing_tools_cpp::memory_tools)
439+
target_link_libraries(test_logging_custom_env ${PROJECT_NAME} osrf_testing_tools_cpp::memory_tools mimick)
440440
endif()
441441

442442
# RCUTILS_LOGGING_MAX_OUTPUT_FORMAT_LEN is defined as 2048, truncation should occur
@@ -452,7 +452,7 @@ if(BUILD_TESTING)
452452
RCUTILS_COLORIZED_OUTPUT=0
453453
)
454454
if(TARGET test_logging_custom_env2)
455-
target_link_libraries(test_logging_custom_env2 ${PROJECT_NAME} osrf_testing_tools_cpp::memory_tools)
455+
target_link_libraries(test_logging_custom_env2 ${PROJECT_NAME} osrf_testing_tools_cpp::memory_tools mimick)
456456
endif()
457457

458458
rcutils_custom_add_gtest(test_logging_bad_env test/test_logging_bad_env.cpp

src/char_array.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,14 @@ rcutils_char_array_vsprintf(rcutils_char_array_t * char_array, const char * form
172172
if (new_size > char_array->buffer_capacity) {
173173
rcutils_ret_t ret = rcutils_char_array_expand_as_needed(char_array, new_size);
174174
if (ret != RCUTILS_RET_OK) {
175-
RCUTILS_SET_ERROR_MSG("char array failed to expand");
176175
return ret;
177176
}
178177

179178
if (_rcutils_char_array_vsprintf(char_array, format, args) != size) {
180179
if (rcutils_char_array_fini(char_array) == RCUTILS_RET_OK) {
181180
RCUTILS_SET_ERROR_MSG("vsprintf on resized char array failed");
182181
} else {
182+
rcutils_reset_error();
183183
RCUTILS_SET_ERROR_MSG("vsprintf on resized char array failed; clean up failed too");
184184
}
185185
return RCUTILS_RET_ERROR;
@@ -196,7 +196,6 @@ rcutils_char_array_memcpy(rcutils_char_array_t * char_array, const char * src, s
196196
{
197197
rcutils_ret_t ret = rcutils_char_array_expand_as_needed(char_array, n);
198198
if (ret != RCUTILS_RET_OK) {
199-
RCUTILS_SET_ERROR_MSG("char array failed to expand");
200199
return ret;
201200
}
202201
memcpy(char_array->buffer, src, n);
@@ -217,7 +216,6 @@ rcutils_char_array_strncat(rcutils_char_array_t * char_array, const char * src,
217216
size_t new_length = current_strlen + n + 1;
218217
rcutils_ret_t ret = rcutils_char_array_expand_as_needed(char_array, new_length);
219218
if (ret != RCUTILS_RET_OK) {
220-
RCUTILS_SET_ERROR_MSG("char array failed to expand");
221219
return ret;
222220
}
223221
#ifndef _WIN32

0 commit comments

Comments
 (0)