Skip to content

Commit d55b3cf

Browse files
bridadangeky
authored andcommitted
Fixing some issues in the tcp/udp tests
1 parent abcdd01 commit d55b3cf

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Echo {
6464
TEST_ASSERT_EQUAL(0, err);
6565

6666
iomutex.lock();
67-
printf("HTTP: Connected to %s:%d\r\n",
67+
printf("HTTP: Connected to %s:%d\r\n",
6868
tcp_addr.get_ip_address(), tcp_addr.get_port());
6969
printf("tx_buffer buffer size: %u\r\n", sizeof(tx_buffer));
7070
printf("rx_buffer buffer size: %u\r\n", sizeof(rx_buffer));
@@ -89,7 +89,7 @@ Echo echoers[MBED_CFG_TCP_CLIENT_ECHO_THREADS];
8989

9090
int main() {
9191
char uuid[48] = {0};
92-
GREENTEA_SETUP_UUID(60, "default_auto", uuid, 48);
92+
GREENTEA_SETUP_UUID(60, "tcp_echo", uuid, 48);
9393
mbed_set_mac_address(uuid, /*coerce control bits*/ 1);
9494

9595
int err = net.connect();

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,23 @@ int main() {
8383
while (success < ECHO_LOOPS) {
8484
prep_buffer(uuid, uuid_len, tx_buffer, sizeof(tx_buffer));
8585
const int ret = sock.sendto(udp_addr, tx_buffer, sizeof(tx_buffer));
86-
printf("[%02d] sent %d Bytes - %.*s \n", i, ret, MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE, tx_buffer);
86+
if (ret >= 0) {
87+
printf("[%02d] sent %d Bytes - %.*s \n", i, ret, ret, tx_buffer);
88+
} else {
89+
printf("[%02d] Network error %d\n", i, ret);
90+
i++;
91+
continue;
92+
}
93+
8794
SocketAddress temp_addr;
8895
const int n = sock.recvfrom(&temp_addr, rx_buffer, sizeof(rx_buffer));
89-
printf("[%02d] recv %d Bytes - %.*s \n", i, ret, MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE, rx_buffer);
96+
if (n >= 0) {
97+
printf("[%02d] receive %d Bytes - %.*s \n", i, n, n, tx_buffer);
98+
} else {
99+
printf("[%02d] Network error %d\n", i, n);
100+
i++;
101+
continue;
102+
}
90103

91104
if ((temp_addr == udp_addr &&
92105
n == sizeof(tx_buffer) &&

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,31 @@ class Echo {
9090
while(success < ECHO_LOOPS) {
9191
prep_buffer(id, uuid_buffer, uuid_len, tx_buffer, sizeof(tx_buffer));
9292
const int ret = sock.sendto(udp_addr, tx_buffer, sizeof(tx_buffer));
93-
iomutex.lock();
94-
printf("[ID:%01d][%02d] sent %d Bytes - %.*s\n", id, i, ret, MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE, tx_buffer);
95-
iomutex.unlock();
93+
if (ret >= 0) {
94+
iomutex.lock();
95+
printf("[ID:%01d][%02d] sent %d Bytes - %.*s \n", id, i, ret, ret, tx_buffer);
96+
iomutex.unlock();
97+
} else {
98+
iomutex.lock();
99+
printf("[ID:%01d][%02d] Network error %d\n", id, i, ret);
100+
iomutex.unlock();
101+
i++;
102+
continue;
103+
}
96104

97105
SocketAddress temp_addr;
98106
const int n = sock.recvfrom(&temp_addr, rx_buffer, sizeof(rx_buffer));
99-
iomutex.lock();
100-
printf("[ID:%01d][%02d] recv %d Bytes - %.*s\n", id, i, ret, MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE, rx_buffer);
101-
iomutex.unlock();
107+
if (n >= 0) {
108+
iomutex.lock();
109+
printf("[ID:%01d][%02d] receive %d Bytes - %.*s \n", id, i, n, n, tx_buffer);
110+
iomutex.unlock();
111+
} else {
112+
iomutex.lock();
113+
printf("[ID:%01d][%02d] Network error %d\n", id, i, n);
114+
iomutex.unlock();
115+
i++;
116+
continue;
117+
}
102118

103119
if ((temp_addr == udp_addr &&
104120
n == sizeof(tx_buffer) &&

0 commit comments

Comments
 (0)