Skip to content

Commit

Permalink
Refs #20849: Apply suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>
  • Loading branch information
elianalf committed May 14, 2024
1 parent 14c17fb commit 11320c0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 66 deletions.
3 changes: 0 additions & 3 deletions test/blackbox/common/BlackboxTests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ void default_send_print(
std::list<HelloWorld> default_helloworld_data_generator(
size_t max = 0);

std::list<HelloWorld> default_large_helloworld_data_generator(
size_t max = 0);

std::list<FixedSized> default_fixed_sized_data_generator(
size_t max = 0);

Expand Down
77 changes: 35 additions & 42 deletions test/blackbox/common/RTPSBlackboxTestsBasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <fastdds/rtps/interfaces/IReaderDataFilter.hpp>
#include <fastdds/rtps/participant/RTPSParticipant.h>
#include <fastdds/rtps/RTPSDomain.h>
#include <fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h>
#include <fastdds/rtps/transport/test_UDPv4TransportDescriptor.h>
#include <gtest/gtest.h>

Expand Down Expand Up @@ -1184,49 +1183,45 @@ TEST(RTPS, participant_ignore_local_endpoints_two_participants)
}

/* Maximum number of bytes allowed for an RTPS datagram generated by this participant. */
TEST(RTPS, Check_max_output_message_size_participant)
TEST(RTPS, max_output_message_size_participant)
{
/* Set up */
// Create the RTPSParticipants with the appropriate value for the property
auto testTransport = std::make_shared<eprosima::fastdds::rtps::test_UDPv4TransportDescriptor>();
std::string segment_size_str = "1470";
const uint32_t segment_size = std::stoul(segment_size_str);
const uint32_t segment_size = 1470;
std::string segment_size_str = std::to_string(segment_size);
testTransport->messages_filter_ = [segment_size](eprosima::fastrtps::rtps::CDRMessage_t& datagram)
{
bool result = datagram.length > segment_size;
EXPECT_FALSE(result);
return result;
EXPECT_LE(datagram.length, segment_size);
return false;
};

// Create the RTPSReader
RTPSWithRegistrationReader<Data1mbPubSubType> reader(TEST_TOPIC_NAME);
reader.init();
EXPECT_TRUE(reader.isInitialized());

eprosima::fastrtps::rtps::RTPSParticipantAttributes patt;
eprosima::fastrtps::rtps::RTPSParticipant* participant_reader =
eprosima::fastrtps::rtps::RTPSDomain::createParticipant(static_cast<uint32_t>(GET_PID()) % 230, patt);
ASSERT_NE(participant_reader, nullptr);
patt.useBuiltinTransports = false;
patt.userTransports.push_back(testTransport);
patt.useBuiltinTransports = false;
patt.userTransports.push_back(testTransport);
patt.properties.properties().emplace_back("fastdds.max_message_size", segment_size_str);
eprosima::fastrtps::rtps::RTPSParticipant* participant_writer =
eprosima::fastrtps::rtps::RTPSDomain::createParticipant(static_cast<uint32_t>(GET_PID()) % 230, patt);
ASSERT_NE(participant_writer, nullptr);

// Create the RTPSWriter
RTPSWithRegistrationWriter<HelloWorldPubSubType> writer(TEST_TOPIC_NAME, participant_writer);
RTPSWithRegistrationWriter<Data1mbPubSubType> writer(TEST_TOPIC_NAME, participant_writer);
writer.init();
EXPECT_TRUE(writer.isInitialized());

// Create the RTPSReader
RTPSWithRegistrationReader<HelloWorldPubSubType> reader(TEST_TOPIC_NAME, participant_reader);
reader.init();
EXPECT_TRUE(reader.isInitialized());

// Wait for discovery
writer.wait_discovery(1, std::chrono::seconds(2));
reader.wait_discovery(1, std::chrono::seconds(2));
EXPECT_EQ(writer.get_matched(), 1u);
EXPECT_EQ(reader.get_matched(), 1u);

// Send samples
auto samples = default_large_helloworld_data_generator(1);
auto samples = default_data16kb_data_generator(1);
reader.expected_data(samples);
reader.startReception();
writer.send(samples);
Expand All @@ -1238,46 +1233,44 @@ TEST(RTPS, Check_max_output_message_size_participant)

/* Tear-down */
eprosima::fastrtps::rtps::RTPSDomain::removeRTPSParticipant(participant_writer);
eprosima::fastrtps::rtps::RTPSDomain::removeRTPSParticipant(participant_reader);
}

/* Maximum number of bytes allowed for an RTPS datagram generated by this writer. */
TEST(RTPS, Check_max_output_message_size_writer)
TEST(RTPS, max_output_message_size_writer)
{
std::string segment_size_str = "1470";
const uint32_t segment_size = std::stoul(segment_size_str);
const uint32_t segment_size = 1470;
std::string segment_size_str = std::to_string(segment_size);

auto testTransport = std::make_shared<eprosima::fastdds::rtps::test_UDPv4TransportDescriptor>();
testTransport->messages_filter_ = [segment_size](eprosima::fastrtps::rtps::CDRMessage_t& datagram)
{
bool result = datagram.length > segment_size;
EXPECT_FALSE(result);
return result;
EXPECT_LE(datagram.length, segment_size);
return false;
};
RTPSWithRegistrationWriter<HelloWorldPubSubType> writer_(TEST_TOPIC_NAME);
writer_.add_property("fastdds.max_message_size", segment_size_str).disable_builtin_transport().add_user_transport_to_pparams(testTransport).init();
ASSERT_TRUE(writer_.isInitialized());
RTPSWithRegistrationWriter<Data1mbPubSubType> writer(TEST_TOPIC_NAME);
writer.add_property("fastdds.max_message_size", segment_size_str).disable_builtin_transport().add_user_transport_to_pparams(testTransport).init();
ASSERT_TRUE(writer.isInitialized());

RTPSWithRegistrationReader<HelloWorldPubSubType> reader_(TEST_TOPIC_NAME);
reader_.init();
EXPECT_TRUE(reader_.isInitialized());
RTPSWithRegistrationReader<Data1mbPubSubType> reader(TEST_TOPIC_NAME);
reader.init();
EXPECT_TRUE(reader.isInitialized());

writer_.wait_discovery();
reader_.wait_discovery();
writer.wait_discovery();
reader.wait_discovery();

EXPECT_EQ(writer_.get_matched(), 1u);
EXPECT_EQ(reader_.get_matched(), 1u);
EXPECT_EQ(writer.get_matched(), 1u);
EXPECT_EQ(reader.get_matched(), 1u);

// Send samples
auto samples = default_large_helloworld_data_generator(1);
reader_.expected_data(samples);
reader_.startReception();
writer_.send(samples);
auto samples = default_data16kb_data_generator(1);
reader.expected_data(samples);
reader.startReception();
writer.send(samples);
EXPECT_TRUE(samples.empty());

// Wait for reception
reader_.block_for_all(std::chrono::seconds(1));
EXPECT_EQ(reader_.getReceivedCount(), 1u);
reader.block_for_all(std::chrono::seconds(1));
EXPECT_EQ(reader.getReceivedCount(), 1u);

}

Expand Down
21 changes: 0 additions & 21 deletions test/blackbox/utils/data_generators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,6 @@ std::list<HelloWorld> default_helloworld_data_generator(
return returnedValue;
}

std::list<HelloWorld> default_large_helloworld_data_generator(
size_t max)
{
uint16_t index = 1;
size_t maximum = max ? max : 10;
std::list<HelloWorld> returnedValue(maximum);

std::generate(returnedValue.begin(), returnedValue.end(), [&index]
{
HelloWorld hello;
hello.index(index);
std::stringstream ss;
ss << std::string(10000, 'a') << std::setw(2) << std::setfill('0') << index;
hello.message(ss.str());
++index;
return hello;
});

return returnedValue;
}

std::list<FixedSized> default_fixed_sized_data_generator(
size_t max)
{
Expand Down

0 comments on commit 11320c0

Please sign in to comment.