mirror of https://github.com/ARMmbed/mbed-os.git
Changed TCP socket test to use shared buffers
Changed RX and TX buffers used in TCP socket tests to global variables to conserve memory.pull/7103/head
parent
9095b037aa
commit
35f064fc69
|
@ -34,6 +34,9 @@ namespace
|
|||
NetworkInterface* net;
|
||||
}
|
||||
|
||||
char tcp_global::rx_buffer[RX_BUFF_SIZE];
|
||||
char tcp_global::tx_buffer[TX_BUFF_SIZE];
|
||||
|
||||
NetworkInterface* get_interface()
|
||||
{
|
||||
return net;
|
||||
|
|
|
@ -24,6 +24,17 @@ void fill_tx_buffer_ascii(char *buff, size_t len);
|
|||
void tcpsocket_connect_to_echo_srv(TCPSocket& sock);
|
||||
void tcpsocket_connect_to_discard_srv(TCPSocket& sock);
|
||||
|
||||
namespace tcp_global
|
||||
{
|
||||
static const int TCP_OS_STACK_SIZE = 1024;
|
||||
|
||||
static const int RX_BUFF_SIZE = 1220;
|
||||
static const int TX_BUFF_SIZE = 1220;
|
||||
|
||||
extern char rx_buffer[RX_BUFF_SIZE];
|
||||
extern char tx_buffer[TX_BUFF_SIZE];
|
||||
}
|
||||
|
||||
/*
|
||||
* Test cases
|
||||
*/
|
||||
|
|
|
@ -31,9 +31,6 @@ namespace
|
|||
static const int SIGIO_TIMEOUT = 5000; //[ms]
|
||||
|
||||
static const int BUFF_SIZE = 1200;
|
||||
char rx_buffer[BUFF_SIZE] = {0};
|
||||
char tx_buffer[BUFF_SIZE] = {0};
|
||||
|
||||
static const int PKTS = 22;
|
||||
static const int pkt_sizes[PKTS] = {1,2,3,4,5,6,7,8,9,10, \
|
||||
100,200,300,400,500,600,700,800,900,1000,\
|
||||
|
@ -54,9 +51,9 @@ void TCPSOCKET_ECHOTEST()
|
|||
int sent;
|
||||
int x = 0;
|
||||
for (int pkt_s = pkt_sizes[x]; x < PKTS; pkt_s = pkt_sizes[x++]) {
|
||||
fill_tx_buffer_ascii(tx_buffer, BUFF_SIZE);
|
||||
fill_tx_buffer_ascii(tcp_global::tx_buffer, BUFF_SIZE);
|
||||
|
||||
sent = sock.send(tx_buffer, pkt_s);
|
||||
sent = sock.send(tcp_global::tx_buffer, pkt_s);
|
||||
if (sent < 0) {
|
||||
printf("[Round#%02d] network error %d\n", x, sent);
|
||||
TEST_FAIL();
|
||||
|
@ -64,14 +61,14 @@ void TCPSOCKET_ECHOTEST()
|
|||
|
||||
int bytes2recv = sent;
|
||||
while (bytes2recv) {
|
||||
recvd = sock.recv(&(rx_buffer[sent-bytes2recv]), bytes2recv);
|
||||
recvd = sock.recv(&(tcp_global::rx_buffer[sent-bytes2recv]), bytes2recv);
|
||||
if (recvd < 0) {
|
||||
printf("[Round#%02d] network error %d\n", x, recvd);
|
||||
TEST_FAIL();
|
||||
}
|
||||
bytes2recv -= recvd;
|
||||
}
|
||||
TEST_ASSERT_EQUAL(0, memcmp(tx_buffer, rx_buffer, sent));
|
||||
TEST_ASSERT_EQUAL(0, memcmp(tcp_global::tx_buffer, tcp_global::rx_buffer, sent));
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
||||
}
|
||||
|
@ -81,7 +78,7 @@ void tcpsocket_echotest_nonblock_receiver(void *receive_bytes)
|
|||
int bytes2recv = *(int*)receive_bytes;
|
||||
int recvd;
|
||||
while (bytes2recv) {
|
||||
recvd = sock.recv(&(rx_buffer[*(int*)receive_bytes-bytes2recv]), bytes2recv);
|
||||
recvd = sock.recv(&(tcp_global::rx_buffer[*(int*)receive_bytes-bytes2recv]), bytes2recv);
|
||||
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
|
||||
wait(1);
|
||||
continue;
|
||||
|
@ -91,7 +88,7 @@ void tcpsocket_echotest_nonblock_receiver(void *receive_bytes)
|
|||
bytes2recv -= recvd;
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL(0, memcmp(tx_buffer, rx_buffer, *(int*)receive_bytes));
|
||||
TEST_ASSERT_EQUAL(0, memcmp(tcp_global::tx_buffer, tcp_global::rx_buffer, *(int*)receive_bytes));
|
||||
|
||||
static int round = 0;
|
||||
printf("[Recevr#%02d] bytes received: %d\n", round++, *(int*)receive_bytes);
|
||||
|
@ -110,22 +107,22 @@ void TCPSOCKET_ECHOTEST_NONBLOCK()
|
|||
int sent;
|
||||
int s_idx = 0;
|
||||
Thread *thread;
|
||||
unsigned char *stack_mem = (unsigned char *)malloc(OS_STACK_SIZE);
|
||||
unsigned char *stack_mem = (unsigned char *)malloc(tcp_global::TCP_OS_STACK_SIZE);
|
||||
TEST_ASSERT_NOT_NULL(stack_mem);
|
||||
|
||||
for (int pkt_s = pkt_sizes[s_idx]; s_idx < PKTS; ++s_idx) {
|
||||
pkt_s = pkt_sizes[s_idx];
|
||||
thread = new Thread(osPriorityNormal,
|
||||
OS_STACK_SIZE,
|
||||
tcp_global::TCP_OS_STACK_SIZE,
|
||||
stack_mem,
|
||||
"receiver");
|
||||
TEST_ASSERT_EQUAL(osOK, thread->start(callback(tcpsocket_echotest_nonblock_receiver, &pkt_s)));
|
||||
|
||||
fill_tx_buffer_ascii(tx_buffer, pkt_s);
|
||||
fill_tx_buffer_ascii(tcp_global::tx_buffer, pkt_s);
|
||||
|
||||
bytes2send = pkt_s;
|
||||
while (bytes2send > 0) {
|
||||
sent = sock.send(&(tx_buffer[pkt_s-bytes2send]), bytes2send);
|
||||
sent = sock.send(&(tcp_global::tx_buffer[pkt_s-bytes2send]), bytes2send);
|
||||
if (sent == NSAPI_ERROR_WOULD_BLOCK) {
|
||||
TEST_ASSERT_NOT_EQUAL(osEventTimeout, osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status);
|
||||
continue;
|
||||
|
|
|
@ -32,8 +32,6 @@ namespace
|
|||
|
||||
static const int BURST_CNT = 100;
|
||||
static const int BURST_SIZE = 1220;
|
||||
char rx_buffer[BURST_SIZE] = {0};
|
||||
char tx_buffer[BURST_SIZE] = {0};
|
||||
}
|
||||
|
||||
static void _sigio_handler(osThreadId id) {
|
||||
|
@ -47,7 +45,7 @@ void TCPSOCKET_ECHOTEST_BURST()
|
|||
sock.sigio(callback(_sigio_handler, Thread::gettid()));
|
||||
|
||||
// TX buffer to be preserved for comparison
|
||||
fill_tx_buffer_ascii(tx_buffer, BURST_SIZE);
|
||||
fill_tx_buffer_ascii(tcp_global::tx_buffer, BURST_SIZE);
|
||||
|
||||
int recvd;
|
||||
int bt_left;
|
||||
|
@ -55,7 +53,7 @@ void TCPSOCKET_ECHOTEST_BURST()
|
|||
for (int i = 0; i < BURST_CNT; i++) {
|
||||
bt_left = BURST_SIZE;
|
||||
while (bt_left > 0) {
|
||||
sent = sock.send(&(tx_buffer[BURST_SIZE-bt_left]), bt_left);
|
||||
sent = sock.send(&(tcp_global::tx_buffer[BURST_SIZE-bt_left]), bt_left);
|
||||
if (sent == NSAPI_ERROR_WOULD_BLOCK) {
|
||||
if(osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
|
||||
TEST_FAIL();
|
||||
|
@ -70,7 +68,7 @@ void TCPSOCKET_ECHOTEST_BURST()
|
|||
|
||||
bt_left = BURST_SIZE;
|
||||
while (bt_left > 0) {
|
||||
recvd = sock.recv(&(rx_buffer[BURST_SIZE-bt_left]), BURST_SIZE);
|
||||
recvd = sock.recv(&(tcp_global::rx_buffer[BURST_SIZE-bt_left]), BURST_SIZE);
|
||||
if (recvd < 0) {
|
||||
printf("[%02d] network error %d\n", i, recvd);
|
||||
break;
|
||||
|
@ -83,7 +81,7 @@ void TCPSOCKET_ECHOTEST_BURST()
|
|||
TEST_FAIL();
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL(0, memcmp(tx_buffer, rx_buffer, BURST_SIZE));
|
||||
TEST_ASSERT_EQUAL(0, memcmp(tcp_global::tx_buffer, tcp_global::rx_buffer, BURST_SIZE));
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
||||
}
|
||||
|
@ -96,7 +94,7 @@ void TCPSOCKET_ECHOTEST_BURST_NONBLOCK()
|
|||
sock.sigio(callback(_sigio_handler, Thread::gettid()));
|
||||
|
||||
// TX buffer to be preserved for comparison
|
||||
fill_tx_buffer_ascii(tx_buffer, BURST_SIZE);
|
||||
fill_tx_buffer_ascii(tcp_global::tx_buffer, BURST_SIZE);
|
||||
|
||||
int sent;
|
||||
int recvd;
|
||||
|
@ -104,7 +102,7 @@ void TCPSOCKET_ECHOTEST_BURST_NONBLOCK()
|
|||
for (int i = 0; i < BURST_CNT; i++) {
|
||||
bt_left = BURST_SIZE;
|
||||
while (bt_left > 0) {
|
||||
sent = sock.send(&(tx_buffer[BURST_SIZE-bt_left]), bt_left);
|
||||
sent = sock.send(&(tcp_global::tx_buffer[BURST_SIZE-bt_left]), bt_left);
|
||||
if (sent == NSAPI_ERROR_WOULD_BLOCK) {
|
||||
if(osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
|
||||
TEST_FAIL();
|
||||
|
@ -120,7 +118,7 @@ void TCPSOCKET_ECHOTEST_BURST_NONBLOCK()
|
|||
|
||||
bt_left = BURST_SIZE;
|
||||
while (bt_left > 0) {
|
||||
recvd = sock.recv(&(rx_buffer[BURST_SIZE-bt_left]), BURST_SIZE);
|
||||
recvd = sock.recv(&(tcp_global::rx_buffer[BURST_SIZE-bt_left]), BURST_SIZE);
|
||||
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
|
||||
if(osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
|
||||
printf("[bt#%02d] packet timeout...", i);
|
||||
|
@ -140,7 +138,7 @@ void TCPSOCKET_ECHOTEST_BURST_NONBLOCK()
|
|||
TEST_FAIL();
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL(0, memcmp(tx_buffer, rx_buffer, BURST_SIZE));
|
||||
TEST_ASSERT_EQUAL(0, memcmp(tcp_global::tx_buffer, tcp_global::rx_buffer, BURST_SIZE));
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue