diff --git a/rcl_logging_spdlog/test/test_logging_interface.cpp b/rcl_logging_spdlog/test/test_logging_interface.cpp index 477f652..ba75774 100644 --- a/rcl_logging_spdlog/test/test_logging_interface.cpp +++ b/rcl_logging_spdlog/test/test_logging_interface.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -162,3 +163,23 @@ TEST_F(LoggingTest, full_cycle) expected_log.str(), actual_log.str()) << "Unexpected log contents in " << log_file_path; } + +TEST_F(LoggingTest, maybe_fail_test) +{ + #ifdef RCUTILS_ENABLE_FAULT_INJECTION + bool fault_injection_enabled = true; + #else + bool fault_injection_enabled = false; + #endif + ASSERT_TRUE(fault_injection_enabled); + + for (int i = 0; i < 10; ++i) { + RCUTILS_SET_FAULT_INJECTION_COUNT(i); + if (RCL_LOGGING_RET_OK == rcl_logging_external_initialize(nullptr, allocator)) { + EXPECT_EQ(RCL_LOGGING_RET_OK, rcl_logging_external_shutdown()); + } else { + EXPECT_TRUE(rcutils_error_is_set()); + rcutils_reset_error(); + } + } +}