mirror of https://github.com/ARMmbed/mbed-os.git
Fix tests-netsocket-udp
Use std::chrono literals and variables where it makes sensepull/13046/head
parent
a3f4cf212d
commit
2b934a228f
|
@ -118,9 +118,9 @@ void fill_tx_buffer_ascii(char *buff, size_t len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int split2half_rmng_udp_test_time()
|
microseconds split2half_rmng_udp_test_time()
|
||||||
{
|
{
|
||||||
return (udp_global::TESTS_TIMEOUT - tc_bucket.read()) / 2;
|
return (udp_global::TESTS_TIMEOUT - tc_bucket.elapsed_time()) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED
|
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED
|
||||||
|
@ -133,7 +133,7 @@ int fetch_stats()
|
||||||
// Test setup
|
// Test setup
|
||||||
utest::v1::status_t greentea_setup(const size_t number_of_cases)
|
utest::v1::status_t greentea_setup(const size_t number_of_cases)
|
||||||
{
|
{
|
||||||
GREENTEA_SETUP(udp_global::TESTS_TIMEOUT, "default_auto");
|
GREENTEA_SETUP(seconds(udp_global::TESTS_TIMEOUT).count(), "default_auto");
|
||||||
_ifup();
|
_ifup();
|
||||||
tc_bucket.start();
|
tc_bucket.start();
|
||||||
return greentea_test_setup_handler(number_of_cases);
|
return greentea_test_setup_handler(number_of_cases);
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include "../test_params.h"
|
#include "../test_params.h"
|
||||||
#include "mbed_trace.h"
|
#include "mbed_trace.h"
|
||||||
|
|
||||||
|
using namespace std::chrono;
|
||||||
|
|
||||||
#define TRACE_GROUP "GRNT"
|
#define TRACE_GROUP "GRNT"
|
||||||
|
|
||||||
NetworkInterface *get_interface();
|
NetworkInterface *get_interface();
|
||||||
|
@ -37,18 +39,18 @@ int fetch_stats(void);
|
||||||
/**
|
/**
|
||||||
* Single testcase might take only half of the remaining execution time
|
* Single testcase might take only half of the remaining execution time
|
||||||
*/
|
*/
|
||||||
int split2half_rmng_udp_test_time(); // [s]
|
microseconds split2half_rmng_udp_test_time();
|
||||||
|
|
||||||
namespace udp_global {
|
namespace udp_global {
|
||||||
#ifdef MBED_GREENTEA_TEST_UDPSOCKET_TIMEOUT_S
|
#ifdef MBED_GREENTEA_TEST_UDPSOCKET_TIMEOUT_S
|
||||||
static const int TESTS_TIMEOUT = MBED_GREENTEA_TEST_UDPSOCKET_TIMEOUT_S;
|
static constexpr seconds TESTS_TIMEOUT(MBED_GREENTEA_TEST_UDPSOCKET_TIMEOUT_S);
|
||||||
#else
|
#else
|
||||||
#define MESH 3
|
#define MESH 3
|
||||||
#define WISUN 0x2345
|
#define WISUN 0x2345
|
||||||
#if MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == MESH && MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == WISUN
|
#if MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == MESH && MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == WISUN
|
||||||
static const int TESTS_TIMEOUT = (25 * 60);
|
static constexpr seconds TESTS_TIMEOUT = 25min;
|
||||||
#else
|
#else
|
||||||
static const int TESTS_TIMEOUT = (20 * 60);
|
static constexpr seconds TESTS_TIMEOUT = 20min;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ static bool pkt_received[PKTS] = {false, false, false, false, false, false, fals
|
||||||
};
|
};
|
||||||
|
|
||||||
Timer tc_exec_time;
|
Timer tc_exec_time;
|
||||||
int time_allotted;
|
microseconds time_allotted;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _sigio_handler()
|
static void _sigio_handler()
|
||||||
|
@ -76,7 +76,7 @@ void UDPSOCKET_ECHOTEST_impl(bool use_sendto)
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.connect(udp_addr));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.connect(udp_addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
sock.set_timeout(SOCKET_TIMEOUT);
|
sock.set_timeout(milliseconds(SOCKET_TIMEOUT).count());
|
||||||
int recvd;
|
int recvd;
|
||||||
int sent;
|
int sent;
|
||||||
int packets_sent = 0;
|
int packets_sent = 0;
|
||||||
|
@ -170,7 +170,7 @@ void UDPSOCKET_ECHOTEST_CONNECT_SEND_RECV()
|
||||||
void UDPSOCKET_ECHOTEST_NONBLOCK_impl(bool use_sendto)
|
void UDPSOCKET_ECHOTEST_NONBLOCK_impl(bool use_sendto)
|
||||||
{
|
{
|
||||||
tc_exec_time.start();
|
tc_exec_time.start();
|
||||||
time_allotted = split2half_rmng_udp_test_time(); // [s]
|
time_allotted = split2half_rmng_udp_test_time();
|
||||||
|
|
||||||
SocketAddress udp_addr;
|
SocketAddress udp_addr;
|
||||||
NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &udp_addr);
|
NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &udp_addr);
|
||||||
|
@ -212,8 +212,12 @@ void UDPSOCKET_ECHOTEST_NONBLOCK_impl(bool use_sendto)
|
||||||
} else if (sent == pkt_s) {
|
} else if (sent == pkt_s) {
|
||||||
packets_sent++;
|
packets_sent++;
|
||||||
} else if (sent == NSAPI_ERROR_WOULD_BLOCK) {
|
} else if (sent == NSAPI_ERROR_WOULD_BLOCK) {
|
||||||
if (tc_exec_time.read() >= time_allotted ||
|
if (
|
||||||
signals.wait_all(SIGNAL_SIGIO_TX, SIGIO_TIMEOUT) == osFlagsErrorTimeout) {
|
(tc_exec_time.elapsed_time() >= time_allotted)
|
||||||
|
|| signals.wait_all(
|
||||||
|
SIGNAL_SIGIO_TX, milliseconds(SIGIO_TIMEOUT).count()
|
||||||
|
) == osFlagsErrorTimeout
|
||||||
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
--retry_cnt;
|
--retry_cnt;
|
||||||
|
@ -231,10 +235,13 @@ void UDPSOCKET_ECHOTEST_NONBLOCK_impl(bool use_sendto)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
|
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
|
||||||
if (tc_exec_time.read() >= time_allotted) {
|
if (tc_exec_time.elapsed_time() >= time_allotted) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
signals.wait_all(SIGNAL_SIGIO_RX, SIGIO_TIMEOUT);
|
signals.wait_all(
|
||||||
|
SIGNAL_SIGIO_RX,
|
||||||
|
milliseconds(SIGIO_TIMEOUT).count()
|
||||||
|
);
|
||||||
--retry_recv;
|
--retry_recv;
|
||||||
continue;
|
continue;
|
||||||
} else if (recvd < 0) {
|
} else if (recvd < 0) {
|
||||||
|
|
Loading…
Reference in New Issue