Greentea Socket bind tests made ipv6-aware

pull/9582/head
Michal Paszta 2019-02-01 14:23:22 +02:00
parent fba66cf7f3
commit 99fc26ecdf
8 changed files with 54 additions and 4 deletions

View File

@ -57,6 +57,15 @@ void drop_bad_packets(TCPSocket &sock, int orig_timeout)
sock.set_timeout(orig_timeout);
}
nsapi_version_t get_ip_version()
{
SocketAddress test;
if (!test.set_ip_address(NetworkInterface::get_default_instance()->get_ip_address())) {
return NSAPI_UNSPEC;
}
return test.get_ip_version();
}
static void _ifup()
{
NetworkInterface *net = NetworkInterface::get_default_instance();

View File

@ -20,6 +20,7 @@
NetworkInterface *get_interface();
void drop_bad_packets(TCPSocket &sock, int orig_timeout);
nsapi_version_t get_ip_version();
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);

View File

@ -39,7 +39,14 @@ void TCPSOCKET_BIND_ADDRESS_INVALID()
return;
}
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 = NSAPI_ERROR_OK;
if (get_ip_version() == NSAPI_IPv4) {
bind_result = sock->bind("190.2.3.4", 1024);
} else if (get_ip_version() == NSAPI_IPv6) {
bind_result = sock->bind("fe80::ff01", 1024);
} else {
TEST_FAIL_MESSAGE("This stack is neither IPv4 nor IPv6");
}
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
TEST_IGNORE_MESSAGE("bind() not supported");
} else {

View File

@ -40,7 +40,14 @@ void TCPSOCKET_BIND_WRONG_TYPE()
}
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};
SocketAddress sockAddr = SocketAddress(addr_bytes, NSAPI_IPv4, 80);
SocketAddress sockAddr;
if (get_ip_version() == NSAPI_IPv4) {
sockAddr = SocketAddress(addr_bytes, NSAPI_IPv4, 80);
} else if (get_ip_version() == NSAPI_IPv6) {
sockAddr = SocketAddress(addr_bytes, NSAPI_IPv6, 80);
} else {
TEST_FAIL_MESSAGE("This stack is neither IPv4 nor IPv6");
}
nsapi_error_t bind_result = sock->bind(sockAddr);
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
TEST_IGNORE_MESSAGE("bind() not supported");

View File

@ -64,6 +64,15 @@ void drop_bad_packets(UDPSocket &sock, int orig_timeout)
sock.set_timeout(orig_timeout);
}
nsapi_version_t get_ip_version()
{
SocketAddress test;
if (!test.set_ip_address(NetworkInterface::get_default_instance()->get_ip_address())) {
return NSAPI_UNSPEC;
}
return test.get_ip_version();
}
void fill_tx_buffer_ascii(char *buff, size_t len)
{
for (size_t i = 0; i < len; ++i) {

View File

@ -20,6 +20,7 @@
NetworkInterface *get_interface();
void drop_bad_packets(UDPSocket &sock, int orig_timeout);
nsapi_version_t get_ip_version();
void fill_tx_buffer_ascii(char *buff, size_t len);
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE

View File

@ -38,7 +38,16 @@ void UDPSOCKET_BIND_ADDRESS_INVALID()
TEST_FAIL();
}
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 = NSAPI_ERROR_OK;
if (get_ip_version() == NSAPI_IPv4) {
bind_result = sock->bind("190.2.3.4", 1024);
} else if (get_ip_version() == NSAPI_IPv6) {
bind_result = sock->bind("fe80::ff01", 1024);
} else {
TEST_FAIL_MESSAGE("This stack is neither IPv4 nor IPv6");
}
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
TEST_IGNORE_MESSAGE("bind() not supported");
} else {

View File

@ -39,7 +39,14 @@ void UDPSOCKET_BIND_WRONG_TYPE()
}
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};
SocketAddress sockAddr = SocketAddress(addr_bytes, NSAPI_IPv4, 80);
SocketAddress sockAddr;
if (get_ip_version() == NSAPI_IPv4) {
sockAddr = SocketAddress(addr_bytes, NSAPI_IPv4, 80);
} else if (get_ip_version() == NSAPI_IPv6) {
sockAddr = SocketAddress(addr_bytes, NSAPI_IPv6, 80);
} else {
TEST_FAIL_MESSAGE("This stack is neither IPv4 nor IPv6");
}
nsapi_error_t bind_result = sock->bind(sockAddr);
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
TEST_IGNORE_MESSAGE("bind() not supported");