Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aligh with rcl that a rosout publisher of a node might not exist #2357

Merged
merged 3 commits into from
Nov 15, 2023
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
11 changes: 6 additions & 5 deletions rclcpp/src/rclcpp/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <utility>

#include "rcl_logging_interface/rcl_logging_interface.h"
#include "rcl/error_handling.h"
#include "rcl/logging_rosout.h"

#include "rclcpp/exceptions.hpp"
Expand Down Expand Up @@ -80,10 +81,12 @@ Logger::get_child(const std::string & suffix)
{
std::lock_guard<std::recursive_mutex> guard(*logging_mutex);
rcl_ret = rcl_logging_rosout_add_sublogger((*name_).c_str(), suffix.c_str());
if (RCL_RET_OK != rcl_ret) {
if (RCL_RET_NOT_FOUND == rcl_ret) {
rcl_reset_error();
fujitatomoya marked this conversation as resolved.
Show resolved Hide resolved
} else if (RCL_RET_OK != rcl_ret) {
exceptions::throw_from_rcl_error(
rcl_ret, "failed to call rcl_logging_rosout_add_sublogger",
rcutils_get_error_state(), rcutils_reset_error);
rcl_get_error_state(), rcl_reset_error);
}
}

Expand All @@ -98,9 +101,7 @@ Logger::get_child(const std::string & suffix)
logger_sublogger_pairname_ptr->second.c_str());
delete logger_sublogger_pairname_ptr;
if (RCL_RET_OK != rcl_ret) {
exceptions::throw_from_rcl_error(
rcl_ret, "failed to call rcl_logging_rosout_remove_sublogger",
rcutils_get_error_state(), rcutils_reset_error);
rcl_reset_error();
}
});
}
Expand Down
10 changes: 10 additions & 0 deletions rclcpp/test/rclcpp/test_rosout_subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,13 @@ TEST_F(TestRosoutSubscription, test_rosoutsubscription_getchild_hierarchy) {
EXPECT_TRUE(future.get());
received_msg_promise = {};
}

TEST_F(TestRosoutSubscription, test_rosoutsubscription_node_rosout_disabled) {
rclcpp::NodeOptions options = rclcpp::NodeOptions().enable_rosout(false);
auto node = std::make_shared<rclcpp::Node>("my_node", options);
auto log_func = [&node] {
auto logger = node->get_logger().get_child("child");
RCLCPP_INFO(logger, "test");
};
ASSERT_NO_THROW(log_func());
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I need a lambda to call RCLCPP_INFO for ASSERT_NO_THROW because there is a compilication issue when I tested below,

  ASSERT_NO_THROW(
  {
    auto logger = node->get_logger().get_child("child");
    RCLCPP_INFO(logger, "test");
  });
RCLCPP_INFO not worked in ASSERT_NO_THROW

In file included from /home/chenlh/Projects/ROS2/ros2-master/local_build_test/rclcpp/include/rclcpp/logging.hpp:24,
                 from /home/chenlh/Projects/ROS2/ros2-master/src/ros2/rclcpp/rclcpp/include/rclcpp/copy_all_parameter_values.hpp:27,
                 from /home/chenlh/Projects/ROS2/ros2-master/src/ros2/rclcpp/rclcpp/include/rclcpp/rclcpp.hpp:171,
                 from /home/chenlh/Projects/ROS2/ros2-master/src/ros2/rclcpp/rclcpp/test/rclcpp/test_rosout_subscription.cpp:21:
/home/chenlh/Projects/ROS2/ros2-master/local_build_test/rclcpp/include/rclcpp/logging.hpp:527:5: error: macro "GTEST_TEST_NO_THROW_" passed 4 arguments, but takes just 2
  527 |     RCUTILS_LOG_INFO_NAMED( \
      |     ^~~~~~~~~~~~~~~~~~~~~~
/home/chenlh/Projects/ROS2/ros2-master/src/ros2/rclcpp/rclcpp/test/rclcpp/test_rosout_subscription.cpp:189:5: note: in expansion of macro ‘RCLCPP_INFO’
  189 |     RCLCPP_INFO(logger, "test");
      |     ^~~~~~~~~~~
In file included from /home/chenlh/Projects/ROS2/ros2-master/local_install_test/gtest_vendor/src/gtest_vendor/include/gtest/gtest.h:62,
                 from /home/chenlh/Projects/ROS2/ros2-master/src/ros2/rclcpp/rclcpp/test/rclcpp/test_rosout_subscription.cpp:15:
/home/chenlh/Projects/ROS2/ros2-master/local_install_test/gtest_vendor/src/gtest_vendor/include/gtest/internal/gtest-internal.h:1461: note: macro "GTEST_TEST_NO_THROW_" defined here
 1461 | #define GTEST_TEST_NO_THROW_(statement, fail) \
      | 
In file included from /home/chenlh/Projects/ROS2/ros2-master/src/ros2/rclcpp/rclcpp/test/rclcpp/test_rosout_subscription.cpp:15:
/home/chenlh/Projects/ROS2/ros2-master/src/ros2/rclcpp/rclcpp/test/rclcpp/test_rosout_subscription.cpp: In member function ‘virtual void TestRosoutSubscription_test_rosoutsubscription_node_rosout_disabled_Test::TestBody()’:
/home/chenlh/Projects/ROS2/ros2-master/src/ros2/rclcpp/rclcpp/test/rclcpp/test_rosout_subscription.cpp:185:3: error: ‘GTEST_TEST_NO_THROW_’ was not declared in this scope
  185 |   ASSERT_NO_THROW(
      |   ^~~~~~~~~~~~~~~
gmake[2]: *** [test/rclcpp/CMakeFiles/test_rosout_subscription.dir/build.make:76: test/rclcpp/CMakeFiles/test_rosout_subscription.dir/test_rosout_subscription.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:4078: test/rclcpp/CMakeFiles/test_rosout_subscription.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
---
--- stderr: rclcpp
In file included from /home/chenlh/Projects/ROS2/ros2-master/local_build_test/rclcpp/include/rclcpp/logging.hpp:24,
                 from /home/chenlh/Projects/ROS2/ros2-master/src/ros2/rclcpp/rclcpp/include/rclcpp/copy_all_parameter_values.hpp:27,
                 from /home/chenlh/Projects/ROS2/ros2-master/src/ros2/rclcpp/rclcpp/include/rclcpp/rclcpp.hpp:171,
                 from /home/chenlh/Projects/ROS2/ros2-master/src/ros2/rclcpp/rclcpp/test/rclcpp/test_rosout_subscription.cpp:21:
/home/chenlh/Projects/ROS2/ros2-master/local_build_test/rclcpp/include/rclcpp/logging.hpp:527:5: error: macro "GTEST_TEST_NO_THROW_" passed 4 arguments, but takes just 2
  527 |     RCUTILS_LOG_INFO_NAMED( \
      |     ^~~~~~~~~~~~~~~~~~~~~~
/home/chenlh/Projects/ROS2/ros2-master/src/ros2/rclcpp/rclcpp/test/rclcpp/test_rosout_subscription.cpp:189:5: note: in expansion of macro ‘RCLCPP_INFO’
  189 |     RCLCPP_INFO(logger, "test");
      |     ^~~~~~~~~~~
In file included from /home/chenlh/Projects/ROS2/ros2-master/local_install_test/gtest_vendor/src/gtest_vendor/include/gtest/gtest.h:62,
                 from /home/chenlh/Projects/ROS2/ros2-master/src/ros2/rclcpp/rclcpp/test/rclcpp/test_rosout_subscription.cpp:15:
/home/chenlh/Projects/ROS2/ros2-master/local_install_test/gtest_vendor/src/gtest_vendor/include/gtest/internal/gtest-internal.h:1461: note: macro "GTEST_TEST_NO_THROW_" defined here
 1461 | #define GTEST_TEST_NO_THROW_(statement, fail) \
      | 
In file included from /home/chenlh/Projects/ROS2/ros2-master/src/ros2/rclcpp/rclcpp/test/rclcpp/test_rosout_subscription.cpp:15:
/home/chenlh/Projects/ROS2/ros2-master/src/ros2/rclcpp/rclcpp/test/rclcpp/test_rosout_subscription.cpp: In member function ‘virtual void TestRosoutSubscription_test_rosoutsubscription_node_rosout_disabled_Test::TestBody()’:
/home/chenlh/Projects/ROS2/ros2-master/src/ros2/rclcpp/rclcpp/test/rclcpp/test_rosout_subscription.cpp:185:3: error: ‘GTEST_TEST_NO_THROW_’ was not declared in this scope
  185 |   ASSERT_NO_THROW(
      |   ^~~~~~~~~~~~~~~
gmake[2]: *** [test/rclcpp/CMakeFiles/test_rosout_subscription.dir/build.make:76: test/rclcpp/CMakeFiles/test_rosout_subscription.dir/test_rosout_subscription.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:4078: test/rclcpp/CMakeFiles/test_rosout_subscription.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
---
Failed   <<< rclcpp [5.24s, exited with code 2]

}