Skip to content

Commit

Permalink
Add function for checking QoS profile compatibility (#180)
Browse files Browse the repository at this point in the history
* Add function for checking QoS profile compatibility

Connected to ros2/rmw#299

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Update tests

Unknown values no longer cause errors, but possibly warnings instead.
We can't test this since it is dependent on the RMW.

We can test for compatibility with no default or unknown values as well as invalid input.

Signed-off-by: Jacob Perron <jacob@openrobotics.org>
  • Loading branch information
jacobperron committed Mar 2, 2021
1 parent dadb0ec commit 3dab7b0
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
12 changes: 12 additions & 0 deletions rmw_implementation/src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,16 @@ RMW_INTERFACE_FN(
bool,
rmw_topic_endpoint_info_array_t *))

RMW_INTERFACE_FN(
rmw_qos_profile_check_compatible,
rmw_ret_t, RMW_RET_ERROR,
5, ARG_TYPES(
const rmw_qos_profile_t,
const rmw_qos_profile_t,
rmw_qos_compatibility_type_t *,
char *,
size_t))

#define GET_SYMBOL(x) symbol_ ## x = get_symbol(#x);

void prefetch_symbols(void)
Expand Down Expand Up @@ -676,6 +686,7 @@ void prefetch_symbols(void)
GET_SYMBOL(rmw_set_log_severity)
GET_SYMBOL(rmw_get_publishers_info_by_topic)
GET_SYMBOL(rmw_get_subscriptions_info_by_topic)
GET_SYMBOL(rmw_qos_profile_check_compatible)
}

void * symbol_rmw_init = nullptr;
Expand Down Expand Up @@ -775,6 +786,7 @@ unload_library()
symbol_rmw_set_log_severity = nullptr;
symbol_rmw_get_publishers_info_by_topic = nullptr;
symbol_rmw_get_subscriptions_info_by_topic = nullptr;
symbol_rmw_qos_profile_check_compatible = nullptr;
symbol_rmw_init = nullptr;
g_rmw_lib.reset();
}
10 changes: 10 additions & 0 deletions test_rmw_implementation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ if(BUILD_TESTING)
ament_target_dependencies(test_client${target_suffix}
osrf_testing_tools_cpp rcutils rmw rmw_implementation test_msgs
)

ament_add_gtest(test_qos_profile_check_compatible${target_suffix}
test/test_qos_profile_check_compatible.cpp
ENV ${rmw_implementation_env_var}
)
target_compile_definitions(test_qos_profile_check_compatible${target_suffix}
PUBLIC "RMW_IMPLEMENTATION=${rmw_implementation}")
ament_target_dependencies(test_qos_profile_check_compatible${target_suffix}
rmw rmw_implementation
)
endmacro()

call_for_each_rmw_implementation(test_api)
Expand Down
61 changes: 61 additions & 0 deletions test_rmw_implementation/test/test_qos_profile_check_compatible.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2021 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>

#include "rmw/qos_profiles.h"

#ifdef RMW_IMPLEMENTATION
# define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX
# define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX)
#else
# define CLASSNAME(NAME, SUFFIX) NAME
#endif

TEST(CLASSNAME(TestQoSProfilesAreCompatible, RMW_IMPLEMENTATION), compatible) {
// A profile without system default or unknown values should be compatible with itself
rmw_qos_profile_t qos = {
RMW_QOS_POLICY_HISTORY_KEEP_LAST,
5,
RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT,
RMW_QOS_POLICY_DURABILITY_VOLATILE,
{1, 0}, // deadline
{1, 0}, // lifespan
RMW_QOS_POLICY_LIVELINESS_AUTOMATIC,
{1, 0}, // liveliness lease duration
false
};
rmw_qos_compatibility_type_t compatible;
size_t reason_size = 100u;
char reason[100];
rmw_ret_t ret = rmw_qos_profile_check_compatible(qos, qos, &compatible, reason, reason_size);
EXPECT_EQ(ret, RMW_RET_OK);
EXPECT_EQ(compatible, RMW_QOS_COMPATIBILITY_OK);
}

TEST(CLASSNAME(TestQoSProfilesAreCompatible, RMW_IMPLEMENTATION), invalid_input) {
// Error on null 'compatible' parameter
{
rmw_ret_t ret = rmw_qos_profile_check_compatible(
rmw_qos_profile_sensor_data, rmw_qos_profile_sensor_data, nullptr, nullptr, 0u);
EXPECT_EQ(ret, RMW_RET_INVALID_ARGUMENT);
}
// Error on null reason and non-zero size
{
rmw_qos_compatibility_type_t compatible;
rmw_ret_t ret = rmw_qos_profile_check_compatible(
rmw_qos_profile_sensor_data, rmw_qos_profile_sensor_data, &compatible, nullptr, 1u);
EXPECT_EQ(ret, RMW_RET_INVALID_ARGUMENT);
}
}

0 comments on commit 3dab7b0

Please sign in to comment.