From c187fcf114eea6e9c8fde954023a4beb206cfa48 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Sun, 2 May 2021 09:48:01 -0400 Subject: [PATCH 1/3] Set rmw log severity Signed-off-by: Christophe Bedard --- rcl/src/rcl/logging.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rcl/src/rcl/logging.c b/rcl/src/rcl/logging.c index c1aebc75e..367242a31 100644 --- a/rcl/src/rcl/logging.c +++ b/rcl/src/rcl/logging.c @@ -31,6 +31,7 @@ extern "C" #include "rcl/macros.h" #include "rcutils/logging.h" #include "rcutils/time.h" +#include "rmw/rmw.h" #define RCL_LOGGING_MAX_OUTPUT_FUNCS (4) @@ -76,6 +77,12 @@ rcl_logging_configure_with_output_handler( if (log_levels) { default_level = (int)log_levels->default_logger_level; rcutils_logging_set_default_logger_level(default_level); + if (RCUTILS_LOG_SEVERITY_UNSET != default_level) { + rmw_ret_t rmw_status = rmw_set_log_severity((rmw_log_severity_t)default_level); + if (RMW_RET_OK != rmw_status) { + return RCL_RET_ERROR; + } + } for (size_t i = 0; i < log_levels->num_logger_settings; ++i) { rcutils_ret_t rcutils_status = rcutils_logging_set_logger_level( From e8a34876bde0621555ba8a4b73836c1ce10e2b35 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Sun, 2 May 2021 20:41:10 -0400 Subject: [PATCH 2/3] Handle unsupported rmw_set_log_severity and print error Signed-off-by: Christophe Bedard --- rcl/src/rcl/logging.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rcl/src/rcl/logging.c b/rcl/src/rcl/logging.c index 367242a31..d25d4c2fe 100644 --- a/rcl/src/rcl/logging.c +++ b/rcl/src/rcl/logging.c @@ -79,7 +79,9 @@ rcl_logging_configure_with_output_handler( rcutils_logging_set_default_logger_level(default_level); if (RCUTILS_LOG_SEVERITY_UNSET != default_level) { rmw_ret_t rmw_status = rmw_set_log_severity((rmw_log_severity_t)default_level); - if (RMW_RET_OK != rmw_status) { + if (RMW_RET_UNSUPPORTED == rmw_status) { + RCUTILS_SAFE_FWRITE_TO_STDERR("rmw_set_log_severity not supported by rmw implementation\n"); + } else if (RMW_RET_OK != rmw_status) { return RCL_RET_ERROR; } } From 90ed0db3e87f868b7bbe811e865585de20d9b742 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Mon, 3 May 2021 09:59:08 -0400 Subject: [PATCH 3/3] Add rmw_set_log_severity failure test Signed-off-by: Christophe Bedard --- rcl/test/rcl/test_logging.cpp | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/rcl/test/rcl/test_logging.cpp b/rcl/test/rcl/test_logging.cpp index 1ce2eda91..16cb9ce7e 100644 --- a/rcl/test/rcl/test_logging.cpp +++ b/rcl/test/rcl/test_logging.cpp @@ -28,6 +28,8 @@ #include "rcutils/logging_macros.h" +#include "rmw/rmw.h" + #include "../mocking_utils/patch.hpp" // Define dummy comparison operators for rcutils_allocator_t type @@ -195,6 +197,41 @@ TEST(TestLogging, test_failing_logger_level_configure) { } } +TEST(TestLogging, test_failing_rmw_set_log_severity) { + const char * argv[] = { + "test_logging", RCL_ROS_ARGS_FLAG, + RCL_LOG_LEVEL_FLAG, "debug"}; + const int argc = sizeof(argv) / sizeof(argv[0]); + rcl_allocator_t default_allocator = rcl_get_default_allocator(); + rcl_arguments_t global_arguments = rcl_get_zero_initialized_arguments(); + ASSERT_EQ(RCL_RET_OK, rcl_parse_arguments(argc, argv, default_allocator, &global_arguments)) << + rcl_get_error_string().str; + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( + { + EXPECT_EQ(RCL_RET_OK, rcl_arguments_fini(&global_arguments)) << rcl_get_error_string().str; + }); + + { + auto mock = mocking_utils::patch_to_fail( + "lib:rcl", rmw_set_log_severity, "failed", RMW_RET_ERROR); + EXPECT_EQ(RCL_RET_ERROR, rcl_logging_configure(&global_arguments, &default_allocator)); + EXPECT_TRUE(rcl_error_is_set()); + rcl_reset_error(); + + EXPECT_EQ(RCL_RET_OK, rcl_logging_fini()) << rcl_get_error_string().str; + } + + { + auto mock = mocking_utils::patch_to_fail( + "lib:rcl", rmw_set_log_severity, "not supported", RMW_RET_UNSUPPORTED); + EXPECT_EQ(RCL_RET_OK, rcl_logging_configure(&global_arguments, &default_allocator)); + EXPECT_TRUE(rcl_error_is_set()); + rcl_reset_error(); + + EXPECT_EQ(RCL_RET_OK, rcl_logging_fini()) << rcl_get_error_string().str; + } +} + TEST(TestLogging, test_failing_external_logging) { const char * argv[] = { "test_logging", RCL_ROS_ARGS_FLAG,