Skip to content

Commit 031d90a

Browse files
author
Ari Parkkila
committed
Fix UDP socket test cases
Fix UDP socket test cases to check more strictly on failure, and lower trace levels to not print errors on successful cases.
1 parent b710066 commit 031d90a

File tree

7 files changed

+23
-19
lines changed

7 files changed

+23
-19
lines changed

TESTS/netsocket/udp/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ static void _ifup()
6969

7070
#define MESH 3
7171
#if MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == MESH
72-
printf("Waiting for GLOBAL_UP\n");
72+
tr_info("Waiting for GLOBAL_UP\n");
7373
while (net->get_connection_status() != NSAPI_STATUS_GLOBAL_UP) {
7474
ThisThread::sleep_for(500);
7575
}
7676
#endif
77-
printf("MBED: UDPClient IP address is '%s'\n", address ? address.get_ip_address() : "null");
77+
tr_info("MBED: UDPClient IP address is '%s'\n", address ? address.get_ip_address() : "null");
7878
}
7979

8080
static void _ifdown()

TESTS/netsocket/udp/udpsocket_echotest.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void UDPSOCKET_ECHOTEST_impl(bool use_sendto)
9999
} else if (sent == pkt_s) {
100100
packets_sent++;
101101
} else {
102-
tr_error("[Round#%02d - Sender] error, returned %d", s_idx, sent);
102+
tr_warn("[Round#%02d - Sender] error, returned %d", s_idx, sent);
103103
continue;
104104
}
105105

@@ -113,7 +113,7 @@ void UDPSOCKET_ECHOTEST_impl(bool use_sendto)
113113
//Check if received duplicated packet
114114
for (unsigned int d_idx = 0; d_idx < PKTS; ++d_idx) {
115115
if (pkt_received[d_idx] && d_idx != s_idx && recvd == pkt_sizes[d_idx]) {
116-
printf("[Round#%02d - Receiver] info, received duplicate packet %d\n", s_idx, d_idx);
116+
tr_warn("[Round#%02d - Receiver] info, received duplicate packet %d\n", s_idx, d_idx);
117117
received_duplicate_packet = true;
118118
break;
119119
}
@@ -123,7 +123,7 @@ void UDPSOCKET_ECHOTEST_impl(bool use_sendto)
123123
if (recvd == pkt_s) {
124124
break;
125125
} else {
126-
tr_error("[Round#%02d - Receiver] error, returned %d", s_idx, recvd);
126+
tr_warn("[Round#%02d - Receiver] error, returned %d", s_idx, recvd);
127127
}
128128
}
129129

@@ -206,7 +206,7 @@ void UDPSOCKET_ECHOTEST_NONBLOCK_impl(bool use_sendto)
206206
}
207207
--retry_cnt;
208208
} else {
209-
tr_error("[Round#%02d - Sender] error, returned %d", s_idx, sent);
209+
tr_warn("[Round#%02d - Sender] error, returned %d", s_idx, sent);
210210
continue;
211211
}
212212

@@ -227,7 +227,7 @@ void UDPSOCKET_ECHOTEST_NONBLOCK_impl(bool use_sendto)
227227
--retry_recv;
228228
continue;
229229
} else if (recvd < 0) {
230-
tr_error("sock.recvfrom returned %d", recvd);
230+
tr_warn("sock.recvfrom returned %d", recvd);
231231
TEST_FAIL();
232232
break;
233233
} else if (recvd == pkt_s) {

TESTS/netsocket/udp/udpsocket_echotest_burst.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void UDPSOCKET_ECHOTEST_BURST()
116116
}
117117
} else if (recvd < 0) {
118118
pkg_fail += BURST_PKTS - j; // Assume all the following packets of the burst to be lost
119-
tr_error("[%02d] network error %d", i, recvd);
119+
tr_warn("[%02d] network error %d", i, recvd);
120120
ThisThread::sleep_for(recv_timeout * 1000);
121121
recv_timeout *= 2; // Back off,
122122
break;
@@ -141,7 +141,7 @@ void UDPSOCKET_ECHOTEST_BURST()
141141
ok_bursts++;
142142
} else {
143143
drop_bad_packets(sock, TIMEOUT);
144-
tr_error("[%02d] burst failure, rcv %d", i, bt_total);
144+
tr_warn("[%02d] burst failure, rcv %d", i, bt_total);
145145
}
146146
}
147147

@@ -217,7 +217,7 @@ void UDPSOCKET_ECHOTEST_BURST_NONBLOCK()
217217
goto PKT_OK;
218218
}
219219
}
220-
tr_error("[bt#%02d] corrupted packet...", i);
220+
tr_warn("[bt#%02d] corrupted packet...", i);
221221
pkg_fail++;
222222
break;
223223
PKT_OK:

TESTS/netsocket/udp/udpsocket_open_limit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void UDPSOCKET_OPEN_LIMIT()
4949
}
5050
ret = sock->open(NetworkInterface::get_default_instance());
5151
if (ret == NSAPI_ERROR_NO_MEMORY || ret == NSAPI_ERROR_NO_SOCKET) {
52-
tr_error("[round#%02d] unable to open new socket, error: %d", i, ret);
52+
tr_info("[round#%02d] unable to open new socket, error: %d", i, ret);
5353
delete sock;
5454
break;
5555
}

TESTS/netsocket/udp/udpsocket_recv_timeout.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ void UDPSOCKET_RECV_TIMEOUT()
7070
}
7171
continue;
7272
} else if (recvd < 0) {
73-
tr_error("[bt#%02d] network error %d", i, recvd);
73+
tr_warn("[bt#%02d] network error %d", i, recvd);
7474
continue;
7575
} else if (temp_addr != udp_addr) {
76-
tr_info("[bt#%02d] packet from wrong address", i);
76+
tr_warn("[bt#%02d] packet from wrong address", i);
7777
continue;
7878
}
7979
TEST_ASSERT_EQUAL(DATA_LEN, recvd);

TESTS/network/multihoming/multihoming_udpsocket_echotest.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void MULTIHOMING_UDPSOCKET_ECHOTEST()
8484
packets_sent++;
8585
}
8686
if (sent != pkt_s) {
87-
printf("[Round#%02d - Sender] error, returned %d\n", s_idx, sent);
87+
tr_warn("[Round#%02d - Sender] error, returned %d\n", s_idx, sent);
8888
continue;
8989
}
9090
recvd = sock.recvfrom(NULL, rx_buffer, pkt_s);
@@ -99,8 +99,10 @@ void MULTIHOMING_UDPSOCKET_ECHOTEST()
9999
// Packet loss up to 30% tolerated
100100
if (packets_sent > 0) {
101101
double loss_ratio = 1 - ((double)packets_recv / (double)packets_sent);
102-
printf("Interface %s, packets sent: %d, packets received %d, loss ratio %.2lf\r\n", interface_name[j], packets_sent, packets_recv, loss_ratio);
102+
tr_warn("Interface %s, packets sent: %d, packets received %d, loss ratio %.2lf\r\n", interface_name[j], packets_sent, packets_recv, loss_ratio);
103103
TEST_ASSERT_DOUBLE_WITHIN(TOLERATED_LOSS_RATIO, EXPECTED_LOSS_RATIO, loss_ratio);
104+
} else {
105+
TEST_FAIL();
104106
}
105107
}
106108
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
@@ -177,7 +179,7 @@ void MULTIHOMING_UDPSOCKET_ECHOTEST_NONBLOCK()
177179
}
178180
--retry_cnt;
179181
} else if (sent != pkt_s) {
180-
printf("[Round#%02d - Sender] error, returned %d\n", s_idx, sent);
182+
tr_warn("[Round#%02d - Sender] error, returned %d\n", s_idx, sent);
181183
continue;
182184
}
183185
if (!tx_sem.try_acquire_for(WAIT2RECV_TIMEOUT * 2)) { // RX might wait up to WAIT2RECV_TIMEOUT before recvfrom
@@ -196,7 +198,7 @@ void MULTIHOMING_UDPSOCKET_ECHOTEST_NONBLOCK()
196198
// Packet loss up to 30% tolerated
197199
if (packets_sent > 0) {
198200
double loss_ratio = 1 - ((double)packets_recv / (double)packets_sent);
199-
printf("Interface %s, Packets sent: %d, packets received %d, loss ratio %.2lf\r\n", interface_name[j], packets_sent, packets_recv, loss_ratio);
201+
tr_info("Interface %s, Packets sent: %d, packets received %d, loss ratio %.2lf\r\n", interface_name[j], packets_sent, packets_recv, loss_ratio);
200202
TEST_ASSERT_DOUBLE_WITHIN(TOLERATED_LOSS_RATIO, EXPECTED_LOSS_RATIO, loss_ratio);
201203

202204
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED
@@ -209,10 +211,12 @@ void MULTIHOMING_UDPSOCKET_ECHOTEST_NONBLOCK()
209211
}
210212
}
211213
loss_ratio = 1 - ((double)udp_stats[j].recv_bytes / (double)udp_stats[j].sent_bytes);
212-
printf("Bytes sent: %d, bytes received %d, loss ratio %.2lf\r\n", udp_stats[j].sent_bytes, udp_stats[j].recv_bytes, loss_ratio);
214+
tr_info("Bytes sent: %d, bytes received %d, loss ratio %.2lf\r\n", udp_stats[j].sent_bytes, udp_stats[j].recv_bytes, loss_ratio);
213215
TEST_ASSERT_DOUBLE_WITHIN(TOLERATED_LOSS_RATIO, EXPECTED_LOSS_RATIO, loss_ratio);
214216

215217
#endif
218+
} else {
219+
TEST_FAIL();
216220
}
217221
}
218222
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());

features/cellular/framework/AT/AT_CellularStack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ nsapi_error_t AT_CellularStack::socket_open(nsapi_socket_t *handle, nsapi_protoc
181181

182182
int index = find_socket_index(0);
183183
if (index == -1) {
184-
tr_error("No free sockets!");
184+
tr_warn("No free sockets!");
185185
_socket_mutex.unlock();
186186
return NSAPI_ERROR_NO_SOCKET;
187187
}

0 commit comments

Comments
 (0)