Skip to content

Commit

Permalink
Refs #21096: Add BB tests
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
  • Loading branch information
Mario-DL committed Jun 3, 2024
1 parent b690e65 commit 7e83b72
Show file tree
Hide file tree
Showing 6 changed files with 374 additions and 10 deletions.
4 changes: 4 additions & 0 deletions test/blackbox/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/builtin_transports_profile.xml
${CMAKE_CURRENT_BINARY_DIR}/builtin_transports_profile.xml)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/auth_handshake_props_profile.xml
${CMAKE_CURRENT_BINARY_DIR}/auth_handshake_props_profile.xml COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/discovery_participants_initial_peers_profile.xml
${CMAKE_CURRENT_BINARY_DIR}/discovery_participants_initial_peers_profile.xml)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/discovery_participants_client_server_profile.xml
${CMAKE_CURRENT_BINARY_DIR}/discovery_participants_client_server_profile.xml)
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/datagrams" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")

if(FASTDDS_PIM_API_TESTS)
Expand Down
30 changes: 25 additions & 5 deletions test/blackbox/api/dds-pim/PubSubReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ class PubSubReader
, status_mask_(eprosima::fastdds::dds::StatusMask::all())
, topic_name_(topic_name)
, initialized_(false)
, use_domain_id_from_profile_(false)
, matched_(0)
, participant_matched_(0)
, receiving_(false)
Expand Down Expand Up @@ -401,11 +402,21 @@ class PubSubReader
DomainParticipantFactory::get_instance()->load_XML_profiles_file(xml_file_);
if (!participant_profile_.empty())
{
participant_ = DomainParticipantFactory::get_instance()->create_participant_with_profile(
(uint32_t)GET_PID() % 230,
participant_profile_,
&participant_listener_,
eprosima::fastdds::dds::StatusMask::none());
if (use_domain_id_from_profile_)
{
participant_ = DomainParticipantFactory::get_instance()->create_participant_with_profile(
participant_profile_,
&participant_listener_,
eprosima::fastdds::dds::StatusMask::none());
}
else
{
participant_ = DomainParticipantFactory::get_instance()->create_participant_with_profile(
(uint32_t)GET_PID() % 230,
participant_profile_,
&participant_listener_,
eprosima::fastdds::dds::StatusMask::none());
}
ASSERT_NE(participant_, nullptr);
ASSERT_TRUE(participant_->is_enabled());
}
Expand Down Expand Up @@ -1819,6 +1830,14 @@ class PubSubReader
participant_profile_ = profile;
}

void set_participant_profile(
const std::string& profile,
bool use_domain_id_from_profile)
{
set_participant_profile(profile);
use_domain_id_from_profile_ = use_domain_id_from_profile;
}

void set_datareader_profile(
const std::string& profile)
{
Expand Down Expand Up @@ -2084,6 +2103,7 @@ class PubSubReader
eprosima::fastrtps::rtps::GUID_t participant_guid_;
eprosima::fastrtps::rtps::GUID_t datareader_guid_;
bool initialized_;
bool use_domain_id_from_profile_;
std::list<type> total_msgs_;
std::mutex mutex_;
std::condition_variable cv_;
Expand Down
31 changes: 26 additions & 5 deletions test/blackbox/api/dds-pim/PubSubWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ class PubSubWriter
, datawriter_(nullptr)
, status_mask_(eprosima::fastdds::dds::StatusMask::all())
, initialized_(false)
, use_domain_id_from_profile_(false)
, matched_(0)
, participant_matched_(0)
, discovery_result_(false)
Expand Down Expand Up @@ -364,11 +365,22 @@ class PubSubWriter
DomainParticipantFactory::get_instance()->load_XML_profiles_file(xml_file_);
if (!participant_profile_.empty())
{
participant_ = DomainParticipantFactory::get_instance()->create_participant_with_profile(
(uint32_t)GET_PID() % 230,
participant_profile_,
&participant_listener_,
eprosima::fastdds::dds::StatusMask::none());
if (use_domain_id_from_profile_)
{
participant_ = DomainParticipantFactory::get_instance()->create_participant_with_profile(
participant_profile_,
&participant_listener_,
eprosima::fastdds::dds::StatusMask::none());
}
else
{
participant_ = DomainParticipantFactory::get_instance()->create_participant_with_profile(
(uint32_t)GET_PID() % 230,
participant_profile_,
&participant_listener_,
eprosima::fastdds::dds::StatusMask::none());
}

ASSERT_NE(participant_, nullptr);
ASSERT_TRUE(participant_->is_enabled());
}
Expand Down Expand Up @@ -1672,6 +1684,14 @@ class PubSubWriter
participant_profile_ = profile;
}

void set_participant_profile(
const std::string& profile,
bool use_domain_id_from_profile)
{
set_participant_profile(profile);
use_domain_id_from_profile_ = use_domain_id_from_profile;
}

void set_datawriter_profile(
const std::string& profile)
{
Expand Down Expand Up @@ -1978,6 +1998,7 @@ class PubSubWriter
eprosima::fastrtps::rtps::GUID_t participant_guid_;
eprosima::fastrtps::rtps::GUID_t datawriter_guid_;
bool initialized_;
bool use_domain_id_from_profile_;
std::mutex mutexDiscovery_;
std::condition_variable cv_;
std::atomic<unsigned int> matched_;
Expand Down
179 changes: 179 additions & 0 deletions test/blackbox/common/DDSBlackboxTestsDiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1925,3 +1925,182 @@ TEST(DDSDiscovery, DataracePDP)
settings.intraprocess_delivery = prev_intraprocess_delivery;
DomainParticipantFactory::get_instance()->set_library_settings(settings);
}

/*!
* @test: Test for validating correct behavior of PID_DOMAIN_ID
*
* This test checks that two PDP Simple participants with the same PID_DOMAIN_ID
* are able to discover each other.
* It also checks that the PID_DOMAIN_ID is sent and received.
*
*/
TEST(DDSDiscovery, pdp_simple_participants_exchange_same_pid_domain_id_and_discover)
{
using namespace eprosima::fastdds::dds;
using namespace eprosima::fastdds::rtps;
using namespace eprosima::fastrtps::rtps;

PubSubReader<HelloWorldPubSubType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldPubSubType> writer(TEST_TOPIC_NAME);

auto reader_test_transport = std::make_shared<test_UDPv4TransportDescriptor>();
auto writer_test_transport = std::make_shared<test_UDPv4TransportDescriptor>();

bool reader_received_pid_domin_id = true;
bool writer_sends_pid_domin_id = true;

auto find_pid_domain_id = [](CDRMessage_t& msg, bool& pid_was_found)
{
uint32_t qos_size = 0;
uint32_t original_pos = msg.pos;
bool is_sentinel = false;

while (!is_sentinel)
{
msg.pos = original_pos + qos_size;

ParameterId_t pid{eprosima::fastdds::dds::PID_SENTINEL};
uint16_t plength = 0;
bool valid = true;

valid &= eprosima::fastrtps::rtps::CDRMessage::readUInt16(&msg, (uint16_t*)&pid);
valid &= eprosima::fastrtps::rtps::CDRMessage::readUInt16(&msg, &plength);

if (pid == eprosima::fastdds::dds::PID_SENTINEL)
{
// PID_SENTINEL is always considered of length 0
plength = 0;
is_sentinel = true;
}

qos_size += (4 + plength);

// Align to 4 byte boundary and prepare for next iteration
qos_size = (qos_size + 3) & ~3;

if (!valid || ((msg.pos + plength) > msg.length))
{
return false;
}
else if (!is_sentinel)
{
if (pid == eprosima::fastdds::dds::PID_DOMAIN_ID)
{
uint32_t domain_id = 0;
eprosima::fastrtps::rtps::CDRMessage::readUInt32(&msg, &domain_id);
if (domain_id == (uint32_t)GET_PID() % 230)
{
pid_was_found = true;
}
break;
}
}
}

// Do not drop the packet in any case
return false;
};

reader_test_transport->drop_builtin_data_messages_filter_ = [&](CDRMessage_t& msg)
{
return find_pid_domain_id(msg, reader_received_pid_domin_id);
};

writer_test_transport->drop_builtin_data_messages_filter_ = [&](CDRMessage_t& msg)
{
return find_pid_domain_id(msg, writer_sends_pid_domin_id);
};

reader.disable_builtin_transport().add_user_transport_to_pparams(reader_test_transport);
writer.disable_builtin_transport().add_user_transport_to_pparams(writer_test_transport);

reader.init();
writer.init();

ASSERT_TRUE(reader.isInitialized());
ASSERT_TRUE(writer.isInitialized());

reader.wait_discovery();
writer.wait_discovery();

ASSERT_TRUE(writer_sends_pid_domin_id);
ASSERT_TRUE(reader_received_pid_domin_id);
}

/*!
* @test: Test for validating correct behavior of PID_DOMAIN_ID
*
* This test checks that two PDP Simple participants in different domains
* do not discover each other despite the first one is initial peer of the second.
*
*/

TEST(DDSDiscovery, pdp_simple_initial_peer_participants_with_different_domain_ids_do_not_discover)
{
PubSubWriter<HelloWorldPubSubType> writer_domain_1(TEST_TOPIC_NAME);
PubSubReader<HelloWorldPubSubType> reader_domain_2(TEST_TOPIC_NAME);

writer_domain_1.set_xml_filename("discovery_participants_initial_peers_profile.xml");
writer_domain_1.set_participant_profile("participant_from_domain_1", true);
writer_domain_1.init();
EXPECT_TRUE(writer_domain_1.isInitialized());

reader_domain_2.set_xml_filename("discovery_participants_initial_peers_profile.xml");
reader_domain_2.set_participant_profile("participant_from_domain_2", true);
reader_domain_2.init();
EXPECT_TRUE(reader_domain_2.isInitialized());

writer_domain_1.wait_discovery(std::chrono::seconds(2));
reader_domain_2.wait_discovery(std::chrono::seconds(2));

ASSERT_FALSE(writer_domain_1.is_matched());
ASSERT_FALSE(reader_domain_2.is_matched());
}

/*!
* @test: Test for validating correct behavior of PID_DOMAIN_ID
*
* This test checks that a Discovery Server and a Client in different domains,
* discover each other.
*
*/

TEST(DDSDiscovery, client_server_participants_with_different_domain_ids_discover)
{
PubSubReader<HelloWorldPubSubType> server_domain_1(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldPubSubType> client_domain_2(TEST_TOPIC_NAME);
PubSubReader<HelloWorldPubSubType> client_domain_3(TEST_TOPIC_NAME);

server_domain_1.set_xml_filename("discovery_participants_client_server_profile.xml");
server_domain_1.set_participant_profile("ds_server", true);
server_domain_1.init();
EXPECT_TRUE(server_domain_1.isInitialized());

client_domain_2.set_xml_filename("discovery_participants_client_server_profile.xml");
client_domain_2.set_participant_profile("ds_client_pub", true);
client_domain_2.init();
EXPECT_TRUE(client_domain_2.isInitialized());

client_domain_3.set_xml_filename("discovery_participants_client_server_profile.xml");
client_domain_3.set_participant_profile("ds_client_sub", true);
client_domain_3.init();
EXPECT_TRUE(client_domain_3.isInitialized());

server_domain_1.wait_discovery(std::chrono::seconds(2));
client_domain_2.wait_discovery(std::chrono::seconds(2));
client_domain_3.wait_discovery(std::chrono::seconds(2));

ASSERT_TRUE(client_domain_2.is_matched());
ASSERT_TRUE(client_domain_3.is_matched());

auto data = default_helloworld_data_generator();
size_t data_size = data.size();

client_domain_3.startReception(data);

client_domain_2.send(data);
EXPECT_TRUE(data.empty());

// All data received
EXPECT_EQ(client_domain_3.block_for_all(std::chrono::seconds(3)), data_size);
}
71 changes: 71 additions & 0 deletions test/blackbox/discovery_participants_client_server_profile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8" ?>
<dds xmlns="http://www.eprosima.com">
<profiles>
<participant profile_name="ds_server">
<domainId>1</domainId>
<rtps>
<prefix>44.53.00.5f.45.50.52.4f.53.49.4d.41</prefix>
<builtin>
<discovery_config>
<discoveryProtocol>SERVER</discoveryProtocol>
</discovery_config>
<metatrafficUnicastLocatorList>
<locator>
<udpv4>
<address>127.0.0.1</address>
<port>14521</port>
</udpv4>
</locator>
</metatrafficUnicastLocatorList>
</builtin>
</rtps>
</participant>

<participant profile_name="ds_client_pub">
<domainId>2</domainId>
<rtps>
<builtin>
<discovery_config>
<discoveryProtocol>CLIENT</discoveryProtocol>
<discoveryServersList>
<RemoteServer prefix="44.53.00.5f.45.50.52.4f.53.49.4d.41">
<metatrafficUnicastLocatorList>
<locator>
<udpv4>
<address>127.0.0.1</address>
<port>14521</port>
</udpv4>
</locator>
</metatrafficUnicastLocatorList>
</RemoteServer>
</discoveryServersList>
</discovery_config>
</builtin>
</rtps>
</participant>

<participant profile_name="ds_client_sub">
<domainId>3</domainId>
<rtps>
<builtin>
<discovery_config>
<discoveryProtocol>CLIENT</discoveryProtocol>
<discoveryServersList>
<RemoteServer prefix="44.53.00.5f.45.50.52.4f.53.49.4d.41">
<metatrafficUnicastLocatorList>
<locator>
<udpv4>
<address>127.0.0.1</address>
<port>14521</port>
</udpv4>
</locator>
</metatrafficUnicastLocatorList>
</RemoteServer>
</discoveryServersList>
</discovery_config>
</builtin>
</rtps>
</participant>

</profiles>
</dds>
Loading

0 comments on commit 7e83b72

Please sign in to comment.