mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #9570 from VeijoPesonen/bugfix-tests-netsocket-udp_udpsocket_echotest_nonblock
tests-netsocket-udp: UDPSOCKET_ECHOTEST_NONBLOCK fixespull/9677/head
commit
091509705f
|
@ -33,10 +33,26 @@
|
|||
|
||||
using namespace utest::v1;
|
||||
|
||||
namespace {
|
||||
Timer tc_bucket; // Timer to limit a test cases run time
|
||||
}
|
||||
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
mbed_stats_socket_t udp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
|
||||
#endif
|
||||
|
||||
void drop_bad_packets(UDPSocket &sock, int orig_timeout)
|
||||
{
|
||||
nsapi_error_t err;
|
||||
sock.set_timeout(0);
|
||||
while (true) {
|
||||
err = sock.recv(NULL, 0);
|
||||
if (err == NSAPI_ERROR_WOULD_BLOCK) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
sock.set_timeout(orig_timeout);
|
||||
}
|
||||
static void _ifup()
|
||||
{
|
||||
NetworkInterface *net = NetworkInterface::get_default_instance();
|
||||
|
@ -51,18 +67,6 @@ static void _ifdown()
|
|||
printf("MBED: ifdown\n");
|
||||
}
|
||||
|
||||
void drop_bad_packets(UDPSocket &sock, int orig_timeout)
|
||||
{
|
||||
nsapi_error_t err;
|
||||
sock.set_timeout(0);
|
||||
while (true) {
|
||||
err = sock.recvfrom(NULL, 0, 0);
|
||||
if (err == NSAPI_ERROR_WOULD_BLOCK) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
sock.set_timeout(orig_timeout);
|
||||
}
|
||||
|
||||
nsapi_version_t get_ip_version()
|
||||
{
|
||||
|
@ -80,6 +84,11 @@ void fill_tx_buffer_ascii(char *buff, size_t len)
|
|||
}
|
||||
}
|
||||
|
||||
int split2half_rmng_udp_test_time()
|
||||
{
|
||||
return (udp_global::TESTS_TIMEOUT - tc_bucket.read()) / 2;
|
||||
}
|
||||
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
int fetch_stats()
|
||||
{
|
||||
|
@ -90,20 +99,20 @@ int fetch_stats()
|
|||
// Test setup
|
||||
utest::v1::status_t greentea_setup(const size_t number_of_cases)
|
||||
{
|
||||
GREENTEA_SETUP(480, "default_auto");
|
||||
GREENTEA_SETUP(udp_global::TESTS_TIMEOUT, "default_auto");
|
||||
_ifup();
|
||||
tc_bucket.start();
|
||||
return greentea_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
||||
void greentea_teardown(const size_t passed, const size_t failed, const failure_t failure)
|
||||
{
|
||||
tc_bucket.stop();
|
||||
_ifdown();
|
||||
return greentea_test_teardown_handler(passed, failed, failure);
|
||||
}
|
||||
|
||||
Case cases[] = {
|
||||
Case("UDPSOCKET_ECHOTEST", UDPSOCKET_ECHOTEST),
|
||||
Case("UDPSOCKET_ECHOTEST_NONBLOCK", UDPSOCKET_ECHOTEST_NONBLOCK),
|
||||
Case("UDPSOCKET_OPEN_CLOSE_REPEAT", UDPSOCKET_OPEN_CLOSE_REPEAT),
|
||||
Case("UDPSOCKET_OPEN_LIMIT", UDPSOCKET_OPEN_LIMIT),
|
||||
Case("UDPSOCKET_RECV_TIMEOUT", UDPSOCKET_RECV_TIMEOUT),
|
||||
|
@ -119,10 +128,11 @@ Case cases[] = {
|
|||
Case("UDPSOCKET_BIND_WRONG_TYPE", UDPSOCKET_BIND_WRONG_TYPE),
|
||||
Case("UDPSOCKET_BIND_UNOPENED", UDPSOCKET_BIND_UNOPENED),
|
||||
Case("UDPSOCKET_SENDTO_INVALID", UDPSOCKET_SENDTO_INVALID),
|
||||
Case("UDPSOCKET_ECHOTEST", UDPSOCKET_ECHOTEST),
|
||||
Case("UDPSOCKET_ECHOTEST_BURST", UDPSOCKET_ECHOTEST_BURST),
|
||||
Case("UDPSOCKET_ECHOTEST_NONBLOCK", UDPSOCKET_ECHOTEST_NONBLOCK),
|
||||
Case("UDPSOCKET_ECHOTEST_BURST_NONBLOCK", UDPSOCKET_ECHOTEST_BURST_NONBLOCK),
|
||||
Case("UDPSOCKET_SENDTO_REPEAT", UDPSOCKET_SENDTO_REPEAT),
|
||||
Case("UDPSOCKET_ECHOTEST", UDPSOCKET_ECHOTEST),
|
||||
Case("UDPSOCKET_ECHOTEST_BURST", UDPSOCKET_ECHOTEST_BURST),
|
||||
};
|
||||
|
||||
Specification specification(greentea_setup, cases, greentea_teardown, greentea_continue_handlers);
|
||||
|
|
|
@ -28,6 +28,15 @@ extern mbed_stats_socket_t udp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
|
|||
int fetch_stats(void);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Single testcase might take only half of the remaining execution time
|
||||
*/
|
||||
int split2half_rmng_udp_test_time(); // [s]
|
||||
|
||||
namespace udp_global {
|
||||
static const int TESTS_TIMEOUT = 480;
|
||||
}
|
||||
|
||||
/*
|
||||
* Test cases
|
||||
*/
|
||||
|
|
|
@ -45,6 +45,8 @@ static const int pkt_sizes[PKTS] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, \
|
|||
100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, \
|
||||
1100, 1200
|
||||
};
|
||||
Timer tc_exec_time;
|
||||
int time_allotted;
|
||||
}
|
||||
|
||||
static void _sigio_handler(osThreadId id)
|
||||
|
@ -106,6 +108,9 @@ void udpsocket_echotest_nonblock_receiver(void *receive_bytes)
|
|||
for (int retry_cnt = 0; retry_cnt <= RETRIES; retry_cnt++) {
|
||||
recvd = sock.recvfrom(NULL, rx_buffer, expt2recv);
|
||||
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
|
||||
if (tc_exec_time.read() >= time_allotted) {
|
||||
break;
|
||||
}
|
||||
wait_ms(WAIT2RECV_TIMEOUT);
|
||||
--retry_cnt;
|
||||
continue;
|
||||
|
@ -118,7 +123,7 @@ void udpsocket_echotest_nonblock_receiver(void *receive_bytes)
|
|||
}
|
||||
}
|
||||
|
||||
drop_bad_packets(sock, -1); // timeout equivalent to set_blocking(false)
|
||||
drop_bad_packets(sock, 0); // timeout equivalent to set_blocking(false)
|
||||
|
||||
tx_sem.release();
|
||||
}
|
||||
|
@ -132,6 +137,8 @@ void UDPSOCKET_ECHOTEST_NONBLOCK()
|
|||
TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state);
|
||||
}
|
||||
#endif
|
||||
tc_exec_time.start();
|
||||
time_allotted = split2half_rmng_udp_test_time(); // [s]
|
||||
|
||||
SocketAddress udp_addr;
|
||||
NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||
|
@ -166,7 +173,8 @@ void UDPSOCKET_ECHOTEST_NONBLOCK()
|
|||
packets_sent++;
|
||||
}
|
||||
if (sent == NSAPI_ERROR_WOULD_BLOCK) {
|
||||
if (osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
|
||||
if (tc_exec_time.read() >= time_allotted ||
|
||||
osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
|
||||
continue;
|
||||
}
|
||||
--retry_cnt;
|
||||
|
@ -209,4 +217,5 @@ void UDPSOCKET_ECHOTEST_NONBLOCK()
|
|||
#endif
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
||||
tc_exec_time.stop();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue