Skip to content

Commit

Permalink
Refs #21131: Update DDSBlackboxTests*
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Dominguez <[email protected]>
  • Loading branch information
Mario-DL committed Jun 18, 2024
1 parent f0f3854 commit c7391f4
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 89 deletions.
19 changes: 8 additions & 11 deletions test/blackbox/common/DDSBlackboxTestsAckPositive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
#include <fastdds/rtps/participant/ParticipantDiscoveryInfo.h>
#include <fastdds/rtps/transport/test_UDPv4TransportDescriptor.h>

// TODO(jlbueno): remove private headers
#include <rtps/transport/test_UDPv4Transport.h>

#include "BlackboxTests.hpp"
#include "../api/dds-pim/CustomPayloadPool.hpp"
#include "../api/dds-pim/PubSubReader.hpp"
Expand Down Expand Up @@ -154,7 +151,7 @@ TEST(AcknackQos, RecoverAfterLosingCommunicationWithDisablePositiveAck)
// Number of samples written by writer
uint32_t writer_samples = 15;

auto testTransport = std::make_shared<test_UDPv4TransportDescriptor>();
auto test_transport = std::make_shared<test_UDPv4TransportDescriptor>();

writer.keep_duration({2, 0});
//writer.history_kind(eprosima::fastdds::dds::KEEP_LAST_HISTORY_QOS);
Expand All @@ -163,7 +160,7 @@ TEST(AcknackQos, RecoverAfterLosingCommunicationWithDisablePositiveAck)
writer.reliability(eprosima::fastdds::dds::RELIABLE_RELIABILITY_QOS);
//writer.lifespan_period(lifespan_s);
writer.disable_builtin_transport();
writer.add_user_transport_to_pparams(testTransport);
writer.add_user_transport_to_pparams(test_transport);
writer.init();

reader.keep_duration({1, 0});
Expand All @@ -190,7 +187,7 @@ TEST(AcknackQos, RecoverAfterLosingCommunicationWithDisablePositiveAck)
// Block reader until reception finished or timeout.
reader.block_for_all();

test_UDPv4Transport::test_UDPv4Transport_ShutdownAllNetwork = true;
test_transport->test_transport_options->test_UDPv4Transport_ShutdownAllNetwork = true;

data = default_helloworld_data_generator(writer_samples);
reader.startReception(data);
Expand All @@ -201,7 +198,7 @@ TEST(AcknackQos, RecoverAfterLosingCommunicationWithDisablePositiveAck)

std::this_thread::sleep_for(std::chrono::seconds(1));

test_UDPv4Transport::test_UDPv4Transport_ShutdownAllNetwork = false;
test_transport->test_transport_options->test_UDPv4Transport_ShutdownAllNetwork = false;

// Block reader until reception finished or timeout.
reader.block_for_all();
Expand All @@ -220,7 +217,7 @@ TEST(AcknackQos, NotRecoverAfterLosingCommunicationWithDisablePositiveAck)
// Number of samples written by writer
uint32_t writer_samples = 15;

auto testTransport = std::make_shared<test_UDPv4TransportDescriptor>();
auto test_transport = std::make_shared<test_UDPv4TransportDescriptor>();

writer.keep_duration({1, 0});
//writer.history_kind(eprosima::fastdds::dds::KEEP_LAST_HISTORY_QOS);
Expand All @@ -229,7 +226,7 @@ TEST(AcknackQos, NotRecoverAfterLosingCommunicationWithDisablePositiveAck)
writer.reliability(eprosima::fastdds::dds::RELIABLE_RELIABILITY_QOS);
//writer.lifespan_period(lifespan_s);
writer.disable_builtin_transport();
writer.add_user_transport_to_pparams(testTransport);
writer.add_user_transport_to_pparams(test_transport);
writer.init();

reader.keep_duration({1, 0});
Expand All @@ -256,7 +253,7 @@ TEST(AcknackQos, NotRecoverAfterLosingCommunicationWithDisablePositiveAck)
// Block reader until reception finished or timeout.
reader.block_for_all();

test_UDPv4Transport::test_UDPv4Transport_ShutdownAllNetwork = true;
test_transport->test_transport_options->test_UDPv4Transport_ShutdownAllNetwork = true;

data = default_helloworld_data_generator(writer_samples);
reader.startReception(data);
Expand All @@ -267,7 +264,7 @@ TEST(AcknackQos, NotRecoverAfterLosingCommunicationWithDisablePositiveAck)

std::this_thread::sleep_for(std::chrono::seconds(2));

test_UDPv4Transport::test_UDPv4Transport_ShutdownAllNetwork = false;
test_transport->test_transport_options->test_UDPv4Transport_ShutdownAllNetwork = false;

// Block reader until reception finished or timeout.
ASSERT_EQ(reader.block_for_all(std::chrono::seconds(1)), 0u);
Expand Down
10 changes: 7 additions & 3 deletions test/blackbox/common/DDSBlackboxTestsBasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <fastdds/rtps/participant/ParticipantDiscoveryInfo.h>
#include <fastdds/rtps/transport/test_UDPv4TransportDescriptor.h>

#include "../utils/filter_helpers.hpp"
#include "BlackboxTests.hpp"
#include "mock/BlackboxMockConsumer.h"
#include "../api/dds-pim/CustomPayloadPool.hpp"
Expand Down Expand Up @@ -392,11 +393,14 @@ bool check_related_sample_identity_field(
msg.pos = original_pos + qos_size;

ParameterId_t pid{PID_SENTINEL};
uint16_t plength = 0;
bool valid = true;
auto msg_pid_pos = msg.pos;
valid &= fastdds::rtps::CDRMessage::readUInt16(&msg, (uint16_t*)&pid);
valid &= fastdds::rtps::CDRMessage::readUInt16(&msg, &plength);
pid = (ParameterId_t)eprosima::fastdds::helpers::cdr_parse_u16(
(char*)&msg.buffer[msg.pos]);
msg.pos += 2;
uint16_t plength = eprosima::fastdds::helpers::cdr_parse_u16(
(char*)&msg.buffer[msg.pos]);
msg.pos += 2;

if (pid == PID_SENTINEL)
{
Expand Down
31 changes: 18 additions & 13 deletions test/blackbox/common/DDSBlackboxTestsContentFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
#include <fastdds/rtps/common/CDRMessage_t.h>
#include <fastdds/rtps/transport/test_UDPv4TransportDescriptor.h>
#include <gtest/gtest.h>
#include <rtps/messages/CDRMessage.hpp>

#include "../types/HelloWorldTypeObjectSupport.hpp"
#include "../types/TestRegression3361PubSubTypes.h"
#include "../types/TestRegression3361TypeObjectSupport.hpp"
#include "../utils/filter_helpers.hpp"
#include "BlackboxTests.hpp"
#include "PubSubReader.hpp"
#include "PubSubWriter.hpp"
Expand Down Expand Up @@ -65,14 +65,16 @@ struct ContentFilterInfoCounter

// Skip extraFlags, read octetsToInlineQos, and calculate inline qos position.
msg.pos += 2;
uint16_t to_inline_qos = 0;
fastdds::rtps::CDRMessage::readUInt16(&msg, &to_inline_qos);
uint16_t to_inline_qos = eprosima::fastdds::helpers::cdr_parse_u16(
(char*)&msg.buffer[msg.pos]);
msg.pos += 2;
uint32_t inline_qos_pos = msg.pos + to_inline_qos;

// Read writerId, and skip if built-in.
msg.pos += 4;
fastdds::rtps::GUID_t writer_guid;
fastdds::rtps::CDRMessage::readEntityId(&msg, &writer_guid.entityId);
writer_guid.entityId = eprosima::fastdds::helpers::cdr_parse_entity_id(
(char*)&msg.buffer[msg.pos]);
msg.pos = old_pos;

if (writer_guid.is_builtin())
Expand All @@ -87,11 +89,12 @@ struct ContentFilterInfoCounter
msg.pos = inline_qos_pos;
while (msg.pos < msg.length)
{
uint16_t pid = 0;
uint16_t plen = 0;

fastdds::rtps::CDRMessage::readUInt16(&msg, &pid);
fastdds::rtps::CDRMessage::readUInt16(&msg, &plen);
uint16_t pid = eprosima::fastdds::helpers::cdr_parse_u16(
(char*)&msg.buffer[msg.pos]);
msg.pos += 2;
uint16_t plen = eprosima::fastdds::helpers::cdr_parse_u16(
(char*)&msg.buffer[msg.pos]);
msg.pos += 2;
uint32_t next_pos = msg.pos + plen;

if (pid == PID_CONTENT_FILTER_INFO)
Expand All @@ -102,13 +105,15 @@ struct ContentFilterInfoCounter
if (plen >= 4 + 4 + 4 + 16)
{
// Read numBitmaps and skip bitmaps
uint32_t num_bitmaps = 0;
fastdds::rtps::CDRMessage::readUInt32(&msg, &num_bitmaps);
uint32_t num_bitmaps = eprosima::fastdds::helpers::cdr_parse_u32(
(char*)&msg.buffer[msg.pos]);
msg.pos += 4;
msg.pos += 4 * num_bitmaps;

// Read numSignatures and keep maximum
uint32_t num_signatures = 0;
fastdds::rtps::CDRMessage::readUInt32(&msg, &num_signatures);
uint32_t num_signatures = eprosima::fastdds::helpers::cdr_parse_u32(
(char*)&msg.buffer[msg.pos]);
msg.pos += 4;
if (max_filter_signature_number < num_signatures)
{
max_filter_signature_number = num_signatures;
Expand Down
17 changes: 13 additions & 4 deletions test/blackbox/common/DDSBlackboxTestsDataReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
#include <fastdds/dds/topic/qos/TopicQos.hpp>
#include <fastdds/dds/topic/Topic.hpp>
#include <fastdds/LibrarySettings.hpp>
#include <fastdds/rtps/common/CDRMessage_t.h>
#include <fastdds/rtps/transport/test_UDPv4TransportDescriptor.h>
#include <rtps/messages/CDRMessage.hpp>

#include "../utils/filter_helpers.hpp"
#include "BlackboxTests.hpp"
#include "PubSubParticipant.hpp"
#include "PubSubReader.hpp"
Expand Down Expand Up @@ -273,9 +274,17 @@ TEST(DDSDataReader, GetFirstUntakenInfoReturnsTheFirstValidChange)

msg.pos += 2; // flags
msg.pos += 2; // octets to inline quos
CDRMessage::readEntityId(&msg, &readerID);
CDRMessage::readEntityId(&msg, &writerID);
CDRMessage::readSequenceNumber(&msg, &sn);
readerID = eprosima::fastdds::helpers::cdr_parse_entity_id(
(char*)&msg.buffer[msg.pos]);
msg.pos += 4;
writerID = eprosima::fastdds::helpers::cdr_parse_entity_id(
(char*)&msg.buffer[msg.pos]);
msg.pos += 4;
sn.high = (int32_t)eprosima::fastdds::helpers::cdr_parse_u32(
(char*)&msg.buffer[msg.pos]);
msg.pos += 4;
sn.low = eprosima::fastdds::helpers::cdr_parse_u32(
(char*)&msg.buffer[msg.pos]);

// restore buffer pos
msg.pos = old_pos;
Expand Down
12 changes: 5 additions & 7 deletions test/blackbox/common/DDSBlackboxTestsDataWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
#include <fastdds/dds/topic/qos/TopicQos.hpp>
#include <fastdds/dds/topic/Topic.hpp>
#include <fastdds/LibrarySettings.hpp>

// TODO(jlbueno): remove private header
#include <rtps/transport/test_UDPv4Transport.h>
#include <fastdds/rtps/transport/test_UDPv4TransportDescriptor.h>

#include "BlackboxTests.hpp"
#include "PubSubReader.hpp"
Expand Down Expand Up @@ -97,9 +95,9 @@ TEST_P(DDSDataWriter, WaitForAcknowledgmentInstance)
PubSubWriter<KeyedHelloWorldPubSubType> writer(TEST_TOPIC_NAME);
PubSubReader<KeyedHelloWorldPubSubType> reader(TEST_TOPIC_NAME);

auto testTransport = std::make_shared<eprosima::fastdds::rtps::test_UDPv4TransportDescriptor>();
auto test_transport = std::make_shared<eprosima::fastdds::rtps::test_UDPv4TransportDescriptor>();

writer.disable_builtin_transport().add_user_transport_to_pparams(testTransport).init();
writer.disable_builtin_transport().add_user_transport_to_pparams(test_transport).init();
ASSERT_TRUE(writer.isInitialized());

reader.reliability(RELIABLE_RELIABILITY_QOS).init();
Expand All @@ -109,7 +107,7 @@ TEST_P(DDSDataWriter, WaitForAcknowledgmentInstance)
reader.wait_discovery();

// Disable communication to prevent reception of ACKs
eprosima::fastdds::rtps::test_UDPv4Transport::test_UDPv4Transport_ShutdownAllNetwork = true;
test_transport->test_transport_options->test_UDPv4Transport_ShutdownAllNetwork = true;

auto data = default_keyedhelloworld_data_generator(2);

Expand Down Expand Up @@ -139,7 +137,7 @@ TEST_P(DDSDataWriter, WaitForAcknowledgmentInstance)
}

// Enable communication and wait for acknowledgment
eprosima::fastdds::rtps::test_UDPv4Transport::test_UDPv4Transport_ShutdownAllNetwork = false;
test_transport->test_transport_options->test_UDPv4Transport_ShutdownAllNetwork = false;

EXPECT_TRUE(writer.waitForInstanceAcked(&sample_1, instance_handle_1, std::chrono::seconds(1)));
EXPECT_TRUE(writer.waitForInstanceAcked(&sample_2, rtps::c_InstanceHandle_Unknown, std::chrono::seconds(1)));
Expand Down
27 changes: 14 additions & 13 deletions test/blackbox/common/DDSBlackboxTestsDiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
#include <fastdds/dds/domain/DomainParticipantListener.hpp>
#include <fastdds/dds/domain/qos/DomainParticipantQos.hpp>
#include <fastdds/rtps/builtin/data/ParticipantProxyData.hpp>
#include <fastdds/rtps/common/CDRMessage_t.h>
#include <fastdds/rtps/common/Locator.h>
#include <fastdds/rtps/participant/ParticipantDiscoveryInfo.h>
#include <fastdds/rtps/transport/test_UDPv4TransportDescriptor.h>
#include <fastdds/rtps/transport/test_UDPv4TransportDescriptor.h>
#include <gtest/gtest.h>

// TODO(jlbueno): remove private header
#include <rtps/transport/test_UDPv4Transport.h>

#include "../utils/filter_helpers.hpp"
#include "BlackboxTests.hpp"
#include "PubSubParticipant.hpp"
#include "PubSubReader.hpp"
Expand Down Expand Up @@ -437,8 +437,8 @@ TEST(DDSDiscovery, DDSNetworkInterfaceChangesAtRunTime)
ASSERT_TRUE(datareader.isInitialized());

// datawriter: launch without interfaces
test_UDPv4Transport::simulate_no_interfaces = true;
auto test_transport = std::make_shared<test_UDPv4TransportDescriptor>();
test_transport->test_transport_options->simulate_no_interfaces = true;
datawriter.disable_builtin_transport().add_user_transport_to_pparams(test_transport).history_depth(100).init();
ASSERT_TRUE(datawriter.isInitialized());

Expand All @@ -461,7 +461,7 @@ TEST(DDSDiscovery, DDSNetworkInterfaceChangesAtRunTime)
EXPECT_EQ(datareader.block_for_all(std::chrono::seconds(3)), 0u);

// enable interfaces
test_UDPv4Transport::simulate_no_interfaces = false;
test_transport->test_transport_options->simulate_no_interfaces = false;
datawriter.participant_set_qos();

// Wait for discovery
Expand Down Expand Up @@ -1975,7 +1975,7 @@ TEST(DDSDiscovery, DataracePDP)
participant_listener.discovery_future.wait();

// Shutdown auxiliary participant's network, so it will be removed after lease duration
test_UDPv4Transport::test_UDPv4Transport_ShutdownAllNetwork = true;
aux_udp_transport->test_transport_options->test_UDPv4Transport_ShutdownAllNetwork = true;
DomainParticipantFactory::get_instance()->delete_participant(aux_participant);
std::this_thread::sleep_for(std::chrono::milliseconds(1500)); // Wait for longer than lease duration

Expand Down Expand Up @@ -2041,13 +2041,14 @@ TEST(DDSDiscovery, pdp_simple_participants_exchange_same_pid_domain_id_and_disco
{
msg.pos = original_pos + qos_size;

ParameterId_t pid{eprosima::fastdds::dds::PID_SENTINEL};
uint16_t plength = 0;
uint16_t pid = eprosima::fastdds::helpers::cdr_parse_u16(
(char*)&msg.buffer[msg.pos]);
msg.pos += 2;
uint16_t plength = eprosima::fastdds::helpers::cdr_parse_u16(
(char*)&msg.buffer[msg.pos]);
msg.pos += 2;
bool valid = true;

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

if (pid == eprosima::fastdds::dds::PID_SENTINEL)
{
// PID_SENTINEL is always considered of length 0
Expand All @@ -2068,8 +2069,8 @@ TEST(DDSDiscovery, pdp_simple_participants_exchange_same_pid_domain_id_and_disco
{
if (pid == eprosima::fastdds::dds::PID_DOMAIN_ID)
{
uint32_t domain_id = 0;
eprosima::fastdds::rtps::CDRMessage::readUInt32(&msg, &domain_id);
uint32_t domain_id = eprosima::fastdds::helpers::cdr_parse_u32(
(char*)&msg.buffer[msg.pos]);
if (domain_id == (uint32_t)GET_PID() % 230)
{
pid_was_found = true;
Expand Down
Loading

0 comments on commit c7391f4

Please sign in to comment.