Fix tests-netsocket-udp

Use std::chrono literals and variables where it makes sense
pull/13046/head
Hugues Kamba 2020-06-18 15:02:16 +01:00
parent a3f4cf212d
commit 2b934a228f
3 changed files with 23 additions and 14 deletions

View File

@ -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
@ -133,7 +133,7 @@ int fetch_stats()
// Test setup
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();
tc_bucket.start();
return greentea_test_setup_handler(number_of_cases);

View File

@ -21,6 +21,8 @@
#include "../test_params.h"
#include "mbed_trace.h"
using namespace std::chrono;
#define TRACE_GROUP "GRNT"
NetworkInterface *get_interface();
@ -37,18 +39,18 @@ int fetch_stats(void);
/**
* 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 {
#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
#define MESH 3
#define WISUN 0x2345
#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
static const int TESTS_TIMEOUT = (20 * 60);
static constexpr seconds TESTS_TIMEOUT = 20min;
#endif
#endif

View File

@ -54,7 +54,7 @@ static bool pkt_received[PKTS] = {false, false, false, false, false, false, fals
};
Timer tc_exec_time;
int time_allotted;
microseconds time_allotted;
}
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));
}
sock.set_timeout(SOCKET_TIMEOUT);
sock.set_timeout(milliseconds(SOCKET_TIMEOUT).count());
int recvd;
int sent;
int packets_sent = 0;
@ -170,7 +170,7 @@ void UDPSOCKET_ECHOTEST_CONNECT_SEND_RECV()
void UDPSOCKET_ECHOTEST_NONBLOCK_impl(bool use_sendto)
{
tc_exec_time.start();
time_allotted = split2half_rmng_udp_test_time(); // [s]
time_allotted = split2half_rmng_udp_test_time();
SocketAddress 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) {
packets_sent++;
} else if (sent == NSAPI_ERROR_WOULD_BLOCK) {
if (tc_exec_time.read() >= time_allotted ||
signals.wait_all(SIGNAL_SIGIO_TX, SIGIO_TIMEOUT) == osFlagsErrorTimeout) {
if (
(tc_exec_time.elapsed_time() >= time_allotted)
|| signals.wait_all(
SIGNAL_SIGIO_TX, milliseconds(SIGIO_TIMEOUT).count()
) == osFlagsErrorTimeout
) {
continue;
}
--retry_cnt;
@ -231,10 +235,13 @@ void UDPSOCKET_ECHOTEST_NONBLOCK_impl(bool use_sendto)
}
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
if (tc_exec_time.read() >= time_allotted) {
if (tc_exec_time.elapsed_time() >= time_allotted) {
break;
}
signals.wait_all(SIGNAL_SIGIO_RX, SIGIO_TIMEOUT);
signals.wait_all(
SIGNAL_SIGIO_RX,
milliseconds(SIGIO_TIMEOUT).count()
);
--retry_recv;
continue;
} else if (recvd < 0) {