Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[21131] Make Blackbox tests not include any private API #4953

Merged
merged 14 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TransportInterface;

/**
* Shared memory transport configuration.
* The kind value for SharedMemTransportDescriptor is given by eprosima::fastdds::rtps::LOCATOR_KIND_SHM.
* The kind is given by eprosima::fastdds::rtps::LOCATOR_KIND_SHM.
*
* - segment_size_: size of the shared memory segment (in octets).
*
Expand Down
96 changes: 71 additions & 25 deletions include/fastdds/rtps/transport/test_UDPv4TransportDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
#include <fastdds/rtps/transport/SocketTransportDescriptor.h>
#include <fastdds/rtps/common/SequenceNumber.h>



namespace eprosima {
namespace fastdds {
namespace rtps {

struct CDRMessage_t;
struct TestUDPv4TransportOptions;

/**
* UDP v4 Test Transport configuration
Expand All @@ -40,57 +39,87 @@ struct test_UDPv4TransportDescriptor : public SocketTransportDescriptor
//! Locator filtering function
typedef std::function<bool (const Locator& destination)> DestinationLocatorFilter;

//! Test transport options
std::shared_ptr<TestUDPv4TransportOptions> test_transport_options = std::make_shared<TestUDPv4TransportOptions>();

//! Test shim parameters
//! Percentage of data messages being dropped
mutable std::atomic<uint8_t> dropDataMessagesPercentage;
mutable std::atomic<uint8_t> dropDataMessagesPercentage{0};
//! Percentage of Data[P] messages being dropped
mutable std::atomic<uint8_t> dropParticipantBuiltinDataMessagesPercentage;
mutable std::atomic<uint8_t> dropParticipantBuiltinDataMessagesPercentage{0};
//! Percentage of Data[W] messages being dropped
mutable std::atomic<uint8_t> dropPublicationBuiltinDataMessagesPercentage;
mutable std::atomic<uint8_t> dropPublicationBuiltinDataMessagesPercentage{0};
//! Percentage of Data[R] messages being dropped
mutable std::atomic<uint8_t> dropSubscriptionBuiltinDataMessagesPercentage;
mutable std::atomic<uint8_t> dropSubscriptionBuiltinDataMessagesPercentage{0};
//! Filtering function for dropping data messages
filter drop_data_messages_filter_;
filter drop_data_messages_filter_ = [](fastdds::rtps::CDRMessage_t&)
{
return false;
};
//! Filtering function for dropping builtin data messages
filter drop_builtin_data_messages_filter_;
filter drop_builtin_data_messages_filter_ = [](fastdds::rtps::CDRMessage_t&)
{
return false;
};
//! Flag to enable dropping of discovery Participant DATA(P) messages
bool dropParticipantBuiltinTopicData;
bool dropParticipantBuiltinTopicData = false;
//! Flag to enable dropping of discovery Writer DATA(W) messages
bool dropPublicationBuiltinTopicData;
bool dropPublicationBuiltinTopicData = false;
//! Flag to enable dropping of discovery Reader DATA(R) messages
bool dropSubscriptionBuiltinTopicData;
bool dropSubscriptionBuiltinTopicData = false;
//! Percentage of data fragments being dropped
mutable std::atomic<uint8_t> dropDataFragMessagesPercentage;
mutable std::atomic<uint8_t> dropDataFragMessagesPercentage{0};
//! Filtering function for dropping data fragments messages
filter drop_data_frag_messages_filter_;
filter drop_data_frag_messages_filter_ = [](fastdds::rtps::CDRMessage_t&)
{
return false;
};
//! Percentage of heartbeats being dropped
mutable std::atomic<uint8_t> dropHeartbeatMessagesPercentage;
mutable std::atomic<uint8_t> dropHeartbeatMessagesPercentage{0};
//! Filtering function for dropping heartbeat messages
filter drop_heartbeat_messages_filter_;
filter drop_heartbeat_messages_filter_ = [](fastdds::rtps::CDRMessage_t&)
{
return false;
};
//! Percentage of AckNacks being dropped
mutable std::atomic<uint8_t> dropAckNackMessagesPercentage;
mutable std::atomic<uint8_t> dropAckNackMessagesPercentage{0};
//! Filtering function for dropping AckNacks
filter drop_ack_nack_messages_filter_;
filter drop_ack_nack_messages_filter_ = [](fastdds::rtps::CDRMessage_t&)
{
return false;
};
//! Percentage of gap messages being dropped
mutable std::atomic<uint8_t> dropGapMessagesPercentage;
mutable std::atomic<uint8_t> dropGapMessagesPercentage{0};
//! Filtering function for dropping gap messages
filter drop_gap_messages_filter_;
filter drop_gap_messages_filter_ = [](fastdds::rtps::CDRMessage_t&)
{
return false;
};
// General filtering function for all kind of sub-messages (indiscriminate)
filter sub_messages_filter_;
filter sub_messages_filter_ = [](fastdds::rtps::CDRMessage_t&)
{
return false;
};

// General drop percentage (indiscriminate)
mutable std::atomic<uint8_t> percentageOfMessagesToDrop;
mutable std::atomic<uint8_t> percentageOfMessagesToDrop{0};
// General filtering function for all kind of messages (indiscriminate)
filter messages_filter_;
filter messages_filter_ = [](fastdds::rtps::CDRMessage_t&)
{
return false;
};

//! Filtering function for dropping messages to specific destinations
DestinationLocatorFilter locator_filter_;
DestinationLocatorFilter locator_filter_ = [](const Locator&)
{
return false;
};

//! Vector containing the message's sequence numbers being dropped
std::vector<fastdds::rtps::SequenceNumber_t> sequenceNumberDataMessagesToDrop;
std::vector<fastdds::rtps::SequenceNumber_t> sequenceNumberDataMessagesToDrop{};

//! Log dropped packets
uint32_t dropLogLength;
uint32_t dropLogLength = 0;

//! Constructor
FASTDDS_EXPORTED_API test_UDPv4TransportDescriptor();
Expand Down Expand Up @@ -123,6 +152,23 @@ struct test_UDPv4TransportDescriptor : public SocketTransportDescriptor
const test_UDPv4TransportDescriptor& t) const;
};

struct TestUDPv4TransportOptions
{
FASTDDS_EXPORTED_API TestUDPv4TransportOptions() = default;
~TestUDPv4TransportOptions() = default;

std::atomic<bool> test_UDPv4Transport_ShutdownAllNetwork{false};
// Handle to a persistent log of dropped packets. Defaults to length 0 (no logging) to prevent wasted resources.
std::vector<std::vector<fastdds::rtps::octet>> test_UDPv4Transport_DropLog{};
std::atomic<uint32_t> test_UDPv4Transport_DropLogLength{0};
std::atomic<bool> always_drop_participant_builtin_topic_data{false};
std::atomic<bool> simulate_no_interfaces{false};
test_UDPv4TransportDescriptor::DestinationLocatorFilter locator_filter = [](const Locator&)
{
return false;
};
};

} // namespace rtps
} // namespace fastdds
} // namespace eprosima
Expand Down
3 changes: 2 additions & 1 deletion src/cpp/rtps/transport/shared_mem/test_SharedMemTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
#ifndef _FASTDDS_TEST_SHAREDMEM_TRANSPORT_H_
#define _FASTDDS_TEST_SHAREDMEM_TRANSPORT_H_

#include <fastdds/rtps/transport/shared_mem/test_SharedMemTransportDescriptor.h>

#include <rtps/transport/shared_mem/SharedMemTransport.h>
#include <rtps/transport/shared_mem/test_SharedMemTransportDescriptor.h>

namespace eprosima {
namespace fastdds {
Expand Down
93 changes: 20 additions & 73 deletions src/cpp/rtps/transport/test_UDPv4Transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,10 @@ namespace eprosima {
namespace fastdds {
namespace rtps {

std::vector<std::vector<octet>> test_UDPv4Transport::test_UDPv4Transport_DropLog;
std::atomic<uint32_t> test_UDPv4Transport::test_UDPv4Transport_DropLogLength(0);
std::atomic<bool> test_UDPv4Transport::test_UDPv4Transport_ShutdownAllNetwork(false);
std::atomic<bool> test_UDPv4Transport::always_drop_participant_builtin_topic_data(false);
std::atomic<bool> test_UDPv4Transport::simulate_no_interfaces(false);
test_UDPv4TransportDescriptor::DestinationLocatorFilter test_UDPv4Transport::locator_filter([](const Locator&)
{
return false;
});

test_UDPv4Transport::test_UDPv4Transport(
const test_UDPv4TransportDescriptor& descriptor)
: drop_data_messages_percentage_(descriptor.dropDataMessagesPercentage)
: test_transport_options(descriptor.test_transport_options)
, drop_data_messages_percentage_(descriptor.dropDataMessagesPercentage)
, drop_participant_builtin_data_messages_percentage_(descriptor.dropParticipantBuiltinDataMessagesPercentage)
, drop_publication_builtin_data_messages_percentage_(descriptor.dropPublicationBuiltinDataMessagesPercentage)
, drop_subscription_builtin_data_messages_percentage_(descriptor.dropSubscriptionBuiltinDataMessagesPercentage)
Expand All @@ -61,70 +52,25 @@ test_UDPv4Transport::test_UDPv4Transport(
, sequence_number_data_messages_to_drop_(descriptor.sequenceNumberDataMessagesToDrop)
, locator_filter_(descriptor.locator_filter_)
{
test_UDPv4Transport_DropLogLength = 0;
test_UDPv4Transport_ShutdownAllNetwork = false;
if (nullptr == test_transport_options)
{
throw std::runtime_error("test_UDPv4Transport: test_transport_options is nullptr");
}

test_transport_options->test_UDPv4Transport_DropLogLength = 0;
test_transport_options->test_UDPv4Transport_ShutdownAllNetwork = false;
UDPv4Transport::mSendBufferSize = descriptor.sendBufferSize;
UDPv4Transport::mReceiveBufferSize = descriptor.receiveBufferSize;
for (auto interf : descriptor.interfaceWhiteList)
{
UDPv4Transport::interface_whitelist_.emplace_back(asio::ip::address_v4::from_string(interf));
}
test_UDPv4Transport_DropLog.clear();
test_UDPv4Transport_DropLogLength = descriptor.dropLogLength;
test_transport_options->test_UDPv4Transport_DropLog.clear();
test_transport_options->test_UDPv4Transport_DropLogLength = descriptor.dropLogLength;
}

test_UDPv4TransportDescriptor::test_UDPv4TransportDescriptor()
: SocketTransportDescriptor(s_maximumMessageSize, s_maximumInitialPeersRange)
, dropDataMessagesPercentage(0)
, dropParticipantBuiltinDataMessagesPercentage(0)
, dropPublicationBuiltinDataMessagesPercentage(0)
, dropSubscriptionBuiltinDataMessagesPercentage(0)
, drop_data_messages_filter_([](CDRMessage_t&)
{
return false;
})
, drop_builtin_data_messages_filter_([](CDRMessage_t&)
{
return false;
})
, dropParticipantBuiltinTopicData(false)
, dropPublicationBuiltinTopicData(false)
, dropSubscriptionBuiltinTopicData(false)
, dropDataFragMessagesPercentage(0)
, drop_data_frag_messages_filter_([](CDRMessage_t&)
{
return false;
})
, dropHeartbeatMessagesPercentage(0)
, drop_heartbeat_messages_filter_([](CDRMessage_t&)
{
return false;
})
, dropAckNackMessagesPercentage(0)
, drop_ack_nack_messages_filter_([](CDRMessage_t&)
{
return false;
})
, dropGapMessagesPercentage(0)
, drop_gap_messages_filter_([](CDRMessage_t&)
{
return false;
})
, sub_messages_filter_([](CDRMessage_t&)
{
return false;
})
, percentageOfMessagesToDrop(0)
, messages_filter_([](CDRMessage_t&)
{
return false;
})
, locator_filter_([](const Locator&)
{
return false;
})
, sequenceNumberDataMessagesToDrop()
, dropLogLength(0)
{
}

Expand Down Expand Up @@ -155,7 +101,7 @@ bool test_UDPv4Transport::get_ips(
bool return_loopback,
bool force_lookup) const
{
if (!simulate_no_interfaces)
if (!test_transport_options->simulate_no_interfaces)
{
return UDPv4Transport::get_ips(locNames, return_loopback, force_lookup);
}
Expand All @@ -178,7 +124,7 @@ bool test_UDPv4Transport::get_ips(
LocatorList test_UDPv4Transport::NormalizeLocator(
const Locator& locator)
{
if (!simulate_no_interfaces)
if (!test_transport_options->simulate_no_interfaces)
{
return UDPv4Transport::NormalizeLocator(locator);
}
Expand Down Expand Up @@ -308,10 +254,10 @@ static bool ReadSubmessageHeader(
bool test_UDPv4Transport::should_drop_locator(
const Locator& remote_locator)
{
return locator_filter(remote_locator) ||
return test_transport_options->locator_filter(remote_locator) ||
locator_filter_(remote_locator) ||
// If there are no interfaces (simulate_no_interfaces), only multicast and localhost traffic is sent
(simulate_no_interfaces &&
(test_transport_options->simulate_no_interfaces &&
!fastdds::rtps::IPLocator::isMulticast(remote_locator) &&
!fastdds::rtps::IPLocator::isLocal(remote_locator));
}
Expand All @@ -320,7 +266,7 @@ bool test_UDPv4Transport::packet_should_drop(
const std::vector<NetworkBuffer>& buffers,
uint32_t total_bytes)
{
if (test_UDPv4Transport_ShutdownAllNetwork)
if (test_transport_options->test_UDPv4Transport_ShutdownAllNetwork)
{
return true;
}
Expand Down Expand Up @@ -380,7 +326,7 @@ bool test_UDPv4Transport::packet_should_drop(

if (writer_id == fastdds::rtps::c_EntityId_SPDPWriter)
{
if (always_drop_participant_builtin_topic_data)
if (test_transport_options->always_drop_participant_builtin_topic_data)
{
return true;
}
Expand Down Expand Up @@ -526,7 +472,8 @@ bool test_UDPv4Transport::log_drop(
uint32_t size)
{
static_cast<void>(size);
if (test_UDPv4Transport_DropLog.size() < test_UDPv4Transport_DropLogLength)
if (test_transport_options->test_UDPv4Transport_DropLog.size() <
test_transport_options->test_UDPv4Transport_DropLogLength)
{
vector<octet> message;
for (const auto& buf: buffers)
Expand All @@ -535,7 +482,7 @@ bool test_UDPv4Transport::log_drop(
message.insert(message.end(), byte_data, byte_data + buf.size);
}
assert(message.size() == size);
test_UDPv4Transport_DropLog.push_back(message);
test_transport_options->test_UDPv4Transport_DropLog.push_back(message);
return true;
}

Expand Down
9 changes: 1 addition & 8 deletions src/cpp/rtps/transport/test_UDPv4Transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,7 @@ class test_UDPv4Transport : public UDPv4Transport
virtual LocatorList NormalizeLocator(
const Locator& locator) override;

FASTDDS_EXPORTED_API static std::atomic<bool> test_UDPv4Transport_ShutdownAllNetwork;
// Handle to a persistent log of dropped packets. Defaults to length 0 (no logging) to prevent wasted resources.
FASTDDS_EXPORTED_API static std::vector<std::vector<fastdds::rtps::octet>> test_UDPv4Transport_DropLog;
FASTDDS_EXPORTED_API static std::atomic<uint32_t> test_UDPv4Transport_DropLogLength;
FASTDDS_EXPORTED_API static std::atomic<bool> always_drop_participant_builtin_topic_data;
FASTDDS_EXPORTED_API static std::atomic<bool> simulate_no_interfaces;

FASTDDS_EXPORTED_API static test_UDPv4TransportDescriptor::DestinationLocatorFilter locator_filter;
std::shared_ptr<TestUDPv4TransportOptions> test_transport_options;

protected:

Expand Down
Loading
Loading