Skip to content

Commit

Permalink
Mock system calls in rcutils API implementation.
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <[email protected]>
  • Loading branch information
hidmic committed Jul 29, 2020
1 parent eabfb01 commit c9d722a
Show file tree
Hide file tree
Showing 10 changed files with 555 additions and 25 deletions.
18 changes: 9 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ if(BUILD_TESTING)
osrf_testing_tools_cpp::memory_tools LIBRARY_PRELOAD_ENVIRONMENT_IS_AVAILABLE)

ament_add_gtest(test_logging test/test_logging.cpp)
target_link_libraries(test_logging ${PROJECT_NAME} osrf_testing_tools_cpp::memory_tools)
target_link_libraries(test_logging ${PROJECT_NAME} mimick osrf_testing_tools_cpp::memory_tools)

add_executable(test_logging_long_messages test/test_logging_long_messages.cpp)
target_link_libraries(test_logging_long_messages ${PROJECT_NAME})
Expand Down Expand Up @@ -234,7 +234,7 @@ if(BUILD_TESTING)
test/test_char_array.cpp
)
if(TARGET test_char_array)
target_link_libraries(test_char_array ${PROJECT_NAME})
target_link_libraries(test_char_array ${PROJECT_NAME} mimick)
endif()

# Can't use C++ with stdatomic_helper.h
Expand Down Expand Up @@ -275,7 +275,7 @@ if(BUILD_TESTING)
test/test_split.cpp
)
if(TARGET test_split)
target_link_libraries(test_split ${PROJECT_NAME})
target_link_libraries(test_split ${PROJECT_NAME} mimick)
endif()

rcutils_custom_add_gtest(test_find
Expand Down Expand Up @@ -322,7 +322,7 @@ if(BUILD_TESTING)
)
if(TARGET test_filesystem)
ament_target_dependencies(test_filesystem "osrf_testing_tools_cpp")
target_link_libraries(test_filesystem ${PROJECT_NAME})
target_link_libraries(test_filesystem ${PROJECT_NAME} mimick)
target_compile_definitions(test_filesystem PRIVATE BUILD_DIR="${CMAKE_CURRENT_BINARY_DIR}")
endif()

Expand All @@ -337,7 +337,7 @@ if(BUILD_TESTING)
test/test_format_string.cpp
)
if(TARGET test_format_string)
target_link_libraries(test_format_string ${PROJECT_NAME})
target_link_libraries(test_format_string ${PROJECT_NAME} mimick)
endif()

rcutils_custom_add_gtest(test_string_map
Expand Down Expand Up @@ -375,14 +375,14 @@ if(BUILD_TESTING)
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(dummy_shared_library PRIVATE "DUMMY_SHARED_LIBRARY_BUILDING_DLL")
endif()
target_link_libraries(test_shared_library ${PROJECT_NAME})
target_link_libraries(test_shared_library ${PROJECT_NAME} mimick)
endif()

rcutils_custom_add_gtest(test_time
test/test_time.cpp
ENV ${memory_tools_test_env_vars})
if(TARGET test_time)
target_link_libraries(test_time ${PROJECT_NAME} osrf_testing_tools_cpp::memory_tools)
target_link_libraries(test_time ${PROJECT_NAME} mimick osrf_testing_tools_cpp::memory_tools)
endif()

rcutils_custom_add_gtest(test_snprintf
Expand Down Expand Up @@ -436,7 +436,7 @@ if(BUILD_TESTING)
RCUTILS_COLORIZED_OUTPUT=1
)
if(TARGET test_logging_custom_env)
target_link_libraries(test_logging_custom_env ${PROJECT_NAME} osrf_testing_tools_cpp::memory_tools)
target_link_libraries(test_logging_custom_env ${PROJECT_NAME} osrf_testing_tools_cpp::memory_tools mimick)
endif()

# RCUTILS_LOGGING_MAX_OUTPUT_FORMAT_LEN is defined as 2048, truncation should occur
Expand All @@ -452,7 +452,7 @@ if(BUILD_TESTING)
RCUTILS_COLORIZED_OUTPUT=0
)
if(TARGET test_logging_custom_env2)
target_link_libraries(test_logging_custom_env2 ${PROJECT_NAME} osrf_testing_tools_cpp::memory_tools)
target_link_libraries(test_logging_custom_env2 ${PROJECT_NAME} osrf_testing_tools_cpp::memory_tools mimick)
endif()

rcutils_custom_add_gtest(test_logging_bad_env test/test_logging_bad_env.cpp
Expand Down
4 changes: 1 addition & 3 deletions src/char_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ rcutils_char_array_vsprintf(rcutils_char_array_t * char_array, const char * form
if (new_size > char_array->buffer_capacity) {
rcutils_ret_t ret = rcutils_char_array_expand_as_needed(char_array, new_size);
if (ret != RCUTILS_RET_OK) {
RCUTILS_SET_ERROR_MSG("char array failed to expand");
return ret;
}

if (_rcutils_char_array_vsprintf(char_array, format, args) != size) {
if (rcutils_char_array_fini(char_array) == RCUTILS_RET_OK) {
RCUTILS_SET_ERROR_MSG("vsprintf on resized char array failed");
} else {
rcutils_reset_error();
RCUTILS_SET_ERROR_MSG("vsprintf on resized char array failed; clean up failed too");
}
return RCUTILS_RET_ERROR;
Expand All @@ -196,7 +196,6 @@ rcutils_char_array_memcpy(rcutils_char_array_t * char_array, const char * src, s
{
rcutils_ret_t ret = rcutils_char_array_expand_as_needed(char_array, n);
if (ret != RCUTILS_RET_OK) {
RCUTILS_SET_ERROR_MSG("char array failed to expand");
return ret;
}
memcpy(char_array->buffer, src, n);
Expand All @@ -217,7 +216,6 @@ rcutils_char_array_strncat(rcutils_char_array_t * char_array, const char * src,
size_t new_length = current_strlen + n + 1;
rcutils_ret_t ret = rcutils_char_array_expand_as_needed(char_array, new_length);
if (ret != RCUTILS_RET_OK) {
RCUTILS_SET_ERROR_MSG("char array failed to expand");
return ret;
}
#ifndef _WIN32
Expand Down
Loading

0 comments on commit c9d722a

Please sign in to comment.