Skip to content

Commit

Permalink
Refs #21710: RTPS APIs tests
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Dominguez <[email protected]>
  • Loading branch information
Mario-DL committed Sep 25, 2024
1 parent 37e9345 commit 1624044
Show file tree
Hide file tree
Showing 5 changed files with 505 additions and 0 deletions.
164 changes: 164 additions & 0 deletions test/blackbox/common/RTPSBlackboxTestsBasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

#include <gtest/gtest.h>

#include <fastdds/dds/builtin/topic/BuiltinTopicKey.hpp>
#include <fastdds/dds/builtin/topic/PublicationBuiltinTopicData.hpp>
#include <fastdds/dds/builtin/topic/SubscriptionBuiltinTopicData.hpp>
#include <fastdds/rtps/attributes/RTPSParticipantAttributes.h>
#include <fastdds/rtps/flowcontrol/FlowControllerDescriptor.hpp>
#include <fastdds/rtps/interfaces/IReaderDataFilter.hpp>
Expand Down Expand Up @@ -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<uint32_t>(writer.getGuid().entityId.value[0]) << 24
| static_cast<uint32_t>(writer.getGuid().entityId.value[1]) << 16
| static_cast<uint32_t>(writer.getGuid().entityId.value[2]) << 8
| static_cast<uint32_t>(writer.getGuid().entityId.value[3]);

part_key.value[0] = static_cast<uint32_t>(guid_prefix.value[0]) << 24
| static_cast<uint32_t>(guid_prefix.value[1]) << 16
| static_cast<uint32_t>(guid_prefix.value[2]) << 8
| static_cast<uint32_t>(guid_prefix.value[3]);
part_key.value[1] = static_cast<uint32_t>(guid_prefix.value[4]) << 24
| static_cast<uint32_t>(guid_prefix.value[5]) << 16
| static_cast<uint32_t>(guid_prefix.value[6]) << 8
| static_cast<uint32_t>(guid_prefix.value[7]);
part_key.value[2] = static_cast<uint32_t>(guid_prefix.value[8]) << 24
| static_cast<uint32_t>(guid_prefix.value[9]) << 16
| static_cast<uint32_t>(guid_prefix.value[10]) << 8
| static_cast<uint32_t>(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<uint32_t>(reader.getGuid().entityId.value[0]) << 24
| static_cast<uint32_t>(reader.getGuid().entityId.value[1]) << 16
| static_cast<uint32_t>(reader.getGuid().entityId.value[2]) << 8
| static_cast<uint32_t>(reader.getGuid().entityId.value[3]);

part_key.value[0] = static_cast<uint32_t>(part_guid_prefix.value[0]) << 24
| static_cast<uint32_t>(part_guid_prefix.value[1]) << 16
| static_cast<uint32_t>(part_guid_prefix.value[2]) << 8
| static_cast<uint32_t>(part_guid_prefix.value[3]);
part_key.value[1] = static_cast<uint32_t>(part_guid_prefix.value[4]) << 24
| static_cast<uint32_t>(part_guid_prefix.value[5]) << 16
| static_cast<uint32_t>(part_guid_prefix.value[6]) << 8
| static_cast<uint32_t>(part_guid_prefix.value[7]);
part_key.value[2] = static_cast<uint32_t>(part_guid_prefix.value[8]) << 24
| static_cast<uint32_t>(part_guid_prefix.value[9]) << 16
| static_cast<uint32_t>(part_guid_prefix.value[10]) << 8
| static_cast<uint32_t>(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<HelloWorldPubSubType> writer(TEST_TOPIC_NAME);
RTPSWithRegistrationReader<HelloWorldPubSubType> 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
Expand Down
153 changes: 153 additions & 0 deletions test/blackbox/common/RTPSBlackboxTestsReader.cpp
Original file line number Diff line number Diff line change
@@ -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 <chrono>
#include <cstdint>
#include <memory>
#include <thread>

#include <gtest/gtest.h>

#include <fastdds/rtps/attributes/RTPSParticipantAttributes.h>
#include <fastdds/rtps/flowcontrol/FlowControllerDescriptor.hpp>
#include <fastdds/rtps/interfaces/IReaderDataFilter.hpp>
#include <fastdds/rtps/participant/RTPSParticipant.h>
#include <fastdds/rtps/RTPSDomain.h>
#include <fastdds/rtps/transport/test_UDPv4TransportDescriptor.h>
#include <fastrtps/log/Log.h>
#include <fastrtps/xmlparser/XMLProfileManager.h>

#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<communication_type>
{
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<HelloWorldPubSubType> reader(TEST_TOPIC_NAME);
RTPSWithRegistrationWriter<HelloWorldPubSubType> 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<GUID_t> 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<std::unique_ptr<RTPSWithRegistrationWriter<HelloWorldPubSubType>>> writers;
std::vector<GUID_t> 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<HelloWorldPubSubType>(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<RTPSReaderTests::ParamType>& info)
{
switch (info.param)
{
case INTRAPROCESS:
return "Intraprocess";
break;
case TRANSPORT:
default:
return "Transport";
}

});
Loading

0 comments on commit 1624044

Please sign in to comment.