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 messages with key to test_communication #542

Open
wants to merge 6 commits into
base: rolling
Choose a base branch
from
Open
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
28 changes: 24 additions & 4 deletions test_communication/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ if(BUILD_TESTING)
foreach(interface_file ${interface_files})
get_filename_component(interface_ns "${interface_file}" DIRECTORY)
get_filename_component(interface_ns "${interface_ns}" NAME)
string_ends_with("${interface_file}" ".msg" is_message)
if(is_message AND interface_ns STREQUAL "msg")
string_ends_with("${interface_file}" ".idl" is_idl)
if(is_idl AND interface_ns STREQUAL "msg")
Comment on lines +44 to +45
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this bug, that is unrelated to this original fix? .idl files are included in messages.

Copy link
Author

Choose a reason for hiding this comment

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

In a way, yes.
ros2/rcl_interfaces#162 uncovered a bug in this CMakeLists.txt file.
The code here is not considering the case where a message is directly defined in a .idl file.

I suppose I could make a separate PR with the changes in 486acce.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we can fix this with another PR, so that we can backport this fix to other distros.

Copy link
Author

Choose a reason for hiding this comment

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

See #549 for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

this can be removed from this PR after #549 is merged

list(APPEND message_files "${interface_file}")
continue()
endif()
Expand All @@ -51,8 +51,7 @@ if(BUILD_TESTING)
list(APPEND service_files "${interface_file}")
continue()
endif()
string_ends_with("${interface_file}" ".idl" is_action)
if(is_action AND interface_ns STREQUAL "action")
if(is_idl AND interface_ns STREQUAL "action")
list(APPEND action_files "${interface_file}")
continue()
endif()
Expand Down Expand Up @@ -204,6 +203,26 @@ if(BUILD_TESTING)
set(TEST_MESSAGE_TYPES "")
foreach(message_file ${message_files})
get_filename_component(message_type "${message_file}" NAME_WE)
set(message_has_keys FALSE)
if(
"${message_type}" STREQUAL "KeyedString" OR
"${message_type}" STREQUAL "ComplexNestedKey"
)
set(message_has_keys TRUE)
endif()

# TODO(MiguelCompany): Only fastrtps RMWs interoperate for keyed messages
if(
message_has_keys AND
(NOT "${rmw_implementation1}" STREQUAL "${rmw_implementation2}") AND
(
(NOT rmw_implementation1_is_fastrtps) OR
(NOT rmw_implementation2_is_fastrtps)
)
)
continue()
endif()

# TODO(dirk-thomas) WStrings published by FastRTPS can't be received
# correctly by Connext on macOS
if(
Expand Down Expand Up @@ -397,6 +416,7 @@ if(BUILD_TESTING)
add_library(subscribe_types STATIC
"test/subscribe_array_types.cpp"
"test/subscribe_basic_types.cpp"
"test/subscribe_key_types.cpp"
"test/subscribe_string_types.cpp")
target_link_libraries(subscribe_types
rclcpp::rclcpp
Expand Down
53 changes: 53 additions & 0 deletions test_communication/test/subscribe_key_types.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2024 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 <string>
#include <vector>

#include "rclcpp/rclcpp.hpp"
#include "test_msgs/msg/keyed_string.hpp"
#include "test_msgs/msg/non_keyed_with_nested_key.hpp"

#include "subscribe_helper.hpp"
#include "subscribe_key_types.hpp"

rclcpp::SubscriptionBase::SharedPtr subscribe_keyed_string(
rclcpp::Node::SharedPtr node,
const std::string & message_type,
const std::vector<test_msgs::msg::KeyedString::SharedPtr> & expected_messages,
std::vector<bool> & received_messages)
{
return subscribe<test_msgs::msg::KeyedString>(
node, message_type, expected_messages, received_messages);
}

rclcpp::SubscriptionBase::SharedPtr subscribe_non_keyed_with_nested_key(
rclcpp::Node::SharedPtr node,
const std::string & message_type,
const std::vector<test_msgs::msg::NonKeyedWithNestedKey::SharedPtr> & expected_messages,
std::vector<bool> & received_messages)
{
return subscribe<test_msgs::msg::NonKeyedWithNestedKey>(
node, message_type, expected_messages, received_messages);
}

rclcpp::SubscriptionBase::SharedPtr subscribe_complex_nested_key(
rclcpp::Node::SharedPtr node,
const std::string & message_type,
const std::vector<test_msgs::msg::ComplexNestedKey::SharedPtr> & expected_messages,
std::vector<bool> & received_messages)
{
return subscribe<test_msgs::msg::ComplexNestedKey>(
node, message_type, expected_messages, received_messages);
}
44 changes: 44 additions & 0 deletions test_communication/test/subscribe_key_types.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2024 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.

#ifndef SUBSCRIBE_KEY_TYPES_HPP_
#define SUBSCRIBE_KEY_TYPES_HPP_

#include <string>
#include <vector>

#include "rclcpp/rclcpp.hpp"
#include "test_msgs/msg/complex_nested_key.hpp"
#include "test_msgs/msg/keyed_string.hpp"
#include "test_msgs/msg/non_keyed_with_nested_key.hpp"

rclcpp::SubscriptionBase::SharedPtr subscribe_keyed_string(
rclcpp::Node::SharedPtr node,
const std::string & message_type,
const std::vector<test_msgs::msg::KeyedString::SharedPtr> & expected_messages,
std::vector<bool> & received_messages);

rclcpp::SubscriptionBase::SharedPtr subscribe_non_keyed_with_nested_key(
rclcpp::Node::SharedPtr node,
const std::string & message_type,
const std::vector<test_msgs::msg::NonKeyedWithNestedKey::SharedPtr> & expected_messages,
std::vector<bool> & received_messages);

rclcpp::SubscriptionBase::SharedPtr subscribe_complex_nested_key(
rclcpp::Node::SharedPtr node,
const std::string & message_type,
const std::vector<test_msgs::msg::ComplexNestedKey::SharedPtr> & expected_messages,
std::vector<bool> & received_messages);

#endif // SUBSCRIBE_KEY_TYPES_HPP_
7 changes: 7 additions & 0 deletions test_communication/test/test_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ int main(int argc, char ** argv)
publish<test_msgs::msg::Strings>(node, message, get_messages_strings());
} else if (message == "WStrings") {
publish<test_msgs::msg::WStrings>(node, message, get_messages_wstrings());
} else if (message == "KeyedString") {
publish<test_msgs::msg::KeyedString>(node, message, get_messages_keyed_string());
} else if (message == "NonKeyedWithNestedKey") {
publish<test_msgs::msg::NonKeyedWithNestedKey>(
node, message, get_messages_non_keyed_with_nested_key());
} else if (message == "ComplexNestedKey") {
publish<test_msgs::msg::ComplexNestedKey>(node, message, get_messages_complex_nested_key());
} else {
fprintf(stderr, "Unknown message argument '%s'\n", message.c_str());
rclcpp::shutdown();
Expand Down
16 changes: 16 additions & 0 deletions test_communication/test/test_publisher_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "subscribe_array_types.hpp"
#include "subscribe_basic_types.hpp"
#include "subscribe_key_types.hpp"
#include "subscribe_string_types.hpp"

template<typename T>
Expand Down Expand Up @@ -98,6 +99,9 @@ int main(int argc, char ** argv)
auto messages_defaults = get_messages_defaults();
auto messages_strings = get_messages_strings();
auto messages_wstrings = get_messages_wstrings();
auto messages_keyed_string = get_messages_keyed_string();
auto messages_non_keyed_with_nested_key = get_messages_non_keyed_with_nested_key();
auto messages_complex_nested_key = get_messages_complex_nested_key();

std::thread spin_thread([node]() {
rclcpp::spin(node);
Expand Down Expand Up @@ -148,6 +152,18 @@ int main(int argc, char ** argv)
} else if (message == "WStrings") {
subscriber = subscribe_wstrings(node, message, messages_wstrings, received_messages);
publish<test_msgs::msg::WStrings>(node, message, messages_wstrings);
} else if (message == "KeyedString") {
subscriber = subscribe_keyed_string(node, message, messages_keyed_string, received_messages);
publish<test_msgs::msg::KeyedString>(node, message, messages_keyed_string);
} else if (message == "NonKeyedWithNestedKey") {
subscriber = subscribe_non_keyed_with_nested_key(
node, message, messages_non_keyed_with_nested_key, received_messages);
publish<test_msgs::msg::NonKeyedWithNestedKey>(
node, message, messages_non_keyed_with_nested_key);
} else if (message == "ComplexNestedKey") {
subscriber = subscribe_complex_nested_key(
node, message, messages_complex_nested_key, received_messages);
publish<test_msgs::msg::ComplexNestedKey>(node, message, messages_complex_nested_key);
} else {
fprintf(stderr, "Unknown message argument '%s'\n", message.c_str());
return 1;
Expand Down
12 changes: 12 additions & 0 deletions test_communication/test/test_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "subscribe_array_types.hpp"
#include "subscribe_basic_types.hpp"
#include "subscribe_key_types.hpp"
#include "subscribe_string_types.hpp"

int main(int argc, char ** argv)
Expand Down Expand Up @@ -53,6 +54,9 @@ int main(int argc, char ** argv)
auto messages_defaults = get_messages_defaults();
auto messages_strings = get_messages_strings();
auto messages_wstrings = get_messages_wstrings();
auto messages_keyed_string = get_messages_keyed_string();
auto messages_non_keyed_with_nested_key = get_messages_non_keyed_with_nested_key();
auto messages_complex_nested_key = get_messages_complex_nested_key();

rclcpp::SubscriptionBase::SharedPtr subscriber;
std::vector<bool> received_messages; // collect flags about received messages
Expand Down Expand Up @@ -85,6 +89,14 @@ int main(int argc, char ** argv)
subscriber = subscribe_strings(node, message, messages_strings, received_messages);
} else if (message == "WStrings") {
subscriber = subscribe_wstrings(node, message, messages_wstrings, received_messages);
} else if (message == "KeyedString") {
subscriber = subscribe_keyed_string(node, message, messages_keyed_string, received_messages);
} else if (message == "NonKeyedWithNestedKey") {
subscriber = subscribe_non_keyed_with_nested_key(
node, message, messages_non_keyed_with_nested_key, received_messages);
} else if (message == "ComplexNestedKey") {
subscriber = subscribe_complex_nested_key(
node, message, messages_complex_nested_key, received_messages);
} else {
fprintf(stderr, "Unknown message argument '%s'\n", message.c_str());
rclcpp::shutdown();
Expand Down