mirror of https://github.com/ARMmbed/mbed-os.git
Update udp test cases to verify network socket statistics
Cases Updated are: 1. UDPSOCKET_ECHOTEST_NONBLOCK 2. UDPSOCKET_OPEN_CLOSE_REPEAT 3. UDPSOCKET_OPEN_LIMITpull/8592/head
parent
09b4bc07ce
commit
e7ea2927fc
|
@ -37,6 +37,10 @@ namespace {
|
|||
NetworkInterface *net;
|
||||
}
|
||||
|
||||
#if defined(MBED_NW_STATS_ENABLED)
|
||||
mbed_stats_socket_t udp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT] = {0};
|
||||
#endif
|
||||
|
||||
NetworkInterface *get_interface()
|
||||
{
|
||||
return net;
|
||||
|
@ -76,6 +80,15 @@ void fill_tx_buffer_ascii(char *buff, size_t len)
|
|||
}
|
||||
}
|
||||
|
||||
int fetch_stats()
|
||||
{
|
||||
#if defined(MBED_NW_STATS_ENABLED)
|
||||
return SocketStats::mbed_stats_socket_get_each(&udp_stats[0], MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Test setup
|
||||
utest::v1::status_t greentea_setup(const size_t number_of_cases)
|
||||
{
|
||||
|
|
|
@ -21,6 +21,11 @@
|
|||
NetworkInterface *get_interface();
|
||||
void drop_bad_packets(UDPSocket &sock, int orig_timeout);
|
||||
void fill_tx_buffer_ascii(char *buff, size_t len);
|
||||
int fetch_stats(void);
|
||||
|
||||
#if defined(MBED_NW_STATS_ENABLED)
|
||||
extern mbed_stats_socket_t udp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Test cases
|
||||
|
|
|
@ -121,6 +121,14 @@ void udpsocket_echotest_nonblock_receiver(void *receive_bytes)
|
|||
|
||||
void UDPSOCKET_ECHOTEST_NONBLOCK()
|
||||
{
|
||||
#if defined(MBED_NW_STATS_ENABLED)
|
||||
int j = 0;
|
||||
int count = fetch_stats();
|
||||
for (; j < count; j++) {
|
||||
TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state);
|
||||
}
|
||||
#endif
|
||||
|
||||
SocketAddress udp_addr;
|
||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||
udp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||
|
@ -174,6 +182,14 @@ void UDPSOCKET_ECHOTEST_NONBLOCK()
|
|||
}
|
||||
}
|
||||
free(stack_mem);
|
||||
|
||||
#if defined(MBED_NW_STATS_ENABLED)
|
||||
TEST_ASSERT_EQUAL(1, fetch_stats());
|
||||
TEST_ASSERT_EQUAL(NSAPI_UDP, udp_stats[0].proto);
|
||||
TEST_ASSERT(udp_stats[0].sent_bytes != 0);
|
||||
TEST_ASSERT(udp_stats[0].recv_bytes != 0);
|
||||
#endif
|
||||
|
||||
// Packet loss up to 30% tolerated
|
||||
if (packets_sent > 0) {
|
||||
double loss_ratio = 1 - ((double)packets_recv / (double)packets_sent);
|
||||
|
|
|
@ -26,6 +26,11 @@ using namespace utest::v1;
|
|||
|
||||
void UDPSOCKET_OPEN_CLOSE_REPEAT()
|
||||
{
|
||||
int count = fetch_stats();
|
||||
for (int j = 0; j < count; j++) {
|
||||
TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state);
|
||||
}
|
||||
|
||||
UDPSocket *sock = new UDPSocket;
|
||||
if (!sock) {
|
||||
TEST_FAIL();
|
||||
|
@ -36,4 +41,9 @@ void UDPSOCKET_OPEN_CLOSE_REPEAT()
|
|||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close());
|
||||
}
|
||||
delete sock;
|
||||
|
||||
count = fetch_stats();
|
||||
for (int j = 0; j < count; j++) {
|
||||
TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "UDPSocket.h"
|
||||
#include "unity/unity.h"
|
||||
#include "utest.h"
|
||||
#include "SocketStats.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
|
@ -70,6 +71,15 @@ void UDPSOCKET_OPEN_LIMIT()
|
|||
break;
|
||||
}
|
||||
|
||||
int count = fetch_stats();
|
||||
int open_count = 0;
|
||||
for (int j = 0; j < count; j++) {
|
||||
if ((udp_stats[j].state == SOCK_OPEN) && (udp_stats[j].proto == NSAPI_UDP)) {
|
||||
open_count++;
|
||||
}
|
||||
}
|
||||
TEST_ASSERT(open_count >= 3);
|
||||
|
||||
UDPSocketItem *tmp;
|
||||
for (UDPSocketItem *it = socket_list_head; it;) {
|
||||
++open_sockets[i];
|
||||
|
|
Loading…
Reference in New Issue