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

Add log on TCP/UDP UT failure and fix UDP UT #2705

Merged
merged 5 commits into from
Apr 29, 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
5 changes: 4 additions & 1 deletion Drv/TcpClient/test/ut/TcpClientTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ void TcpClientTester ::test_with_loop(U32 iterations, bool recv_thread) {
server.configure("127.0.0.1", port, 0, 100);
this->component.configure("127.0.0.1", port, 0, 100);
serverStat = server.startup();
ASSERT_EQ(serverStat, SOCK_SUCCESS);

ASSERT_EQ(serverStat, SOCK_SUCCESS)
<< "TCP server startup error: " << strerror(errno) << std::endl
<< "Port: " << port << std::endl;

// Start up a receive thread
if (recv_thread) {
Expand Down
4 changes: 3 additions & 1 deletion Drv/TcpServer/test/ut/TcpServerTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ void TcpServerTester ::test_with_loop(U32 iterations, bool recv_thread) {
EXPECT_TRUE(Drv::Test::wait_on_started(this->component.getSocketHandler(), true, SOCKET_RETRY_INTERVAL_MS/10 + 1));
} else {
serverStat = this->component.startup();
EXPECT_EQ(serverStat, SOCK_SUCCESS);
ASSERT_EQ(serverStat, SOCK_SUCCESS)
<< "TCP server startup error: " << strerror(errno) << std::endl
<< "Port: " << port << std::endl;
}
EXPECT_TRUE(component.getSocketHandler().isStarted());

Expand Down
28 changes: 23 additions & 5 deletions Drv/Udp/test/ut/UdpTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,21 @@ void UdpTester::test_with_loop(U32 iterations, bool recv_thread) {
Drv::SocketIpStatus status1 = Drv::SOCK_SUCCESS;
Drv::SocketIpStatus status2 = Drv::SOCK_SUCCESS;

U16 port1 = Drv::Test::get_free_port();
U16 port1 = Drv::Test::get_free_port(true);
ASSERT_NE(0, port1);
U16 port2 = Drv::Test::get_free_port();
U16 port2 = Drv::Test::get_free_port(true);
ASSERT_NE(0, port2);

uint8_t attempt_to_find_available_port = 100;

while ((port1 == port2) && attempt_to_find_available_port > 0)
{
U16 port2 = Drv::Test::get_free_port(true);
ASSERT_NE(0, port2);
--attempt_to_find_available_port;
}
ASSERT_NE(port1, port2);

// Configure the component
this->component.configureSend("127.0.0.1", port1, 0, 100);
this->component.configureRecv("127.0.0.1", port2);
Expand All @@ -52,17 +62,25 @@ void UdpTester::test_with_loop(U32 iterations, bool recv_thread) {
// Not testing with reconnect thread, we will need to open ourselves
if (not recv_thread) {
status1 = this->component.open();

EXPECT_EQ(status1, Drv::SOCK_SUCCESS)
<< "UDP socket open error: " << strerror(errno)
<< "Port1: " << port1
<< "Port2: " << port2;

} else {
EXPECT_TRUE(Drv::Test::wait_on_change(this->component.getSocketHandler(), true, SOCKET_RETRY_INTERVAL_MS/10 + 1));
}
EXPECT_TRUE(this->component.getSocketHandler().isOpened());

udp2.configureSend("127.0.0.1", port2, 0, 100);
udp2.configureRecv("127.0.0.1", port1);
status2 = udp2.open();;
status2 = udp2.open();

EXPECT_EQ(status1, Drv::SOCK_SUCCESS);
EXPECT_EQ(status2, Drv::SOCK_SUCCESS);
EXPECT_EQ(status2, Drv::SOCK_SUCCESS)
<< "UDP socket open error: " << strerror(errno) << std::endl
<< "Port1: " << port1 << std::endl
<< "Port2: " << port2 << std::endl;

// If all the opens worked, then run this
if ((Drv::SOCK_SUCCESS == status1) && (Drv::SOCK_SUCCESS == status2) &&
Expand Down
Loading