-
Notifications
You must be signed in to change notification settings - Fork 183
Add function to get publisher actual qos settings #406
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bf4296c
Add rcl_publisher_get_actual_qos function
ivanpauno 0f34fb7
Add test for rcl_publisher_get_actual_qos
ivanpauno 9551395
Modified doc string
ivanpauno cbd46cb
Corrected with PR comments
ivanpauno 6695ead
Correct RMW_IMPLEMENTATION checking. Add opensplice system default qo…
ivanpauno 2d7bb57
Add system default test for connext
ivanpauno c91a27b
Corrected with PR comments
ivanpauno 8c2cae2
Solve windows build problem
ivanpauno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,221 @@ | ||
| // 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 <gtest/gtest.h> | ||
wjwwood marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "rcl/error_handling.h" | ||
| #include "rcl/rcl.h" | ||
| #include "rcl/publisher.h" | ||
|
|
||
| #include "rcutils/logging_macros.h" | ||
|
|
||
| #include "test_msgs/msg/primitives.h" | ||
| #include "test_msgs/srv/primitives.h" | ||
|
|
||
| #define STRINGIFY_(x) #x | ||
| #define STRINGIFY(x) STRINGIFY_(x) | ||
|
||
|
|
||
| #ifdef RMW_IMPLEMENTATION | ||
| # define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX | ||
| # define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX) | ||
| # define RMW_IMPLEMENTATION_STR STRINGIFY(RMW_IMPLEMENTATION) | ||
| #else | ||
| # define CLASSNAME(NAME, SUFFIX) NAME | ||
| #endif | ||
|
|
||
| #define TEST_FIXTURE_P_RMW(test_fixture_name) CLASSNAME(test_fixture_name, \ | ||
| RMW_IMPLEMENTATION) | ||
| #define APPLY(macro, ...) 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, ...) APPLY( \ | ||
| INSTANTIATE_TEST_CASE_P, instance_name, CLASSNAME(test_case_name, \ | ||
| RMW_IMPLEMENTATION), __VA_ARGS__) | ||
|
|
||
| /** | ||
| * Parameterized test. | ||
| * The first param are the NodeOptions used to create the nodes. | ||
| * The second param are the expect intraprocess count results. | ||
| */ | ||
| struct TestParameters | ||
| { | ||
| rmw_qos_profile_t qos_to_set; | ||
| rmw_qos_profile_t qos_expected; | ||
| std::string description; | ||
| }; | ||
|
|
||
| std::ostream & operator<<( | ||
| std::ostream & out, | ||
| const TestParameters & params) | ||
| { | ||
| out << params.description; | ||
| return out; | ||
| } | ||
|
|
||
| class TEST_FIXTURE_P_RMW (TestGetActualQoS) | ||
| : public ::testing::TestWithParam<TestParameters> | ||
| { | ||
| public: | ||
| rcl_node_t * node_ptr; | ||
| rcl_context_t * context_ptr; | ||
| void SetUp() | ||
| { | ||
| rcl_ret_t ret; | ||
| rcl_node_options_t node_options = rcl_node_get_default_options(); | ||
|
|
||
| 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; | ||
| this->context_ptr = new rcl_context_t; | ||
| *this->context_ptr = rcl_get_zero_initialized_context(); | ||
| ret = rcl_init(0, nullptr, &init_options, this->context_ptr); | ||
| ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; | ||
| this->node_ptr = new rcl_node_t; | ||
| *this->node_ptr = rcl_get_zero_initialized_node(); | ||
| const char * name = "test_get_actual_qos_node"; | ||
| ret = rcl_node_init(this->node_ptr, name, "", this->context_ptr, &node_options); | ||
| ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; | ||
| } | ||
|
|
||
| void TearDown() | ||
| { | ||
| rcl_ret_t ret; | ||
|
|
||
| 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; | ||
| } | ||
| }; | ||
|
|
||
| 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; | ||
|
|
||
| rcl_publisher_t pub = rcl_get_zero_initialized_publisher(); | ||
| rcl_publisher_options_t pub_ops = rcl_publisher_get_default_options(); | ||
| pub_ops.qos = parameters.qos_to_set; | ||
| auto ts = ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, Primitives); | ||
| ret = rcl_publisher_init(&pub, this->node_ptr, ts, topic_name.c_str(), &pub_ops); | ||
| EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; | ||
| rcl_reset_error(); | ||
|
|
||
| rmw_qos_profile_t qos; | ||
| ret = rcl_publisher_get_actual_qos(&pub, &qos); | ||
| EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; | ||
| EXPECT_EQ( | ||
| qos.history, | ||
| parameters.qos_expected.history); | ||
| EXPECT_EQ( | ||
| qos.depth, | ||
| parameters.qos_expected.depth); | ||
| EXPECT_EQ( | ||
| qos.reliability, | ||
| parameters.qos_expected.reliability); | ||
| EXPECT_EQ( | ||
| qos.durability, | ||
| parameters.qos_expected.durability); | ||
| EXPECT_EQ( | ||
| 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(); | ||
| } | ||
|
|
||
| std::vector<TestParameters> | ||
| get_parameters() | ||
| { | ||
| std::vector<TestParameters> | ||
| parameters({ | ||
| /* | ||
| Testing with default qos settings. | ||
| */ | ||
| { | ||
| 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 | ||
| }, | ||
| { | ||
| RMW_QOS_POLICY_HISTORY_KEEP_ALL, | ||
| 1000, | ||
| RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT, | ||
| RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL, | ||
| true | ||
| }, | ||
| "publisher_non_default_qos" | ||
| } | ||
| }); | ||
|
|
||
| #ifdef RMW_IMPLEMENTATION_STR | ||
| std::string rmw_implementation_str = RMW_IMPLEMENTATION_STR; | ||
| if (!rmw_implementation_str.compare("rmw_fastrtps_cpp") || | ||
| !rmw_implementation_str.compare("rmw_fastrtps_dynamic_cpp")) | ||
| { | ||
| rmw_qos_profile_t expected_system_default_qos = { | ||
| RMW_QOS_POLICY_HISTORY_KEEP_LAST, | ||
| 1, | ||
| RMW_QOS_POLICY_RELIABILITY_RELIABLE, | ||
| RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL, | ||
| false}; | ||
| parameters.push_back({ | ||
| rmw_qos_profile_system_default, | ||
| expected_system_default_qos, | ||
| "publisher_system_default_qos"}); | ||
| } else if (!rmw_implementation_str.compare("rmw_opensplice_cpp") || | ||
| !rmw_implementation_str.compare("rmw_connext_cpp") || | ||
| !rmw_implementation_str.compare("rmw_connext_dynamic_cpp")) | ||
| { | ||
| rmw_qos_profile_t expected_system_default_qos = { | ||
| RMW_QOS_POLICY_HISTORY_KEEP_LAST, | ||
| 1, | ||
| RMW_QOS_POLICY_RELIABILITY_RELIABLE, | ||
| RMW_QOS_POLICY_DURABILITY_VOLATILE, | ||
| false}; | ||
| parameters.push_back({ | ||
| rmw_qos_profile_system_default, | ||
| expected_system_default_qos, | ||
| "publisher_system_default_qos"}); | ||
| } | ||
wjwwood marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #endif | ||
| return parameters; | ||
| } | ||
|
|
||
| INSTANTIATE_TEST_CASE_P_RMW( | ||
| TestWithDifferentQoSSettings, | ||
| TestGetActualQoS, | ||
| ::testing::ValuesIn(get_parameters()), | ||
| ::testing::PrintToStringParamName()); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether or not you need to do this, but you may need to use
rcl_publisher_is_valid_except_contexthere instead, depending on how/where we use this function in rclcpp. Basically right now, this function will fail afterrclcpp::shutdown()/rcl_shutdown()is called (or if SIGINT is received).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the right thing to do is to leave it as-is and explicitly handle/suppress this issue, e.g.:
https://github.com/ros2/rclcpp/blob/b352d450319e84dd28aed78b800ab40938cec5c2/rclcpp/include/rclcpp/publisher.hpp#L350-L353
Since this is just an accessor (should be possible to calculate this during init) then it is maybe ok to access it during post-shutdown?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I can do, is to call rcl_publisher_get_actual_qos in rcl_publisher_init, after creating the rmw publisher. Then, it's possible to store the corrected rcl_options, which could be accessed in post-shutdown.
rcl/rcl/src/rcl/publisher.c
Lines 167 to 175 in 03dec21
In that case, the method in rclcpp should be get_options, and get_actual_qos is unnecessary.
If not, the other option is to handle the error in rclcpp.
Any thoughts about which path take?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
get_options, should (in my opinion) return the original options used. I could be convinced otherwise, but for now, that's what I think.So in that light I'd say we still need
get_actual_qos.Why can't you just calculate the actual qos and store it separately (redundantly) during init?
Handling the error in rclcpp is possible, but only if it allows us to fail gracefully (not to be confused with silently). For instance, if we need to get the actual qos in order to decide the behavior of the publish function, you have to ask yourself what we'll do it it is unavailable, and if that mitigating action is ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me, I will add that.