Update tcp test cases to verify network socket statistics

Cases Updated are:
1. TCPSOCKET_ECHOTEST_NONBLOCK
2. TCPSOCKET_OPEN_CLOSE_REPEAT
3. TCPSOCKET_OPEN_LIMIT
pull/8592/head
Deepika 2018-11-15 17:17:46 -06:00 committed by deepikabhavnani
parent e7ea2927fc
commit eec54a0fc9
5 changed files with 51 additions and 0 deletions

View File

@ -38,6 +38,10 @@ NetworkInterface *net;
Timer tc_bucket; // Timer to limit a test cases run time
}
#if defined(MBED_NW_STATS_ENABLED)
mbed_stats_socket_t tcp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT] = {0};
#endif
char tcp_global::rx_buffer[RX_BUFF_SIZE];
char tcp_global::tx_buffer[TX_BUFF_SIZE];
@ -115,6 +119,15 @@ int split2half_rmng_tcp_test_time()
return (tcp_global::TESTS_TIMEOUT - tc_bucket.read()) / 2;
}
int fetch_stats()
{
#if defined(MBED_NW_STATS_ENABLED)
return SocketStats::mbed_stats_socket_get_each(&tcp_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)
{

View File

@ -23,6 +23,11 @@ void drop_bad_packets(TCPSocket &sock, int orig_timeout);
void fill_tx_buffer_ascii(char *buff, size_t len);
nsapi_error_t tcpsocket_connect_to_echo_srv(TCPSocket &sock);
nsapi_error_t tcpsocket_connect_to_discard_srv(TCPSocket &sock);
int fetch_stats(void);
#if defined(MBED_NW_STATS_ENABLED)
extern mbed_stats_socket_t tcp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
#endif
/**
* Single testcase might take only half of the remaining execution time

View File

@ -114,6 +114,12 @@ void tcpsocket_echotest_nonblock_receiver(void *receive_bytes)
void TCPSOCKET_ECHOTEST_NONBLOCK()
{
int j = 0;
int count = fetch_stats();
for (; j < count; j++) {
TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state);
}
tc_exec_time.start();
time_allotted = split2half_rmng_tcp_test_time(); // [s]
@ -160,6 +166,14 @@ void TCPSOCKET_ECHOTEST_NONBLOCK()
bytes2send -= sent;
}
printf("[Sender#%02d] bytes sent: %d\n", s_idx, pkt_s);
count = fetch_stats();
for (j = 0; j < count; j++) {
if ((tcp_stats[j].state == SOCK_OPEN) && (tcp_stats[j].proto == NSAPI_TCP)) {
break;
}
}
TEST_ASSERT_EQUAL(bytes2send, tcp_stats[j].sent_bytes);
tx_sem.wait(split2half_rmng_tcp_test_time());
thread->join();
delete thread;

View File

@ -26,6 +26,11 @@ using namespace utest::v1;
void TCPSOCKET_OPEN_CLOSE_REPEAT()
{
int count = fetch_stats();
for (int j = 0; j < count; j++) {
TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state);
}
TCPSocket *sock = new TCPSocket;
if (!sock) {
TEST_FAIL();
@ -36,4 +41,9 @@ void TCPSOCKET_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, tcp_stats[j].state);
}
}

View File

@ -70,6 +70,15 @@ void TCPSOCKET_OPEN_LIMIT()
break;
}
int count = fetch_stats();
int open_count = 0;
for (int j = 0; j < count; j++) {
if ((tcp_stats[j].state == SOCK_OPEN) && (tcp_stats[j].proto == NSAPI_TCP)) {
open_count++;
}
}
TEST_ASSERT(open_count >= 4);
TCPSocketItem *tmp;
for (TCPSocketItem *it = socket_list_head; it;) {
++open_sockets[i];