Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rcl_logging_spdlog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ if(BUILD_TESTING)
ament_add_gtest(test_logging_interface test/test_logging_interface.cpp)
if(TARGET test_logging_interface)
target_link_libraries(test_logging_interface ${PROJECT_NAME})
target_compile_definitions(test_logging_interface PUBLIC RCUTILS_ENABLE_FAULT_INJECTION)
ament_target_dependencies(test_logging_interface rcpputils)
endif()
endif()
Expand Down
14 changes: 14 additions & 0 deletions rcl_logging_spdlog/test/test_logging_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <rcutils/env.h>
#include <rcutils/error_handling.h>
#include <rcutils/logging.h>
#include <rcutils/testing/fault_injection.h>

#include <limits.h>
#include <fstream>
Expand Down Expand Up @@ -162,3 +163,16 @@ TEST_F(LoggingTest, full_cycle)
expected_log.str(),
actual_log.str()) << "Unexpected log contents in " << log_file_path;
}

TEST_F(LoggingTest, init_fini_maybe_fail_test)
{
RCUTILS_FAULT_INJECTION_TEST(
{
if (RCL_LOGGING_RET_OK == rcl_logging_external_initialize(nullptr, allocator)) {
EXPECT_EQ(RCL_LOGGING_RET_OK, rcl_logging_external_shutdown());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brawner what if rcl_logging_external_shutdown() fails because of fault injection?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rcl_logging_external_shutdown() is currently very simple and doesn't call any external functions. The EXPECT_EQ will help notify people this test needs to be fixed should that function be modified.

https://github.com/ros2/rcl_logging/blob/master/rcl_logging_spdlog/src/rcl_logging_spdlog.cpp#L150-L154

} else {
EXPECT_TRUE(rcutils_error_is_set());
rcutils_reset_error();
}
});
}