From f2fdb57f785817807d7def2553a474947a3f5887 Mon Sep 17 00:00:00 2001 From: Barry Xu Date: Wed, 23 Oct 2019 16:52:24 +0800 Subject: [PATCH 1/6] Add flag to enable/disable rosout logging in each node individually. Signed-off-by: Barry Xu --- rcl/include/rcl/node_options.h | 3 +++ rcl/src/rcl/node.c | 9 ++++++--- rcl/src/rcl/node_options.c | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/rcl/include/rcl/node_options.h b/rcl/include/rcl/node_options.h index 2512c9f04..69c174480 100644 --- a/rcl/include/rcl/node_options.h +++ b/rcl/include/rcl/node_options.h @@ -57,6 +57,9 @@ typedef struct rcl_node_options_t /// Command line arguments that apply only to this node. rcl_arguments_t arguments; + + /// Flag to disable rosout for this node + bool disable_rosout; } rcl_node_options_t; /// Return the default node options in a rcl_node_options_t. diff --git a/rcl/src/rcl/node.c b/rcl/src/rcl/node.c index 5522c790f..b048b7442 100644 --- a/rcl/src/rcl/node.c +++ b/rcl/src/rcl/node.c @@ -358,7 +358,7 @@ rcl_node_init( } // The initialization for the rosout publisher requires the node to be in initialized to a point // that it can create new topic publishers - if (rcl_logging_rosout_enabled()) { + if (rcl_logging_rosout_enabled() && !node->impl->options.disable_rosout) { ret = rcl_logging_rosout_init_publisher_for_node(node); if (ret != RCL_RET_OK) { // error message already set @@ -376,7 +376,10 @@ rcl_node_init( goto cleanup; fail: if (node->impl) { - if (rcl_logging_rosout_enabled() && node->impl->logger_name) { + if (rcl_logging_rosout_enabled() && + !node->impl->options.disable_rosout && + node->impl->logger_name) + { ret = rcl_logging_rosout_fini_publisher_for_node(node); RCUTILS_LOG_ERROR_EXPRESSION_NAMED((ret != RCL_RET_OK && ret != RCL_RET_NOT_INIT), ROS_PACKAGE_NAME, "Failed to fini publisher for node: %i", ret); @@ -443,7 +446,7 @@ rcl_node_fini(rcl_node_t * node) rcl_allocator_t allocator = node->impl->options.allocator; rcl_ret_t result = RCL_RET_OK; rcl_ret_t rcl_ret = RCL_RET_OK; - if (rcl_logging_rosout_enabled()) { + if (rcl_logging_rosout_enabled() && !node->impl->options.disable_rosout) { rcl_ret = rcl_logging_rosout_fini_publisher_for_node(node); if (rcl_ret != RCL_RET_OK && rcl_ret != RCL_RET_NOT_INIT) { RCL_SET_ERROR_MSG("Unable to fini publisher for node."); diff --git a/rcl/src/rcl/node_options.c b/rcl/src/rcl/node_options.c index 3d7eddcb9..8dc6b47a8 100644 --- a/rcl/src/rcl/node_options.c +++ b/rcl/src/rcl/node_options.c @@ -30,6 +30,7 @@ rcl_node_get_default_options() static rcl_node_options_t default_options = { .domain_id = RCL_NODE_OPTIONS_DEFAULT_DOMAIN_ID, .use_global_arguments = true, + .disable_rosout = false, }; // Must set the allocator after because it is not a compile time constant. default_options.allocator = rcl_get_default_allocator(); @@ -51,6 +52,7 @@ rcl_node_options_copy( options_out->domain_id = options->domain_id; options_out->allocator = options->allocator; options_out->use_global_arguments = options->use_global_arguments; + options_out->disable_rosout = options->disable_rosout; if (NULL != options->arguments.impl) { rcl_ret_t ret = rcl_arguments_copy(&(options->arguments), &(options_out->arguments)); return ret; From ba06e5d1a63a7b688184f70be89c736de586b78a Mon Sep 17 00:00:00 2001 From: Barry Xu Date: Tue, 29 Oct 2019 09:38:20 +0800 Subject: [PATCH 2/6] keep implementation consistency by using enable_rosout name Signed-off-by: Barry Xu --- rcl/include/rcl/node_options.h | 4 ++-- rcl/src/rcl/node.c | 6 +++--- rcl/src/rcl/node_options.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/rcl/include/rcl/node_options.h b/rcl/include/rcl/node_options.h index 69c174480..7f0941164 100644 --- a/rcl/include/rcl/node_options.h +++ b/rcl/include/rcl/node_options.h @@ -58,8 +58,8 @@ typedef struct rcl_node_options_t /// Command line arguments that apply only to this node. rcl_arguments_t arguments; - /// Flag to disable rosout for this node - bool disable_rosout; + /// Flag to enable rosout for this node + bool enable_rosout; } rcl_node_options_t; /// Return the default node options in a rcl_node_options_t. diff --git a/rcl/src/rcl/node.c b/rcl/src/rcl/node.c index b048b7442..aae446042 100644 --- a/rcl/src/rcl/node.c +++ b/rcl/src/rcl/node.c @@ -358,7 +358,7 @@ rcl_node_init( } // The initialization for the rosout publisher requires the node to be in initialized to a point // that it can create new topic publishers - if (rcl_logging_rosout_enabled() && !node->impl->options.disable_rosout) { + if (rcl_logging_rosout_enabled() && node->impl->options.enable_rosout) { ret = rcl_logging_rosout_init_publisher_for_node(node); if (ret != RCL_RET_OK) { // error message already set @@ -377,7 +377,7 @@ rcl_node_init( fail: if (node->impl) { if (rcl_logging_rosout_enabled() && - !node->impl->options.disable_rosout && + node->impl->options.enable_rosout && node->impl->logger_name) { ret = rcl_logging_rosout_fini_publisher_for_node(node); @@ -446,7 +446,7 @@ rcl_node_fini(rcl_node_t * node) rcl_allocator_t allocator = node->impl->options.allocator; rcl_ret_t result = RCL_RET_OK; rcl_ret_t rcl_ret = RCL_RET_OK; - if (rcl_logging_rosout_enabled() && !node->impl->options.disable_rosout) { + if (rcl_logging_rosout_enabled() && node->impl->options.enable_rosout) { rcl_ret = rcl_logging_rosout_fini_publisher_for_node(node); if (rcl_ret != RCL_RET_OK && rcl_ret != RCL_RET_NOT_INIT) { RCL_SET_ERROR_MSG("Unable to fini publisher for node."); diff --git a/rcl/src/rcl/node_options.c b/rcl/src/rcl/node_options.c index 8dc6b47a8..fa7880811 100644 --- a/rcl/src/rcl/node_options.c +++ b/rcl/src/rcl/node_options.c @@ -30,7 +30,7 @@ rcl_node_get_default_options() static rcl_node_options_t default_options = { .domain_id = RCL_NODE_OPTIONS_DEFAULT_DOMAIN_ID, .use_global_arguments = true, - .disable_rosout = false, + .enable_rosout = true, }; // Must set the allocator after because it is not a compile time constant. default_options.allocator = rcl_get_default_allocator(); @@ -52,7 +52,7 @@ rcl_node_options_copy( options_out->domain_id = options->domain_id; options_out->allocator = options->allocator; options_out->use_global_arguments = options->use_global_arguments; - options_out->disable_rosout = options->disable_rosout; + options_out->enable_rosout = options->enable_rosout; if (NULL != options->arguments.impl) { rcl_ret_t ret = rcl_arguments_copy(&(options->arguments), &(options_out->arguments)); return ret; From 44b0906fd9de7c6569720e6f3cb0b84f2880a45c Mon Sep 17 00:00:00 2001 From: Barry Xu Date: Mon, 25 Nov 2019 11:16:09 +0800 Subject: [PATCH 3/6] add test cases for logging and rosout Signed-off-by: Barry Xu --- rcl/test/CMakeLists.txt | 8 ++ rcl/test/rcl/test_logging_rosout.cpp | 189 +++++++++++++++++++++++++++ 2 files changed, 197 insertions(+) create mode 100644 rcl/test/rcl/test_logging_rosout.cpp diff --git a/rcl/test/CMakeLists.txt b/rcl/test/CMakeLists.txt index fe0642225..401cc3b62 100644 --- a/rcl/test/CMakeLists.txt +++ b/rcl/test/CMakeLists.txt @@ -206,6 +206,14 @@ function(test_target_function) AMENT_DEPENDENCIES ${rmw_implementation} "osrf_testing_tools_cpp" ) + rcl_add_custom_gtest(test_logging_rosout${target_suffix} + SRCS rcl/test_logging_rosout.cpp + ENV ${rmw_implementation_env_var} + APPEND_LIBRARY_DIRS ${extra_lib_dirs} + LIBRARIES ${PROJECT_NAME} + AMENT_DEPENDENCIES ${rmw_implementation} "osrf_testing_tools_cpp" "rcl_interfaces" + ) + rcl_add_custom_gtest(test_namespace${target_suffix} SRCS test_namespace.cpp ENV ${rmw_implementation_env_var} diff --git a/rcl/test/rcl/test_logging_rosout.cpp b/rcl/test/rcl/test_logging_rosout.cpp new file mode 100644 index 000000000..dd68629fa --- /dev/null +++ b/rcl/test/rcl/test_logging_rosout.cpp @@ -0,0 +1,189 @@ +// Copyright 2019 Open Source Robotics Foundation, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include +#include +#include + +#include "rcl/subscription.h" + +#include "rcl/rcl.h" + +#include "rcl_interfaces/msg/log.h" + +#include "osrf_testing_tools_cpp/scope_exit.hpp" +#include "rcl/error_handling.h" +#include "rcutils/logging_macros.h" + +#ifdef RMW_IMPLEMENTATION +# define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX +# define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX) +#else +# define CLASSNAME(NAME, SUFFIX) NAME +#endif + +class CLASSNAME (TestLoggingRosoutFixture, RMW_IMPLEMENTATION) : public ::testing::Test +{ +public: + rcl_context_t * context_ptr; + rcl_node_t * node_ptr; + rcl_subscription_t * subscription_ptr; + void SetUp(int argc, const char* argv[], bool enable_node_option_rosout) + { + rcl_ret_t ret; + rcl_init_options_t init_options = rcl_get_zero_initialized_init_options(); + ret = rcl_init_options_init(&init_options, rcl_get_default_allocator()); + ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ + EXPECT_EQ(RCL_RET_OK, rcl_init_options_fini(&init_options)) << rcl_get_error_string().str; + }); + this->context_ptr = new rcl_context_t; + *this->context_ptr = rcl_get_zero_initialized_context(); + + ret = rcl_init(argc, argv, &init_options, this->context_ptr); + ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + + // create node + rcl_node_options_t node_options = rcl_node_get_default_options(); + if (!enable_node_option_rosout) { + node_options.enable_rosout = enable_node_option_rosout; + } + const char * name = "test_rcl_node_logging_rosout"; + const char * namespace_ = "/ns"; + this->node_ptr = new rcl_node_t; + *this->node_ptr = rcl_get_zero_initialized_node(); + ret = rcl_node_init(this->node_ptr, name, namespace_, this->context_ptr, &node_options); + ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + + // create rosout subscription + const rosidl_message_type_support_t * ts = + ROSIDL_GET_MSG_TYPE_SUPPORT(rcl_interfaces, msg, Log); + const char * topic = "rosout"; + this->subscription_ptr = new rcl_subscription_t; + *this->subscription_ptr = rcl_get_zero_initialized_subscription(); + rcl_subscription_options_t subscription_options = rcl_subscription_get_default_options(); + ret = rcl_subscription_init(this->subscription_ptr, this->node_ptr, ts, topic, &subscription_options); + ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + } + + void TearDown() + { + rcl_ret_t ret = rcl_subscription_fini(this->subscription_ptr, this->node_ptr); + delete this->subscription_ptr; + EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + ret = rcl_node_fini(this->node_ptr); + delete this->node_ptr; + EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + ret = rcl_shutdown(this->context_ptr); + EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + ret = rcl_context_fini(this->context_ptr); + delete this->context_ptr; + EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + } +}; + +void +wait_for_subscription_to_be_ready( + rcl_subscription_t * subscription, + rcl_context_t * context, + size_t max_tries, + int64_t period_ms, + bool & success) +{ + rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set(); + rcl_ret_t ret = + rcl_wait_set_init(&wait_set, 1, 0, 0, 0, 0, 0, context, rcl_get_default_allocator()); + ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ + rcl_ret_t ret = rcl_wait_set_fini(&wait_set); + ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + }); + size_t iteration = 0; + do { + ++iteration; + ret = rcl_wait_set_clear(&wait_set); + ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + ret = rcl_wait_set_add_subscription(&wait_set, subscription, NULL); + ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + ret = rcl_wait(&wait_set, RCL_MS_TO_NS(period_ms)); + if (ret == RCL_RET_TIMEOUT) { + continue; + } + ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + for (size_t i = 0; i < wait_set.size_of_subscriptions; ++i) { + if (wait_set.subscriptions[i] && wait_set.subscriptions[i] == subscription) { + success = true; + return; + } + } + } while (iteration < max_tries); + success = false; +} + +/* Basic nominal test of having rosout logging globally enabled and locally enabled in a node + */ +TEST_F(CLASSNAME(TestLoggingRosoutFixture, RMW_IMPLEMENTATION), test_enable_global_rosout_enable_nodeoption) { + SetUp(0, nullptr, true); + + // log + RCUTILS_LOG_INFO_NAMED(rcl_node_get_logger_name(this->node_ptr), "SOMETHING"); + + bool success; + wait_for_subscription_to_be_ready(this->subscription_ptr, this->context_ptr, 10, 100, success); + ASSERT_TRUE(success); +} + + +/* Basic nominal test of having rosout logging globally enabled and locally disabled in a node + */ +TEST_F(CLASSNAME(TestLoggingRosoutFixture, RMW_IMPLEMENTATION), test_enable_global_rosout_disable_nodeoption) { + SetUp(0, nullptr, false); + + // log + RCUTILS_LOG_INFO_NAMED(rcl_node_get_logger_name(this->node_ptr), "SOMETHING"); + + bool success; + wait_for_subscription_to_be_ready(this->subscription_ptr, this->context_ptr, 10, 100, success); + ASSERT_FALSE(success); +} + +/* Basic nominal test of having rosout logging globally disabled and locally enabled in a node + */ +TEST_F(CLASSNAME(TestLoggingRosoutFixture, RMW_IMPLEMENTATION), test_disable_global_rosout_enable_nodeoption) { + const char* argv[] = {"--ros-args", "--disable-rosout-logs"}; + SetUp(2, argv, true); + + // log + RCUTILS_LOG_INFO_NAMED(rcl_node_get_logger_name(this->node_ptr), "SOMETHING"); + + bool success; + wait_for_subscription_to_be_ready(this->subscription_ptr, this->context_ptr, 10, 100, success); + ASSERT_FALSE(success); +} + +/* Basic nominal test of having rosout logging globally disabled and locally disabled in a node + */ +TEST_F(CLASSNAME(TestLoggingRosoutFixture, RMW_IMPLEMENTATION), test_disable_global_rosout_disable_nodeoption) { + const char* argv[] = {"--ros-args", "--disable-rosout-logs"}; + SetUp(2, argv, false); + + // log + RCUTILS_LOG_INFO_NAMED(rcl_node_get_logger_name(this->node_ptr), "SOMETHING"); + + bool success; + wait_for_subscription_to_be_ready(this->subscription_ptr, this->context_ptr, 10, 100, success); + ASSERT_FALSE(success); +} From e17a642a1b9e11551dd6157c39283d10585c0a6c Mon Sep 17 00:00:00 2001 From: Barry Xu Date: Wed, 27 Nov 2019 09:45:25 +0800 Subject: [PATCH 4/6] test with gtest of value-parameterized-tests feature Signed-off-by: Barry Xu --- rcl/test/rcl/test_logging_rosout.cpp | 185 ++++++++++++++++++--------- 1 file changed, 126 insertions(+), 59 deletions(-) diff --git a/rcl/test/rcl/test_logging_rosout.cpp b/rcl/test/rcl/test_logging_rosout.cpp index dd68629fa..c1b95e425 100644 --- a/rcl/test/rcl/test_logging_rosout.cpp +++ b/rcl/test/rcl/test_logging_rosout.cpp @@ -14,18 +14,14 @@ #include -#include #include -#include - -#include "rcl/subscription.h" - -#include "rcl/rcl.h" - -#include "rcl_interfaces/msg/log.h" +#include #include "osrf_testing_tools_cpp/scope_exit.hpp" #include "rcl/error_handling.h" +#include "rcl/rcl.h" +#include "rcl/subscription.h" +#include "rcl_interfaces/msg/log.h" #include "rcutils/logging_macros.h" #ifdef RMW_IMPLEMENTATION @@ -35,14 +31,42 @@ # define CLASSNAME(NAME, SUFFIX) NAME #endif -class CLASSNAME (TestLoggingRosoutFixture, RMW_IMPLEMENTATION) : public ::testing::Test +#define EXPAND(x) x +#define TEST_FIXTURE_P_RMW(test_fixture_name) CLASSNAME(test_fixture_name, \ + RMW_IMPLEMENTATION) +#define APPLY(macro, ...) EXPAND(macro(__VA_ARGS__)) +#define TEST_P_RMW(test_case_name, test_name) \ + APPLY(TEST_P, \ + CLASSNAME(test_case_name, RMW_IMPLEMENTATION), test_name) +#define INSTANTIATE_TEST_CASE_P_RMW(instance_name, test_case_name, ...) \ + EXPAND(APPLY(INSTANTIATE_TEST_CASE_P, instance_name, \ + CLASSNAME(test_case_name, RMW_IMPLEMENTATION), __VA_ARGS__)) + +struct TestParameters +{ + int argc; + const char** argv; + bool enable_node_option_rosout; + bool expected_success; + std::string description; +}; + +// for ::testing::PrintToStringParamName() to show the exact test case name +std::ostream & operator<<( + std::ostream & out, + const TestParameters & params) +{ + out << params.description; + return out; +} + +class TEST_FIXTURE_P_RMW(TestLoggingRosoutFixture) + : public ::testing::TestWithParam { public: - rcl_context_t * context_ptr; - rcl_node_t * node_ptr; - rcl_subscription_t * subscription_ptr; - void SetUp(int argc, const char* argv[], bool enable_node_option_rosout) + void SetUp() { + auto param = GetParam(); rcl_ret_t ret; rcl_init_options_t init_options = rcl_get_zero_initialized_init_options(); ret = rcl_init_options_init(&init_options, rcl_get_default_allocator()); @@ -53,13 +77,13 @@ class CLASSNAME (TestLoggingRosoutFixture, RMW_IMPLEMENTATION) : public ::testin this->context_ptr = new rcl_context_t; *this->context_ptr = rcl_get_zero_initialized_context(); - ret = rcl_init(argc, argv, &init_options, this->context_ptr); + ret = rcl_init(param.argc, param.argv, &init_options, this->context_ptr); ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; // create node rcl_node_options_t node_options = rcl_node_get_default_options(); - if (!enable_node_option_rosout) { - node_options.enable_rosout = enable_node_option_rosout; + if (!param.enable_node_option_rosout) { + node_options.enable_rosout = param.enable_node_option_rosout; } const char * name = "test_rcl_node_logging_rosout"; const char * namespace_ = "/ns"; @@ -75,7 +99,8 @@ class CLASSNAME (TestLoggingRosoutFixture, RMW_IMPLEMENTATION) : public ::testin this->subscription_ptr = new rcl_subscription_t; *this->subscription_ptr = rcl_get_zero_initialized_subscription(); rcl_subscription_options_t subscription_options = rcl_subscription_get_default_options(); - ret = rcl_subscription_init(this->subscription_ptr, this->node_ptr, ts, topic, &subscription_options); + ret = rcl_subscription_init( + this->subscription_ptr, this->node_ptr, ts, topic, &subscription_options); ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; } @@ -93,6 +118,11 @@ class CLASSNAME (TestLoggingRosoutFixture, RMW_IMPLEMENTATION) : public ::testin delete this->context_ptr; EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; } + +protected: + rcl_context_t * context_ptr; + rcl_node_t * node_ptr; + rcl_subscription_t * subscription_ptr; }; void @@ -133,57 +163,94 @@ wait_for_subscription_to_be_ready( success = false; } -/* Basic nominal test of having rosout logging globally enabled and locally enabled in a node - */ -TEST_F(CLASSNAME(TestLoggingRosoutFixture, RMW_IMPLEMENTATION), test_enable_global_rosout_enable_nodeoption) { - SetUp(0, nullptr, true); - - // log - RCUTILS_LOG_INFO_NAMED(rcl_node_get_logger_name(this->node_ptr), "SOMETHING"); - - bool success; - wait_for_subscription_to_be_ready(this->subscription_ptr, this->context_ptr, 10, 100, success); - ASSERT_TRUE(success); -} - - -/* Basic nominal test of having rosout logging globally enabled and locally disabled in a node +/* Testing the subscriber of topic 'rosout' whether to get event from logging or not. */ -TEST_F(CLASSNAME(TestLoggingRosoutFixture, RMW_IMPLEMENTATION), test_enable_global_rosout_disable_nodeoption) { - SetUp(0, nullptr, false); - +TEST_P_RMW(TestLoggingRosoutFixture, test_logging_rosout) { // log RCUTILS_LOG_INFO_NAMED(rcl_node_get_logger_name(this->node_ptr), "SOMETHING"); bool success; wait_for_subscription_to_be_ready(this->subscription_ptr, this->context_ptr, 10, 100, success); - ASSERT_FALSE(success); + ASSERT_EQ(success, GetParam().expected_success); } -/* Basic nominal test of having rosout logging globally disabled and locally enabled in a node - */ -TEST_F(CLASSNAME(TestLoggingRosoutFixture, RMW_IMPLEMENTATION), test_disable_global_rosout_enable_nodeoption) { - const char* argv[] = {"--ros-args", "--disable-rosout-logs"}; - SetUp(2, argv, true); +// +// create set of input and expected values +// +std::vector +get_parameters() +{ + std::vector parameters; + static int s_argc = 2; + static const char* s_argv_enable_rosout[] = {"--ros-args", "--enable-rosout-logs"}; + static const char* s_argv_disable_rosout[] = {"--ros-args", "--disable-rosout-logs"}; - // log - RCUTILS_LOG_INFO_NAMED(rcl_node_get_logger_name(this->node_ptr), "SOMETHING"); + /* + * Test with enable(implicit) global rosout logs and enable node option of rosout. + */ + parameters.push_back({ + 0, + nullptr, + true, + true, + "test_enable_implicit_global_rosout_enable_node_option" + }); + /* + * Test with enable(implicit) global rosout logs and disable node option of rosout. + */ + parameters.push_back({ + 0, + nullptr, + false, + false, + "test_enable_implicit_global_rosout_disable_node_option" + }); + /* + * Test with enable(explicit) global rosout logs and enable node option of rosout. + */ + parameters.push_back({ + s_argc, + s_argv_enable_rosout, + true, + true, + "test_enable_explicit_global_rosout_enable_node_option" + }); + /* + * Test with enable(implicit) global rosout logs and disable node option of rosout. + */ + parameters.push_back({ + s_argc, + s_argv_enable_rosout, + false, + false, + "test_enable_explicit_global_rosout_disable_node_option" + }); + /* + * Test with disable global rosout logs and enable node option of rosout. + */ + parameters.push_back({ + s_argc, + s_argv_disable_rosout, + true, + false, + "test_disable_global_rosout_enable_node_option" + }); + /* + * Test with disable global rosout logs and disable node option of rosout. + */ + parameters.push_back({ + s_argc, + s_argv_disable_rosout, + false, + false, + "test_disable_global_rosout_disable_node_option" + }); - bool success; - wait_for_subscription_to_be_ready(this->subscription_ptr, this->context_ptr, 10, 100, success); - ASSERT_FALSE(success); + return parameters; } -/* Basic nominal test of having rosout logging globally disabled and locally disabled in a node - */ -TEST_F(CLASSNAME(TestLoggingRosoutFixture, RMW_IMPLEMENTATION), test_disable_global_rosout_disable_nodeoption) { - const char* argv[] = {"--ros-args", "--disable-rosout-logs"}; - SetUp(2, argv, false); - - // log - RCUTILS_LOG_INFO_NAMED(rcl_node_get_logger_name(this->node_ptr), "SOMETHING"); - - bool success; - wait_for_subscription_to_be_ready(this->subscription_ptr, this->context_ptr, 10, 100, success); - ASSERT_FALSE(success); -} +INSTANTIATE_TEST_CASE_P_RMW( + TestLoggingRosoutWithDifferentSettings, + TestLoggingRosoutFixture, + ::testing::ValuesIn(get_parameters()), + ::testing::PrintToStringParamName()); From 6faac82f958b00edf1cfdc9ffd4e756d1674eb91 Mon Sep 17 00:00:00 2001 From: Barry Xu Date: Wed, 27 Nov 2019 17:54:42 +0800 Subject: [PATCH 5/6] update comments Signed-off-by: Barry Xu --- rcl/test/rcl/test_logging_rosout.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rcl/test/rcl/test_logging_rosout.cpp b/rcl/test/rcl/test_logging_rosout.cpp index c1b95e425..034391da9 100644 --- a/rcl/test/rcl/test_logging_rosout.cpp +++ b/rcl/test/rcl/test_logging_rosout.cpp @@ -216,7 +216,7 @@ get_parameters() "test_enable_explicit_global_rosout_enable_node_option" }); /* - * Test with enable(implicit) global rosout logs and disable node option of rosout. + * Test with enable(explicit) global rosout logs and disable node option of rosout. */ parameters.push_back({ s_argc, From 12c3dd4b41bbe602410698d4ca1c51f1587659f2 Mon Sep 17 00:00:00 2001 From: Barry Xu Date: Thu, 28 Nov 2019 09:36:17 +0800 Subject: [PATCH 6/6] fix uncrustify code Signed-off-by: Barry Xu --- rcl/test/rcl/test_logging_rosout.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rcl/test/rcl/test_logging_rosout.cpp b/rcl/test/rcl/test_logging_rosout.cpp index 034391da9..7d64060c2 100644 --- a/rcl/test/rcl/test_logging_rosout.cpp +++ b/rcl/test/rcl/test_logging_rosout.cpp @@ -45,7 +45,7 @@ struct TestParameters { int argc; - const char** argv; + const char ** argv; bool enable_node_option_rosout; bool expected_success; std::string description; @@ -60,7 +60,7 @@ std::ostream & operator<<( return out; } -class TEST_FIXTURE_P_RMW(TestLoggingRosoutFixture) +class TEST_FIXTURE_P_RMW (TestLoggingRosoutFixture) : public ::testing::TestWithParam { public: @@ -182,8 +182,8 @@ get_parameters() { std::vector parameters; static int s_argc = 2; - static const char* s_argv_enable_rosout[] = {"--ros-args", "--enable-rosout-logs"}; - static const char* s_argv_disable_rosout[] = {"--ros-args", "--disable-rosout-logs"}; + static const char * s_argv_enable_rosout[] = {"--ros-args", "--enable-rosout-logs"}; + static const char * s_argv_disable_rosout[] = {"--ros-args", "--disable-rosout-logs"}; /* * Test with enable(implicit) global rosout logs and enable node option of rosout.