mirror of https://github.com/ARMmbed/mbed-os.git
TCP/UDP greentea tests refactoring and cleanup
parent
44696009bd
commit
c92dac82fe
|
@ -243,6 +243,10 @@ content at minimum:
|
||||||
"help" : "Port of echo server",
|
"help" : "Port of echo server",
|
||||||
"value" : "7"
|
"value" : "7"
|
||||||
}
|
}
|
||||||
|
"echo-server-discard-port" : {
|
||||||
|
"help" : "Discard port of echo server",
|
||||||
|
"value" : "9"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
using namespace utest::v1;
|
using namespace utest::v1;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
NetworkInterface *net;
|
|
||||||
Timer tc_bucket; // Timer to limit a test cases run time
|
Timer tc_bucket; // Timer to limit a test cases run time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,11 +44,6 @@ mbed_stats_socket_t tcp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
|
||||||
char tcp_global::rx_buffer[RX_BUFF_SIZE];
|
char tcp_global::rx_buffer[RX_BUFF_SIZE];
|
||||||
char tcp_global::tx_buffer[TX_BUFF_SIZE];
|
char tcp_global::tx_buffer[TX_BUFF_SIZE];
|
||||||
|
|
||||||
NetworkInterface *get_interface()
|
|
||||||
{
|
|
||||||
return net;
|
|
||||||
}
|
|
||||||
|
|
||||||
void drop_bad_packets(TCPSocket &sock, int orig_timeout)
|
void drop_bad_packets(TCPSocket &sock, int orig_timeout)
|
||||||
{
|
{
|
||||||
nsapi_error_t err;
|
nsapi_error_t err;
|
||||||
|
@ -65,7 +59,7 @@ void drop_bad_packets(TCPSocket &sock, int orig_timeout)
|
||||||
|
|
||||||
static void _ifup()
|
static void _ifup()
|
||||||
{
|
{
|
||||||
net = NetworkInterface::get_default_instance();
|
NetworkInterface *net = NetworkInterface::get_default_instance();
|
||||||
nsapi_error_t err = net->connect();
|
nsapi_error_t err = net->connect();
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
|
||||||
printf("MBED: TCPClient IP address is '%s'\n", net->get_ip_address());
|
printf("MBED: TCPClient IP address is '%s'\n", net->get_ip_address());
|
||||||
|
@ -73,38 +67,42 @@ static void _ifup()
|
||||||
|
|
||||||
static void _ifdown()
|
static void _ifdown()
|
||||||
{
|
{
|
||||||
net->disconnect();
|
NetworkInterface::get_default_instance()->disconnect();
|
||||||
printf("MBED: ifdown\n");
|
printf("MBED: ifdown\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsapi_error_t tcpsocket_connect_to_srv(TCPSocket &sock, uint16_t port)
|
||||||
|
{
|
||||||
|
SocketAddress tcp_addr;
|
||||||
|
|
||||||
|
NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
|
||||||
|
tcp_addr.set_port(port);
|
||||||
|
|
||||||
|
printf("MBED: Server '%s', port %d\n", tcp_addr.get_ip_address(), tcp_addr.get_port());
|
||||||
|
|
||||||
|
nsapi_error_t err = sock.open(NetworkInterface::get_default_instance());
|
||||||
|
if (err != NSAPI_ERROR_OK) {
|
||||||
|
printf("Error from sock.open: %d\n", err);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = sock.connect(tcp_addr);
|
||||||
|
if (err != NSAPI_ERROR_OK) {
|
||||||
|
printf("Error from sock.connect: %d\n", err);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NSAPI_ERROR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
nsapi_error_t tcpsocket_connect_to_echo_srv(TCPSocket &sock)
|
nsapi_error_t tcpsocket_connect_to_echo_srv(TCPSocket &sock)
|
||||||
{
|
{
|
||||||
SocketAddress tcp_addr;
|
return tcpsocket_connect_to_srv(sock, MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||||
|
|
||||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
|
|
||||||
tcp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
|
||||||
|
|
||||||
nsapi_error_t err = sock.open(get_interface());
|
|
||||||
if (err != NSAPI_ERROR_OK) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sock.connect(tcp_addr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsapi_error_t tcpsocket_connect_to_discard_srv(TCPSocket &sock)
|
nsapi_error_t tcpsocket_connect_to_discard_srv(TCPSocket &sock)
|
||||||
{
|
{
|
||||||
SocketAddress tcp_addr;
|
return tcpsocket_connect_to_srv(sock, MBED_CONF_APP_ECHO_SERVER_DISCARD_PORT);
|
||||||
|
|
||||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
|
|
||||||
tcp_addr.set_port(9);
|
|
||||||
|
|
||||||
nsapi_error_t err = sock.open(get_interface());
|
|
||||||
if (err != NSAPI_ERROR_OK) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sock.connect(tcp_addr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void fill_tx_buffer_ascii(char *buff, size_t len)
|
void fill_tx_buffer_ascii(char *buff, size_t len)
|
||||||
|
|
|
@ -36,9 +36,10 @@ void TCPSOCKET_BIND_ADDRESS()
|
||||||
TCPSocket *sock = new TCPSocket;
|
TCPSocket *sock = new TCPSocket;
|
||||||
if (!sock) {
|
if (!sock) {
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||||
SocketAddress sockAddr = SocketAddress(get_interface()->get_ip_address(), 80);
|
SocketAddress sockAddr = SocketAddress(NetworkInterface::get_default_instance()->get_ip_address(), 80);
|
||||||
nsapi_error_t bind_result = sock->bind(sockAddr);
|
nsapi_error_t bind_result = sock->bind(sockAddr);
|
||||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||||
|
|
|
@ -36,8 +36,9 @@ void TCPSOCKET_BIND_ADDRESS_INVALID()
|
||||||
TCPSocket *sock = new TCPSocket;
|
TCPSocket *sock = new TCPSocket;
|
||||||
if (!sock) {
|
if (!sock) {
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||||
nsapi_error_t bind_result = sock->bind("190.2.3.4", 1024);
|
nsapi_error_t bind_result = sock->bind("190.2.3.4", 1024);
|
||||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||||
|
|
|
@ -36,8 +36,9 @@ void TCPSOCKET_BIND_ADDRESS_NULL()
|
||||||
TCPSocket *sock = new TCPSocket;
|
TCPSocket *sock = new TCPSocket;
|
||||||
if (!sock) {
|
if (!sock) {
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||||
nsapi_error_t bind_result = sock->bind(NULL, 1024);
|
nsapi_error_t bind_result = sock->bind(NULL, 1024);
|
||||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||||
|
|
|
@ -36,9 +36,10 @@ void TCPSOCKET_BIND_ADDRESS_PORT()
|
||||||
TCPSocket *sock = new TCPSocket;
|
TCPSocket *sock = new TCPSocket;
|
||||||
if (!sock) {
|
if (!sock) {
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||||
nsapi_error_t bind_result = sock->bind(get_interface()->get_ip_address(), 80);
|
nsapi_error_t bind_result = sock->bind(NetworkInterface::get_default_instance()->get_ip_address(), 80);
|
||||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -36,8 +36,9 @@ void TCPSOCKET_BIND_PORT()
|
||||||
TCPSocket *sock = new TCPSocket;
|
TCPSocket *sock = new TCPSocket;
|
||||||
if (!sock) {
|
if (!sock) {
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||||
nsapi_error_t bind_result = sock->bind(1024);
|
nsapi_error_t bind_result = sock->bind(1024);
|
||||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||||
|
|
|
@ -36,8 +36,9 @@ void TCPSOCKET_BIND_PORT_FAIL()
|
||||||
TCPSocket *sock = new TCPSocket;
|
TCPSocket *sock = new TCPSocket;
|
||||||
if (!sock) {
|
if (!sock) {
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||||
nsapi_error_t bind_result = sock->bind(1024);
|
nsapi_error_t bind_result = sock->bind(1024);
|
||||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||||
|
@ -51,7 +52,7 @@ void TCPSOCKET_BIND_PORT_FAIL()
|
||||||
if (!sock2) {
|
if (!sock2) {
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock2->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock2->open(NetworkInterface::get_default_instance()));
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock2->bind(1024));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock2->bind(1024));
|
||||||
|
|
||||||
delete sock;
|
delete sock;
|
||||||
|
|
|
@ -36,6 +36,7 @@ void TCPSOCKET_BIND_UNOPENED()
|
||||||
TCPSocket *sock = new TCPSocket;
|
TCPSocket *sock = new TCPSocket;
|
||||||
if (!sock) {
|
if (!sock) {
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
nsapi_error_t bind_result = sock->bind(1024);
|
nsapi_error_t bind_result = sock->bind(1024);
|
||||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||||
|
|
|
@ -36,8 +36,9 @@ void TCPSOCKET_BIND_WRONG_TYPE()
|
||||||
TCPSocket *sock = new TCPSocket;
|
TCPSocket *sock = new TCPSocket;
|
||||||
if (!sock) {
|
if (!sock) {
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||||
char addr_bytes[16] = {0xfe, 0x80, 0xff, 0x1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
char addr_bytes[16] = {0xfe, 0x80, 0xff, 0x1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
SocketAddress sockAddr = SocketAddress(addr_bytes, NSAPI_IPv4, 80);
|
SocketAddress sockAddr = SocketAddress(addr_bytes, NSAPI_IPv4, 80);
|
||||||
nsapi_error_t bind_result = sock->bind(sockAddr);
|
nsapi_error_t bind_result = sock->bind(sockAddr);
|
||||||
|
|
|
@ -27,7 +27,7 @@ using namespace utest::v1;
|
||||||
void TCPSOCKET_CONNECT_INVALID()
|
void TCPSOCKET_CONNECT_INVALID()
|
||||||
{
|
{
|
||||||
TCPSocket sock;
|
TCPSocket sock;
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||||
|
|
||||||
TEST_ASSERT(sock.connect(NULL, 9) < 0);
|
TEST_ASSERT(sock.connect(NULL, 9) < 0);
|
||||||
TEST_ASSERT(sock.connect("", 9) < 0);
|
TEST_ASSERT(sock.connect("", 9) < 0);
|
||||||
|
|
|
@ -36,14 +36,25 @@ static const int pkt_sizes[PKTS] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, \
|
||||||
};
|
};
|
||||||
TCPSocket sock;
|
TCPSocket sock;
|
||||||
Semaphore tx_sem(0, 1);
|
Semaphore tx_sem(0, 1);
|
||||||
|
events::EventQueue *event_queue;
|
||||||
|
int bytes2recv;
|
||||||
|
int bytes2recv_total;
|
||||||
|
|
||||||
Timer tc_exec_time;
|
Timer tc_exec_time;
|
||||||
int time_allotted;
|
int time_allotted;
|
||||||
|
bool receive_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tcpsocket_echotest_nonblock_receive();
|
||||||
|
|
||||||
static void _sigio_handler(osThreadId id)
|
static void _sigio_handler(osThreadId id)
|
||||||
{
|
{
|
||||||
osSignalSet(id, SIGNAL_SIGIO);
|
osSignalSet(id, SIGNAL_SIGIO);
|
||||||
|
if (event_queue != NULL) {
|
||||||
|
event_queue->call(tcpsocket_echotest_nonblock_receive);
|
||||||
|
} else {
|
||||||
|
TEST_FAIL_MESSAGE("_sigio_handler running when event_queue is NULL");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPSOCKET_ECHOTEST()
|
void TCPSOCKET_ECHOTEST()
|
||||||
|
@ -83,33 +94,31 @@ void TCPSOCKET_ECHOTEST()
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
||||||
}
|
}
|
||||||
|
|
||||||
void tcpsocket_echotest_nonblock_receiver(void *receive_bytes)
|
void tcpsocket_echotest_nonblock_receive()
|
||||||
{
|
{
|
||||||
int bytes2recv = *(int *)receive_bytes;
|
int recvd = sock.recv(&(tcp_global::rx_buffer[bytes2recv_total - bytes2recv]), bytes2recv);
|
||||||
int recvd;
|
|
||||||
while (bytes2recv) {
|
|
||||||
recvd = sock.recv(&(tcp_global::rx_buffer[*(int *)receive_bytes - bytes2recv]), bytes2recv);
|
|
||||||
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
|
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
|
||||||
if (tc_exec_time.read() >= time_allotted) {
|
if (tc_exec_time.read() >= time_allotted) {
|
||||||
TEST_FAIL();
|
receive_error = true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
wait(1);
|
return;
|
||||||
continue;
|
|
||||||
} else if (recvd < 0) {
|
} else if (recvd < 0) {
|
||||||
TEST_FAIL();
|
receive_error = true;
|
||||||
break;
|
} else {
|
||||||
}
|
|
||||||
bytes2recv -= recvd;
|
bytes2recv -= recvd;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL(0, memcmp(tcp_global::tx_buffer, tcp_global::rx_buffer, *(int *)receive_bytes));
|
if (bytes2recv == 0) {
|
||||||
|
TEST_ASSERT_EQUAL(0, memcmp(tcp_global::tx_buffer, tcp_global::rx_buffer, bytes2recv_total));
|
||||||
|
|
||||||
static int round = 0;
|
static int round = 0;
|
||||||
printf("[Recevr#%02d] bytes received: %d\n", round++, *(int *)receive_bytes);
|
printf("[Recevr#%02d] bytes received: %d\n", round++, bytes2recv_total);
|
||||||
|
|
||||||
tx_sem.release();
|
tx_sem.release();
|
||||||
|
} else if (receive_error || bytes2recv < 0) {
|
||||||
|
TEST_FAIL();
|
||||||
|
tx_sem.release();
|
||||||
|
}
|
||||||
|
// else - no error, not all bytes were received yet.
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPSOCKET_ECHOTEST_NONBLOCK()
|
void TCPSOCKET_ECHOTEST_NONBLOCK()
|
||||||
|
@ -124,6 +133,9 @@ void TCPSOCKET_ECHOTEST_NONBLOCK()
|
||||||
tc_exec_time.start();
|
tc_exec_time.start();
|
||||||
time_allotted = split2half_rmng_tcp_test_time(); // [s]
|
time_allotted = split2half_rmng_tcp_test_time(); // [s]
|
||||||
|
|
||||||
|
EventQueue queue(2 * EVENTS_EVENT_SIZE);
|
||||||
|
event_queue = &queue;
|
||||||
|
|
||||||
tcpsocket_connect_to_echo_srv(sock);
|
tcpsocket_connect_to_echo_srv(sock);
|
||||||
sock.set_blocking(false);
|
sock.set_blocking(false);
|
||||||
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));
|
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));
|
||||||
|
@ -131,17 +143,20 @@ void TCPSOCKET_ECHOTEST_NONBLOCK()
|
||||||
int bytes2send;
|
int bytes2send;
|
||||||
int sent;
|
int sent;
|
||||||
int s_idx = 0;
|
int s_idx = 0;
|
||||||
Thread *thread;
|
receive_error = false;
|
||||||
unsigned char *stack_mem = (unsigned char *)malloc(tcp_global::TCP_OS_STACK_SIZE);
|
unsigned char *stack_mem = (unsigned char *)malloc(tcp_global::TCP_OS_STACK_SIZE);
|
||||||
TEST_ASSERT_NOT_NULL(stack_mem);
|
TEST_ASSERT_NOT_NULL(stack_mem);
|
||||||
|
Thread *receiver_thread = new Thread(osPriorityNormal,
|
||||||
for (int pkt_s = pkt_sizes[s_idx]; s_idx < PKTS; ++s_idx) {
|
|
||||||
pkt_s = pkt_sizes[s_idx];
|
|
||||||
thread = new Thread(osPriorityNormal,
|
|
||||||
tcp_global::TCP_OS_STACK_SIZE,
|
tcp_global::TCP_OS_STACK_SIZE,
|
||||||
stack_mem,
|
stack_mem,
|
||||||
"receiver");
|
"receiver");
|
||||||
TEST_ASSERT_EQUAL(osOK, thread->start(callback(tcpsocket_echotest_nonblock_receiver, &pkt_s)));
|
|
||||||
|
TEST_ASSERT_EQUAL(osOK, receiver_thread->start(callback(&queue, &EventQueue::dispatch_forever)));
|
||||||
|
|
||||||
|
for (int pkt_s = pkt_sizes[s_idx]; s_idx < PKTS; ++s_idx) {
|
||||||
|
pkt_s = pkt_sizes[s_idx];
|
||||||
|
bytes2recv = pkt_s;
|
||||||
|
bytes2recv_total = pkt_s;
|
||||||
|
|
||||||
fill_tx_buffer_ascii(tcp_global::tx_buffer, pkt_s);
|
fill_tx_buffer_ascii(tcp_global::tx_buffer, pkt_s);
|
||||||
|
|
||||||
|
@ -151,16 +166,12 @@ void TCPSOCKET_ECHOTEST_NONBLOCK()
|
||||||
if (sent == NSAPI_ERROR_WOULD_BLOCK) {
|
if (sent == NSAPI_ERROR_WOULD_BLOCK) {
|
||||||
if (tc_exec_time.read() >= time_allotted ||
|
if (tc_exec_time.read() >= time_allotted ||
|
||||||
osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
|
osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
|
||||||
thread->terminate();
|
|
||||||
delete thread;
|
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
} else if (sent <= 0) {
|
} else if (sent <= 0) {
|
||||||
printf("[Sender#%02d] network error %d\n", s_idx, sent);
|
printf("[Sender#%02d] network error %d\n", s_idx, sent);
|
||||||
thread->terminate();
|
|
||||||
delete thread;
|
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
@ -176,12 +187,17 @@ void TCPSOCKET_ECHOTEST_NONBLOCK()
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(bytes2send, tcp_stats[j].sent_bytes);
|
TEST_ASSERT_EQUAL(bytes2send, tcp_stats[j].sent_bytes);
|
||||||
#endif
|
#endif
|
||||||
tx_sem.wait(split2half_rmng_tcp_test_time());
|
tx_sem.wait(split2half_rmng_tcp_test_time() * 1000); // *1000 to convert s->ms
|
||||||
thread->join();
|
if (receive_error) {
|
||||||
delete thread;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
END:
|
END:
|
||||||
|
sock.sigio(NULL);
|
||||||
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
||||||
|
receiver_thread->terminate();
|
||||||
|
delete receiver_thread;
|
||||||
|
receiver_thread = NULL;
|
||||||
tc_exec_time.stop();
|
tc_exec_time.stop();
|
||||||
free(stack_mem);
|
free(stack_mem);
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,8 +78,7 @@ void TCPSOCKET_ECHOTEST_BURST()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bt_left != 0) {
|
if (bt_left != 0) {
|
||||||
drop_bad_packets(sock, 0);
|
TEST_FAIL_MESSAGE("bt_left != 0");
|
||||||
TEST_FAIL();
|
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +141,6 @@ void TCPSOCKET_ECHOTEST_BURST_NONBLOCK()
|
||||||
|
|
||||||
if (bt_left != 0) {
|
if (bt_left != 0) {
|
||||||
printf("network error %d, missing %d bytes from a burst\n", recvd, bt_left);
|
printf("network error %d, missing %d bytes from a burst\n", recvd, bt_left);
|
||||||
drop_bad_packets(sock, -1);
|
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,10 +38,10 @@ static nsapi_error_t _tcpsocket_connect_to_daytime_srv(TCPSocket &sock)
|
||||||
{
|
{
|
||||||
SocketAddress tcp_addr;
|
SocketAddress tcp_addr;
|
||||||
|
|
||||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
|
NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
|
||||||
tcp_addr.set_port(13);
|
tcp_addr.set_port(13);
|
||||||
|
|
||||||
nsapi_error_t err = sock.open(get_interface());
|
nsapi_error_t err = sock.open(NetworkInterface::get_default_instance());
|
||||||
if (err != NSAPI_ERROR_OK) {
|
if (err != NSAPI_ERROR_OK) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ void TCPSOCKET_OPEN_CLOSE_REPEAT()
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close());
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close());
|
||||||
}
|
}
|
||||||
delete sock;
|
delete sock;
|
||||||
|
|
|
@ -38,7 +38,7 @@ void TCPSOCKET_OPEN_DESTRUCT()
|
||||||
if (!sock) {
|
if (!sock) {
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||||
delete sock;
|
delete sock;
|
||||||
}
|
}
|
||||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||||
|
|
|
@ -46,7 +46,7 @@ void TCPSOCKET_OPEN_LIMIT()
|
||||||
if (!sock) {
|
if (!sock) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ret = sock->open(get_interface());
|
ret = sock->open(NetworkInterface::get_default_instance());
|
||||||
if (ret == NSAPI_ERROR_NO_MEMORY || ret == NSAPI_ERROR_NO_SOCKET) {
|
if (ret == NSAPI_ERROR_NO_MEMORY || ret == NSAPI_ERROR_NO_SOCKET) {
|
||||||
printf("[round#%02d] unable to open new socket, error: %d\n", i, ret);
|
printf("[round#%02d] unable to open new socket, error: %d\n", i, ret);
|
||||||
delete sock;
|
delete sock;
|
||||||
|
|
|
@ -37,8 +37,8 @@ void TCPSOCKET_OPEN_TWICE()
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock->open(NetworkInterface::get_default_instance()));
|
||||||
|
|
||||||
delete sock;
|
delete sock;
|
||||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||||
|
|
|
@ -33,10 +33,10 @@ static nsapi_error_t _tcpsocket_connect_to_chargen_srv(TCPSocket &sock)
|
||||||
{
|
{
|
||||||
SocketAddress tcp_addr;
|
SocketAddress tcp_addr;
|
||||||
|
|
||||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
|
NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
|
||||||
tcp_addr.set_port(19);
|
tcp_addr.set_port(19);
|
||||||
|
|
||||||
nsapi_error_t err = sock.open(get_interface());
|
nsapi_error_t err = sock.open(NetworkInterface::get_default_instance());
|
||||||
if (err != NSAPI_ERROR_OK) {
|
if (err != NSAPI_ERROR_OK) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ using namespace utest::v1;
|
||||||
void TCPSOCKET_SETSOCKOPT_KEEPALIVE_VALID()
|
void TCPSOCKET_SETSOCKOPT_KEEPALIVE_VALID()
|
||||||
{
|
{
|
||||||
TCPSocket sock;
|
TCPSocket sock;
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||||
int32_t seconds = 7200;
|
int32_t seconds = 7200;
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.setsockopt(NSAPI_SOCKET, NSAPI_KEEPALIVE, &seconds, sizeof(int)));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.setsockopt(NSAPI_SOCKET, NSAPI_KEEPALIVE, &seconds, sizeof(int)));
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.connect(MBED_CONF_APP_ECHO_SERVER_ADDR, 9));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.connect(MBED_CONF_APP_ECHO_SERVER_ADDR, 9));
|
||||||
|
|
|
@ -33,22 +33,13 @@
|
||||||
|
|
||||||
using namespace utest::v1;
|
using namespace utest::v1;
|
||||||
|
|
||||||
namespace {
|
|
||||||
NetworkInterface *net;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||||
mbed_stats_socket_t udp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
|
mbed_stats_socket_t udp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
NetworkInterface *get_interface()
|
|
||||||
{
|
|
||||||
return net;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _ifup()
|
static void _ifup()
|
||||||
{
|
{
|
||||||
net = NetworkInterface::get_default_instance();
|
NetworkInterface *net = NetworkInterface::get_default_instance();
|
||||||
nsapi_error_t err = net->connect();
|
nsapi_error_t err = net->connect();
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
|
||||||
printf("MBED: UDPClient IP address is '%s'\n", net->get_ip_address());
|
printf("MBED: UDPClient IP address is '%s'\n", net->get_ip_address());
|
||||||
|
@ -56,7 +47,7 @@ static void _ifup()
|
||||||
|
|
||||||
static void _ifdown()
|
static void _ifdown()
|
||||||
{
|
{
|
||||||
net->disconnect();
|
NetworkInterface::get_default_instance()->disconnect();
|
||||||
printf("MBED: ifdown\n");
|
printf("MBED: ifdown\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,8 @@ void UDPSOCKET_BIND_ADDRESS()
|
||||||
if (!sock) {
|
if (!sock) {
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||||
SocketAddress sockAddr = SocketAddress(get_interface()->get_ip_address(), 80);
|
SocketAddress sockAddr = SocketAddress(NetworkInterface::get_default_instance()->get_ip_address(), 80);
|
||||||
nsapi_error_t bind_result = sock->bind(sockAddr);
|
nsapi_error_t bind_result = sock->bind(sockAddr);
|
||||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||||
|
|
|
@ -37,7 +37,7 @@ void UDPSOCKET_BIND_ADDRESS_INVALID()
|
||||||
if (!sock) {
|
if (!sock) {
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||||
nsapi_error_t bind_result = sock->bind("190.2.3.4", 1024);
|
nsapi_error_t bind_result = sock->bind("190.2.3.4", 1024);
|
||||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||||
|
|
|
@ -37,7 +37,7 @@ void UDPSOCKET_BIND_ADDRESS_NULL()
|
||||||
if (!sock) {
|
if (!sock) {
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||||
nsapi_error_t bind_result = sock->bind(NULL, 1024);
|
nsapi_error_t bind_result = sock->bind(NULL, 1024);
|
||||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||||
|
|
|
@ -37,8 +37,8 @@ void UDPSOCKET_BIND_ADDRESS_PORT()
|
||||||
if (!sock) {
|
if (!sock) {
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||||
nsapi_error_t bind_result = sock->bind(get_interface()->get_ip_address(), 80);
|
nsapi_error_t bind_result = sock->bind(NetworkInterface::get_default_instance()->get_ip_address(), 80);
|
||||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -37,7 +37,7 @@ void UDPSOCKET_BIND_PORT()
|
||||||
if (!sock) {
|
if (!sock) {
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||||
nsapi_error_t bind_result = sock->bind(1024);
|
nsapi_error_t bind_result = sock->bind(1024);
|
||||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||||
|
|
|
@ -37,7 +37,7 @@ void UDPSOCKET_BIND_PORT_FAIL()
|
||||||
if (!sock) {
|
if (!sock) {
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||||
nsapi_error_t bind_result = sock->bind(1024);
|
nsapi_error_t bind_result = sock->bind(1024);
|
||||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||||
|
@ -51,7 +51,7 @@ void UDPSOCKET_BIND_PORT_FAIL()
|
||||||
if (!sock2) {
|
if (!sock2) {
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock2->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock2->open(NetworkInterface::get_default_instance()));
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock2->bind(1024));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock2->bind(1024));
|
||||||
|
|
||||||
delete sock;
|
delete sock;
|
||||||
|
|
|
@ -37,7 +37,7 @@ void UDPSOCKET_BIND_WRONG_TYPE()
|
||||||
if (!sock) {
|
if (!sock) {
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||||
char addr_bytes[16] = {0xfe, 0x80, 0xff, 0x1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
char addr_bytes[16] = {0xfe, 0x80, 0xff, 0x1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
SocketAddress sockAddr = SocketAddress(addr_bytes, NSAPI_IPv4, 80);
|
SocketAddress sockAddr = SocketAddress(addr_bytes, NSAPI_IPv4, 80);
|
||||||
nsapi_error_t bind_result = sock->bind(sockAddr);
|
nsapi_error_t bind_result = sock->bind(sockAddr);
|
||||||
|
|
|
@ -55,11 +55,11 @@ static void _sigio_handler(osThreadId id)
|
||||||
void UDPSOCKET_ECHOTEST()
|
void UDPSOCKET_ECHOTEST()
|
||||||
{
|
{
|
||||||
SocketAddress udp_addr;
|
SocketAddress udp_addr;
|
||||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||||
udp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
udp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||||
|
|
||||||
UDPSocket sock;
|
UDPSocket sock;
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||||
|
|
||||||
int recvd;
|
int recvd;
|
||||||
int sent;
|
int sent;
|
||||||
|
@ -134,10 +134,10 @@ void UDPSOCKET_ECHOTEST_NONBLOCK()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SocketAddress udp_addr;
|
SocketAddress udp_addr;
|
||||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||||
udp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
udp_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.open(NetworkInterface::get_default_instance()));
|
||||||
sock.set_blocking(false);
|
sock.set_blocking(false);
|
||||||
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));
|
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));
|
||||||
|
|
||||||
|
|
|
@ -71,12 +71,12 @@ static void _sigio_handler(osThreadId id)
|
||||||
void UDPSOCKET_ECHOTEST_BURST()
|
void UDPSOCKET_ECHOTEST_BURST()
|
||||||
{
|
{
|
||||||
SocketAddress udp_addr;
|
SocketAddress udp_addr;
|
||||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||||
udp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
udp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||||
|
|
||||||
UDPSocket sock;
|
UDPSocket sock;
|
||||||
const int TIMEOUT = 5000; // [ms]
|
const int TIMEOUT = 5000; // [ms]
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||||
sock.set_timeout(TIMEOUT);
|
sock.set_timeout(TIMEOUT);
|
||||||
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));
|
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));
|
||||||
|
|
||||||
|
@ -150,11 +150,11 @@ void UDPSOCKET_ECHOTEST_BURST()
|
||||||
void UDPSOCKET_ECHOTEST_BURST_NONBLOCK()
|
void UDPSOCKET_ECHOTEST_BURST_NONBLOCK()
|
||||||
{
|
{
|
||||||
SocketAddress udp_addr;
|
SocketAddress udp_addr;
|
||||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||||
udp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
udp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||||
|
|
||||||
UDPSocket sock;
|
UDPSocket sock;
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||||
sock.set_blocking(false);
|
sock.set_blocking(false);
|
||||||
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));
|
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ void UDPSOCKET_OPEN_CLOSE_REPEAT()
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close());
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close());
|
||||||
}
|
}
|
||||||
delete sock;
|
delete sock;
|
||||||
|
|
|
@ -38,7 +38,7 @@ void UDPSOCKET_OPEN_DESTRUCT()
|
||||||
if (!sock) {
|
if (!sock) {
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||||
delete sock;
|
delete sock;
|
||||||
}
|
}
|
||||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||||
|
|
|
@ -47,7 +47,7 @@ void UDPSOCKET_OPEN_LIMIT()
|
||||||
if (!sock) {
|
if (!sock) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ret = sock->open(get_interface());
|
ret = sock->open(NetworkInterface::get_default_instance());
|
||||||
if (ret == NSAPI_ERROR_NO_MEMORY || ret == NSAPI_ERROR_NO_SOCKET) {
|
if (ret == NSAPI_ERROR_NO_MEMORY || ret == NSAPI_ERROR_NO_SOCKET) {
|
||||||
printf("[round#%02d] unable to open new socket, error: %d\n", i, ret);
|
printf("[round#%02d] unable to open new socket, error: %d\n", i, ret);
|
||||||
delete sock;
|
delete sock;
|
||||||
|
|
|
@ -37,8 +37,8 @@ void UDPSOCKET_OPEN_TWICE()
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock->open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock->open(NetworkInterface::get_default_instance()));
|
||||||
|
|
||||||
delete sock;
|
delete sock;
|
||||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||||
|
|
|
@ -37,14 +37,14 @@ static void _sigio_handler(osThreadId id)
|
||||||
void UDPSOCKET_RECV_TIMEOUT()
|
void UDPSOCKET_RECV_TIMEOUT()
|
||||||
{
|
{
|
||||||
SocketAddress udp_addr;
|
SocketAddress udp_addr;
|
||||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||||
udp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
udp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||||
|
|
||||||
static const int DATA_LEN = 100;
|
static const int DATA_LEN = 100;
|
||||||
char buff[DATA_LEN] = {0};
|
char buff[DATA_LEN] = {0};
|
||||||
|
|
||||||
UDPSocket sock;
|
UDPSocket sock;
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||||
sock.set_timeout(100);
|
sock.set_timeout(100);
|
||||||
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));
|
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ using namespace utest::v1;
|
||||||
void UDPSOCKET_SENDTO_INVALID()
|
void UDPSOCKET_SENDTO_INVALID()
|
||||||
{
|
{
|
||||||
UDPSocket sock;
|
UDPSocket sock;
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||||
|
|
||||||
TEST_ASSERT(sock.sendto(NULL, 9, NULL, 0) < 0);
|
TEST_ASSERT(sock.sendto(NULL, 9, NULL, 0) < 0);
|
||||||
TEST_ASSERT(sock.sendto("", 9, NULL, 0) < 0);
|
TEST_ASSERT(sock.sendto("", 9, NULL, 0) < 0);
|
||||||
|
|
|
@ -27,10 +27,10 @@ using namespace utest::v1;
|
||||||
void UDPSOCKET_SENDTO_REPEAT()
|
void UDPSOCKET_SENDTO_REPEAT()
|
||||||
{
|
{
|
||||||
UDPSocket sock;
|
UDPSocket sock;
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||||
|
|
||||||
SocketAddress udp_addr;
|
SocketAddress udp_addr;
|
||||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||||
udp_addr.set_port(9);
|
udp_addr.set_port(9);
|
||||||
|
|
||||||
int sent;
|
int sent;
|
||||||
|
|
|
@ -30,10 +30,10 @@ void UDPSOCKET_SENDTO_TIMEOUT()
|
||||||
fill_tx_buffer_ascii(tx_buffer, sizeof(tx_buffer));
|
fill_tx_buffer_ascii(tx_buffer, sizeof(tx_buffer));
|
||||||
|
|
||||||
UDPSocket sock;
|
UDPSocket sock;
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||||
|
|
||||||
SocketAddress udp_addr;
|
SocketAddress udp_addr;
|
||||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||||
udp_addr.set_port(9);
|
udp_addr.set_port(9);
|
||||||
|
|
||||||
Timer timer;
|
Timer timer;
|
||||||
|
|
|
@ -7,6 +7,10 @@
|
||||||
"echo-server-port" : {
|
"echo-server-port" : {
|
||||||
"help" : "Port of echo server",
|
"help" : "Port of echo server",
|
||||||
"value" : "7"
|
"value" : "7"
|
||||||
|
},
|
||||||
|
"echo-server-discard-port" : {
|
||||||
|
"help" : "Discard port of echo server",
|
||||||
|
"value" : "9"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"target_overrides": {
|
"target_overrides": {
|
||||||
|
|
|
@ -7,6 +7,10 @@
|
||||||
"echo-server-port" : {
|
"echo-server-port" : {
|
||||||
"help" : "Port of echo server",
|
"help" : "Port of echo server",
|
||||||
"value" : "7"
|
"value" : "7"
|
||||||
|
},
|
||||||
|
"echo-server-discard-port" : {
|
||||||
|
"help" : "Discard port of echo server",
|
||||||
|
"value" : "9"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"target_overrides": {
|
"target_overrides": {
|
||||||
|
|
|
@ -7,6 +7,10 @@
|
||||||
"echo-server-port" : {
|
"echo-server-port" : {
|
||||||
"help" : "Port of echo server",
|
"help" : "Port of echo server",
|
||||||
"value" : "7"
|
"value" : "7"
|
||||||
|
},
|
||||||
|
"echo-server-discard-port" : {
|
||||||
|
"help" : "Discard port of echo server",
|
||||||
|
"value" : "9"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"target_overrides": {
|
"target_overrides": {
|
||||||
|
|
|
@ -7,6 +7,10 @@
|
||||||
"echo-server-port" : {
|
"echo-server-port" : {
|
||||||
"help" : "Port of echo server",
|
"help" : "Port of echo server",
|
||||||
"value" : "7"
|
"value" : "7"
|
||||||
|
},
|
||||||
|
"echo-server-discard-port" : {
|
||||||
|
"help" : "Discard port of echo server",
|
||||||
|
"value" : "9"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"target_overrides": {
|
"target_overrides": {
|
||||||
|
|
|
@ -8,6 +8,10 @@
|
||||||
"help" : "Port of echo server",
|
"help" : "Port of echo server",
|
||||||
"value" : "7"
|
"value" : "7"
|
||||||
},
|
},
|
||||||
|
"echo-server-discard-port" : {
|
||||||
|
"help" : "Discard port of echo server",
|
||||||
|
"value" : "9"
|
||||||
|
},
|
||||||
"sim-blockdevice": {
|
"sim-blockdevice": {
|
||||||
"help": "Simulated block device, requires sufficient heap",
|
"help": "Simulated block device, requires sufficient heap",
|
||||||
"macro_name": "MBED_TEST_SIM_BLOCKDEVICE",
|
"macro_name": "MBED_TEST_SIM_BLOCKDEVICE",
|
||||||
|
|
|
@ -8,6 +8,10 @@
|
||||||
"help" : "Port of echo server",
|
"help" : "Port of echo server",
|
||||||
"value" : "7"
|
"value" : "7"
|
||||||
},
|
},
|
||||||
|
"echo-server-discard-port" : {
|
||||||
|
"help" : "Discard port of echo server",
|
||||||
|
"value" : "9"
|
||||||
|
},
|
||||||
"sim-blockdevice": {
|
"sim-blockdevice": {
|
||||||
"help": "Simulated block device, requires sufficient heap",
|
"help": "Simulated block device, requires sufficient heap",
|
||||||
"macro_name": "MBED_TEST_SIM_BLOCKDEVICE",
|
"macro_name": "MBED_TEST_SIM_BLOCKDEVICE",
|
||||||
|
|
|
@ -8,6 +8,10 @@
|
||||||
"help" : "Port of echo server",
|
"help" : "Port of echo server",
|
||||||
"value" : "7"
|
"value" : "7"
|
||||||
},
|
},
|
||||||
|
"echo-server-discard-port" : {
|
||||||
|
"help" : "Discard port of echo server",
|
||||||
|
"value" : "9"
|
||||||
|
},
|
||||||
"wifi-secure-ssid": {
|
"wifi-secure-ssid": {
|
||||||
"help": "WiFi SSID for WPA2 secured network",
|
"help": "WiFi SSID for WPA2 secured network",
|
||||||
"value": "\"SSID-SECURE\""
|
"value": "\"SSID-SECURE\""
|
||||||
|
|
|
@ -8,6 +8,10 @@
|
||||||
"help" : "Port of echo server",
|
"help" : "Port of echo server",
|
||||||
"value" : "7"
|
"value" : "7"
|
||||||
},
|
},
|
||||||
|
"echo-server-discard-port" : {
|
||||||
|
"help" : "Discard port of echo server",
|
||||||
|
"value" : "9"
|
||||||
|
},
|
||||||
"WIFI-TX" : {
|
"WIFI-TX" : {
|
||||||
"help" : "Wifi TX pin",
|
"help" : "Wifi TX pin",
|
||||||
"value" : "D8"
|
"value" : "D8"
|
||||||
|
|
|
@ -7,6 +7,10 @@
|
||||||
"echo-server-port" : {
|
"echo-server-port" : {
|
||||||
"help" : "Port of echo server",
|
"help" : "Port of echo server",
|
||||||
"value" : "7"
|
"value" : "7"
|
||||||
|
},
|
||||||
|
"echo-server-discard-port" : {
|
||||||
|
"help" : "Discard port of echo server",
|
||||||
|
"value" : "9"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"target_overrides": {
|
"target_overrides": {
|
||||||
|
|
|
@ -7,6 +7,10 @@
|
||||||
"echo-server-port" : {
|
"echo-server-port" : {
|
||||||
"help" : "Port of echo server",
|
"help" : "Port of echo server",
|
||||||
"value" : "7"
|
"value" : "7"
|
||||||
|
},
|
||||||
|
"echo-server-discard-port" : {
|
||||||
|
"help" : "Discard port of echo server",
|
||||||
|
"value" : "9"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"target_overrides": {
|
"target_overrides": {
|
||||||
|
|
|
@ -7,6 +7,10 @@
|
||||||
"echo-server-port" : {
|
"echo-server-port" : {
|
||||||
"help" : "Port of echo server",
|
"help" : "Port of echo server",
|
||||||
"value" : null
|
"value" : null
|
||||||
|
},
|
||||||
|
"echo-server-discard-port" : {
|
||||||
|
"help" : "Discard port of echo server",
|
||||||
|
"value" : null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"target_overrides": {
|
"target_overrides": {
|
||||||
|
|
Loading…
Reference in New Issue