Skip to content

Commit 0328ffd

Browse files
michalpasztamobicaadbridge
authored andcommitted
UDPSOCKET_ECHOTEST fails if a packet of any given size was not sent at least once
1 parent 74f0a3e commit 0328ffd

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

TESTS/netsocket/README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -785,9 +785,9 @@ Verify working of different packet sizes.
785785

786786
**Expected result:**
787787

788-
All sendto() calls should return the packet size. All recvfrom() calls
789-
should return the same sized packet that was send with same content.
790-
Calculate packet loss rate, maximum tolerated packet loss rate is 30%
788+
At least one sendto() call of every size should return the packet size.
789+
Errors returned from recvfrom() calls are tolerated.
790+
Calculate packet loss rate, maximum tolerated packet loss rate is 30%.
791791

792792

793793

@@ -819,11 +819,9 @@ mode
819819

820820
**Expected result:**
821821

822-
All sendto() calls should return the packet size. All recvfrom() calls
823-
should return the same sized packet that was send with same content or
824-
NSAPI_ERROR_WOULD_BLOCK.
825-
826-
Calculate packet loss rate, maximum tolerated packet loss rate is 30%
822+
At least one sendto() call of every size should return the packet size.
823+
Errors returned from recvfrom() calls are tolerated.
824+
Calculate packet loss rate, maximum tolerated packet loss rate is 30%.
827825

828826

829827

TESTS/netsocket/udp/udpsocket_echotest.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,28 +74,33 @@ void UDPSOCKET_ECHOTEST()
7474
int pkt_s = pkt_sizes[s_idx];
7575

7676
fill_tx_buffer_ascii(tx_buffer, BUFF_SIZE);
77+
int packets_sent_prev = packets_sent;
7778

7879
for (int retry_cnt = 0; retry_cnt <= 2; retry_cnt++) {
7980
memset(rx_buffer, 0, BUFF_SIZE);
8081
sent = sock.sendto(udp_addr, tx_buffer, pkt_s);
8182
if (check_oversized_packets(sent, pkt_s)) {
8283
TEST_IGNORE_MESSAGE("This device does not handle oversized packets");
83-
} else if (sent > 0) {
84+
} else if (sent == pkt_s) {
8485
packets_sent++;
85-
}
86-
if (sent != pkt_s) {
86+
} else {
8787
printf("[Round#%02d - Sender] error, returned %d\n", s_idx, sent);
8888
continue;
8989
}
9090
recvd = sock.recvfrom(NULL, rx_buffer, pkt_s);
9191
if (recvd == pkt_s) {
9292
break;
93+
} else {
94+
printf("[Round#%02d - Receiver] error, returned %d\n", s_idx, recvd);
9395
}
9496
}
9597
if (memcmp(tx_buffer, rx_buffer, pkt_s) == 0) {
9698
packets_recv++;
9799
}
100+
// Make sure that at least one packet of every size was sent.
101+
TEST_ASSERT_TRUE(packets_sent > packets_sent_prev);
98102
}
103+
99104
// Packet loss up to 30% tolerated
100105
if (packets_sent > 0) {
101106
double loss_ratio = 1 - ((double)packets_recv / (double)packets_sent);
@@ -154,6 +159,7 @@ void UDPSOCKET_ECHOTEST_NONBLOCK()
154159

155160
for (int s_idx = 0; s_idx < sizeof(pkt_sizes) / sizeof(*pkt_sizes); ++s_idx) {
156161
int pkt_s = pkt_sizes[s_idx];
162+
int packets_sent_prev = packets_sent;
157163

158164
thread = new Thread(osPriorityNormal,
159165
OS_STACK_SIZE,
@@ -165,16 +171,15 @@ void UDPSOCKET_ECHOTEST_NONBLOCK()
165171
fill_tx_buffer_ascii(tx_buffer, pkt_s);
166172

167173
sent = sock.sendto(udp_addr, tx_buffer, pkt_s);
168-
if (sent > 0) {
174+
if (sent == pkt_s) {
169175
packets_sent++;
170-
}
171-
if (sent == NSAPI_ERROR_WOULD_BLOCK) {
176+
} else if (sent == NSAPI_ERROR_WOULD_BLOCK) {
172177
if (tc_exec_time.read() >= time_allotted ||
173178
osSignalWait(SIGNAL_SIGIO_TX, SIGIO_TIMEOUT).status == osEventTimeout) {
174179
continue;
175180
}
176181
--retry_cnt;
177-
} else if (sent != pkt_s) {
182+
} else {
178183
printf("[Round#%02d - Sender] error, returned %d\n", s_idx, sent);
179184
continue;
180185
}
@@ -183,6 +188,8 @@ void UDPSOCKET_ECHOTEST_NONBLOCK()
183188
}
184189
break;
185190
}
191+
// Make sure that at least one packet of every size was sent.
192+
TEST_ASSERT_TRUE(packets_sent > packets_sent_prev);
186193
thread->join();
187194
delete thread;
188195
if (memcmp(tx_buffer, rx_buffer, pkt_s) == 0) {

0 commit comments

Comments
 (0)