Skip to content

Greentea Socket test improvements #9582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions TESTS/netsocket/dns/asynchronous_dns_cancel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void ASYNCHRONOUS_DNS_CANCEL()
count++;
} else {
// No memory to initiate DNS query, callback will not be called
printf("Error: No memory to initiate DNS query for %s\n", dns_test_hosts[i]);
data[i].result = NSAPI_ERROR_NO_MEMORY;
data[i].value_set = true;
}
Expand Down
9 changes: 9 additions & 0 deletions TESTS/netsocket/tcp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tcp/tcp_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion TESTS/netsocket/tcp/tcpsocket_bind_address_invalid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 8 additions & 1 deletion TESTS/netsocket/tcp/tcpsocket_bind_wrong_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
9 changes: 9 additions & 0 deletions TESTS/netsocket/udp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/udp/udp_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion TESTS/netsocket/udp/udpsocket_bind_address_invalid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 8 additions & 1 deletion TESTS/netsocket/udp/udpsocket_bind_wrong_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion TESTS/netsocket/udp/udpsocket_recv_timeout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void UDPSOCKET_RECV_TIMEOUT()
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT);
printf("MBED: recvfrom() took: %dms\n", timer.read_ms());
TEST_ASSERT_INT_WITHIN(50, 150, timer.read_ms());
TEST_ASSERT_INT_WITHIN(51, 150, timer.read_ms());
continue;
} else if (recvd < 0) {
printf("[bt#%02d] network error %d\n", i, recvd);
Expand Down