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

Add function to get publisher actual qos settings #406

Merged
merged 8 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion rcl/include/rcl/publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,11 @@ rcl_publisher_get_subscription_count(
/// Get the actual qos settings of the publisher.
/**
* Used to get the actual qos settings of the publisher.
* This resolves what is the actual value of RMW_*_SYSTEM_DEFAULT.
* The actual configuration applied when using RMW_*_SYSTEM_DEFAULT
* can only be resolved after the creation of the publisher, and it
* depends on the underlying rmw implementation.
* If the underlying setting in use can't be represented in ROS terms,
* it will be set to RMW_*_UNKNOWN.
*
* <hr>
* Attribute | Adherence
Expand Down
2 changes: 1 addition & 1 deletion rcl/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function(test_target_function)
ENV ${rmw_implementation_env_var}
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
LIBRARIES ${PROJECT_NAME}
AMENT_DEPENDENCIES ${rmw_implementation} "osrf_testing_tools_cpp" "test_msgs"
AMENT_DEPENDENCIES ${rmw_implementation} "test_msgs"
)

rcl_add_custom_gtest(test_init${target_suffix}
Expand Down
122 changes: 76 additions & 46 deletions rcl/test/rcl/test_get_actual_qos.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 Open Source Robotics Foundation, Inc.
// 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.
Expand All @@ -11,11 +11,11 @@
// 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 <gtest/gtest.h>
wjwwood marked this conversation as resolved.
Show resolved Hide resolved

#include <chrono>
#include <string>
#include <thread>
#include <vector>

#include "rcl/error_handling.h"
#include "rcl/rcl.h"
Expand All @@ -42,29 +42,32 @@
INSTANTIATE_TEST_CASE_P, instance_name, CLASSNAME(test_case_name, \
RMW_IMPLEMENTATION), __VA_ARGS__)

// One const for each of the RMW_IMPLEMENTATION values
const char * rmw_fastrtps_cpp = "rmw_fastrtps_cpp";
const char * rmw_fastrtps_dynamic_cpp = "rmw_fastrtps_dynamic_cpp";
Copy link
Member

Choose a reason for hiding this comment

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

Are these used?

Copy link
Member Author

@ivanpauno ivanpauno Mar 26, 2019

Choose a reason for hiding this comment

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

RMW_IMPLEMENTATION is one of the symbols rmw_fastrtps_cpp, rmw_fastrtps_dynamic_cpp, etc, depending on the underlying rmw implementation being used (I will add the others when ending with each implementation).
Maybe it is not too clear, but I didn't have a better idea.

Copy link
Member Author

@ivanpauno ivanpauno Mar 26, 2019

Choose a reason for hiding this comment

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

To be clearer, one of them is used here:

// RMW_IMPLEMENTATION is one of the const char * defined above
if (std::string("rmw_fastrtps_cpp").compare(RMW_IMPLEMENTATION) ||
std::string("rmw_fastrtps_dynamic_cpp").compare(RMW_IMPLEMENTATION))

Copy link
Member

Choose a reason for hiding this comment

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

How are they used there? I see you're creating an std::string using a literal of the same name, but I don't see the const char * declared at the top of the file being used here...

Copy link
Member Author

Choose a reason for hiding this comment

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

RMW_IMPLEMENTATION was a token, not an string, which was exactly one of the const on the top of the file. A really bad idea. I solved this in a proper way now.


/**
* Parameterized test.
* The first param are the NodeOptions used to create the nodes.
* The second param are the expect intraprocess count results.
*/
struct CLASSNAME (TestParameters, RMW_IMPLEMENTATION)
struct TestParameters
{
rmw_qos_profile_t qos_to_set;
rmw_qos_profile_t qos_expected;
std::string description;
rmw_qos_profile_t qos_to_set;
rmw_qos_profile_t qos_expected;
std::string description;
};

std::ostream & operator<<(
std::ostream & out,
const CLASSNAME(TestParameters, RMW_IMPLEMENTATION) & params)
const TestParameters & params)
{
out << params.description;
return out;
}


class CLASSNAME (TestGetActualQoS, RMW_IMPLEMENTATION)
: public ::testing::TestWithParam<CLASSNAME(TestParameters, RMW_IMPLEMENTATION)>
class TEST_FIXTURE_P_RMW (TestGetActualQoS)
: public ::testing::TestWithParam<TestParameters>
{
public:
rcl_node_t * node_ptr;
Expand Down Expand Up @@ -105,9 +108,8 @@ class CLASSNAME (TestGetActualQoS, RMW_IMPLEMENTATION)
}
};

TEST_P(CLASSNAME(TestGetActualQoS, RMW_IMPLEMENTATION), test_publisher_get_qos_settings) {
CLASSNAME(TestParameters, RMW_IMPLEMENTATION) parameters =
GetParam();
TEST_P_RMW(TestGetActualQoS, test_publisher_get_qos_settings) {
TestParameters parameters = GetParam();
std::string topic_name("/test_publisher_get_actual_qos__");
rcl_ret_t ret;

Expand All @@ -123,59 +125,87 @@ TEST_P(CLASSNAME(TestGetActualQoS, RMW_IMPLEMENTATION), test_publisher_get_qos_s
ret = rcl_publisher_get_actual_qos(&pub, &qos);
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
EXPECT_EQ(
parameters.qos_to_set.history,
qos.history,
parameters.qos_expected.history);
EXPECT_EQ(
parameters.qos_to_set.depth,
qos.depth,
parameters.qos_expected.depth);
EXPECT_EQ(
parameters.qos_to_set.reliability,
qos.reliability,
parameters.qos_expected.reliability);
EXPECT_EQ(
parameters.qos_to_set.durability,
qos.durability,
parameters.qos_expected.durability);
EXPECT_EQ(
parameters.qos_to_set.avoid_ros_namespace_conventions,
qos.avoid_ros_namespace_conventions,
parameters.qos_expected.avoid_ros_namespace_conventions);

ret = rcl_publisher_fini(&pub, this->node_ptr);
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
rcl_reset_error();
}

CLASSNAME(TestParameters, RMW_IMPLEMENTATION) parameters[] = {
/*
Testing with default qos settings.
*/
{
rmw_qos_profile_default,
rmw_qos_profile_default,
"publisher_default_qos"
},
/*
Test with non-default settings.
*/
{
std::vector<TestParameters>
get_parameters()
{
std::vector<TestParameters>
parameters({
/*
Testing with default qos settings.
*/
{
RMW_QOS_POLICY_HISTORY_KEEP_ALL,
1000,
RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT,
RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL,
true
rmw_qos_profile_default,
rmw_qos_profile_default,
"publisher_default_qos"
},
/*
Test with non-default settings.
*/
{
RMW_QOS_POLICY_HISTORY_KEEP_ALL,
1000,
RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT,
RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL,
true
},
"publisher_non_default_qos"
{
RMW_QOS_POLICY_HISTORY_KEEP_ALL,
1000,
RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT,
RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL,
true
},
{
RMW_QOS_POLICY_HISTORY_KEEP_ALL,
1000,
RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT,
RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL,
true
},
"publisher_non_default_qos"
}
});
rmw_qos_profile_t expected_system_default_qos;

#ifdef RMW_IMPLEMENTATION
// RMW_IMPLEMENTATION is one of the const char * defined above
if (std::string("rmw_fastrtps_cpp").compare(RMW_IMPLEMENTATION) ||
std::string("rmw_fastrtps_dynamic_cpp").compare(RMW_IMPLEMENTATION))
{
expected_system_default_qos.history =
RMW_QOS_POLICY_HISTORY_KEEP_LAST;
expected_system_default_qos.depth = 1;
expected_system_default_qos.reliability =
RMW_QOS_POLICY_RELIABILITY_RELIABLE;
expected_system_default_qos.durability =
RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL;
expected_system_default_qos.avoid_ros_namespace_conventions =
false;
}
wjwwood marked this conversation as resolved.
Show resolved Hide resolved
};
parameters.push_back({
rmw_qos_profile_system_default,
expected_system_default_qos,
"publisher_system_default_qos"});
#endif
return parameters;
}

INSTANTIATE_TEST_CASE_P_RMW(
TestWithDifferentQoSSettings,
TestGetActualQoS,
::testing::ValuesIn(parameters),
::testing::ValuesIn(get_parameters()),
::testing::PrintToStringParamName());