diff --git a/test/blackbox/common/RTPSBlackboxTestsBasic.cpp b/test/blackbox/common/RTPSBlackboxTestsBasic.cpp index 409fdc3dff..62a377afb2 100644 --- a/test/blackbox/common/RTPSBlackboxTestsBasic.cpp +++ b/test/blackbox/common/RTPSBlackboxTestsBasic.cpp @@ -21,6 +21,9 @@ #include +#include +#include +#include #include #include #include @@ -1276,6 +1279,167 @@ TEST(RTPS, max_output_message_size_writer) } +bool validate_publication_builtin_topic_data( + const eprosima::fastdds::dds::builtin::PublicationBuiltinTopicData& pubdata, + const RTPSWriter& writer, + const TopicAttributes& topic_atts, + const WriterQos& writer_qos, + const GUID_t& participant_guid) +{ + bool ret = true; + + eprosima::fastdds::dds::builtin::BuiltinTopicKey_t w_key, part_key; + GuidPrefix_t guid_prefix = participant_guid.guidPrefix; + + // This conversions may be included later in utils + w_key.value[0] = 0; + w_key.value[1] = 0; + w_key.value[2] = static_cast(writer.getGuid().entityId.value[0]) << 24 + | static_cast(writer.getGuid().entityId.value[1]) << 16 + | static_cast(writer.getGuid().entityId.value[2]) << 8 + | static_cast(writer.getGuid().entityId.value[3]); + + part_key.value[0] = static_cast(guid_prefix.value[0]) << 24 + | static_cast(guid_prefix.value[1]) << 16 + | static_cast(guid_prefix.value[2]) << 8 + | static_cast(guid_prefix.value[3]); + part_key.value[1] = static_cast(guid_prefix.value[4]) << 24 + | static_cast(guid_prefix.value[5]) << 16 + | static_cast(guid_prefix.value[6]) << 8 + | static_cast(guid_prefix.value[7]); + part_key.value[2] = static_cast(guid_prefix.value[8]) << 24 + | static_cast(guid_prefix.value[9]) << 16 + | static_cast(guid_prefix.value[10]) << 8 + | static_cast(guid_prefix.value[11]); + + ret &= (0 == memcmp(pubdata.key.value, w_key.value, sizeof(eprosima::fastdds::dds::builtin::BuiltinTopicKey_t))); + ret &= + (0 == + memcmp(pubdata.participant_key.value, part_key.value, + sizeof(eprosima::fastdds::dds::builtin::BuiltinTopicKey_t))); + ret &= (pubdata.topic_name == topic_atts.topicName.to_string()); + ret &= (pubdata.type_name == topic_atts.topicDataType.to_string()); + + // Writer Qos + ret &= (pubdata.durability == writer_qos.m_durability); + ret &= (pubdata.durability_service == writer_qos.m_durabilityService); + ret &= (pubdata.deadline == writer_qos.m_deadline); + ret &= (pubdata.latency_budget == writer_qos.m_latencyBudget); + ret &= (pubdata.liveliness == writer_qos.m_liveliness); + ret &= (pubdata.reliability == writer_qos.m_reliability); + ret &= (pubdata.lifespan == writer_qos.m_lifespan); + ret &= (pubdata.user_data == writer_qos.m_userData); + ret &= (pubdata.ownership == writer_qos.m_ownership); + ret &= (pubdata.ownership_strength == writer_qos.m_ownershipStrength); + ret &= (pubdata.destination_order == writer_qos.m_destinationOrder); + + // Publisher Qos + ret &= (pubdata.presentation == writer_qos.m_presentation); + ret &= (pubdata.partition == writer_qos.m_partition); + // topicdata not implemented + ret &= (pubdata.group_data == writer_qos.m_groupData); + + return ret; +} + +bool validate_subscription_builtin_topic_data( + const eprosima::fastdds::dds::builtin::SubscriptionBuiltinTopicData& subdata, + const RTPSReader& reader, + const TopicAttributes& topic_atts, + const ReaderQos& reader_qos, + const GUID_t& participant_guid) +{ + bool ret = true; + + eprosima::fastdds::dds::builtin::BuiltinTopicKey_t r_key, part_key; + eprosima::fastrtps::rtps::GuidPrefix_t part_guid_prefix = participant_guid.guidPrefix; + + // This conversions may be included later in utils + r_key.value[0] = 0; + r_key.value[1] = 0; + r_key.value[2] = static_cast(reader.getGuid().entityId.value[0]) << 24 + | static_cast(reader.getGuid().entityId.value[1]) << 16 + | static_cast(reader.getGuid().entityId.value[2]) << 8 + | static_cast(reader.getGuid().entityId.value[3]); + + part_key.value[0] = static_cast(part_guid_prefix.value[0]) << 24 + | static_cast(part_guid_prefix.value[1]) << 16 + | static_cast(part_guid_prefix.value[2]) << 8 + | static_cast(part_guid_prefix.value[3]); + part_key.value[1] = static_cast(part_guid_prefix.value[4]) << 24 + | static_cast(part_guid_prefix.value[5]) << 16 + | static_cast(part_guid_prefix.value[6]) << 8 + | static_cast(part_guid_prefix.value[7]); + part_key.value[2] = static_cast(part_guid_prefix.value[8]) << 24 + | static_cast(part_guid_prefix.value[9]) << 16 + | static_cast(part_guid_prefix.value[10]) << 8 + | static_cast(part_guid_prefix.value[11]); + + ret &= (0 == memcmp(subdata.key.value, r_key.value, sizeof(eprosima::fastdds::dds::builtin::BuiltinTopicKey_t))); + ret &= + (0 == + memcmp(subdata.participant_key.value, part_key.value, + sizeof(eprosima::fastdds::dds::builtin::BuiltinTopicKey_t))); + ret &= (subdata.topic_name == topic_atts.topicName.to_string()); + ret &= (subdata.type_name == topic_atts.topicDataType.to_string()); + + // RTPS Reader + ret &= (subdata.durability == reader_qos.m_durability); + ret &= (subdata.deadline == reader_qos.m_deadline); + ret &= (subdata.latency_budget == reader_qos.m_latencyBudget); + ret &= (subdata.liveliness == reader_qos.m_liveliness); + ret &= (subdata.reliability == reader_qos.m_reliability); + ret &= (subdata.ownership == reader_qos.m_ownership); + ret &= (subdata.destination_order == reader_qos.m_destinationOrder); + ret &= (subdata.user_data == reader_qos.m_userData); + // time based filter not implemented + + // Subscriber Qos + ret &= (subdata.presentation == reader_qos.m_presentation); + ret &= (subdata.partition == reader_qos.m_partition); + ret &= (subdata.group_data == reader_qos.m_groupData); + + return ret; +} + +/** + * Tests get_publication_info() get_subscription_info() RTPSParticipant APIs + */ +TEST_P(RTPS, rtps_participant_get_pubsub_info) +{ + RTPSWithRegistrationWriter writer(TEST_TOPIC_NAME); + RTPSWithRegistrationReader reader(TEST_TOPIC_NAME); + + writer.init(); + reader.init(); + + ASSERT_TRUE(writer.isInitialized()); + ASSERT_TRUE(reader.isInitialized()); + + writer.wait_discovery(); + reader.wait_discovery(); + + ASSERT_TRUE(writer.get_matched()); + ASSERT_TRUE(reader.get_matched()); + + eprosima::fastdds::dds::builtin::PublicationBuiltinTopicData pubdata; + eprosima::fastdds::dds::builtin::SubscriptionBuiltinTopicData subdata; + + // Get publication info from the reader participant and validate it + bool ret = reader.get_rtps_participant()->get_publication_info(writer.guid(), pubdata); + ASSERT_TRUE(ret); + ASSERT_TRUE(validate_publication_builtin_topic_data(pubdata, writer.get_native_writer(), + writer.get_topic_attributes(), + writer.get_writerqos(), reader.get_rtps_participant()->getGuid())); + + // Get subscription info from the reader participant and validate it + ret = writer.get_rtps_participant()->get_subscription_info(reader.guid(), subdata); + ASSERT_TRUE(ret); + ASSERT_TRUE(validate_subscription_builtin_topic_data(subdata, reader.get_native_reader(), + reader.get_topic_attributes(), + reader.get_readerqos(), reader.get_rtps_participant()->getGuid())); +} + #ifdef INSTANTIATE_TEST_SUITE_P #define GTEST_INSTANTIATE_TEST_MACRO(x, y, z, w) INSTANTIATE_TEST_SUITE_P(x, y, z, w) #else diff --git a/test/blackbox/common/RTPSBlackboxTestsReader.cpp b/test/blackbox/common/RTPSBlackboxTestsReader.cpp new file mode 100644 index 0000000000..2ddb8d0210 --- /dev/null +++ b/test/blackbox/common/RTPSBlackboxTestsReader.cpp @@ -0,0 +1,153 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// 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 "BlackboxTests.hpp" + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "RTPSWithRegistrationReader.hpp" +#include "RTPSWithRegistrationWriter.hpp" + +using namespace eprosima::fastrtps; +using namespace eprosima::fastrtps::rtps; + +enum communication_type +{ + TRANSPORT, + INTRAPROCESS +}; + +class RTPSReaderTests : public testing::TestWithParam +{ +public: + + void SetUp() override + { + LibrarySettingsAttributes library_settings; + switch (GetParam()) + { + case INTRAPROCESS: + library_settings.intraprocess_delivery = IntraprocessDeliveryType::INTRAPROCESS_FULL; + xmlparser::XMLProfileManager::library_settings(library_settings); + break; + case TRANSPORT: + default: + break; + } + } + + void TearDown() override + { + LibrarySettingsAttributes library_settings; + switch (GetParam()) + { + case INTRAPROCESS: + library_settings.intraprocess_delivery = IntraprocessDeliveryType::INTRAPROCESS_OFF; + xmlparser::XMLProfileManager::library_settings(library_settings); + break; + case TRANSPORT: + default: + break; + } + } + +}; + +/** + * Tests get_matched_guids() RTPSReader API + */ +TEST_P(RTPSReaderTests, rtpsreader_get_matched_guids) +{ + RTPSWithRegistrationReader reader(TEST_TOPIC_NAME); + RTPSWithRegistrationWriter writer(TEST_TOPIC_NAME); + + reader.reliability(eprosima::fastrtps::rtps::RELIABLE) + .init(); + + writer.reliability(eprosima::fastrtps::rtps::BEST_EFFORT) + .init(); + + ASSERT_TRUE(reader.isInitialized()); + ASSERT_TRUE(writer.isInitialized()); + + // Expect not to discover + reader.wait_discovery(std::chrono::seconds(1)); + ASSERT_FALSE(reader.get_matched()); + + std::vector matched_guids; + auto& native_rtps_reader = reader.get_native_reader(); + ASSERT_FALSE(native_rtps_reader.get_matched_guids(matched_guids)); + ASSERT_TRUE(matched_guids.empty()); + + writer.destroy(); + reader.wait_undiscovery(); + + const size_t num_matched_writers = 3; + std::vector>> writers; + std::vector expected_matched_guids; + + writers.reserve(num_matched_writers); + expected_matched_guids.reserve(num_matched_writers); + + for (size_t i = 0; i < num_matched_writers; ++i) + { + writers.emplace_back(new RTPSWithRegistrationWriter(TEST_TOPIC_NAME)); + writers.back()->init(); + expected_matched_guids.emplace_back(writers.back()->guid()); + } + + reader.wait_discovery(num_matched_writers, std::chrono::seconds::zero()); + ASSERT_EQ(num_matched_writers, reader.get_matched()); + native_rtps_reader.get_matched_guids(matched_guids); + ASSERT_EQ(expected_matched_guids.size(), matched_guids.size()); + ASSERT_TRUE(std::is_permutation(expected_matched_guids.begin(), expected_matched_guids.end(), + matched_guids.begin())); +} + +#ifdef INSTANTIATE_TEST_SUITE_P +#define GTEST_INSTANTIATE_TEST_MACRO(x, y, z, w) INSTANTIATE_TEST_SUITE_P(x, y, z, w) +#else +#define GTEST_INSTANTIATE_TEST_MACRO(x, y, z, w) INSTANTIATE_TEST_CASE_P(x, y, z, w) +#endif // ifdef INSTANTIATE_TEST_SUITE_P + +GTEST_INSTANTIATE_TEST_MACRO(RTPSReaderTests, + RTPSReaderTests, + testing::Values(TRANSPORT, INTRAPROCESS), + [](const testing::TestParamInfo& info) + { + switch (info.param) + { + case INTRAPROCESS: + return "Intraprocess"; + break; + case TRANSPORT: + default: + return "Transport"; + } + + }); diff --git a/test/blackbox/common/RTPSBlackboxTestsWriter.cpp b/test/blackbox/common/RTPSBlackboxTestsWriter.cpp new file mode 100644 index 0000000000..5a48f620f0 --- /dev/null +++ b/test/blackbox/common/RTPSBlackboxTestsWriter.cpp @@ -0,0 +1,153 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// 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 "BlackboxTests.hpp" + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "RTPSWithRegistrationReader.hpp" +#include "RTPSWithRegistrationWriter.hpp" + +using namespace eprosima::fastrtps; +using namespace eprosima::fastrtps::rtps; + +enum communication_type +{ + TRANSPORT, + INTRAPROCESS +}; + +class RTPSWriterTests : public testing::TestWithParam +{ +public: + + void SetUp() override + { + LibrarySettingsAttributes library_settings; + switch (GetParam()) + { + case INTRAPROCESS: + library_settings.intraprocess_delivery = IntraprocessDeliveryType::INTRAPROCESS_FULL; + xmlparser::XMLProfileManager::library_settings(library_settings); + break; + case TRANSPORT: + default: + break; + } + } + + void TearDown() override + { + LibrarySettingsAttributes library_settings; + switch (GetParam()) + { + case INTRAPROCESS: + library_settings.intraprocess_delivery = IntraprocessDeliveryType::INTRAPROCESS_OFF; + xmlparser::XMLProfileManager::library_settings(library_settings); + break; + case TRANSPORT: + default: + break; + } + } + +}; + +/** + * Tests get_matched_guids() RTPSWriter API + */ +TEST_P(RTPSWriterTests, rtpswriter_get_matched_guids) +{ + RTPSWithRegistrationWriter writer(TEST_TOPIC_NAME); + RTPSWithRegistrationReader reader(TEST_TOPIC_NAME); + + writer.reliability(eprosima::fastrtps::rtps::BEST_EFFORT) + .init(); + + reader.reliability(eprosima::fastrtps::rtps::RELIABLE) + .init(); + + ASSERT_TRUE(writer.isInitialized()); + ASSERT_TRUE(reader.isInitialized()); + + // Expect not to discover + writer.wait_discovery(std::chrono::seconds(1)); + ASSERT_FALSE(writer.get_matched()); + + std::vector matched_guids; + auto& native_rtps_writer = writer.get_native_writer(); + ASSERT_FALSE(native_rtps_writer.get_matched_guids(matched_guids)); + ASSERT_TRUE(matched_guids.empty()); + + reader.destroy(); + writer.wait_undiscovery(); + + const size_t num_matched_readers = 3; + std::vector>> readers; + std::vector expected_matched_guids; + + readers.reserve(num_matched_readers); + expected_matched_guids.reserve(num_matched_readers); + + for (size_t i = 0; i < num_matched_readers; ++i) + { + readers.emplace_back(new RTPSWithRegistrationReader(TEST_TOPIC_NAME)); + readers.back()->init(); + expected_matched_guids.emplace_back(readers.back()->guid()); + } + + writer.wait_discovery(num_matched_readers, std::chrono::seconds::zero()); + ASSERT_EQ(num_matched_readers, writer.get_matched()); + native_rtps_writer.get_matched_guids(matched_guids); + ASSERT_EQ(expected_matched_guids.size(), matched_guids.size()); + ASSERT_TRUE(std::is_permutation(expected_matched_guids.begin(), expected_matched_guids.end(), + matched_guids.begin())); +} + +#ifdef INSTANTIATE_TEST_SUITE_P +#define GTEST_INSTANTIATE_TEST_MACRO(x, y, z, w) INSTANTIATE_TEST_SUITE_P(x, y, z, w) +#else +#define GTEST_INSTANTIATE_TEST_MACRO(x, y, z, w) INSTANTIATE_TEST_CASE_P(x, y, z, w) +#endif // ifdef INSTANTIATE_TEST_SUITE_P + +GTEST_INSTANTIATE_TEST_MACRO(RTPSWriterTests, + RTPSWriterTests, + testing::Values(TRANSPORT, INTRAPROCESS), + [](const testing::TestParamInfo& info) + { + switch (info.param) + { + case INTRAPROCESS: + return "Intraprocess"; + break; + case TRANSPORT: + default: + return "Transport"; + } + + }); diff --git a/test/blackbox/common/RTPSWithRegistrationReader.hpp b/test/blackbox/common/RTPSWithRegistrationReader.hpp index d48300ca83..3d92b25c1b 100644 --- a/test/blackbox/common/RTPSWithRegistrationReader.hpp +++ b/test/blackbox/common/RTPSWithRegistrationReader.hpp @@ -551,6 +551,21 @@ class RTPSWithRegistrationReader return *reader_; } + eprosima::fastrtps::ReaderQos& get_readerqos() + { + return reader_qos_; + } + + eprosima::fastrtps::TopicAttributes& get_topic_attributes() + { + return topic_attr_; + } + + eprosima::fastrtps::rtps::RTPSParticipant* get_rtps_participant() + { + return participant_; + } + private: void receive_one( diff --git a/test/blackbox/common/RTPSWithRegistrationWriter.hpp b/test/blackbox/common/RTPSWithRegistrationWriter.hpp index 0b35f07cd9..448ef3669b 100644 --- a/test/blackbox/common/RTPSWithRegistrationWriter.hpp +++ b/test/blackbox/common/RTPSWithRegistrationWriter.hpp @@ -573,6 +573,26 @@ class RTPSWithRegistrationWriter return writer_->getGuid(); } + eprosima::fastrtps::rtps::RTPSWriter& get_native_writer() const + { + return *writer_; + } + + eprosima::fastrtps::WriterQos& get_writerqos() + { + return writer_qos_; + } + + eprosima::fastrtps::TopicAttributes& get_topic_attributes() + { + return topic_attr_; + } + + eprosima::fastrtps::rtps::RTPSParticipant* get_rtps_participant() + { + return participant_; + } + private: void on_reader_discovery(