Greentea TCP test cases - check all socket calls

pull/6665/head
Veijo Pesonen 2018-05-15 10:53:52 +03:00 committed by Seppo Takalo
parent 1fef1602a2
commit 4fa57e36fe
8 changed files with 42 additions and 49 deletions

View File

@ -68,6 +68,26 @@ static void _ifdown() {
printf("MBED: ifdown\n");
}
void tcpsocket_connect_to_echo_srv(TCPSocket& sock) {
SocketAddress tcp_addr;
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
tcp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.connect(tcp_addr));
}
void tcpsocket_connect_to_discard_srv(TCPSocket& sock) {
SocketAddress tcp_addr;
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
tcp_addr.set_port(9);
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.connect(tcp_addr));
}
void fill_tx_buffer_ascii(char *buff, size_t len)
{
for (size_t i = 0; i<len; ++i) {

View File

@ -21,6 +21,8 @@
NetworkInterface* get_interface();
void drop_bad_packets(TCPSocket& sock);
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);
/*
* Test cases

View File

@ -48,13 +48,7 @@ static void _sigio_handler(osThreadId id) {
void test_tcpsocket_echotest()
{
SocketAddress tcp_addr;
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
tcp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
TCPSocket sock;
sock.open(get_interface());
sock.connect(tcp_addr);
tcpsocket_connect_to_echo_srv(sock);
int recvd;
int sent;
@ -82,7 +76,7 @@ void test_tcpsocket_echotest()
}
TEST_ASSERT_EQUAL(0, memcmp(tx_buffer, rx_buffer, sent));
}
sock.close();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
}
void tcpsocket_echotest_nonblock_receiver(void *receive_bytes)
@ -111,12 +105,7 @@ void tcpsocket_echotest_nonblock_receiver(void *receive_bytes)
void test_tcpsocket_echotest_nonblock()
{
SocketAddress tcp_addr;
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
tcp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
sock.open(get_interface());
sock.connect(tcp_addr);
tcpsocket_connect_to_echo_srv(sock);
sock.set_blocking(false);
sock.sigio(callback(_sigio_handler, Thread::gettid()));
@ -155,5 +144,5 @@ void test_tcpsocket_echotest_nonblock()
delete thread;
}
free(stack_mem);
sock.close();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
}

View File

@ -40,13 +40,8 @@ static void _sigio_handler(osThreadId id) {
void test_tcpsocket_echotest_burst()
{
SocketAddress tcp_addr;
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
tcp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
TCPSocket sock;
sock.open(get_interface());
sock.connect(tcp_addr);
tcpsocket_connect_to_echo_srv(sock);
sock.sigio(callback(_sigio_handler, Thread::gettid()));
// TX buffer to be preserved for comparison
@ -88,18 +83,13 @@ void test_tcpsocket_echotest_burst()
TEST_ASSERT_EQUAL(0, memcmp(tx_buffer, rx_buffer, BURST_SIZE));
}
sock.close();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
}
void test_tcpsocket_echotest_burst_nonblock()
{
SocketAddress tcp_addr;
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
tcp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
TCPSocket sock;
sock.open(get_interface());
sock.connect(tcp_addr);
tcpsocket_connect_to_echo_srv(sock);
sock.set_blocking(false);
sock.sigio(callback(_sigio_handler, Thread::gettid()));
@ -150,5 +140,5 @@ void test_tcpsocket_echotest_burst_nonblock()
TEST_ASSERT_EQUAL(0, memcmp(tx_buffer, rx_buffer, BURST_SIZE));
}
sock.close();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
}

View File

@ -32,16 +32,11 @@ static void _sigio_handler(osThreadId id) {
void test_tcpsocket_recv_timeout()
{
SocketAddress tcp_addr;
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
tcp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
static const int DATA_LEN = 100;
char buff[DATA_LEN] = {0};
TCPSocket sock;
sock.open(get_interface());
sock.connect(tcp_addr);
tcpsocket_connect_to_echo_srv(sock);
sock.set_timeout(100);
sock.sigio(callback(_sigio_handler, Thread::gettid()));
@ -72,5 +67,5 @@ void test_tcpsocket_recv_timeout()
pkt_unrecvd -= recvd;
}
}
sock.close();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
}

View File

@ -28,8 +28,7 @@ using namespace utest::v1;
void test_tcpsocket_send_repeat()
{
TCPSocket sock;
sock.open(get_interface());
sock.connect(MBED_CONF_APP_ECHO_SERVER_ADDR, 9);
tcpsocket_connect_to_discard_srv(sock);
int err;
Timer timer;
@ -38,5 +37,6 @@ void test_tcpsocket_send_repeat()
err = sock.send(tx_buffer, sizeof(tx_buffer));
TEST_ASSERT_EQUAL(sizeof(tx_buffer), err);
}
sock.close();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
}

View File

@ -28,8 +28,7 @@ using namespace utest::v1;
void test_tcpsocket_send_timeout()
{
TCPSocket sock;
sock.open(get_interface());
sock.connect(MBED_CONF_APP_ECHO_SERVER_ADDR, 9);
tcpsocket_connect_to_discard_srv(sock);
int err;
Timer timer;
@ -42,5 +41,6 @@ void test_tcpsocket_send_timeout()
TEST_ASSERT_EQUAL(sizeof(tx_buffer), err);
TEST_ASSERT(timer.read_ms() <= 800);
}
sock.close();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
}

View File

@ -43,8 +43,7 @@ static void _sigio_handler2(osThreadId id) {
static void check_const_len_rand_sequence()
{
TCPSocket sock;
sock.open(get_interface());
sock.connect(MBED_CONF_APP_ECHO_SERVER_ADDR, MBED_CONF_APP_ECHO_SERVER_PORT);
tcpsocket_connect_to_echo_srv(sock);
sock.sigio(callback(_sigio_handler1, Thread::gettid()));
static const int BUFF_SIZE = 10;
@ -90,15 +89,13 @@ static void check_const_len_rand_sequence()
}
TEST_ASSERT_EQUAL(0, memcmp(tx_buff, rx_buff, BUFF_SIZE));
}
sock.close();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
}
static void check_var_len_rand_sequence()
{
TCPSocket sock;
sock.open(get_interface());
sock.connect(MBED_CONF_APP_ECHO_SERVER_ADDR, MBED_CONF_APP_ECHO_SERVER_PORT);
tcpsocket_connect_to_echo_srv(sock);
sock.sigio(callback(_sigio_handler2, Thread::gettid()));
static const int BUFF_SIZE = 1001;
@ -145,7 +142,7 @@ static void check_var_len_rand_sequence()
TEST_ASSERT_EQUAL(0, memcmp(tx_buff, rx_buff, i));
}
sock.close();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
}
void test_tcpsocket_thread_per_socket_safety()