diff --git a/rclcpp/include/rclcpp/any_subscription_callback.hpp b/rclcpp/include/rclcpp/any_subscription_callback.hpp index 728da63e73..061ded9c4b 100644 --- a/rclcpp/include/rclcpp/any_subscription_callback.hpp +++ b/rclcpp/include/rclcpp/any_subscription_callback.hpp @@ -16,6 +16,7 @@ #define RCLCPP__ANY_SUBSCRIPTION_CALLBACK_HPP_ #include +#include //TODO remove when removed std::cout s #include #include #include @@ -686,21 +687,21 @@ class AnySubscriptionCallback std::is_same_v )) { - callback(message); + // callback(message); //TODO Convert } else if constexpr ( // NOLINT[readability/braces] is_ta && ( std::is_same_v|| std::is_same_v )) { - callback(message, message_info); + // callback(message, message_info); //TODO Convert } else if constexpr ( // NOLINT[readability/braces] is_ta && ( std::is_same_v|| std::is_same_v )) { - callback(message); + // callback(message); //TODO Convert } else if constexpr ( // NOLINT[readability/braces] is_ta && ( std::is_same_v|| @@ -711,29 +712,29 @@ class AnySubscriptionCallback } // conditions for ros message type else if constexpr (std::is_same_v) { // NOLINT - callback(*message); + //callback(*message); //TODO convert to rosMessage } else if constexpr (std::is_same_v) { - callback(*message, message_info); + //callback(*message, message_info); //TODO convert to rosMessage } else if constexpr ( // NOLINT[readability/braces] std::is_same_v|| std::is_same_v) { - callback(create_ros_unique_ptr_from_ros_shared_ptr_message(message)); + // callback(create_ros_unique_ptr_from_ros_shared_ptr_message(message)); } else if constexpr ( // NOLINT[readability/braces] std::is_same_v|| std::is_same_v) { - callback(create_ros_unique_ptr_from_ros_shared_ptr_message(message), message_info); + // callback(create_ros_unique_ptr_from_ros_shared_ptr_message(message), message_info); } else if constexpr ( // NOLINT[readability/braces] std::is_same_v|| std::is_same_v) { - callback(message); + // callback(message); } else if constexpr ( // NOLINT[readability/braces] std::is_same_v|| std::is_same_v) { - callback(message, message_info); + // callback(message, message_info); } // condition to catch SerializedMessage types else if constexpr ( // NOLINT[readability/braces] @@ -765,6 +766,9 @@ class AnySubscriptionCallback std::unique_ptr message, const rclcpp::MessageInfo & message_info) { + + std::cout << "ASC dispatch_intra_process" << std::endl; + TRACEPOINT(callback_start, static_cast(this), true); // Check if the variant is "unset", throw if it is. if (callback_variant_.index() == 0) { @@ -779,13 +783,17 @@ class AnySubscriptionCallback using T = std::decay_t; static constexpr bool is_ta = rclcpp::TypeAdapter::is_specialized::value; + std::cout << "IS TA: " << is_ta << std::endl; + // conditions for custom type if constexpr (is_ta && std::is_same_v) { //We won't need to convert //auto local_message = convert_ros_message_to_custom_type_unique_ptr(*message); + std::cout << "ASC crcb" << std::endl; callback(*message); } else if constexpr (is_ta && std::is_same_v) { // NOLINT //auto local_message = convert_ros_message_to_custom_type_unique_ptr(*message); + std::cout << "ASC crcb+info" << std::endl; callback(*message, message_info); } else if constexpr ( // NOLINT[readability/braces] is_ta && ( @@ -793,58 +801,62 @@ class AnySubscriptionCallback std::is_same_v )) { + std::cout << "ASC unorshcb" << std::endl; //callback(convert_ros_message_to_custom_type_unique_ptr(*message)); - callback(message); + callback(std::move(message)); //TODO convert } else if constexpr ( // NOLINT[readability/braces] is_ta && ( std::is_same_v|| std::is_same_v )) { + std::cout << "ASC unorshcb+info" << std::endl; //callback(convert_ros_message_to_custom_type_unique_ptr(*message), message_info); - callback(message, message_info); + callback(std::move(message), message_info); //TODO convert } else if constexpr ( // NOLINT[readability/braces] is_ta && ( std::is_same_v|| std::is_same_v )) { + std::cout << "ASC shconsrref" << std::endl; //callback(convert_ros_message_to_custom_type_unique_ptr(*message)); - callback(message); + // callback(message); //TODO Convert } else if constexpr ( // NOLINT[readability/braces] is_ta && ( std::is_same_v|| std::is_same_v )) { + std::cout << "ASC shconsrref+info" << std::endl; //callback(convert_ros_message_to_custom_type_unique_ptr(*message), message_info); - callback(message, message_info); + //callback(message, message_info); //TODO Convert } // conditions for ros message type else if constexpr (std::is_same_v) { // NOLINT - callback(*message); + //callback(*message); } else if constexpr (std::is_same_v) { - callback(*message, message_info); + // callback(*message, message_info); } else if constexpr ( // NOLINT[readability/braces] std::is_same_v|| std::is_same_v) { - callback(std::move(message)); + // callback(std::move(message)); } else if constexpr ( // NOLINT[readability/braces] std::is_same_v|| std::is_same_v) { - callback(std::move(message), message_info); + // callback(std::move(message), message_info); } else if constexpr ( // NOLINT[readability/braces] std::is_same_v|| std::is_same_v) { - callback(std::move(message)); + // callback(std::move(message)); } else if constexpr ( // NOLINT[readability/braces] std::is_same_v|| std::is_same_v) { - callback(std::move(message), message_info); + // callback(std::move(message), message_info); } // condition to catch SerializedMessage types else if constexpr ( // NOLINT[readability/braces] diff --git a/rclcpp/include/rclcpp/experimental/intra_process_manager.hpp b/rclcpp/include/rclcpp/experimental/intra_process_manager.hpp index f60c796886..5cc0b83db7 100644 --- a/rclcpp/include/rclcpp/experimental/intra_process_manager.hpp +++ b/rclcpp/include/rclcpp/experimental/intra_process_manager.hpp @@ -427,12 +427,18 @@ class IntraProcessManager throw std::runtime_error("subscription has unexpectedly gone out of scope"); } auto subscription_base = subscription_it->second.lock(); + std::cout << "Subscription Base?" << std::endl; if (subscription_base) { + + std::cout << "Typed Subscription" << std::endl; + auto subscription = std::dynamic_pointer_cast< rclcpp::experimental::SubscriptionIntraProcessBuffer >(subscription_base); if (nullptr == subscription) { + std::cout << "ROSMessage Subscription" << std::endl; + auto ros_message_subscription = std::dynamic_pointer_cast< rclcpp::experimental::ROSMessageIntraProcessBuffer >(subscription_base); @@ -445,6 +451,8 @@ class IntraProcessManager "allocator types, which is not supported"); } else { + std::cout << "ROSMessage TypeAdapted Subscription" << std::endl; + using ROSMessageType = typename rclcpp::TypeAdapter::ros_message_type; if constexpr (rclcpp::TypeAdapter::is_specialized::value) { @@ -474,7 +482,7 @@ class IntraProcessManager } } else { - + std::cout << "Typed Subscription" << std::endl; if (std::next(it) == subscription_ids.end()) { // If this is the last subscription, give up ownership subscription->provide_intra_process_data(std::move(message)); @@ -491,6 +499,7 @@ class IntraProcessManager } } else { + std::cout << "Erasing subscription" << std::endl; subscriptions_.erase(subscription_it); } } diff --git a/rclcpp/include/rclcpp/experimental/subscription_intra_process_buffer.hpp b/rclcpp/include/rclcpp/experimental/subscription_intra_process_buffer.hpp index 954d6ea4a4..2874c321b8 100644 --- a/rclcpp/include/rclcpp/experimental/subscription_intra_process_buffer.hpp +++ b/rclcpp/include/rclcpp/experimental/subscription_intra_process_buffer.hpp @@ -18,10 +18,11 @@ #include #include +#include //TODO remove #include #include -#include #include +#include #include #include "rcl/error_handling.h" @@ -106,6 +107,8 @@ class SubscriptionIntraProcessBuffer : public ROSMessageIntraProcessBuffer::is_specialized::value) { buffer_->add_shared(std::move(message)); trigger_guard_condition(); @@ -120,7 +123,7 @@ class SubscriptionIntraProcessBuffer : public ROSMessageIntraProcessBuffer::is_specialized::value) { buffer_->add_unique(std::move(message)); trigger_guard_condition(); @@ -137,6 +140,7 @@ class SubscriptionIntraProcessBuffer : public ROSMessageIntraProcessBufferadd_shared(std::move(message)); trigger_guard_condition(); } @@ -144,6 +148,7 @@ class SubscriptionIntraProcessBuffer : public ROSMessageIntraProcessBufferadd_unique(std::move(message)); trigger_guard_condition(); } diff --git a/rclcpp/include/rclcpp/subscription.hpp b/rclcpp/include/rclcpp/subscription.hpp index 9d4d92315a..af82c860b4 100644 --- a/rclcpp/include/rclcpp/subscription.hpp +++ b/rclcpp/include/rclcpp/subscription.hpp @@ -408,7 +408,8 @@ class Subscription : public SubscriptionBase using SubscriptionIntraProcessT = rclcpp::experimental::SubscriptionIntraProcess< SubscribedType, AllocatorT, - SubscribedTypeDeleter>; + SubscribedTypeDeleter, + MessageT>; std::shared_ptr subscription_intra_process_; }; diff --git a/rclcpp/test/rclcpp/CMakeLists.txt b/rclcpp/test/rclcpp/CMakeLists.txt index c8292a530b..4762bc5d27 100644 --- a/rclcpp/test/rclcpp/CMakeLists.txt +++ b/rclcpp/test/rclcpp/CMakeLists.txt @@ -15,391 +15,6 @@ rosidl_generate_interfaces(${PROJECT_NAME}_test_msgs # Need the target name to depend on generated interface libraries rosidl_get_typesupport_target(cpp_typesupport_target "${PROJECT_NAME}_test_msgs" "rosidl_typesupport_cpp") -ament_add_gtest( - test_allocator_common - allocator/test_allocator_common.cpp) -if(TARGET test_allocator_common) - target_link_libraries(test_allocator_common ${PROJECT_NAME}) -endif() -ament_add_gtest( - test_allocator_deleter - allocator/test_allocator_deleter.cpp) -if(TARGET test_allocator_deleter) - target_link_libraries(test_allocator_deleter ${PROJECT_NAME}) -endif() -ament_add_gtest( - test_exceptions - exceptions/test_exceptions.cpp) -if(TARGET test_exceptions) - target_link_libraries(test_exceptions ${PROJECT_NAME} mimick) -endif() - -# Increasing timeout because connext can take a long time to destroy nodes -# TODO(brawner) remove when destroying Node for Connext is resolved. See: -# https://github.com/ros2/rclcpp/issues/1250 -ament_add_gtest( - test_allocator_memory_strategy - strategies/test_allocator_memory_strategy.cpp - TIMEOUT 360) -if(TARGET test_allocator_memory_strategy) - ament_target_dependencies(test_allocator_memory_strategy - "rcl" - "test_msgs" - ) - target_link_libraries(test_allocator_memory_strategy ${PROJECT_NAME}) -endif() -ament_add_gtest(test_message_pool_memory_strategy strategies/test_message_pool_memory_strategy.cpp) -if(TARGET test_message_pool_memory_strategy) - ament_target_dependencies(test_message_pool_memory_strategy - "rcl" - "test_msgs" - ) - target_link_libraries(test_message_pool_memory_strategy ${PROJECT_NAME}) -endif() -ament_add_gtest(test_any_service_callback test_any_service_callback.cpp) -if(TARGET test_any_service_callback) - ament_target_dependencies(test_any_service_callback - "test_msgs" - ) - target_link_libraries(test_any_service_callback ${PROJECT_NAME}) -endif() -ament_add_gtest(test_any_subscription_callback test_any_subscription_callback.cpp) -if(TARGET test_any_subscription_callback) - ament_target_dependencies(test_any_subscription_callback - "test_msgs" - ) - target_link_libraries(test_any_subscription_callback ${PROJECT_NAME}) -endif() -ament_add_gtest(test_client test_client.cpp) -if(TARGET test_client) - ament_target_dependencies(test_client - "rcl_interfaces" - "rmw" - "rosidl_runtime_cpp" - "rosidl_typesupport_cpp" - "test_msgs" - ) - target_link_libraries(test_client ${PROJECT_NAME} mimick) -endif() -ament_add_gtest(test_create_timer test_create_timer.cpp) -if(TARGET test_create_timer) - ament_target_dependencies(test_create_timer - "rcl_interfaces" - "rmw" - "rcl" - "rosidl_runtime_cpp" - "rosidl_typesupport_cpp" - ) - target_link_libraries(test_create_timer ${PROJECT_NAME}) - target_include_directories(test_create_timer PRIVATE ./) -endif() -ament_add_gtest(test_create_subscription test_create_subscription.cpp) -if(TARGET test_create_subscription) - target_link_libraries(test_create_subscription ${PROJECT_NAME}) - ament_target_dependencies(test_create_subscription - "test_msgs" - ) -endif() -ament_add_gtest(test_add_callback_groups_to_executor - test_add_callback_groups_to_executor.cpp - TIMEOUT 120) -if(TARGET test_add_callback_groups_to_executor) - target_link_libraries(test_add_callback_groups_to_executor ${PROJECT_NAME}) - ament_target_dependencies(test_add_callback_groups_to_executor - "test_msgs" - ) -endif() -ament_add_gtest(test_expand_topic_or_service_name test_expand_topic_or_service_name.cpp) -if(TARGET test_expand_topic_or_service_name) - ament_target_dependencies(test_expand_topic_or_service_name - "rcl_interfaces" - "rmw" - "rosidl_runtime_cpp" - "rosidl_typesupport_cpp" - ) - target_link_libraries(test_expand_topic_or_service_name ${PROJECT_NAME} mimick) -endif() -ament_add_gtest(test_function_traits test_function_traits.cpp) -if(TARGET test_function_traits) - target_include_directories(test_function_traits PUBLIC ../../include) - ament_target_dependencies(test_function_traits - "rcl_interfaces" - "rmw" - "rosidl_runtime_cpp" - "rosidl_typesupport_cpp" - ) -endif() -ament_add_gtest( - test_future_return_code - test_future_return_code.cpp) -if(TARGET test_future_return_code) - target_link_libraries(test_future_return_code ${PROJECT_NAME}) -endif() -ament_add_gmock(test_intra_process_manager test_intra_process_manager.cpp) -if(TARGET test_intra_process_manager) - ament_target_dependencies(test_intra_process_manager - "rcl" - "rcl_interfaces" - "rmw" - "rosidl_runtime_cpp" - "rosidl_typesupport_cpp" - ) - target_link_libraries(test_intra_process_manager ${PROJECT_NAME}) -endif() -ament_add_gmock(test_intra_process_manager_with_allocators test_intra_process_manager_with_allocators.cpp) -if(TARGET test_intra_process_manager_with_allocators) - ament_target_dependencies(test_intra_process_manager_with_allocators - "test_msgs" - ) - target_link_libraries(test_intra_process_manager_with_allocators ${PROJECT_NAME}) -endif() -ament_add_gtest(test_ring_buffer_implementation test_ring_buffer_implementation.cpp) -if(TARGET test_ring_buffer_implementation) - ament_target_dependencies(test_ring_buffer_implementation - "rcl_interfaces" - "rmw" - "rosidl_runtime_cpp" - "rosidl_typesupport_cpp" - ) - target_link_libraries(test_ring_buffer_implementation ${PROJECT_NAME}) -endif() -ament_add_gtest(test_intra_process_buffer test_intra_process_buffer.cpp) -if(TARGET test_intra_process_buffer) - ament_target_dependencies(test_intra_process_buffer - "rcl_interfaces" - "rmw" - "rosidl_runtime_cpp" - "rosidl_typesupport_cpp" - ) - target_link_libraries(test_intra_process_buffer ${PROJECT_NAME}) -endif() - -ament_add_gtest(test_loaned_message test_loaned_message.cpp) -ament_target_dependencies(test_loaned_message - "test_msgs" -) -target_link_libraries(test_loaned_message ${PROJECT_NAME} mimick) - -ament_add_gtest(test_memory_strategy test_memory_strategy.cpp) -ament_target_dependencies(test_memory_strategy - "test_msgs" -) -target_link_libraries(test_memory_strategy ${PROJECT_NAME}) - -ament_add_gtest(test_message_memory_strategy test_message_memory_strategy.cpp) -ament_target_dependencies(test_message_memory_strategy - "test_msgs" -) -target_link_libraries(test_message_memory_strategy ${PROJECT_NAME}) - -ament_add_gtest(test_node test_node.cpp TIMEOUT 240) -if(TARGET test_node) - ament_target_dependencies(test_node - "rcl_interfaces" - "rcpputils" - "rmw" - "rosidl_runtime_cpp" - "rosidl_typesupport_cpp" - "test_msgs" - ) - target_link_libraries(test_node ${PROJECT_NAME} mimick) -endif() - -ament_add_gtest(test_node_interfaces__get_node_interfaces - node_interfaces/test_get_node_interfaces.cpp) -if(TARGET test_node_interfaces__get_node_interfaces) - target_link_libraries(test_node_interfaces__get_node_interfaces ${PROJECT_NAME}) -endif() -ament_add_gtest(test_node_interfaces__node_base - node_interfaces/test_node_base.cpp) -if(TARGET test_node_interfaces__node_base) - target_link_libraries(test_node_interfaces__node_base ${PROJECT_NAME} mimick) -endif() -ament_add_gtest(test_node_interfaces__node_clock - node_interfaces/test_node_clock.cpp) -if(TARGET test_node_interfaces__node_clock) - target_link_libraries(test_node_interfaces__node_clock ${PROJECT_NAME}) -endif() -ament_add_gtest(test_node_interfaces__node_graph - node_interfaces/test_node_graph.cpp - TIMEOUT 120) -if(TARGET test_node_interfaces__node_graph) - ament_target_dependencies( - test_node_interfaces__node_graph - "test_msgs") - target_link_libraries(test_node_interfaces__node_graph ${PROJECT_NAME} mimick) -endif() -ament_add_gtest(test_node_interfaces__node_parameters - node_interfaces/test_node_parameters.cpp) -if(TARGET test_node_interfaces__node_parameters) - target_link_libraries(test_node_interfaces__node_parameters ${PROJECT_NAME} mimick) -endif() -ament_add_gtest(test_node_interfaces__node_services - node_interfaces/test_node_services.cpp) -if(TARGET test_node_interfaces__node_services) - target_link_libraries(test_node_interfaces__node_services ${PROJECT_NAME} mimick) -endif() -ament_add_gtest(test_node_interfaces__node_timers - node_interfaces/test_node_timers.cpp) -if(TARGET test_node_interfaces__node_timers) - target_link_libraries(test_node_interfaces__node_timers ${PROJECT_NAME} mimick) -endif() -ament_add_gtest(test_node_interfaces__node_topics - node_interfaces/test_node_topics.cpp) -if(TARGET test_node_interfaces__node_topics) - ament_target_dependencies( - test_node_interfaces__node_topics - "test_msgs") - target_link_libraries(test_node_interfaces__node_topics ${PROJECT_NAME} mimick) -endif() -ament_add_gtest(test_node_interfaces__node_waitables - node_interfaces/test_node_waitables.cpp) -if(TARGET test_node_interfaces__node_waitables) - target_link_libraries(test_node_interfaces__node_waitables ${PROJECT_NAME} mimick) -endif() - -# TODO(wjwwood): reenable these build failure tests when I can get Jenkins to ignore their output -# rclcpp_add_build_failure_test(build_failure__get_node_topics_interface_const_ref_rclcpp_node -# node_interfaces/test_does_not_compile/get_node_topics_interface_const_ref_rclcpp_node.cpp) -# target_link_libraries(build_failure__get_node_topics_interface_const_ref_rclcpp_node -# ${PROJECT_NAME}) - -# rclcpp_add_build_failure_test(build_failure__get_node_topics_interface_const_ptr_rclcpp_node -# node_interfaces/test_does_not_compile/get_node_topics_interface_const_ptr_rclcpp_node.cpp) -# target_link_libraries(build_failure__get_node_topics_interface_const_ptr_rclcpp_node -# ${PROJECT_NAME}) - -# rclcpp_add_build_failure_test(build_failure__get_node_topics_interface_const_ref_wrapped_node -# node_interfaces/test_does_not_compile/get_node_topics_interface_const_ref_wrapped_node.cpp) -# target_link_libraries(build_failure__get_node_topics_interface_const_ref_rclcpp_node -# ${PROJECT_NAME}) - -# rclcpp_add_build_failure_test(build_failure__get_node_topics_interface_const_ptr_wrapped_node -# node_interfaces/test_does_not_compile/get_node_topics_interface_const_ptr_wrapped_node.cpp) -# target_link_libraries(build_failure__get_node_topics_interface_const_ptr_rclcpp_node -# ${PROJECT_NAME}) - -ament_add_gtest(test_node_global_args test_node_global_args.cpp) -if(TARGET test_node_global_args) - ament_target_dependencies(test_node_global_args - "rcl_interfaces" - "rmw" - "rosidl_runtime_cpp" - "rosidl_typesupport_cpp" - ) - target_link_libraries(test_node_global_args ${PROJECT_NAME}) -endif() -ament_add_gtest(test_node_options test_node_options.cpp) -if(TARGET test_node_options) - ament_target_dependencies(test_node_options "rcl") - target_link_libraries(test_node_options ${PROJECT_NAME} mimick) -endif() -ament_add_gtest(test_init_options test_init_options.cpp) -if(TARGET test_init_options) - ament_target_dependencies(test_init_options "rcl") - target_link_libraries(test_init_options ${PROJECT_NAME} mimick) -endif() -ament_add_gtest(test_parameter_client test_parameter_client.cpp) -if(TARGET test_parameter_client) - ament_target_dependencies(test_parameter_client - "rcl_interfaces" - ) - target_link_libraries(test_parameter_client ${PROJECT_NAME}) -endif() -ament_add_gtest(test_parameter_service test_parameter_service.cpp) -if(TARGET test_parameter_service) - ament_target_dependencies(test_parameter_service - "rcl_interfaces" - ) - target_link_libraries(test_parameter_service ${PROJECT_NAME}) -endif() -ament_add_gtest(test_parameter_events_filter test_parameter_events_filter.cpp) -if(TARGET test_parameter_events_filter) - ament_target_dependencies(test_parameter_events_filter - "rcl_interfaces" - "rmw" - "rosidl_runtime_cpp" - "rosidl_typesupport_cpp" - ) - target_link_libraries(test_parameter_events_filter ${PROJECT_NAME}) -endif() -ament_add_gtest(test_parameter test_parameter.cpp) -if(TARGET test_parameter) - ament_target_dependencies(test_parameter - "rcl_interfaces" - "rmw" - "rosidl_runtime_cpp" - "rosidl_typesupport_cpp" - ) - target_link_libraries(test_parameter ${PROJECT_NAME}) -endif() -ament_add_gtest(test_parameter_event_handler test_parameter_event_handler.cpp) -if(TARGET test_parameter_event_handler) - ament_target_dependencies(test_parameter_event_handler - "rcl_interfaces" - "rmw" - "rosidl_generator_cpp" - "rosidl_typesupport_cpp" - ) - target_link_libraries(test_parameter_event_handler ${PROJECT_NAME}) -endif() -ament_add_gtest(test_parameter_map test_parameter_map.cpp) -if(TARGET test_parameter_map) - target_link_libraries(test_parameter_map ${PROJECT_NAME}) -endif() -ament_add_gtest(test_publisher test_publisher.cpp TIMEOUT 120) -if(TARGET test_publisher) - ament_target_dependencies(test_publisher - "rcl" - "rmw" - "rosidl_runtime_cpp" - "rosidl_typesupport_cpp" - "test_msgs" - ) - target_link_libraries(test_publisher ${PROJECT_NAME} mimick) -endif() - -set(append_library_dirs "${CMAKE_CURRENT_BINARY_DIR}") -if(WIN32) - set(append_library_dirs "${append_library_dirs}/$") -endif() - -ament_add_gtest(test_publisher_with_type_adapter test_publisher_with_type_adapter.cpp - APPEND_LIBRARY_DIRS "${append_library_dirs}" -) -if(TARGET test_publisher_with_type_adapter) - ament_target_dependencies(test_publisher_with_type_adapter - "rcutils" - "rcl_interfaces" - "rmw" - "rosidl_runtime_cpp" - "rosidl_typesupport_cpp" - "test_msgs" - ) - target_link_libraries(test_publisher_with_type_adapter - ${PROJECT_NAME} - mimick - ${cpp_typesupport_target}) -endif() - -ament_add_gtest(test_subscription_with_type_adapter test_subscription_with_type_adapter.cpp - APPEND_LIBRARY_DIRS "${append_library_dirs}" -) -if(TARGET test_subscription_with_type_adapter) - ament_target_dependencies(test_subscription_with_type_adapter - "rcutils" - "rcl_interfaces" - "rmw" - "rosidl_runtime_cpp" - "rosidl_typesupport_cpp" - "test_msgs" - ) - target_link_libraries(test_subscription_with_type_adapter - ${PROJECT_NAME} - mimick - ${cpp_typesupport_target}) -endif() - ament_add_gtest(test_subscription_publisher_with_same_type_adapter test_subscription_publisher_with_same_type_adapter.cpp APPEND_LIBRARY_DIRS "${append_library_dirs}" ) @@ -417,343 +32,3 @@ if(TARGET test_subscription_publisher_with_same_type_adapter) mimick ${cpp_typesupport_target}) endif() - -ament_add_gtest(test_publisher_subscription_count_api test_publisher_subscription_count_api.cpp) -if(TARGET test_publisher_subscription_count_api) - ament_target_dependencies(test_publisher_subscription_count_api - "rcl_interfaces" - "rmw" - "rosidl_runtime_cpp" - "rosidl_typesupport_cpp" - "test_msgs" - ) - target_link_libraries(test_publisher_subscription_count_api ${PROJECT_NAME}) -endif() -ament_add_gtest(test_qos test_qos.cpp) -if(TARGET test_qos) - ament_target_dependencies(test_qos - "rmw" - ) - target_link_libraries(test_qos - ${PROJECT_NAME} - ) -endif() -function(test_generic_pubsub_for_rmw_implementation) - set(rmw_implementation_env_var RMW_IMPLEMENTATION=${rmw_implementation}) - ament_add_gmock(test_generic_pubsub${target_suffix} test_generic_pubsub.cpp - ENV ${rmw_implementation_env_var} - ) - if(TARGET test_generic_pubsub${target_suffix}) - target_link_libraries(test_generic_pubsub${target_suffix} ${PROJECT_NAME}) - ament_target_dependencies(test_generic_pubsub${target_suffix} - "rcpputils" - "rosidl_typesupport_cpp" - "test_msgs" - ) - endif() -endfunction() -call_for_each_rmw_implementation(test_generic_pubsub_for_rmw_implementation) -ament_add_gtest(test_qos_event test_qos_event.cpp) -if(TARGET test_qos_event) - ament_target_dependencies(test_qos_event - "rmw" - "test_msgs" - ) - target_link_libraries(test_qos_event - ${PROJECT_NAME} - mimick - ) -endif() -ament_add_gmock(test_qos_overriding_options test_qos_overriding_options.cpp) -if(TARGET test_qos_overriding_options) - target_link_libraries(test_qos_overriding_options - ${PROJECT_NAME} - ) -endif() -ament_add_gmock(test_qos_parameters test_qos_parameters.cpp) -if(TARGET test_qos_parameters) - target_link_libraries(test_qos_parameters - ${PROJECT_NAME} - ) -endif() -ament_add_gtest(test_rate test_rate.cpp) -if(TARGET test_rate) - ament_target_dependencies(test_rate - "rcl_interfaces" - "rmw" - "rosidl_runtime_cpp" - "rosidl_typesupport_cpp" - ) - target_link_libraries(test_rate - ${PROJECT_NAME} - ) -endif() -ament_add_gtest(test_serialized_message_allocator test_serialized_message_allocator.cpp) -if(TARGET test_serialized_message_allocator) - ament_target_dependencies(test_serialized_message_allocator - test_msgs - ) - target_link_libraries(test_serialized_message_allocator - ${PROJECT_NAME} - ) -endif() -ament_add_gtest(test_serialized_message test_serialized_message.cpp) -if(TARGET test_serialized_message) - ament_target_dependencies(test_serialized_message - test_msgs - ) - target_link_libraries(test_serialized_message - ${PROJECT_NAME} - ) -endif() -ament_add_gtest(test_service test_service.cpp) -if(TARGET test_service) - ament_target_dependencies(test_service - "rcl_interfaces" - "rmw" - "rosidl_runtime_cpp" - "rosidl_typesupport_cpp" - "test_msgs" - ) - target_link_libraries(test_service ${PROJECT_NAME} mimick) -endif() -# Creating and destroying nodes is slow with Connext, so this needs larger timeout. -ament_add_gtest(test_subscription test_subscription.cpp TIMEOUT 120) -if(TARGET test_subscription) - ament_target_dependencies(test_subscription - "rcl_interfaces" - "rmw" - "rosidl_runtime_cpp" - "rosidl_typesupport_cpp" - "test_msgs" - ) - target_link_libraries(test_subscription ${PROJECT_NAME} mimick) -endif() -ament_add_gtest(test_subscription_publisher_count_api test_subscription_publisher_count_api.cpp) -if(TARGET test_subscription_publisher_count_api) - ament_target_dependencies(test_subscription_publisher_count_api - "rcl_interfaces" - "rmw" - "rosidl_runtime_cpp" - "rosidl_typesupport_cpp" - "test_msgs" - ) - target_link_libraries(test_subscription_publisher_count_api ${PROJECT_NAME}) -endif() -ament_add_gtest(test_subscription_traits test_subscription_traits.cpp) -if(TARGET test_subscription_traits) - ament_target_dependencies(test_subscription_traits - "rcl" - "test_msgs" - ) - target_link_libraries(test_subscription_traits ${PROJECT_NAME}) -endif() -ament_add_gtest(test_type_support test_type_support.cpp) -if(TARGET test_type_support) - ament_target_dependencies(test_type_support - "rmw" - "rosidl_runtime_cpp" - "rosidl_typesupport_cpp" - "test_msgs" - ) - target_link_libraries(test_type_support ${PROJECT_NAME}) -endif() -ament_add_gmock(test_typesupport_helpers test_typesupport_helpers.cpp) -if(TARGET test_typesupport_helpers) - target_link_libraries(test_typesupport_helpers ${PROJECT_NAME}) -endif() -ament_add_gtest(test_find_weak_nodes test_find_weak_nodes.cpp) -if(TARGET test_find_weak_nodes) - ament_target_dependencies(test_find_weak_nodes - "rcl" - ) - target_link_libraries(test_find_weak_nodes ${PROJECT_NAME}) -endif() - -ament_add_gtest(test_externally_defined_services test_externally_defined_services.cpp) -ament_target_dependencies(test_externally_defined_services - "rcl" - "test_msgs" -) -target_link_libraries(test_externally_defined_services ${PROJECT_NAME}) - -ament_add_gtest(test_duration test_duration.cpp - APPEND_LIBRARY_DIRS "${append_library_dirs}") -if(TARGET test_duration) - ament_target_dependencies(test_duration - "rcl") - target_link_libraries(test_duration ${PROJECT_NAME}) -endif() - -ament_add_gtest(test_logger test_logger.cpp) -target_link_libraries(test_logger ${PROJECT_NAME}) - -ament_add_gmock(test_logging test_logging.cpp) -target_link_libraries(test_logging ${PROJECT_NAME}) - -ament_add_gtest(test_time test_time.cpp - APPEND_LIBRARY_DIRS "${append_library_dirs}") -if(TARGET test_time) - ament_target_dependencies(test_time - "rcl") - target_link_libraries(test_time ${PROJECT_NAME}) -endif() - -ament_add_gtest(test_timer test_timer.cpp - APPEND_LIBRARY_DIRS "${append_library_dirs}") -if(TARGET test_timer) - ament_target_dependencies(test_timer - "rcl") - target_link_libraries(test_timer ${PROJECT_NAME} mimick) -endif() - -ament_add_gtest(test_time_source test_time_source.cpp - APPEND_LIBRARY_DIRS "${append_library_dirs}") -if(TARGET test_time_source) - ament_target_dependencies(test_time_source - "rcl") - target_link_libraries(test_time_source ${PROJECT_NAME}) -endif() - -ament_add_gtest(test_utilities test_utilities.cpp - APPEND_LIBRARY_DIRS "${append_library_dirs}") -if(TARGET test_utilities) - ament_target_dependencies(test_utilities - "rcl") - target_link_libraries(test_utilities ${PROJECT_NAME} mimick) -endif() - -ament_add_gtest(test_wait_for_message test_wait_for_message.cpp) -if(TARGET test_wait_for_message) - ament_target_dependencies(test_wait_for_message - "test_msgs") - target_link_libraries(test_wait_for_message ${PROJECT_NAME}) -endif() - -ament_add_gtest(test_interface_traits test_interface_traits.cpp - APPEND_LIBRARY_DIRS "${append_library_dirs}") -if(TARGET test_interface_traits) - ament_target_dependencies(test_interface_traits - "rcl") - target_link_libraries(test_interface_traits ${PROJECT_NAME}) -endif() - -# TODO(brawner) remove when destroying Node for Connext is resolved. See: -# https://github.com/ros2/rclcpp/issues/1250 -ament_add_gtest( - test_executors - executors/test_executors.cpp - APPEND_LIBRARY_DIRS "${append_library_dirs}" - TIMEOUT 180) -if(TARGET test_executors) - ament_target_dependencies(test_executors - "rcl" - "test_msgs") - target_link_libraries(test_executors ${PROJECT_NAME}) -endif() - -ament_add_gtest(test_static_single_threaded_executor executors/test_static_single_threaded_executor.cpp - APPEND_LIBRARY_DIRS "${append_library_dirs}") -if(TARGET test_static_single_threaded_executor) - ament_target_dependencies(test_static_single_threaded_executor - "test_msgs") - target_link_libraries(test_static_single_threaded_executor ${PROJECT_NAME} mimick) -endif() - -ament_add_gtest(test_multi_threaded_executor executors/test_multi_threaded_executor.cpp - APPEND_LIBRARY_DIRS "${append_library_dirs}") -if(TARGET test_multi_threaded_executor) - ament_target_dependencies(test_multi_threaded_executor - "rcl") - target_link_libraries(test_multi_threaded_executor ${PROJECT_NAME}) -endif() - -ament_add_gtest(test_static_executor_entities_collector executors/test_static_executor_entities_collector.cpp - APPEND_LIBRARY_DIRS "${append_library_dirs}" TIMEOUT 120) -if(TARGET test_static_executor_entities_collector) - ament_target_dependencies(test_static_executor_entities_collector - "rcl" - "test_msgs") - target_link_libraries(test_static_executor_entities_collector ${PROJECT_NAME} mimick) -endif() - -ament_add_gtest(test_guard_condition test_guard_condition.cpp - APPEND_LIBRARY_DIRS "${append_library_dirs}") -if(TARGET test_guard_condition) - target_link_libraries(test_guard_condition ${PROJECT_NAME} mimick) -endif() - -ament_add_gtest(test_wait_set test_wait_set.cpp - APPEND_LIBRARY_DIRS "${append_library_dirs}") -if(TARGET test_wait_set) - ament_target_dependencies(test_wait_set "test_msgs") - target_link_libraries(test_wait_set ${PROJECT_NAME}) -endif() - -ament_add_gtest(test_subscription_topic_statistics topic_statistics/test_subscription_topic_statistics.cpp - APPEND_LIBRARY_DIRS "${append_library_dirs}" -) -if(TARGET test_subscription_topic_statistics) - ament_target_dependencies(test_subscription_topic_statistics - "builtin_interfaces" - "libstatistics_collector" - "rcl_interfaces" - "rcutils" - "rmw" - "rosidl_runtime_cpp" - "rosidl_typesupport_cpp" - "statistics_msgs" - "test_msgs") - target_link_libraries(test_subscription_topic_statistics - ${PROJECT_NAME} - ${cpp_typesupport_target}) -endif() - -ament_add_gtest(test_subscription_options test_subscription_options.cpp) -if(TARGET test_subscription_options) - ament_target_dependencies(test_subscription_options "rcl") - target_link_libraries(test_subscription_options ${PROJECT_NAME}) -endif() - -ament_add_gtest(test_dynamic_storage wait_set_policies/test_dynamic_storage.cpp) -if(TARGET test_dynamic_storage) - ament_target_dependencies(test_dynamic_storage "rcl" "test_msgs") - target_link_libraries(test_dynamic_storage ${PROJECT_NAME}) -endif() - -ament_add_gtest(test_storage_policy_common wait_set_policies/test_storage_policy_common.cpp) -if(TARGET test_storage_policy_common) - ament_target_dependencies(test_storage_policy_common "rcl" "test_msgs") - target_link_libraries(test_storage_policy_common ${PROJECT_NAME} mimick) -endif() - -ament_add_gtest(test_static_storage wait_set_policies/test_static_storage.cpp) -if(TARGET test_static_storage) - ament_target_dependencies(test_static_storage "rcl" "test_msgs") - target_link_libraries(test_static_storage ${PROJECT_NAME}) -endif() - -ament_add_gtest(test_thread_safe_synchronization wait_set_policies/test_thread_safe_synchronization.cpp) -if(TARGET test_thread_safe_synchronization) - ament_target_dependencies(test_thread_safe_synchronization "rcl" "test_msgs") - target_link_libraries(test_thread_safe_synchronization ${PROJECT_NAME}) -endif() - -ament_add_gtest(test_rosout_qos test_rosout_qos.cpp) -if(TARGET test_rosout_qos) - ament_target_dependencies(test_rosout_qos "rcl") - target_link_libraries(test_rosout_qos ${PROJECT_NAME}) -endif() - -ament_add_gtest(test_executor test_executor.cpp - APPEND_LIBRARY_DIRS "${append_library_dirs}" - TIMEOUT 120) -if(TARGET test_executor) - ament_target_dependencies(test_executor "rcl") - target_link_libraries(test_executor ${PROJECT_NAME} mimick) -endif() - -ament_add_gtest(test_graph_listener test_graph_listener.cpp) -if(TARGET test_graph_listener) - target_link_libraries(test_graph_listener ${PROJECT_NAME} mimick) -endif() diff --git a/rclcpp/test/test_subscription_publisher_with_same_type_adapter.cpp b/rclcpp/test/test_subscription_publisher_with_same_type_adapter.cpp deleted file mode 100644 index 84699b3816..0000000000 --- a/rclcpp/test/test_subscription_publisher_with_same_type_adapter.cpp +++ /dev/null @@ -1,194 +0,0 @@ -// 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 - -#include -#include -#include -#include -#include -#include -#include - -#include "rclcpp/exceptions.hpp" -#include "rclcpp/loaned_message.hpp" -#include "rclcpp/rclcpp.hpp" - -#include "../mocking_utils/patch.hpp" -#include "../utils/rclcpp_gtest_macros.hpp" - -#include "test_msgs/msg/empty.hpp" -#include "rclcpp/msg/string.hpp" - - -#ifdef RMW_IMPLEMENTATION -# define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX -# define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX) -#else -# define CLASSNAME(NAME, SUFFIX) NAME -#endif - - -using namespace std::chrono_literals; - -static const int g_max_loops = 200; -static const std::chrono::milliseconds g_sleep_per_loop(10); - - -class TestSubscriptionPublisher : public ::testing::Test -{ -public: - static void SetUpTestCase() - { - if (!rclcpp::ok()) { - rclcpp::init(0, nullptr); - } - } - -protected: - void initialize(const rclcpp::NodeOptions & node_options = rclcpp::NodeOptions()) - { - node = std::make_shared("my_node", "/ns", node_options); - } - - void TearDown() - { - node.reset(); - } - - rclcpp::Node::SharedPtr node; -}; - -class CLASSNAME (test_intra_process_within_one_node, RMW_IMPLEMENTATION) : public ::testing::Test -{ -public: - static void SetUpTestCase() - { - rclcpp::init(0, nullptr); - } - - static void TearDownTestCase() - { - rclcpp::shutdown(); - } -}; - -namespace rclcpp -{ - -template<> -struct TypeAdapter -{ - using is_specialized = std::true_type; - using custom_type = std::string; - using ros_message_type = rclcpp::msg::String; - - static void - convert_to_ros_message( - const custom_type & source, - ros_message_type & destination) - { - (void) source; - (void) destination; - throw std::runtime_error("This should not happen"); - } - - static void - convert_to_custom( - const ros_message_type & source, - custom_type & destination) - { - (void) source; - (void) destination; - throw std::runtime_error("This should not happen"); - } -}; - -} // namespace rclcpp - -void wait_for_message_to_be_received( - bool & is_received, - const std::shared_ptr & node) -{ - rclcpp::executors::SingleThreadedExecutor executor; - executor.add_node(node); - executor.spin_once(std::chrono::milliseconds(0)); - int i = 0; - while (!is_received && i < g_max_loops) { - printf("spin_node_once() - callback (1) expected - try %d/%d\n", ++i, g_max_loops); - executor.spin_once(g_sleep_per_loop); - } -} - -/* - * Testing that subscriber receives type adapted types and ROS message types with intra proccess communications. - */ -TEST_F( - CLASSNAME(test_intra_process_within_one_node, RMW_IMPLEMENTATION), - check_type_adapted_messages_are_received_by_intra_process_subscription) { - using StringTypeAdapter = rclcpp::TypeAdapter; - const std::string message_data = "Message Data"; - const std::string topic_name = "topic_name"; - - RCLCPP_WARN(rclcpp::get_node_logger(nullptr), "BLASSS"); - - auto node = rclcpp::Node::make_shared( - "test_intra_process", - rclcpp::NodeOptions().use_intra_process_comms(true)); - auto pub = node->create_publisher(topic_name, 1); - - { - { // std::unique_ptr - bool is_received = false; - auto callback = - [message_data, &is_received]( - std::unique_ptr msg) -> void { - is_received = true; - ASSERT_STREQ(message_data.c_str(), (*msg).c_str()); - }; - auto sub = node->create_subscription(topic_name, 1, callback); - - - RCLCPP_WARN(rclcpp::get_node_logger(nullptr), "BLASSS"); - - auto pu_message = std::make_unique(message_data); - pub->publish(std::move(pu_message)); - - ASSERT_FALSE(is_received); - wait_for_message_to_be_received(is_received, node); - ASSERT_TRUE(is_received); - } - { // std::unique_ptr with message info - bool is_received = false; - auto callback = - [message_data, &is_received]( - std::unique_ptr msg, - const rclcpp::MessageInfo & message_info) -> void { - is_received = true; - ASSERT_STREQ(message_data.c_str(), (*msg).c_str()); - ASSERT_TRUE(message_info.get_rmw_message_info().from_intra_process); - }; - auto sub = node->create_subscription(topic_name, 1, callback); - - auto pu_message = std::make_unique(message_data); - pub->publish(std::move(pu_message)); - - ASSERT_FALSE(is_received); - wait_for_message_to_be_received(is_received, node); - ASSERT_TRUE(is_received); - } - } -}