mirror of https://github.com/ARMmbed/mbed-os.git
Greentea Socket bind tests made ipv6-aware
parent
fba66cf7f3
commit
99fc26ecdf
|
@ -57,6 +57,15 @@ void drop_bad_packets(TCPSocket &sock, int orig_timeout)
|
||||||
sock.set_timeout(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()
|
static void _ifup()
|
||||||
{
|
{
|
||||||
NetworkInterface *net = NetworkInterface::get_default_instance();
|
NetworkInterface *net = NetworkInterface::get_default_instance();
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
NetworkInterface *get_interface();
|
NetworkInterface *get_interface();
|
||||||
void drop_bad_packets(TCPSocket &sock, int orig_timeout);
|
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);
|
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_echo_srv(TCPSocket &sock);
|
||||||
nsapi_error_t tcpsocket_connect_to_discard_srv(TCPSocket &sock);
|
nsapi_error_t tcpsocket_connect_to_discard_srv(TCPSocket &sock);
|
||||||
|
|
|
@ -39,7 +39,14 @@ void TCPSOCKET_BIND_ADDRESS_INVALID()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
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) {
|
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -40,7 +40,14 @@ void TCPSOCKET_BIND_WRONG_TYPE()
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
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;
|
||||||
|
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);
|
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");
|
||||||
|
|
|
@ -64,6 +64,15 @@ void drop_bad_packets(UDPSocket &sock, int orig_timeout)
|
||||||
sock.set_timeout(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)
|
void fill_tx_buffer_ascii(char *buff, size_t len)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < len; ++i) {
|
for (size_t i = 0; i < len; ++i) {
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
NetworkInterface *get_interface();
|
NetworkInterface *get_interface();
|
||||||
void drop_bad_packets(UDPSocket &sock, int orig_timeout);
|
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);
|
void fill_tx_buffer_ascii(char *buff, size_t len);
|
||||||
|
|
||||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||||
|
|
|
@ -38,7 +38,16 @@ void UDPSOCKET_BIND_ADDRESS_INVALID()
|
||||||
TEST_FAIL();
|
TEST_FAIL();
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
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) {
|
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -39,7 +39,14 @@ void UDPSOCKET_BIND_WRONG_TYPE()
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
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;
|
||||||
|
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);
|
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");
|
||||||
|
|
Loading…
Reference in New Issue