mirror of https://github.com/ARMmbed/mbed-os.git
Fixes Greentea UDP test cases
udpsocket_echotest.cpp udpsocket_echotest_burst.cpppull/6665/head
parent
4fa57e36fe
commit
1b041721a0
|
|
@ -55,7 +55,7 @@ static void _ifdown() {
|
|||
printf("MBED: ifdown\n");
|
||||
}
|
||||
|
||||
void drop_bad_packets(UDPSocket& sock) {
|
||||
void drop_bad_packets(UDPSocket& sock, int orig_timeout) {
|
||||
nsapi_error_t err;
|
||||
sock.set_timeout(0);
|
||||
while (true) {
|
||||
|
|
@ -64,6 +64,7 @@ void drop_bad_packets(UDPSocket& sock) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
sock.set_timeout(orig_timeout);
|
||||
}
|
||||
|
||||
void fill_tx_buffer_ascii(char *buff, size_t len)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
#define UDP_TESTS_H
|
||||
|
||||
NetworkInterface* get_interface();
|
||||
void drop_bad_packets(UDPSocket& sock);
|
||||
void drop_bad_packets(UDPSocket& sock, int orig_timeout);
|
||||
void fill_tx_buffer_ascii(char *buff, size_t len);
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -90,6 +90,7 @@ void udpsocket_echotest_nonblock_receiver(void *receive_bytes)
|
|||
recvd = sock.recvfrom(NULL, rx_buffer, expt2recv);
|
||||
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
|
||||
wait_ms(WAIT2RECV_TIMEOUT);
|
||||
--retry_cnt;
|
||||
continue;
|
||||
} else if (recvd == expt2recv) {
|
||||
break;
|
||||
|
|
@ -97,8 +98,7 @@ void udpsocket_echotest_nonblock_receiver(void *receive_bytes)
|
|||
}
|
||||
|
||||
TEST_ASSERT_EQUAL(0, memcmp(tx_buffer, rx_buffer, expt2recv));
|
||||
drop_bad_packets(sock);
|
||||
sock.set_blocking(false);
|
||||
drop_bad_packets(sock, -1); // timeout equivalent to set_blocking(false)
|
||||
|
||||
tx_sem.release();
|
||||
}
|
||||
|
|
@ -136,6 +136,7 @@ void test_udpsocket_echotest_nonblock()
|
|||
if (osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
|
||||
continue;
|
||||
}
|
||||
--retry_cnt;
|
||||
} else if (sent != pkt_s) {
|
||||
printf("[Round#%02d - Sender] error, returned %d\n", s_idx, sent);
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#define SIGNAL_SIGIO 0x1
|
||||
#define SIGIO_TIMEOUT 5000 //[ms]
|
||||
#define RECV_TIMEOUT 1 //[s]
|
||||
|
||||
namespace
|
||||
{
|
||||
|
|
@ -56,6 +57,10 @@ void free_tx_buffers() {
|
|||
}
|
||||
}
|
||||
|
||||
static void _sigio_handler(osThreadId id) {
|
||||
osSignalSet(id, SIGNAL_SIGIO);
|
||||
}
|
||||
|
||||
void test_udpsocket_echotest_burst()
|
||||
{
|
||||
SocketAddress udp_addr;
|
||||
|
|
@ -63,71 +68,75 @@ void test_udpsocket_echotest_burst()
|
|||
udp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||
|
||||
UDPSocket sock;
|
||||
const int TIMEOUT = 5000; // [ms]
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
||||
sock.set_timeout(5000);
|
||||
sock.set_timeout(TIMEOUT);
|
||||
sock.sigio(callback(_sigio_handler, Thread::gettid()));
|
||||
|
||||
// TX buffers to be preserved for comparison
|
||||
prepare_tx_buffers();
|
||||
|
||||
int bt_total = 0;
|
||||
int ok_bursts = 0;
|
||||
int pkg_fail = 0;
|
||||
SocketAddress temp_addr;
|
||||
int recvd = 0;
|
||||
int bt_total = 0;
|
||||
int recv_timeout = RECV_TIMEOUT;;
|
||||
SocketAddress temp_addr;
|
||||
for (int i = 0; i < BURST_CNT; i++) {
|
||||
for (int x = 0; x < BURST_PKTS; x++) {
|
||||
TEST_ASSERT_EQUAL(tx_buffers[x].len, sock.sendto(udp_addr, tx_buffers[x].payload, tx_buffers[x].len));
|
||||
}
|
||||
|
||||
recvd = 0;
|
||||
bt_total = 0;
|
||||
recvd = 0;
|
||||
for (int j = 0; j < BURST_PKTS; j++) {
|
||||
recvd = sock.recvfrom(&temp_addr, rx_buffer, 500);
|
||||
if (recvd < 0) {
|
||||
pkg_fail++;
|
||||
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
|
||||
if(osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
|
||||
pkg_fail += BURST_PKTS-j;
|
||||
break;
|
||||
}
|
||||
} else if (recvd < 0) {
|
||||
pkg_fail += BURST_PKTS-j; // Assume all the following packets of the burst to be lost
|
||||
printf("[%02d] network error %d\n", i, recvd);
|
||||
continue;
|
||||
wait(recv_timeout);
|
||||
recv_timeout *= 2; // Back off,
|
||||
break;
|
||||
} else if (temp_addr != udp_addr) {
|
||||
printf("[%02d] packet from wrong address\n", i);
|
||||
--j;
|
||||
continue;
|
||||
}
|
||||
|
||||
recv_timeout = recv_timeout > RECV_TIMEOUT ? recv_timeout/2 : RECV_TIMEOUT;
|
||||
|
||||
// Packets might arrive unordered
|
||||
for (int k = 0; k < BURST_PKTS; k++) {
|
||||
if (tx_buffers[k].len == recvd &&
|
||||
(memcmp(tx_buffers[k].payload, rx_buffer, recvd) == 0)) {
|
||||
bt_total += recvd;
|
||||
goto PKT_OK;
|
||||
}
|
||||
}
|
||||
pkg_fail++;
|
||||
break;
|
||||
PKT_OK:
|
||||
continue;
|
||||
}
|
||||
|
||||
if (bt_total == RECV_TOTAL) {
|
||||
ok_bursts++;
|
||||
} else {
|
||||
drop_bad_packets(sock);
|
||||
drop_bad_packets(sock, TIMEOUT);
|
||||
printf("[%02d] burst failure\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
free_tx_buffers();
|
||||
|
||||
// Packet loss up to 10% tolerated
|
||||
TEST_ASSERT_INT_WITHIN((BURST_CNT*BURST_PKTS/10), BURST_CNT*BURST_PKTS, BURST_CNT*BURST_PKTS-pkg_fail);
|
||||
// 90% of the bursts need to be successful
|
||||
TEST_ASSERT_INT_WITHIN((BURST_CNT/10), BURST_CNT, ok_bursts);
|
||||
// Packet loss up to 1/4 tolerated
|
||||
TEST_ASSERT_INT_WITHIN((BURST_CNT*BURST_PKTS/4), BURST_CNT*BURST_PKTS, BURST_CNT*BURST_PKTS-pkg_fail);
|
||||
// 3/4 of the bursts need to be successful
|
||||
TEST_ASSERT_INT_WITHIN((BURST_CNT/4), BURST_CNT, ok_bursts);
|
||||
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
||||
}
|
||||
|
||||
static void _sigio_handler(osThreadId id) {
|
||||
osSignalSet(id, SIGNAL_SIGIO);
|
||||
}
|
||||
|
||||
void test_udpsocket_echotest_burst_nonblock()
|
||||
{
|
||||
SocketAddress udp_addr;
|
||||
|
|
@ -188,7 +197,7 @@ PKT_OK:
|
|||
if (bt_total == RECV_TOTAL) {
|
||||
ok_bursts++;
|
||||
} else {
|
||||
drop_bad_packets(sock);
|
||||
drop_bad_packets(sock, -1); // timeout equivalent to set_blocking(false)
|
||||
sock.set_blocking(false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue