Skip to content

Commit 5c4d5e3

Browse files
author
Cruz Monrreal
authored
Merge pull request #9582 from michalpasztamobica/greentea_socket_improvements
Greentea Socket test improvements
2 parents 58cba25 + b3fd8a9 commit 5c4d5e3

10 files changed

+56
-5
lines changed

TESTS/netsocket/dns/asynchronous_dns_cancel.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void ASYNCHRONOUS_DNS_CANCEL()
4242
count++;
4343
} else {
4444
// No memory to initiate DNS query, callback will not be called
45+
printf("Error: No memory to initiate DNS query for %s\n", dns_test_hosts[i]);
4546
data[i].result = NSAPI_ERROR_NO_MEMORY;
4647
data[i].value_set = true;
4748
}

TESTS/netsocket/tcp/main.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ void drop_bad_packets(TCPSocket &sock, int orig_timeout)
5757
sock.set_timeout(orig_timeout);
5858
}
5959

60+
nsapi_version_t get_ip_version()
61+
{
62+
SocketAddress test;
63+
if (!test.set_ip_address(NetworkInterface::get_default_instance()->get_ip_address())) {
64+
return NSAPI_UNSPEC;
65+
}
66+
return test.get_ip_version();
67+
}
68+
6069
static void _ifup()
6170
{
6271
NetworkInterface *net = NetworkInterface::get_default_instance();

TESTS/netsocket/tcp/tcp_tests.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
NetworkInterface *get_interface();
2222
void drop_bad_packets(TCPSocket &sock, int orig_timeout);
23+
nsapi_version_t get_ip_version();
2324
void fill_tx_buffer_ascii(char *buff, size_t len);
2425
nsapi_error_t tcpsocket_connect_to_echo_srv(TCPSocket &sock);
2526
nsapi_error_t tcpsocket_connect_to_discard_srv(TCPSocket &sock);

TESTS/netsocket/tcp/tcpsocket_bind_address_invalid.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ void TCPSOCKET_BIND_ADDRESS_INVALID()
3939
return;
4040
}
4141
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
42-
nsapi_error_t bind_result = sock->bind("190.2.3.4", 1024);
42+
nsapi_error_t bind_result = NSAPI_ERROR_OK;
43+
if (get_ip_version() == NSAPI_IPv4) {
44+
bind_result = sock->bind("190.2.3.4", 1024);
45+
} else if (get_ip_version() == NSAPI_IPv6) {
46+
bind_result = sock->bind("fe80::ff01", 1024);
47+
} else {
48+
TEST_FAIL_MESSAGE("This stack is neither IPv4 nor IPv6");
49+
}
4350
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
4451
TEST_IGNORE_MESSAGE("bind() not supported");
4552
} else {

TESTS/netsocket/tcp/tcpsocket_bind_wrong_type.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ void TCPSOCKET_BIND_WRONG_TYPE()
4040
}
4141
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
4242
char addr_bytes[16] = {0xfe, 0x80, 0xff, 0x1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
43-
SocketAddress sockAddr = SocketAddress(addr_bytes, NSAPI_IPv4, 80);
43+
SocketAddress sockAddr;
44+
if (get_ip_version() == NSAPI_IPv4) {
45+
sockAddr = SocketAddress(addr_bytes, NSAPI_IPv4, 80);
46+
} else if (get_ip_version() == NSAPI_IPv6) {
47+
sockAddr = SocketAddress(addr_bytes, NSAPI_IPv6, 80);
48+
} else {
49+
TEST_FAIL_MESSAGE("This stack is neither IPv4 nor IPv6");
50+
}
4451
nsapi_error_t bind_result = sock->bind(sockAddr);
4552
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
4653
TEST_IGNORE_MESSAGE("bind() not supported");

TESTS/netsocket/udp/main.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ void drop_bad_packets(UDPSocket &sock, int orig_timeout)
6464
sock.set_timeout(orig_timeout);
6565
}
6666

67+
nsapi_version_t get_ip_version()
68+
{
69+
SocketAddress test;
70+
if (!test.set_ip_address(NetworkInterface::get_default_instance()->get_ip_address())) {
71+
return NSAPI_UNSPEC;
72+
}
73+
return test.get_ip_version();
74+
}
75+
6776
void fill_tx_buffer_ascii(char *buff, size_t len)
6877
{
6978
for (size_t i = 0; i < len; ++i) {

TESTS/netsocket/udp/udp_tests.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
NetworkInterface *get_interface();
2222
void drop_bad_packets(UDPSocket &sock, int orig_timeout);
23+
nsapi_version_t get_ip_version();
2324
void fill_tx_buffer_ascii(char *buff, size_t len);
2425

2526
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE

TESTS/netsocket/udp/udpsocket_bind_address_invalid.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,16 @@ void UDPSOCKET_BIND_ADDRESS_INVALID()
3838
TEST_FAIL();
3939
}
4040
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
41-
nsapi_error_t bind_result = sock->bind("190.2.3.4", 1024);
41+
42+
nsapi_error_t bind_result = NSAPI_ERROR_OK;
43+
if (get_ip_version() == NSAPI_IPv4) {
44+
bind_result = sock->bind("190.2.3.4", 1024);
45+
} else if (get_ip_version() == NSAPI_IPv6) {
46+
bind_result = sock->bind("fe80::ff01", 1024);
47+
} else {
48+
TEST_FAIL_MESSAGE("This stack is neither IPv4 nor IPv6");
49+
}
50+
4251
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
4352
TEST_IGNORE_MESSAGE("bind() not supported");
4453
} else {

TESTS/netsocket/udp/udpsocket_bind_wrong_type.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ void UDPSOCKET_BIND_WRONG_TYPE()
3939
}
4040
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
4141
char addr_bytes[16] = {0xfe, 0x80, 0xff, 0x1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
42-
SocketAddress sockAddr = SocketAddress(addr_bytes, NSAPI_IPv4, 80);
42+
SocketAddress sockAddr;
43+
if (get_ip_version() == NSAPI_IPv4) {
44+
sockAddr = SocketAddress(addr_bytes, NSAPI_IPv4, 80);
45+
} else if (get_ip_version() == NSAPI_IPv6) {
46+
sockAddr = SocketAddress(addr_bytes, NSAPI_IPv6, 80);
47+
} else {
48+
TEST_FAIL_MESSAGE("This stack is neither IPv4 nor IPv6");
49+
}
4350
nsapi_error_t bind_result = sock->bind(sockAddr);
4451
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
4552
TEST_IGNORE_MESSAGE("bind() not supported");

TESTS/netsocket/udp/udpsocket_recv_timeout.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void UDPSOCKET_RECV_TIMEOUT()
6262
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
6363
osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT);
6464
printf("MBED: recvfrom() took: %dms\n", timer.read_ms());
65-
TEST_ASSERT_INT_WITHIN(50, 150, timer.read_ms());
65+
TEST_ASSERT_INT_WITHIN(51, 150, timer.read_ms());
6666
continue;
6767
} else if (recvd < 0) {
6868
printf("[bt#%02d] network error %d\n", i, recvd);

0 commit comments

Comments
 (0)