Skip to content

Commit eec54a0

Browse files
author
Deepika
committed
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
1 parent e7ea292 commit eec54a0

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed

TESTS/netsocket/tcp/main.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ NetworkInterface *net;
3838
Timer tc_bucket; // Timer to limit a test cases run time
3939
}
4040

41+
#if defined(MBED_NW_STATS_ENABLED)
42+
mbed_stats_socket_t tcp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT] = {0};
43+
#endif
44+
4145
char tcp_global::rx_buffer[RX_BUFF_SIZE];
4246
char tcp_global::tx_buffer[TX_BUFF_SIZE];
4347

@@ -115,6 +119,15 @@ int split2half_rmng_tcp_test_time()
115119
return (tcp_global::TESTS_TIMEOUT - tc_bucket.read()) / 2;
116120
}
117121

122+
int fetch_stats()
123+
{
124+
#if defined(MBED_NW_STATS_ENABLED)
125+
return SocketStats::mbed_stats_socket_get_each(&tcp_stats[0], MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT);
126+
#else
127+
return 0;
128+
#endif
129+
}
130+
118131
// Test setup
119132
utest::v1::status_t greentea_setup(const size_t number_of_cases)
120133
{

TESTS/netsocket/tcp/tcp_tests.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ void drop_bad_packets(TCPSocket &sock, int orig_timeout);
2323
void fill_tx_buffer_ascii(char *buff, size_t len);
2424
nsapi_error_t tcpsocket_connect_to_echo_srv(TCPSocket &sock);
2525
nsapi_error_t tcpsocket_connect_to_discard_srv(TCPSocket &sock);
26+
int fetch_stats(void);
27+
28+
#if defined(MBED_NW_STATS_ENABLED)
29+
extern mbed_stats_socket_t tcp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
30+
#endif
2631

2732
/**
2833
* Single testcase might take only half of the remaining execution time

TESTS/netsocket/tcp/tcpsocket_echotest.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ void tcpsocket_echotest_nonblock_receiver(void *receive_bytes)
114114

115115
void TCPSOCKET_ECHOTEST_NONBLOCK()
116116
{
117+
int j = 0;
118+
int count = fetch_stats();
119+
for (; j < count; j++) {
120+
TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state);
121+
}
122+
117123
tc_exec_time.start();
118124
time_allotted = split2half_rmng_tcp_test_time(); // [s]
119125

@@ -160,6 +166,14 @@ void TCPSOCKET_ECHOTEST_NONBLOCK()
160166
bytes2send -= sent;
161167
}
162168
printf("[Sender#%02d] bytes sent: %d\n", s_idx, pkt_s);
169+
count = fetch_stats();
170+
for (j = 0; j < count; j++) {
171+
if ((tcp_stats[j].state == SOCK_OPEN) && (tcp_stats[j].proto == NSAPI_TCP)) {
172+
break;
173+
}
174+
}
175+
TEST_ASSERT_EQUAL(bytes2send, tcp_stats[j].sent_bytes);
176+
163177
tx_sem.wait(split2half_rmng_tcp_test_time());
164178
thread->join();
165179
delete thread;

TESTS/netsocket/tcp/tcpsocket_open_close_repeat.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ using namespace utest::v1;
2626

2727
void TCPSOCKET_OPEN_CLOSE_REPEAT()
2828
{
29+
int count = fetch_stats();
30+
for (int j = 0; j < count; j++) {
31+
TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state);
32+
}
33+
2934
TCPSocket *sock = new TCPSocket;
3035
if (!sock) {
3136
TEST_FAIL();
@@ -36,4 +41,9 @@ void TCPSOCKET_OPEN_CLOSE_REPEAT()
3641
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close());
3742
}
3843
delete sock;
44+
45+
count = fetch_stats();
46+
for (int j = 0; j < count; j++) {
47+
TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state);
48+
}
3949
}

TESTS/netsocket/tcp/tcpsocket_open_limit.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ void TCPSOCKET_OPEN_LIMIT()
7070
break;
7171
}
7272

73+
int count = fetch_stats();
74+
int open_count = 0;
75+
for (int j = 0; j < count; j++) {
76+
if ((tcp_stats[j].state == SOCK_OPEN) && (tcp_stats[j].proto == NSAPI_TCP)) {
77+
open_count++;
78+
}
79+
}
80+
TEST_ASSERT(open_count >= 4);
81+
7382
TCPSocketItem *tmp;
7483
for (TCPSocketItem *it = socket_list_head; it;) {
7584
++open_sockets[i];

0 commit comments

Comments
 (0)