Skip to content

Commit 11f4ee0

Browse files
committed
Making UDP test less strict on dropped/mismatched packets.
Before, the UDP test was very strict on the number of packets it would try to match before failing. Now it will keep trying for the whole test to get enough passing packets. It also includes the test's UUID so you can validate which packets are being received.
1 parent 150951f commit 11f4ee0

File tree

1 file changed

+24
-12
lines changed
  • features/FEATURE_LWIP/TESTS/mbedmicro-net/udp_echo

1 file changed

+24
-12
lines changed

features/FEATURE_LWIP/TESTS/mbedmicro-net/udp_echo/main.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "unity/unity.h"
1313

1414
#ifndef MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE
15-
#define MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE 256
15+
#define MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE 64
1616
#endif
1717

1818
#ifndef MBED_CFG_UDP_CLIENT_ECHO_TIMEOUT
@@ -27,15 +27,25 @@ namespace {
2727
const int ECHO_LOOPS = 16;
2828
}
2929

30-
void prep_buffer(char *tx_buffer, size_t tx_size) {
31-
for (size_t i=0; i<tx_size; ++i) {
30+
void prep_buffer(char *uuid_buffer, size_t uuid_len, char *tx_buffer, size_t tx_size) {
31+
size_t i = 0;
32+
33+
for (; i<uuid_len; ++i) {
34+
tx_buffer[i] = uuid_buffer[i];
35+
}
36+
37+
tx_buffer[i++] = ' ';
38+
39+
for (; i<tx_size; ++i) {
3240
tx_buffer[i] = (rand() % 10) + '0';
3341
}
3442
}
3543

3644
int main() {
37-
GREENTEA_SETUP(60, "udp_echo");
38-
45+
char uuid[48] = {0};
46+
GREENTEA_SETUP_UUID(60, "udp_echo", uuid, 48);
47+
printf("Got a uuid of %s\r\n", uuid);
48+
size_t uuid_len = strlen(uuid);
3949
EthernetInterface eth;
4050
eth.connect();
4151
printf("UDP client IP Address is %s\n", eth.get_ip_address());
@@ -62,24 +72,26 @@ int main() {
6272
SocketAddress udp_addr(ipbuf, port);
6373

6474
int success = 0;
65-
66-
for (int i=0; i < ECHO_LOOPS; ++i) {
67-
prep_buffer(tx_buffer, sizeof(tx_buffer));
75+
int i = 0;
76+
while (success < ECHO_LOOPS) {
77+
prep_buffer(uuid, uuid_len, tx_buffer, sizeof(tx_buffer));
6878
const int ret = sock.sendto(udp_addr, tx_buffer, sizeof(tx_buffer));
69-
printf("[%02d] sent...%d Bytes \n", i, ret);
70-
79+
printf("[%02d] sent %d Bytes - %.*s \n", i, ret, MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE, tx_buffer);
7180
SocketAddress temp_addr;
7281
const int n = sock.recvfrom(&temp_addr, rx_buffer, sizeof(rx_buffer));
73-
printf("[%02d] recv...%d Bytes \n", i, n);
82+
printf("[%02d] recv %d Bytes - %.*s \n", i, ret, MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE, rx_buffer);
7483

7584
if ((temp_addr == udp_addr &&
7685
n == sizeof(tx_buffer) &&
7786
memcmp(rx_buffer, tx_buffer, sizeof(rx_buffer)) == 0)) {
7887
success += 1;
88+
89+
printf("[%02d] success #%d\n", i, success);
7990
}
91+
i++;
8092
}
8193

82-
bool result = (success > 3*ECHO_LOOPS/4);
94+
bool result = success == ECHO_LOOPS;
8395

8496
sock.close();
8597
eth.disconnect();

0 commit comments

Comments
 (0)