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

[22441] Improve Blackbox TCP tests suite (backport #5467) #5477

Open
wants to merge 1 commit into
base: 2.10.x
Choose a base branch
from
Open
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
290 changes: 271 additions & 19 deletions test/blackbox/common/BlackboxTestsTransportTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,30 +521,57 @@ TEST_P(TransportTCP, TCPLocalhost)
// Test for ==operator TCPTransportDescriptor is not required as it is an abstract class and in TCPv6 is same method
// Test for copy TCPTransportDescriptor is not required as it is an abstract class and in TCPv6 is same method

// Test == operator for TCPv4
TEST_P(TransportTCP, TCPv4_equal_operator)
// Test == operator for TCPv4/v6
TEST_P(TransportTCP, TCP_equal_operator)
{
<<<<<<< HEAD
// TCPv4TransportDescriptor
TCPv4TransportDescriptor tcpv4_transport_1;
TCPv4TransportDescriptor tcpv4_transport_2;

// Compare equal in defult values
ASSERT_EQ(tcpv4_transport_1, tcpv4_transport_2);

// Modify default values in 1
tcpv4_transport_1.set_WAN_address("80.80.99.45");

ASSERT_FALSE(tcpv4_transport_1 == tcpv4_transport_2); // operator== != operator!=, using operator== == false instead

// Modify default values in 2
tcpv4_transport_2.set_WAN_address("80.80.99.45");

ASSERT_EQ(tcpv4_transport_1, tcpv4_transport_2);
=======
if (use_ipv6)
{
// TCPv6TransportDescriptor
TCPv6TransportDescriptor transport1;
TCPv6TransportDescriptor transport2;
// Compare equal in defult values
ASSERT_EQ(transport1, transport2);
>>>>>>> 0c799f4ca (Improve Blackbox TCP tests suite (#5467))

// Modify some default values in 1
transport1.enable_tcp_nodelay = !transport1.enable_tcp_nodelay; // change default value
transport1.max_logical_port = transport1.max_logical_port + 10; // change default value
transport1.add_listener_port(123u * 98u);
ASSERT_FALSE(transport1 == transport2); // operator== != operator!=, using operator== == false instead

// Modify some default values in 2
transport2.enable_tcp_nodelay = !transport2.enable_tcp_nodelay; // change default value
transport2.max_logical_port = transport2.max_logical_port + 10; // change default value
transport2.add_listener_port(123u * 98u);
ASSERT_EQ(transport1, transport2);
}
else
{
// TCPv4TransportDescriptor
TCPv4TransportDescriptor transport1;
TCPv4TransportDescriptor transport2;
// Compare equal in defult values
ASSERT_EQ(transport1, transport2);

// Modify default values in 1
transport1.set_WAN_address("80.80.99.45");
ASSERT_FALSE(transport1 == transport2); // operator== != operator!=, using operator== == false instead

// Modify default values in 2
transport2.set_WAN_address("80.80.99.45");
ASSERT_EQ(transport1, transport2);
}
}

// Test copy constructor and copy assignment for TCPv4
TEST_P(TransportTCP, TCPv4_copy)
// Test copy constructor and copy assignment for TCPv4/v6
TEST_P(TransportTCP, TCP_copy)
{
<<<<<<< HEAD
TCPv4TransportDescriptor tcpv4_transport;
tcpv4_transport.set_WAN_address("80.80.99.45");

Expand All @@ -555,17 +582,48 @@ TEST_P(TransportTCP, TCPv4_copy)
// Copy assignment
TCPv4TransportDescriptor tcpv4_transport_copy = tcpv4_transport;
EXPECT_EQ(tcpv4_transport_copy, tcpv4_transport);
=======
if (use_ipv6)
{
// Change some varibles in order to check the non default creation
TCPv6TransportDescriptor tcpv6_transport;
tcpv6_transport.enable_tcp_nodelay = !tcpv6_transport.enable_tcp_nodelay; // change default value
tcpv6_transport.max_logical_port = tcpv6_transport.max_logical_port + 10; // change default value
tcpv6_transport.add_listener_port(123u * 98u);
// Copy constructor
TCPv6TransportDescriptor tcpv6_transport_copy_constructor(tcpv6_transport);
EXPECT_EQ(tcpv6_transport, tcpv6_transport_copy_constructor);

// Copy assignment
TCPv6TransportDescriptor tcpv6_transport_copy = tcpv6_transport;
EXPECT_EQ(tcpv6_transport_copy, tcpv6_transport);
}
else
{
TCPv4TransportDescriptor tcpv4_transport;
tcpv4_transport.set_WAN_address("80.80.99.45");

// Copy constructor
TCPv4TransportDescriptor tcpv4_transport_copy_constructor(tcpv4_transport);
EXPECT_EQ(tcpv4_transport, tcpv4_transport_copy_constructor);

// Copy assignment
TCPv4TransportDescriptor tcpv4_transport_copy = tcpv4_transport;
EXPECT_EQ(tcpv4_transport_copy, tcpv4_transport);
}
>>>>>>> 0c799f4ca (Improve Blackbox TCP tests suite (#5467))
}

// Test get_WAN_address member function
TEST_P(TransportTCP, TCPv4_get_WAN_address)
TEST(TransportTCP, TCPv4_get_WAN_address)
{
// TCPv4TransportDescriptor
TCPv4TransportDescriptor tcpv4_transport;
tcpv4_transport.set_WAN_address("80.80.99.45");
ASSERT_EQ(tcpv4_transport.get_WAN_address(), "80.80.99.45");
}

<<<<<<< HEAD
// Test == operator for TCPv6
TEST_P(TransportTCP, TCPv6_equal_operator)
{
Expand Down Expand Up @@ -610,9 +668,11 @@ TEST_P(TransportTCP, TCPv6_copy)
EXPECT_EQ(tcpv6_transport_copy, tcpv6_transport);
}

=======
>>>>>>> 0c799f4ca (Improve Blackbox TCP tests suite (#5467))
// Test connection is successfully restablished after dropping and relaunching a TCP client (requester)
// Issue -> https://github.com/eProsima/Fast-DDS/issues/2409
TEST(TransportTCP, Client_reconnection)
TEST_P(TransportTCP, Client_reconnection)
{
TCPReqRepHelloWorldReplier* replier;
TCPReqRepHelloWorldRequester* requester;
Expand Down Expand Up @@ -671,21 +731,45 @@ TEST(TransportTCP, Client_reconnection)
delete requester;
}

<<<<<<< HEAD
// Test copy constructor and copy assignment for TCPv4
TEST_P(TransportTCP, TCPv4_autofill_port)
=======
// Test zero listening port for TCPv4/v6
TEST_P(TransportTCP, TCP_autofill_port)
>>>>>>> 0c799f4ca (Improve Blackbox TCP tests suite (#5467))
{
PubSubReader<HelloWorldPubSubType> p1(TEST_TOPIC_NAME);
PubSubReader<HelloWorldPubSubType> p2(TEST_TOPIC_NAME);

std::shared_ptr<TCPTransportDescriptor> p1_transport;
std::shared_ptr<TCPTransportDescriptor> p2_transport;
if (use_ipv6)
{
// TCPv6TransportDescriptor
p1_transport = std::make_shared<TCPv6TransportDescriptor>();
p2_transport = std::make_shared<TCPv6TransportDescriptor>();
}
else
{
// TCPv4TransportDescriptor
p1_transport = std::make_shared<TCPv4TransportDescriptor>();
p2_transport = std::make_shared<TCPv4TransportDescriptor>();
}

// Add TCP Transport with listening port 0
<<<<<<< HEAD
auto p1_transport = std::make_shared<TCPv4TransportDescriptor>();
=======
>>>>>>> 0c799f4ca (Improve Blackbox TCP tests suite (#5467))
p1_transport->add_listener_port(0);
p1.disable_builtin_transport().add_user_transport_to_pparams(p1_transport);
p1.init();
ASSERT_TRUE(p1.isInitialized());

// Add TCP Transport with listening port different from 0
uint16_t port = 12345;
<<<<<<< HEAD
auto p2_transport = std::make_shared<TCPv4TransportDescriptor>();
p2_transport->add_listener_port(port);
p2.disable_builtin_transport().add_user_transport_to_pparams(p2_transport);
Expand Down Expand Up @@ -717,6 +801,8 @@ TEST_P(TransportTCP, TCPv6_autofill_port)
// Add TCP Transport with listening port different from 0
uint16_t port = 12345;
auto p2_transport = std::make_shared<TCPv6TransportDescriptor>();
=======
>>>>>>> 0c799f4ca (Improve Blackbox TCP tests suite (#5467))
p2_transport->add_listener_port(port);
p2.disable_builtin_transport().add_user_transport_to_pparams(p2_transport);
p2.init();
Expand Down Expand Up @@ -840,6 +926,87 @@ TEST_P(TransportTCP, large_data_topology)
writers.clear();
}

<<<<<<< HEAD
=======
// This test verifies that if having a server with several listening ports, only the first one is used.
TEST_P(TransportTCP, multiple_listening_ports)
{
// Create a server with several listening ports
PubSubReader<HelloWorldPubSubType>* server = new PubSubReader<HelloWorldPubSubType>(TEST_TOPIC_NAME);
uint16_t server_port_1 = 10000;
uint16_t server_port_2 = 10001;

test_transport_->add_listener_port(server_port_1);
test_transport_->add_listener_port(server_port_2);
server->disable_builtin_transport().add_user_transport_to_pparams(test_transport_).init();
ASSERT_TRUE(server->isInitialized());

// Create two clients each one connecting to a different port
PubSubWriter<HelloWorldPubSubType>* client_1 = new PubSubWriter<HelloWorldPubSubType>(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldPubSubType>* client_2 = new PubSubWriter<HelloWorldPubSubType>(TEST_TOPIC_NAME);
std::shared_ptr<eprosima::fastdds::rtps::TCPTransportDescriptor> client_transport_1;
std::shared_ptr<eprosima::fastdds::rtps::TCPTransportDescriptor> client_transport_2;
Locator_t initialPeerLocator_1;
Locator_t initialPeerLocator_2;
if (use_ipv6)
{
client_transport_1 = std::make_shared<eprosima::fastdds::rtps::TCPv6TransportDescriptor>();
client_transport_2 = std::make_shared<eprosima::fastdds::rtps::TCPv6TransportDescriptor>();
initialPeerLocator_1.kind = LOCATOR_KIND_TCPv6;
initialPeerLocator_2.kind = LOCATOR_KIND_TCPv6;
IPLocator::setIPv6(initialPeerLocator_1, "::1");
IPLocator::setIPv6(initialPeerLocator_2, "::1");
}
else
{
client_transport_1 = std::make_shared<eprosima::fastdds::rtps::TCPv4TransportDescriptor>();
client_transport_2 = std::make_shared<eprosima::fastdds::rtps::TCPv4TransportDescriptor>();
initialPeerLocator_1.kind = LOCATOR_KIND_TCPv4;
initialPeerLocator_2.kind = LOCATOR_KIND_TCPv4;
IPLocator::setIPv4(initialPeerLocator_1, 127, 0, 0, 1);
IPLocator::setIPv4(initialPeerLocator_2, 127, 0, 0, 1);
}
client_1->disable_builtin_transport().add_user_transport_to_pparams(client_transport_1);
client_2->disable_builtin_transport().add_user_transport_to_pparams(client_transport_2);
initialPeerLocator_1.port = server_port_1;
initialPeerLocator_2.port = server_port_2;
LocatorList_t initial_peer_list_1;
LocatorList_t initial_peer_list_2;
initial_peer_list_1.push_back(initialPeerLocator_1);
initial_peer_list_2.push_back(initialPeerLocator_2);
client_1->initial_peers(initial_peer_list_1);
client_2->initial_peers(initial_peer_list_2);
client_1->init();
client_2->init();
ASSERT_TRUE(client_1->isInitialized());
ASSERT_TRUE(client_2->isInitialized());

// Wait for discovery.
server->wait_discovery();
client_1->wait_discovery();
client_2->wait_discovery(std::chrono::seconds(1));
EXPECT_EQ(server->get_matched(), 1U);
EXPECT_EQ(client_1->get_matched(), 1U);
EXPECT_EQ(client_2->get_matched(), 0U);

// Send data
auto data = default_helloworld_data_generator();
server->startReception(data);
client_1->send(data);
// In this test all data should be sent.
ASSERT_TRUE(data.empty());
// Block server until reception finished.
server->block_for_all();
// Wait for all data to be acked.
EXPECT_TRUE(client_1->waitForAllAcked(std::chrono::milliseconds(100)));

// Release TCP client and server resources.
delete client_1;
delete client_2;
delete server;
}

>>>>>>> 0c799f4ca (Improve Blackbox TCP tests suite (#5467))
// Test TCP send resource cleaning. This test matches a server with a client and then releases the
// client resources. After PDP unbind message, the server removes the client
// from the send resource list.
Expand Down Expand Up @@ -1253,6 +1420,91 @@ TEST_P(TransportTCP, large_message_large_data_send_receive)
reader.block_for_all();
}

<<<<<<< HEAD
=======
// Test CreateInitialConnection for TCP
TEST_P(TransportTCP, TCP_initial_peers_connection)
{
PubSubWriter<HelloWorldPubSubType> p1(TEST_TOPIC_NAME);
PubSubReader<HelloWorldPubSubType> p2(TEST_TOPIC_NAME);
PubSubReader<HelloWorldPubSubType> p3(TEST_TOPIC_NAME);

// Add TCP Transport with listening port
std::shared_ptr<TCPTransportDescriptor> p1_transport;
std::shared_ptr<TCPTransportDescriptor> p2_transport;
std::shared_ptr<TCPTransportDescriptor> p3_transport;
if (use_ipv6)
{
// TCPv6TransportDescriptor
p1_transport = std::make_shared<TCPv6TransportDescriptor>();
p2_transport = std::make_shared<TCPv6TransportDescriptor>();
p3_transport = std::make_shared<TCPv6TransportDescriptor>();
}
else
{
// TCPv4TransportDescriptor
p1_transport = std::make_shared<TCPv4TransportDescriptor>();
p2_transport = std::make_shared<TCPv4TransportDescriptor>();
p3_transport = std::make_shared<TCPv4TransportDescriptor>();
}
p1_transport->add_listener_port(global_port);
p2_transport->add_listener_port(global_port + 1);
p3_transport->add_listener_port(global_port - 1);

// Add initial peer to clients
Locator_t initialPeerLocator;
initialPeerLocator.port = global_port;
if (use_ipv6)
{
initialPeerLocator.kind = LOCATOR_KIND_TCPv6;
IPLocator::setIPv6(initialPeerLocator, "::1");
}
else
{
initialPeerLocator.kind = LOCATOR_KIND_TCPv4;
IPLocator::setIPv4(initialPeerLocator, 127, 0, 0, 1);
}
LocatorList_t initial_peer_list;
initial_peer_list.push_back(initialPeerLocator);

// Setup participants
p1.disable_builtin_transport()
.add_user_transport_to_pparams(p1_transport);

p2.disable_builtin_transport()
.initial_peers(initial_peer_list)
.add_user_transport_to_pparams(p2_transport);

p3.disable_builtin_transport()
.initial_peers(initial_peer_list)
.add_user_transport_to_pparams(p3_transport);

// Init participants
p1.init();
p2.init();
p3.init();
ASSERT_TRUE(p1.isInitialized());
ASSERT_TRUE(p2.isInitialized());
ASSERT_TRUE(p3.isInitialized());

// Wait for discovery
p1.wait_discovery(2, std::chrono::seconds(0));
p2.wait_discovery(std::chrono::seconds(0), 1);
p3.wait_discovery(std::chrono::seconds(0), 1);

// Send and receive data
auto data = default_helloworld_data_generator();
p2.startReception(data);
p3.startReception(data);

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

p2.block_for_all();
p3.block_for_all();
}

>>>>>>> 0c799f4ca (Improve Blackbox TCP tests suite (#5467))
#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