Skip to content

Commit f590258

Browse files
authored
Add component send only test (configSend, open) (#4465)
* Add component send only (configSend, open) test * Formatting
1 parent 5baf407 commit f590258

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

Drv/Udp/test/ut/UdpTestMain.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ TEST(Nominal, UdpBasicMessaging) {
99
tester.test_basic_messaging();
1010
}
1111

12+
TEST(Nominal, UdpBasicUnidirectionalMessaging) {
13+
Drv::UdpTester tester;
14+
tester.test_basic_unidirectional_messaging();
15+
}
16+
1217
TEST(Nominal, UdpBasicReceiveThread) {
1318
Drv::UdpTester tester;
1419
tester.test_receive_thread();
@@ -19,6 +24,11 @@ TEST(Reconnect, UdpMultiMessaging) {
1924
tester.test_multiple_messaging();
2025
}
2126

27+
TEST(Reconnect, UdpMultiUnidirectionalMessaging) {
28+
Drv::UdpTester tester;
29+
tester.test_multiple_unidirectional_messaging();
30+
}
31+
2232
TEST(Reconnect, UdpReceiveThreadReconnect) {
2333
Drv::UdpTester tester;
2434
tester.test_advanced_reconnect();

Drv/Udp/test/ut/UdpTester.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace Drv {
2424
// Construction and destruction
2525
// ----------------------------------------------------------------------
2626

27-
void UdpTester::test_with_loop(U32 iterations, bool recv_thread) {
27+
void UdpTester::test_with_loop(U32 iterations, bool recv_thread, bool send_only) {
2828
U8 buffer[sizeof(m_data_storage)] = {};
2929
Drv::SocketIpStatus status1 = Drv::SOCK_SUCCESS;
3030
Drv::SocketIpStatus status2 = Drv::SOCK_SUCCESS;
@@ -47,8 +47,9 @@ void UdpTester::test_with_loop(U32 iterations, bool recv_thread) {
4747

4848
// Configure the component
4949
this->component.configureSend("127.0.0.1", port1, 0, 100);
50-
this->component.configureRecv("127.0.0.1", port2);
51-
50+
if (not send_only) {
51+
this->component.configureRecv("127.0.0.1", port2);
52+
}
5253
// Start up a receive thread
5354
if (recv_thread) {
5455
Os::TaskString name("receiver thread");
@@ -72,8 +73,10 @@ void UdpTester::test_with_loop(U32 iterations, bool recv_thread) {
7273
Drv::Test::get_configured_delay_ms() / 10 + 1));
7374
}
7475
EXPECT_TRUE(this->component.isOpened());
75-
76-
udp2.configureSend("127.0.0.1", port2, 0, 100);
76+
// Other side socket only receives when component is send-only
77+
if (not send_only) {
78+
udp2.configureSend("127.0.0.1", port2, 0, 100);
79+
}
7780
udp2.configureRecv("127.0.0.1", port1);
7881
status2 = udp2.open(udp2_fd);
7982

@@ -93,7 +96,7 @@ void UdpTester::test_with_loop(U32 iterations, bool recv_thread) {
9396
Drv::Test::receive_all(udp2, udp2_fd, buffer, size);
9497
Drv::Test::validate_random_buffer(m_data_buffer, buffer);
9598
// If receive thread is live, try the other way
96-
if (recv_thread) {
99+
if (recv_thread and not send_only) {
97100
m_spinner = false;
98101
m_data_buffer.setSize(sizeof(m_data_storage));
99102
udp2.send(udp2_fd, m_data_buffer.getData(), m_data_buffer.getSize());
@@ -144,6 +147,14 @@ void UdpTester ::test_multiple_messaging() {
144147
test_with_loop(100);
145148
}
146149

150+
void UdpTester ::test_basic_unidirectional_messaging() {
151+
test_with_loop(1, false, true);
152+
}
153+
154+
void UdpTester ::test_multiple_unidirectional_messaging() {
155+
test_with_loop(100, false, true);
156+
}
157+
147158
void UdpTester ::test_receive_thread() {
148159
test_with_loop(1, true);
149160
}

Drv/Udp/test/ut/UdpTester.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ class UdpTester : public UdpGTestBase {
5757
//!
5858
void test_multiple_messaging();
5959

60+
//! Test basic messaging in unidirectional mode
61+
//!
62+
void test_basic_unidirectional_messaging();
63+
64+
//! Test basic reconnection behavior in unidirectional mode
65+
//!
66+
void test_multiple_unidirectional_messaging();
67+
6068
//! Test receive via thread
6169
//!
6270
void test_receive_thread();
@@ -69,7 +77,7 @@ class UdpTester : public UdpGTestBase {
6977
void test_buffer_deallocation();
7078

7179
// Helpers
72-
void test_with_loop(U32 iterations, bool recv_thread = false);
80+
void test_with_loop(U32 iterations, bool recv_thread = false, bool send_only = false);
7381

7482
bool wait_on_change(Drv::IpSocket& socket, bool open, U32 iterations);
7583

0 commit comments

Comments
 (0)