From 42df56c391935ca79bdb21aea556fb9e3ea40422 Mon Sep 17 00:00:00 2001 From: Jamie Smith Date: Sat, 3 Aug 2024 00:25:00 -0700 Subject: [PATCH] Make network tests properly support boards with wifi again (#317) * Make network tests properly support boards with wifi again * Style fixes * Style fix again --- .../netsocket/tests/TESTS/CMakeLists.txt | 19 +++++ .../common/greentea_get_network_interface.h | 76 +++++++++++++++++++ .../netsocket/tests/TESTS/netsocket/README.md | 75 +----------------- .../dns/asynchronous_dns_multi_ip.cpp | 2 +- .../dns/asynchronous_dns_timeouts.cpp | 2 +- .../tests/TESTS/netsocket/dns/dns_tests.h | 1 + .../tests/TESTS/netsocket/dns/main.cpp | 12 +-- .../dns/synchronous_dns_multi_ip.cpp | 2 +- .../tests/TESTS/netsocket/tcp/main.cpp | 19 ++--- .../tests/TESTS/netsocket/tcp/tcp_tests.h | 1 + .../netsocket/tcp/tcpsocket_bind_address.cpp | 4 +- .../tcp/tcpsocket_bind_address_invalid.cpp | 2 +- .../netsocket/tcp/tcpsocket_bind_port.cpp | 2 +- .../tcp/tcpsocket_bind_port_fail.cpp | 4 +- .../tcp/tcpsocket_bind_wrong_type.cpp | 2 +- .../tcp/tcpsocket_connect_invalid.cpp | 4 +- .../tcp/tcpsocket_endpoint_close.cpp | 4 +- .../tcp/tcpsocket_open_close_repeat.cpp | 2 +- .../netsocket/tcp/tcpsocket_open_destruct.cpp | 2 +- .../netsocket/tcp/tcpsocket_open_limit.cpp | 2 +- .../netsocket/tcp/tcpsocket_open_twice.cpp | 4 +- .../netsocket/tcp/tcpsocket_recv_100k.cpp | 4 +- .../tcpsocket_setsockopt_keepalive_valid.cpp | 4 +- .../tests/TESTS/netsocket/tls/main.cpp | 16 ++-- .../tests/TESTS/netsocket/tls/tls_tests.h | 1 + .../tls/tlssocket_cert_in_filesystem.cpp | 4 +- .../tls/tlssocket_connect_invalid.cpp | 2 +- .../tls/tlssocket_endpoint_close.cpp | 4 +- .../tls/tlssocket_handshake_invalid.cpp | 2 +- .../TESTS/netsocket/tls/tlssocket_no_cert.cpp | 4 +- .../netsocket/tls/tlssocket_open_destruct.cpp | 2 +- .../netsocket/tls/tlssocket_open_limit.cpp | 2 +- .../netsocket/tls/tlssocket_open_twice.cpp | 4 +- .../netsocket/tls/tlssocket_send_closed.cpp | 4 +- .../tls/tlssocket_send_unconnected.cpp | 2 +- .../tests/TESTS/netsocket/udp/main.cpp | 15 ++-- .../netsocket/udp/udpsocket_bind_address.cpp | 6 +- .../udp/udpsocket_bind_address_invalid.cpp | 3 +- .../udp/udpsocket_bind_address_null.cpp | 3 +- .../netsocket/udp/udpsocket_bind_port.cpp | 3 +- .../udp/udpsocket_bind_port_fail.cpp | 5 +- .../netsocket/udp/udpsocket_bind_unopened.cpp | 1 + .../udp/udpsocket_bind_wrong_type.cpp | 3 +- .../netsocket/udp/udpsocket_echotest.cpp | 9 ++- .../udp/udpsocket_echotest_burst.cpp | 10 ++- .../udp/udpsocket_open_close_repeat.cpp | 3 +- .../netsocket/udp/udpsocket_open_destruct.cpp | 3 +- .../netsocket/udp/udpsocket_open_limit.cpp | 3 +- .../netsocket/udp/udpsocket_open_twice.cpp | 5 +- .../netsocket/udp/udpsocket_recv_timeout.cpp | 5 +- .../udp/udpsocket_sendto_invalid.cpp | 5 +- .../netsocket/udp/udpsocket_sendto_repeat.cpp | 5 +- .../udp/udpsocket_sendto_timeout.cpp | 5 +- .../tests/TESTS/network/CMakeLists.txt | 3 +- .../tests/TESTS/network/interface/main.cpp | 7 -- .../networkinterface_conn_disc_repeat.cpp | 2 +- .../interface/networkinterface_status.cpp | 6 +- .../interface/networkinterface_tests.h | 2 + .../tests/TESTS/network/wifi/CMakeLists.txt | 31 +++++--- .../TESTS/network/wifi/get_interface.cpp | 45 ----------- .../tests/TESTS/network/wifi/get_security.cpp | 54 ------------- .../tests/TESTS/network/wifi/main.cpp | 41 ++-------- .../TESTS/network/wifi/template_mbed_app.txt | 41 ---------- .../TESTS/network/wifi/wifi-constructor.cpp | 2 +- .../tests/TESTS/network/wifi/wifi_connect.cpp | 55 -------------- .../wifi/wifi_connect_disconnect_nonblock.cpp | 17 +---- .../wifi/wifi_connect_disconnect_repeat.cpp | 16 ++-- .../wifi/wifi_connect_nocredentials.cpp | 4 +- .../wifi/wifi_connect_params_channel.cpp | 8 +- .../wifi/wifi_connect_params_channel_fail.cpp | 10 +-- .../network/wifi/wifi_connect_params_null.cpp | 2 +- .../wifi/wifi_connect_params_valid_secure.cpp | 12 ++- .../network/wifi/wifi_connect_secure.cpp | 46 ----------- .../network/wifi/wifi_connect_secure_fail.cpp | 12 +-- .../TESTS/network/wifi/wifi_get_rssi.cpp | 10 ++- .../tests/TESTS/network/wifi/wifi_scan.cpp | 23 ++---- .../TESTS/network/wifi/wifi_scan_null.cpp | 2 +- .../TESTS/network/wifi/wifi_set_channel.cpp | 2 +- .../network/wifi/wifi_set_credential.cpp | 6 +- .../tests/TESTS/network/wifi/wifi_tests.h | 36 +-------- 80 files changed, 301 insertions(+), 582 deletions(-) create mode 100644 connectivity/netsocket/tests/TESTS/common/greentea_get_network_interface.h delete mode 100644 connectivity/netsocket/tests/TESTS/network/wifi/get_interface.cpp delete mode 100644 connectivity/netsocket/tests/TESTS/network/wifi/get_security.cpp delete mode 100644 connectivity/netsocket/tests/TESTS/network/wifi/template_mbed_app.txt delete mode 100644 connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect.cpp delete mode 100644 connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_secure.cpp diff --git a/connectivity/netsocket/tests/TESTS/CMakeLists.txt b/connectivity/netsocket/tests/TESTS/CMakeLists.txt index 1d260efa47..d269ac7790 100644 --- a/connectivity/netsocket/tests/TESTS/CMakeLists.txt +++ b/connectivity/netsocket/tests/TESTS/CMakeLists.txt @@ -5,5 +5,24 @@ if(DEFAULT_IFC_IDX EQUAL -1) set(TEST_SKIPPED "No default network interface on this target") endif() +# Set up variables for wi-fi SSID and password +if("MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE=WIFI" IN_LIST MBED_CONFIG_DEFINITIONS) + set(MBED_GREENTEA_WIFI_SECURE_SSID "" CACHE STRING "SSID of a secured wi-fi network with internet access, for greentea tests which need to connect to wifi") + set(MBED_GREENTEA_WIFI_SECURE_PASSWORD "" CACHE STRING "Password to the network given by MBED_GREENTEA_WIFI_SECURE_SSID") + set(MBED_GREENTEA_WIFI_SECURE_PROTOCOL "WPA2" CACHE STRING "WiFi security protocol, valid values are WEP, WPA, WPA2, WPA_WPA2, WPA3, WPA3_WPA2, NONE") + + if("${MBED_GREENTEA_WIFI_SECURE_SSID}" STREQUAL "" OR "${MBED_GREENTEA_WIFI_SECURE_PASSWORD}" STREQUAL "") + message(WARNING "MBED_GREENTEA_WIFI_SECURE_SSID and MBED_GREENTEA_WIFI_SECURE_PASSWORD must be set in order for wi-fi greentea tests to pass") + else() + add_compile_definitions( + "MBED_GREENTEA_WIFI_SECURE_SSID=\"${MBED_GREENTEA_WIFI_SECURE_SSID}\"" + "MBED_GREENTEA_WIFI_SECURE_PASSWORD=\"${MBED_GREENTEA_WIFI_SECURE_PASSWORD}\"" + MBED_GREENTEA_WIFI_SECURE_PROTOCOL=${MBED_GREENTEA_WIFI_SECURE_PROTOCOL}) + endif() +endif() + +# Pull in common util header +include_directories(common) + add_subdirectory(netsocket) add_subdirectory(network) \ No newline at end of file diff --git a/connectivity/netsocket/tests/TESTS/common/greentea_get_network_interface.h b/connectivity/netsocket/tests/TESTS/common/greentea_get_network_interface.h new file mode 100644 index 0000000000..9aa166e3d7 --- /dev/null +++ b/connectivity/netsocket/tests/TESTS/common/greentea_get_network_interface.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2024 Jamie Smith, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef MBED_OS_GREENTEA_GET_NETWORK_INTERFACE_H +#define MBED_OS_GREENTEA_GET_NETWORK_INTERFACE_H + +#include "WiFiInterface.h" +#include "NetworkInterface.h" + +#define WIFI 2 +#if !defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE) || \ + (MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == WIFI && !defined(MBED_GREENTEA_WIFI_SECURE_SSID)) +#error [NOT_SUPPORTED] No network configuration found for this target. +#endif + +/* + * Read the MBED_GREENTEA_WIFI_SECURE_PROTOCOL define from CMake and get the type of wifi + * security in use + */ +inline nsapi_security get_wifi_security() +{ +#define JOIN(x, y) JOIN_AGAIN(x, y) +#define JOIN_AGAIN(x, y) x ## y + return JOIN(NSAPI_SECURITY_, MBED_GREENTEA_WIFI_SECURE_PROTOCOL); +#undef JOIN +#undef JOIN_AGAIN +} + +/* + * Get the wifi interface for this board, or nullptr if there is none + */ +inline WiFiInterface *get_wifi_interface() +{ + auto *const wifi_interface = WiFiInterface::get_default_instance(); + if (wifi_interface == nullptr) { + return nullptr; + } + + // Set the credentials based on CMake settings so it actually can connect to the internet + wifi_interface->set_credentials(MBED_GREENTEA_WIFI_SECURE_SSID, + MBED_GREENTEA_WIFI_SECURE_PASSWORD, + get_wifi_security()); + + return wifi_interface; +} + +/* + * Get the default network interface for this board. + * For wifi, this also configures in the credentials passed to CMake. + */ +inline NetworkInterface *get_network_interface() +{ +#if MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == WIFI + return get_wifi_interface(); +#else + return NetworkInterface::get_default_instance(); +#endif + +} + +#endif //MBED_OS_GREENTEA_GET_NETWORK_INTERFACE_H diff --git a/connectivity/netsocket/tests/TESTS/netsocket/README.md b/connectivity/netsocket/tests/TESTS/netsocket/README.md index 6e6574e82d..75c548d247 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/README.md +++ b/connectivity/netsocket/tests/TESTS/netsocket/README.md @@ -307,7 +307,7 @@ git checkout master cd .. ``` -Also, building socket test cases requires a special macro to enable all tests, so create an `mbed_app.json` file with the following content at minimum: +To configure the echo server to a non-default IP and port, you can create an mbed_app.json with the following content: ``` { @@ -336,77 +336,10 @@ Also, building socket test cases requires a special macro to enable all tests, s } ``` -Wi-Fi tests require some more configuration, so for Wi-Fi purposes, the `mbed_app.json` might look like this: - +Wi-Fi tests require configuration of your wifi network, so you might run CMake like this: ``` -{ - "config": { - "wifi-secure-ssid": { - "help": "WiFi SSID for WPA2 secured network", - "value": "\"test-network\"" - }, - "wifi-unsecure-ssid": { - "help": "WiFi SSID for unsecure netwrok", - "value": "\"unsecure-test-net\"" - }, - "wifi-password": { - "help": "WiFi Password", - "value": "\"password\"" - }, - "wifi-secure-protocol": { - "help": "WiFi security protocol, valid values are WEP, WPA, WPA2, WPA_WPA2", - "value": "\"WPA2\"" - }, - "wifi-ch-secure": { - "help": "Channel number of secure SSID", - "value": 6 - }, - "wifi-ch-unsecure": { - "help": "Channel number of unsecure SSID", - "value": 6 - }, - "ap-mac-secure": { - "help": "BSSID of secure AP in form of AA:BB:CC:DD:EE:FF", - "value": "\"58:8b:f3:99:f2:9c\"" - }, - "ap-mac-unsecure": { - "help": "BSSID of unsecure AP in form of \"AA:BB:CC:DD:EE:FF\"", - "value": "\"58:8b:f3:99:c2:08\"" - }, - "max-scan-size": { - "help": "How many networks may appear in Wifi scan result", - "value": 30 - }, - "echo-server-addr" : { - "help" : "IP address of echo server", - "value" : "\"echo.mbedcloudtesting.com\"" - }, - "echo-server-port" : { - "help" : "Port of echo server", - "value" : "7" - }, - "echo-server-discard-port" : { - "help" : "Discard port of echo server", - "value" : "9" - }, - "echo-server-port-tls" : { - "help" : "Port of echo server for TLS", - "value" : "2007" - }, - "echo-server-discard-port-tls" : { - "help" : "Discard port of echo server for TLS", - "value" : "2009" - } - }, - "target_overrides": { - "*": { - "target.network-default-interface-type": "WIFI", - "nsapi.default-wifi-ssid": "\"WIFI_SSID\"", - "nsapi.default-wifi-password": "\"WIFI_PASSWORD\"", - "nsapi.default-wifi-security": "WPA_WPA2" - } - } -} +cmake "-DMBED_GREENTEA_WIFI_SECURE_SSID=My Wifi Network Name" -DMBED_GREENTEA_WIFI_SECURE_PASSWORD=MyWifiNetworkPassword + -DMBED_GREENTEA_WIFI_SECURE_CHANNEL=5 ``` Cellular tests require some more configuration, so for cellular purposes, the `mbed_app.json` might look like this: diff --git a/connectivity/netsocket/tests/TESTS/netsocket/dns/asynchronous_dns_multi_ip.cpp b/connectivity/netsocket/tests/TESTS/netsocket/dns/asynchronous_dns_multi_ip.cpp index 50150818fc..4223ee8280 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/dns/asynchronous_dns_multi_ip.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/dns/asynchronous_dns_multi_ip.cpp @@ -65,7 +65,7 @@ void do_getaddrinfo_async(const char hosts[][DNS_TEST_HOST_LEN], unsigned int op unsigned int count = 0; for (unsigned int i = 0; i < op_count; i++) { data[i].semaphore = &semaphore; - nsapi_error_t err = NetworkInterface::get_default_instance()->getaddrinfo_async(hosts[i], &hints, mbed::Callback(getaddrinfo_cb, (void *) &data[i])); + nsapi_error_t err = get_network_interface()->getaddrinfo_async(hosts[i], &hints, mbed::Callback(getaddrinfo_cb, (void *) &data[i])); TEST_ASSERT(err >= 0 || err == NSAPI_ERROR_NO_MEMORY || err == NSAPI_ERROR_BUSY); if (err >= 0) { // Callback will be called diff --git a/connectivity/netsocket/tests/TESTS/netsocket/dns/asynchronous_dns_timeouts.cpp b/connectivity/netsocket/tests/TESTS/netsocket/dns/asynchronous_dns_timeouts.cpp index 046dcef8de..5a93881045 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/dns/asynchronous_dns_timeouts.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/dns/asynchronous_dns_timeouts.cpp @@ -74,7 +74,7 @@ void ASYNCHRONOUS_DNS_TIMEOUTS() nsapi_error_t result; int count = MAX_TRIAL_ATTEMPTS; do { - result = NetworkInterface::get_default_instance()->gethostbyname(dns_test_hosts[0], &address); + result = get_network_interface()->gethostbyname(dns_test_hosts[0], &address); if (result == NSAPI_ERROR_OK) { return; } diff --git a/connectivity/netsocket/tests/TESTS/netsocket/dns/dns_tests.h b/connectivity/netsocket/tests/TESTS/netsocket/dns/dns_tests.h index bb33885d5b..925a0de967 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/dns/dns_tests.h +++ b/connectivity/netsocket/tests/TESTS/netsocket/dns/dns_tests.h @@ -20,6 +20,7 @@ #include "nsapi_dns.h" #include "mbed_trace.h" +#include "greentea_get_network_interface.h" #define TRACE_GROUP "GRNT" diff --git a/connectivity/netsocket/tests/TESTS/netsocket/dns/main.cpp b/connectivity/netsocket/tests/TESTS/netsocket/dns/main.cpp index d9723f44cb..8d14b3c2a9 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/dns/main.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/dns/main.cpp @@ -18,13 +18,6 @@ #if !defined(MBED_CONF_RTOS_PRESENT) #error [NOT_SUPPORTED] dns test cases require a RTOS to run. #else - -#define WIFI 2 -#if !defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE) || \ - (MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == WIFI && !defined(MBED_CONF_NSAPI_DEFAULT_WIFI_SSID)) -#error [NOT_SUPPORTED] No network configuration found for this target. -#else - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" @@ -167,7 +160,7 @@ static void net_bringup() nsapi_dns_reset(); MBED_ASSERT(MBED_CONF_APP_DNS_TEST_HOSTS_NUM >= MBED_CONF_NSAPI_DNS_CACHE_SIZE && MBED_CONF_APP_DNS_TEST_HOSTS_NUM >= MBED_CONF_APP_DNS_SIMULT_QUERIES + 1); - net = NetworkInterface::get_default_instance(); + net = get_network_interface(); TEST_ASSERT_NOT_NULL_MESSAGE(net, "No NetworkInterface configured"); nsapi_error_t err = net->connect(); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err); @@ -186,7 +179,7 @@ static void net_bringup() static void net_bringdown() { - NetworkInterface::get_default_instance()->disconnect(); + get_network_interface()->disconnect(); tr_info("MBED: ifdown"); } @@ -238,5 +231,4 @@ int main() return !Harness::run(specification); } -#endif // !defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE) || (MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == WIFI && !defined(MBED_CONF_NSAPI_DEFAULT_WIFI_SSID)) #endif // !defined(MBED_CONF_RTOS_PRESENT) diff --git a/connectivity/netsocket/tests/TESTS/netsocket/dns/synchronous_dns_multi_ip.cpp b/connectivity/netsocket/tests/TESTS/netsocket/dns/synchronous_dns_multi_ip.cpp index 0189274b0b..c462b22655 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/dns/synchronous_dns_multi_ip.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/dns/synchronous_dns_multi_ip.cpp @@ -47,7 +47,7 @@ void do_getaddrinfo(const char hosts[][DNS_TEST_HOST_LEN], unsigned int op_count SocketAddress hints{{NSAPI_UNSPEC}, 80}; for (unsigned int i = 0; i < op_count; i++) { SocketAddress *result; - nsapi_error_t err = NetworkInterface::get_default_instance()->get_default_instance()->getaddrinfo(hosts[i], &hints, &result); + nsapi_error_t err = get_network_interface()->getaddrinfo(hosts[i], &hints, &result); if (err == NSAPI_ERROR_DNS_FAILURE) { (*exp_dns_failure)++; diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tcp/main.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tcp/main.cpp index 588dfe3b52..740c9284d3 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tcp/main.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tcp/main.cpp @@ -19,12 +19,6 @@ #error [NOT_SUPPORTED] tcp test cases require a RTOS to run #else -#define WIFI 2 -#if !defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE) || \ - (MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == WIFI && !defined(MBED_CONF_NSAPI_DEFAULT_WIFI_SSID)) -#error [NOT_SUPPORTED] No network configuration found for this target. -#else - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity/unity.h" @@ -66,7 +60,7 @@ void drop_bad_packets(TCPSocket &sock, int orig_timeout) nsapi_version_t get_ip_version() { SocketAddress test; - if (NetworkInterface::get_default_instance()->get_ip_address(&test) != NSAPI_ERROR_OK) { + if (get_network_interface()->get_ip_address(&test) != NSAPI_ERROR_OK) { return NSAPI_UNSPEC; } return test.get_ip_version(); @@ -74,7 +68,7 @@ nsapi_version_t get_ip_version() static void _ifup() { - NetworkInterface *net = NetworkInterface::get_default_instance(); + NetworkInterface *net = get_network_interface(); TEST_ASSERT_NOT_NULL_MESSAGE(net, "No NetworkInterface configured"); nsapi_error_t err = net->connect(); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err); @@ -93,7 +87,7 @@ static void _ifup() static void _ifdown() { - NetworkInterface::get_default_instance()->disconnect(); + get_network_interface()->disconnect(); tr_info("MBED: ifdown"); } @@ -101,12 +95,12 @@ nsapi_error_t tcpsocket_connect_to_srv(TCPSocket &sock, uint16_t port) { SocketAddress tcp_addr; - NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &tcp_addr); + get_network_interface()->gethostbyname(ECHO_SERVER_ADDR, &tcp_addr); tcp_addr.set_port(port); tr_info("MBED: Server '%s', port %d", tcp_addr.get_ip_address(), tcp_addr.get_port()); - nsapi_error_t err = sock.open(NetworkInterface::get_default_instance()); + nsapi_error_t err = sock.open(get_network_interface()); if (err != NSAPI_ERROR_OK) { tr_error("Error from sock.open: %d", err); return err; @@ -137,7 +131,7 @@ bool is_tcp_supported() static bool tested = false; if (!tested) { TCPSocket socket; - supported = socket.open(NetworkInterface::get_default_instance()) == NSAPI_ERROR_OK; + supported = socket.open(get_network_interface()) == NSAPI_ERROR_OK; } return supported; } @@ -253,5 +247,4 @@ int main() } #endif // ECHO_SERVER_ADDR -#endif // !defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE) || (MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == WIFI && !defined(MBED_CONF_NSAPI_DEFAULT_WIFI_SSID)) #endif // !defined(MBED_CONF_RTOS_PRESENT) diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcp_tests.h b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcp_tests.h index fe36f2afc7..c3ce9221d6 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcp_tests.h +++ b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcp_tests.h @@ -20,6 +20,7 @@ #include "../test_params.h" #include "mbed_trace.h" +#include "greentea_get_network_interface.h" #define TRACE_GROUP "GRNT" diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_bind_address.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_bind_address.cpp index 85cfb4c099..cd61660a49 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_bind_address.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_bind_address.cpp @@ -33,9 +33,9 @@ void TCPSOCKET_BIND_ADDRESS() TEST_FAIL(); return; } - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_network_interface())); SocketAddress sockAddr; - NetworkInterface::get_default_instance()->get_ip_address(&sockAddr); + get_network_interface()->get_ip_address(&sockAddr); sockAddr.set_port(80); nsapi_error_t bind_result = sock->bind(sockAddr); if (bind_result == NSAPI_ERROR_UNSUPPORTED) { diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_bind_address_invalid.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_bind_address_invalid.cpp index c987048499..969e9ca6f5 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_bind_address_invalid.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_bind_address_invalid.cpp @@ -31,7 +31,7 @@ void TCPSOCKET_BIND_ADDRESS_INVALID() SKIP_IF_TCP_UNSUPPORTED(); TCPSocket sock; - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_network_interface())); nsapi_error_t bind_result = NSAPI_ERROR_OK; if (get_ip_version() == NSAPI_IPv4) { SocketAddress a("190.2.3.4", 1024); diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_bind_port.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_bind_port.cpp index 1c2e2514f8..167f312946 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_bind_port.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_bind_port.cpp @@ -33,7 +33,7 @@ void TCPSOCKET_BIND_PORT() TEST_FAIL(); return; } - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_network_interface())); nsapi_error_t bind_result = sock->bind(1024); if (bind_result == NSAPI_ERROR_UNSUPPORTED) { TEST_IGNORE_MESSAGE("bind() not supported"); diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_bind_port_fail.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_bind_port_fail.cpp index 2087761ecb..177da1bd4a 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_bind_port_fail.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_bind_port_fail.cpp @@ -33,7 +33,7 @@ void TCPSOCKET_BIND_PORT_FAIL() TEST_FAIL(); return; } - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_network_interface())); nsapi_error_t bind_result = sock->bind(1024); if (bind_result == NSAPI_ERROR_UNSUPPORTED) { TEST_IGNORE_MESSAGE("bind() not supported"); @@ -47,7 +47,7 @@ void TCPSOCKET_BIND_PORT_FAIL() if (!sock2) { TEST_FAIL(); } - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock2->open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock2->open(get_network_interface())); TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock2->bind(1024)); delete sock; diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_bind_wrong_type.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_bind_wrong_type.cpp index f6fbe42f8c..1d8a347c99 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_bind_wrong_type.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_bind_wrong_type.cpp @@ -30,7 +30,7 @@ void TCPSOCKET_BIND_WRONG_TYPE() SKIP_IF_TCP_UNSUPPORTED(); TCPSocket sock; - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_network_interface())); char addr_bytes[16] = {0xfe, 0x80, 0xff, 0x1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; SocketAddress sockAddr; if (get_ip_version() == NSAPI_IPv4) { diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_connect_invalid.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_connect_invalid.cpp index cff424a541..5ca13e2be6 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_connect_invalid.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_connect_invalid.cpp @@ -29,7 +29,7 @@ void TCPSOCKET_CONNECT_INVALID() { SKIP_IF_TCP_UNSUPPORTED(); TCPSocket sock; - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_network_interface())); SocketAddress address; address.set_port(9); @@ -37,7 +37,7 @@ void TCPSOCKET_CONNECT_INVALID() TEST_ASSERT_FALSE(address.set_ip_address(NULL)); // Valid address for the final check - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &address)); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, get_network_interface()->gethostbyname(ECHO_SERVER_ADDR, &address)); address.set_port(ECHO_SERVER_DISCARD_PORT); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.connect(address)); diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_endpoint_close.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_endpoint_close.cpp index 0985019fa8..6a216abb3d 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_endpoint_close.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_endpoint_close.cpp @@ -39,10 +39,10 @@ static nsapi_error_t _tcpsocket_connect_to_daytime_srv(TCPSocket &sock) { SocketAddress tcp_addr; - NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &tcp_addr); + get_network_interface()->gethostbyname(ECHO_SERVER_ADDR, &tcp_addr); tcp_addr.set_port(13); - nsapi_error_t err = sock.open(NetworkInterface::get_default_instance()); + nsapi_error_t err = sock.open(get_network_interface()); if (err != NSAPI_ERROR_OK) { return err; } diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_open_close_repeat.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_open_close_repeat.cpp index f93bcca13f..52c5c12242 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_open_close_repeat.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_open_close_repeat.cpp @@ -34,7 +34,7 @@ void TCPSOCKET_OPEN_CLOSE_REPEAT() } for (int i = 0; i < 2; i++) { - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_network_interface())); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close()); } delete sock; diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_open_destruct.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_open_destruct.cpp index c8dd5c825f..ad332eafce 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_open_destruct.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_open_destruct.cpp @@ -33,7 +33,7 @@ void TCPSOCKET_OPEN_DESTRUCT() if (!sock) { TEST_FAIL(); } - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_network_interface())); delete sock; } } diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_open_limit.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_open_limit.cpp index c4ed6ad512..9ffdf0e8f6 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_open_limit.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_open_limit.cpp @@ -48,7 +48,7 @@ void TCPSOCKET_OPEN_LIMIT() if (!sock) { break; } - ret = sock->open(NetworkInterface::get_default_instance()); + ret = sock->open(get_network_interface()); if (ret == NSAPI_ERROR_NO_MEMORY || ret == NSAPI_ERROR_NO_SOCKET) { tr_error("[round#%02d] unable to open new socket, error: %d", i, ret); delete sock; diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_open_twice.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_open_twice.cpp index 63fdd1886b..3ead5b7ef1 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_open_twice.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_open_twice.cpp @@ -33,8 +33,8 @@ void TCPSOCKET_OPEN_TWICE() TEST_FAIL(); } - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance())); - TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock->open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_network_interface())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock->open(get_network_interface())); delete sock; } diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_recv_100k.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_recv_100k.cpp index 63317188fd..1f503027c1 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_recv_100k.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_recv_100k.cpp @@ -37,10 +37,10 @@ static nsapi_error_t _tcpsocket_connect_to_chargen_srv(TCPSocket &sock) { SocketAddress tcp_addr; - NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &tcp_addr); + get_network_interface()->gethostbyname(ECHO_SERVER_ADDR, &tcp_addr); tcp_addr.set_port(19); - nsapi_error_t err = sock.open(NetworkInterface::get_default_instance()); + nsapi_error_t err = sock.open(get_network_interface()); if (err != NSAPI_ERROR_OK) { return err; } diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_setsockopt_keepalive_valid.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_setsockopt_keepalive_valid.cpp index 800b559bb5..a4264dc0bc 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_setsockopt_keepalive_valid.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tcp/tcpsocket_setsockopt_keepalive_valid.cpp @@ -29,7 +29,7 @@ void TCPSOCKET_SETSOCKOPT_KEEPALIVE_VALID() { SKIP_IF_TCP_UNSUPPORTED(); TCPSocket sock; - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_network_interface())); int32_t seconds = 7200; int ret = sock.setsockopt(NSAPI_SOCKET, NSAPI_KEEPALIVE, &seconds, sizeof(int)); @@ -42,7 +42,7 @@ void TCPSOCKET_SETSOCKOPT_KEEPALIVE_VALID() TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, ret); SocketAddress address; - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &address)); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, get_network_interface()->gethostbyname(ECHO_SERVER_ADDR, &address)); address.set_port(9); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.connect(address)); // LWIP stack does not support getsockopt so the part below is commented out diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tls/main.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tls/main.cpp index c3a5d7e86a..38cd1dcf80 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tls/main.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tls/main.cpp @@ -18,11 +18,6 @@ #if !defined(MBED_CONF_RTOS_PRESENT) #error [NOT_SUPPORTED] tls test cases require a RTOS to run #else -#define WIFI 2 -#if !defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE) || \ - (MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == WIFI && !defined(MBED_CONF_NSAPI_DEFAULT_WIFI_SSID)) -#error [NOT_SUPPORTED] No network configuration found for this target. -#else #include "mbed.h" #include "greentea-client/test_env.h" @@ -70,7 +65,7 @@ void drop_bad_packets(TLSSocket &sock, int orig_timeout) static void _ifup() { - NetworkInterface *net = NetworkInterface::get_default_instance(); + NetworkInterface *net = get_network_interface(); TEST_ASSERT_NOT_NULL_MESSAGE(net, "No NetworkInterface configured"); nsapi_error_t err = net->connect(); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err); @@ -89,7 +84,7 @@ static void _ifup() static void _ifdown() { - NetworkInterface::get_default_instance()->disconnect(); + get_network_interface()->disconnect(); tr_info("MBED: ifdown\n"); } @@ -97,12 +92,12 @@ nsapi_error_t tlssocket_connect_to_srv(TLSSocket &sock, uint16_t port) { SocketAddress tls_addr; - NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &tls_addr); + get_network_interface()->gethostbyname(ECHO_SERVER_ADDR, &tls_addr); tls_addr.set_port(port); tr_info("MBED: Server '%s', port %d\n", tls_addr.get_ip_address(), tls_addr.get_port()); - nsapi_error_t err = sock.open(NetworkInterface::get_default_instance()); + nsapi_error_t err = sock.open(get_network_interface()); if (err != NSAPI_ERROR_OK) { tr_error("Error from sock.open: %d\n", err); return err; @@ -139,7 +134,7 @@ bool is_tcp_supported() static bool tested = false; if (!tested) { TCPSocket socket; - supported = socket.open(NetworkInterface::get_default_instance()) == NSAPI_ERROR_OK; + supported = socket.open(get_network_interface()) == NSAPI_ERROR_OK; } return supported; } @@ -276,5 +271,4 @@ int main() #endif // defined(MBEDTLS_SSL_CLI_C) || defined(DOXYGEN_ONLY) #endif // ECHO_SERVER_ADDR -#endif // !defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE) || (MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == WIFI && !defined(MBED_CONF_NSAPI_DEFAULT_WIFI_SSID)) #endif // !defined(MBED_CONF_RTOS_PRESENT) diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tls/tls_tests.h b/connectivity/netsocket/tests/TESTS/netsocket/tls/tls_tests.h index cf471b8f6c..06d1ceefeb 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tls/tls_tests.h +++ b/connectivity/netsocket/tests/TESTS/netsocket/tls/tls_tests.h @@ -21,6 +21,7 @@ #include "../test_params.h" #include "TLSSocket.h" #include "mbed_trace.h" +#include "greentea_get_network_interface.h" #define TRACE_GROUP "GRNT" diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_cert_in_filesystem.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_cert_in_filesystem.cpp index cf3dff2e93..e45fad3626 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_cert_in_filesystem.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_cert_in_filesystem.cpp @@ -40,11 +40,11 @@ void TLSSOCKET_CERT_IN_FILESYSTEM() fclose(fp); TLSSocket sock; - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_network_interface())); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.set_root_ca_cert_path("/fs")); SocketAddress a; - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &a)); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, get_network_interface()->gethostbyname(ECHO_SERVER_ADDR, &a)); a.set_port(ECHO_SERVER_PORT_TLS); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.connect(a)); } \ No newline at end of file diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_connect_invalid.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_connect_invalid.cpp index b3516a8fe6..ead8a87a78 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_connect_invalid.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_connect_invalid.cpp @@ -30,7 +30,7 @@ void TLSSOCKET_CONNECT_INVALID() { SKIP_IF_TCP_UNSUPPORTED(); TLSSocket sock; - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_network_interface())); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.set_root_ca_cert(tls_global::cert)); SocketAddress address; diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_endpoint_close.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_endpoint_close.cpp index 97c7f21084..00ed331591 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_endpoint_close.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_endpoint_close.cpp @@ -40,10 +40,10 @@ static nsapi_error_t _tlssocket_connect_to_daytime_srv(TLSSocket &sock) { SocketAddress tls_addr; - NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &tls_addr); + get_network_interface()->gethostbyname(ECHO_SERVER_ADDR, &tls_addr); tls_addr.set_port(2013); - nsapi_error_t err = sock.open(NetworkInterface::get_default_instance()); + nsapi_error_t err = sock.open(get_network_interface()); if (err != NSAPI_ERROR_OK) { return err; } diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_handshake_invalid.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_handshake_invalid.cpp index 0c6db374b8..3331db14b4 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_handshake_invalid.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_handshake_invalid.cpp @@ -30,7 +30,7 @@ void TLSSOCKET_HANDSHAKE_INVALID() { const int https_port = 443; SKIP_IF_TCP_UNSUPPORTED(); - NetworkInterface *net = NetworkInterface::get_default_instance(); + NetworkInterface *net = get_network_interface(); #if (MBED_CONF_NSAPI_DEFAULT_STACK == NANOSTACK || (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP && defined(MBED_CONF_LWIP_PPP_IPV6_ENABLED))) SocketAddress address; diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_no_cert.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_no_cert.cpp index ab05f97152..2820766935 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_no_cert.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_no_cert.cpp @@ -30,9 +30,9 @@ void TLSSOCKET_NO_CERT() { SKIP_IF_TCP_UNSUPPORTED(); TLSSocket sock; - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_network_interface())); SocketAddress a; - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &a)); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, get_network_interface()->gethostbyname(ECHO_SERVER_ADDR, &a)); a.set_port(ECHO_SERVER_PORT_TLS); TEST_ASSERT_EQUAL(NSAPI_ERROR_AUTH_FAILURE, sock.connect(a)); diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_open_destruct.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_open_destruct.cpp index 5be16286c6..866f53094e 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_open_destruct.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_open_destruct.cpp @@ -34,7 +34,7 @@ void TLSSOCKET_OPEN_DESTRUCT() if (!sock) { TEST_FAIL(); } - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_network_interface())); delete sock; } } diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_open_limit.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_open_limit.cpp index 74c72027d2..afb458d6af 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_open_limit.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_open_limit.cpp @@ -49,7 +49,7 @@ void TLSSOCKET_OPEN_LIMIT() if (!sock) { break; } - ret = sock->open(NetworkInterface::get_default_instance()); + ret = sock->open(get_network_interface()); if (ret == NSAPI_ERROR_NO_MEMORY || ret == NSAPI_ERROR_NO_SOCKET) { tr_error("[round#%02d] unable to open new socket, error: %d\n", i, ret); delete sock; diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_open_twice.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_open_twice.cpp index 7cc8ad4087..db9840bfc4 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_open_twice.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_open_twice.cpp @@ -34,8 +34,8 @@ void TLSSOCKET_OPEN_TWICE() TEST_FAIL(); } - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance())); - TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock->open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_network_interface())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock->open(get_network_interface())); delete sock; } diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_send_closed.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_send_closed.cpp index 7dd1a7db0a..0223144f1b 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_send_closed.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_send_closed.cpp @@ -30,10 +30,10 @@ void TLSSOCKET_SEND_CLOSED() { SKIP_IF_TCP_UNSUPPORTED(); TLSSocket sock; - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_network_interface())); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.set_root_ca_cert(tls_global::cert)); SocketAddress a; - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &a)); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, get_network_interface()->gethostbyname(ECHO_SERVER_ADDR, &a)); a.set_port(ECHO_SERVER_PORT_TLS); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.connect(a)); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close()); diff --git a/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_send_unconnected.cpp b/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_send_unconnected.cpp index ff26277313..8b4b90ce2d 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_send_unconnected.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/tls/tlssocket_send_unconnected.cpp @@ -30,7 +30,7 @@ void TLSSOCKET_SEND_UNCONNECTED() { SKIP_IF_TCP_UNSUPPORTED(); TLSSocket sock; - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_network_interface())); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.set_root_ca_cert(tls_global::cert)); TEST_ASSERT_EQUAL(NSAPI_ERROR_NO_CONNECTION, sock.send("12345", 5)); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close()); diff --git a/connectivity/netsocket/tests/TESTS/netsocket/udp/main.cpp b/connectivity/netsocket/tests/TESTS/netsocket/udp/main.cpp index c496c95d83..5816525fa0 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/udp/main.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/udp/main.cpp @@ -19,12 +19,6 @@ #error [NOT_SUPPORTED] udp test cases require a RTOS to run. #else -#define WIFI 2 -#if !defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE) || \ - (MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == WIFI && !defined(MBED_CONF_NSAPI_DEFAULT_WIFI_SSID)) -#error [NOT_SUPPORTED] No network configuration found for this target. -#else - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity/unity.h" @@ -32,6 +26,7 @@ #include "utest/utest_stack_trace.h" #include "udp_tests.h" #include "ip6string.h" +#include "greentea_get_network_interface.h" #ifndef ECHO_SERVER_ADDR #error [NOT_SUPPORTED] Requires parameters for echo server @@ -61,7 +56,8 @@ void drop_bad_packets(UDPSocket &sock, int orig_timeout) } static void _ifup() { - NetworkInterface *net = NetworkInterface::get_default_instance(); + NetworkInterface *net = get_network_interface(); + TEST_ASSERT_NOT_NULL_MESSAGE(net, "No NetworkInterface configured"); nsapi_error_t err = net->connect(); @@ -85,7 +81,7 @@ static void _ifup() static void _ifdown() { - NetworkInterface::get_default_instance()->disconnect(); + get_network_interface()->disconnect(); tr_info("MBED: ifdown"); } @@ -93,7 +89,7 @@ static void _ifdown() nsapi_version_t get_ip_version() { SocketAddress test; - if (NetworkInterface::get_default_instance()->get_ip_address(&test) != NSAPI_ERROR_OK) { + if (get_network_interface()->get_ip_address(&test) != NSAPI_ERROR_OK) { return NSAPI_UNSPEC; } return test.get_ip_version(); @@ -223,5 +219,4 @@ int main() } #endif // ECHO_SERVER_ADDR -#endif // !defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE) || (MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == WIFI && !defined(MBED_CONF_NSAPI_DEFAULT_WIFI_SSID)) #endif // !defined(MBED_CONF_RTOS_PRESENT) diff --git a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_address.cpp b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_address.cpp index 7c83f41f14..97337f7636 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_address.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_address.cpp @@ -21,6 +21,8 @@ #include "UDPSocket.h" #include "unity/unity.h" #include "utest.h" +#include "greentea_get_network_interface.h" + using namespace utest::v1; @@ -30,9 +32,9 @@ void UDPSOCKET_BIND_ADDRESS() if (!sock) { TEST_FAIL(); } - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_network_interface())); SocketAddress sockAddr; - NetworkInterface::get_default_instance()->get_ip_address(&sockAddr); + get_network_interface()->get_ip_address(&sockAddr); sockAddr.set_port(80); nsapi_error_t bind_result = sock->bind(sockAddr); if (bind_result == NSAPI_ERROR_UNSUPPORTED) { diff --git a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_address_invalid.cpp b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_address_invalid.cpp index a31f163ffb..92fd968feb 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_address_invalid.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_address_invalid.cpp @@ -21,6 +21,7 @@ #include "UDPSocket.h" #include "unity/unity.h" #include "utest.h" +#include "greentea_get_network_interface.h" using namespace utest::v1; @@ -30,7 +31,7 @@ void UDPSOCKET_BIND_ADDRESS_INVALID() if (!sock) { TEST_FAIL(); } - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_network_interface())); nsapi_error_t bind_result = NSAPI_ERROR_OK; if (get_ip_version() == NSAPI_IPv4) { diff --git a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_address_null.cpp b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_address_null.cpp index 63e27ef1b8..11df242893 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_address_null.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_address_null.cpp @@ -21,6 +21,7 @@ #include "UDPSocket.h" #include "unity/unity.h" #include "utest.h" +#include "greentea_get_network_interface.h" using namespace utest::v1; @@ -30,7 +31,7 @@ void UDPSOCKET_BIND_ADDRESS_NULL() if (!sock) { TEST_FAIL(); } - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_network_interface())); nsapi_error_t bind_result = sock->bind(nullptr); if (bind_result == NSAPI_ERROR_UNSUPPORTED) { TEST_IGNORE_MESSAGE("bind() not supported"); diff --git a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_port.cpp b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_port.cpp index ec8dfb6fbc..45deae8ecf 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_port.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_port.cpp @@ -21,6 +21,7 @@ #include "UDPSocket.h" #include "unity/unity.h" #include "utest.h" +#include "greentea_get_network_interface.h" using namespace utest::v1; @@ -30,7 +31,7 @@ void UDPSOCKET_BIND_PORT() if (!sock) { TEST_FAIL(); } - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_network_interface())); nsapi_error_t bind_result = sock->bind(1024); if (bind_result == NSAPI_ERROR_UNSUPPORTED) { TEST_IGNORE_MESSAGE("bind() not supported"); diff --git a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_port_fail.cpp b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_port_fail.cpp index 90973fd030..9780e667d9 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_port_fail.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_port_fail.cpp @@ -21,6 +21,7 @@ #include "UDPSocket.h" #include "unity/unity.h" #include "utest.h" +#include "greentea_get_network_interface.h" using namespace utest::v1; @@ -30,7 +31,7 @@ void UDPSOCKET_BIND_PORT_FAIL() if (!sock) { TEST_FAIL(); } - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_network_interface())); nsapi_error_t bind_result = sock->bind(1024); if (bind_result == NSAPI_ERROR_UNSUPPORTED) { TEST_IGNORE_MESSAGE("bind() not supported"); @@ -44,7 +45,7 @@ void UDPSOCKET_BIND_PORT_FAIL() if (!sock2) { TEST_FAIL(); } - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock2->open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock2->open(get_network_interface())); TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock2->bind(1024)); delete sock; diff --git a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_unopened.cpp b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_unopened.cpp index cbe1e27fa5..ca99f2664f 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_unopened.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_unopened.cpp @@ -21,6 +21,7 @@ #include "UDPSocket.h" #include "unity/unity.h" #include "utest.h" +#include "greentea_get_network_interface.h" using namespace utest::v1; diff --git a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_wrong_type.cpp b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_wrong_type.cpp index 1b5887ae6b..00bc5433cf 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_wrong_type.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_bind_wrong_type.cpp @@ -21,6 +21,7 @@ #include "UDPSocket.h" #include "unity/unity.h" #include "utest.h" +#include "greentea_get_network_interface.h" using namespace utest::v1; @@ -30,7 +31,7 @@ void UDPSOCKET_BIND_WRONG_TYPE() if (!sock) { TEST_FAIL(); } - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_network_interface())); char addr_bytes[16] = {0xfe, 0x80, 0xff, 0x1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; SocketAddress sockAddr; if (get_ip_version() == NSAPI_IPv4) { diff --git a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_echotest.cpp b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_echotest.cpp index 530ba97a02..5726575078 100755 --- a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_echotest.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_echotest.cpp @@ -22,6 +22,7 @@ #include "unity/unity.h" #include "utest.h" #include "udp_tests.h" +#include "greentea_get_network_interface.h" using namespace std::chrono; using namespace utest::v1; @@ -66,11 +67,11 @@ void UDPSOCKET_ECHOTEST_impl(bool use_sendto) { SocketAddress udp_addr; SocketAddress recv_addr; - NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &udp_addr); + get_network_interface()->gethostbyname(ECHO_SERVER_ADDR, &udp_addr); udp_addr.set_port(ECHO_SERVER_PORT); UDPSocket sock; - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_network_interface())); if (!use_sendto) { TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.connect(udp_addr)); @@ -173,14 +174,14 @@ void UDPSOCKET_ECHOTEST_NONBLOCK_impl(bool use_sendto) time_allotted = split2half_rmng_udp_test_time(); SocketAddress udp_addr; - NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &udp_addr); + get_network_interface()->gethostbyname(ECHO_SERVER_ADDR, &udp_addr); udp_addr.set_port(ECHO_SERVER_PORT); sock = new UDPSocket(); if (sock == NULL) { TEST_FAIL_MESSAGE("UDPSocket not created"); return; } - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_network_interface())); if (!use_sendto) { TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->connect(udp_addr)); diff --git a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_echotest_burst.cpp b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_echotest_burst.cpp index 23eca8853d..d3351b3f7f 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_echotest_burst.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_echotest_burst.cpp @@ -21,6 +21,8 @@ #include "unity/unity.h" #include "utest.h" #include "udp_tests.h" +#include "greentea_get_network_interface.h" + #ifdef MBED_CONF_APP_BAUD_RATE #include "CellularDevice.h" #endif // MBED_CONF_CELLULAR_PRESENT @@ -78,12 +80,12 @@ void UDPSOCKET_ECHOTEST_BURST() #endif SocketAddress udp_addr; - NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &udp_addr); + get_network_interface()->gethostbyname(ECHO_SERVER_ADDR, &udp_addr); udp_addr.set_port(ECHO_SERVER_PORT); UDPSocket sock; const int TIMEOUT = 5000; // [ms] - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_network_interface())); sock.set_timeout(TIMEOUT); sock.sigio(callback(_sigio_handler, ThisThread::get_id())); @@ -167,11 +169,11 @@ void UDPSOCKET_ECHOTEST_BURST_NONBLOCK() #endif SocketAddress udp_addr; - NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &udp_addr); + get_network_interface()->gethostbyname(ECHO_SERVER_ADDR, &udp_addr); udp_addr.set_port(ECHO_SERVER_PORT); UDPSocket sock; - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_network_interface())); sock.set_blocking(false); sock.sigio(callback(_sigio_handler, ThisThread::get_id())); diff --git a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_open_close_repeat.cpp b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_open_close_repeat.cpp index de83bcbef8..42480231f2 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_open_close_repeat.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_open_close_repeat.cpp @@ -21,6 +21,7 @@ #include "UDPSocket.h" #include "unity/unity.h" #include "utest.h" +#include "greentea_get_network_interface.h" using namespace utest::v1; @@ -32,7 +33,7 @@ void UDPSOCKET_OPEN_CLOSE_REPEAT() } for (int i = 0; i < 2; i++) { - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_network_interface())); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close()); } delete sock; diff --git a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_open_destruct.cpp b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_open_destruct.cpp index adeb47e91b..d05c5406c9 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_open_destruct.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_open_destruct.cpp @@ -21,6 +21,7 @@ #include "UDPSocket.h" #include "unity/unity.h" #include "utest.h" +#include "greentea_get_network_interface.h" using namespace utest::v1; @@ -31,7 +32,7 @@ void UDPSOCKET_OPEN_DESTRUCT() if (!sock) { TEST_FAIL(); } - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_network_interface())); delete sock; } } diff --git a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_open_limit.cpp b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_open_limit.cpp index c2b8555692..cca86c9452 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_open_limit.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_open_limit.cpp @@ -22,6 +22,7 @@ #include "unity/unity.h" #include "utest.h" #include "SocketStats.h" +#include "greentea_get_network_interface.h" using namespace utest::v1; @@ -47,7 +48,7 @@ void UDPSOCKET_OPEN_LIMIT() if (!sock) { break; } - ret = sock->open(NetworkInterface::get_default_instance()); + ret = sock->open(get_network_interface()); if (ret == NSAPI_ERROR_NO_MEMORY || ret == NSAPI_ERROR_NO_SOCKET) { tr_info("[round#%02d] unable to open new socket, error: %d", i, ret); delete sock; diff --git a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_open_twice.cpp b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_open_twice.cpp index 670757c911..399789f1bb 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_open_twice.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_open_twice.cpp @@ -21,6 +21,7 @@ #include "UDPSocket.h" #include "unity/unity.h" #include "utest.h" +#include "greentea_get_network_interface.h" using namespace utest::v1; @@ -31,8 +32,8 @@ void UDPSOCKET_OPEN_TWICE() TEST_FAIL(); } - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance())); - TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock->open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_network_interface())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock->open(get_network_interface())); delete sock; } diff --git a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_recv_timeout.cpp b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_recv_timeout.cpp index 410316b387..f130c2bf1b 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_recv_timeout.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_recv_timeout.cpp @@ -21,6 +21,7 @@ #include "unity/unity.h" #include "utest.h" #include "udp_tests.h" +#include "greentea_get_network_interface.h" using namespace utest::v1; @@ -38,14 +39,14 @@ static void _sigio_handler(osThreadId id) void UDPSOCKET_RECV_TIMEOUT() { SocketAddress udp_addr; - NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &udp_addr); + get_network_interface()->gethostbyname(ECHO_SERVER_ADDR, &udp_addr); udp_addr.set_port(ECHO_SERVER_PORT); static const int DATA_LEN = 100; char buff[DATA_LEN] = {0}; UDPSocket sock; - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_network_interface())); sock.set_timeout(100); sock.sigio(callback(_sigio_handler, ThisThread::get_id())); diff --git a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_sendto_invalid.cpp b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_sendto_invalid.cpp index b15311449c..10aff0205f 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_sendto_invalid.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_sendto_invalid.cpp @@ -21,13 +21,14 @@ #include "unity/unity.h" #include "utest.h" #include "udp_tests.h" +#include "greentea_get_network_interface.h" using namespace utest::v1; void UDPSOCKET_SENDTO_INVALID() { UDPSocket sock; - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_network_interface())); SocketAddress addr; addr.set_ip_address(""); @@ -35,7 +36,7 @@ void UDPSOCKET_SENDTO_INVALID() // UDP will be able to send 0 bytes, but no particular error is raised TEST_ASSERT_EQUAL(sock.sendto(addr, NULL, 0), 0); - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &addr)); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, get_network_interface()->gethostbyname(ECHO_SERVER_ADDR, &addr)); addr.set_port(9); nsapi_error_t result = sock.sendto(addr, NULL, 0); if (result != NSAPI_ERROR_UNSUPPORTED) { diff --git a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_sendto_repeat.cpp b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_sendto_repeat.cpp index 4b01a6c51a..2c61f0baf9 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_sendto_repeat.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_sendto_repeat.cpp @@ -21,17 +21,18 @@ #include "unity/unity.h" #include "utest.h" #include "udp_tests.h" +#include "greentea_get_network_interface.h" using namespace utest::v1; void UDPSOCKET_SENDTO_REPEAT() { UDPSocket sock; - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_network_interface())); SocketAddress udp_addr; TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, - NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &udp_addr)); + get_network_interface()->gethostbyname(ECHO_SERVER_ADDR, &udp_addr)); udp_addr.set_port(9); int sent; diff --git a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_sendto_timeout.cpp b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_sendto_timeout.cpp index a44ffcb9d6..6c5a98fc45 100644 --- a/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_sendto_timeout.cpp +++ b/connectivity/netsocket/tests/TESTS/netsocket/udp/udpsocket_sendto_timeout.cpp @@ -21,6 +21,7 @@ #include "unity/unity.h" #include "utest.h" #include "udp_tests.h" +#include "greentea_get_network_interface.h" using namespace utest::v1; @@ -30,10 +31,10 @@ void UDPSOCKET_SENDTO_TIMEOUT() fill_tx_buffer_ascii(tx_buffer, sizeof(tx_buffer)); UDPSocket sock; - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_network_interface())); SocketAddress udp_addr; - NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &udp_addr); + get_network_interface()->gethostbyname(ECHO_SERVER_ADDR, &udp_addr); udp_addr.set_port(9); Timer timer; diff --git a/connectivity/netsocket/tests/TESTS/network/CMakeLists.txt b/connectivity/netsocket/tests/TESTS/network/CMakeLists.txt index ea3b68a98e..c6fdaff2dd 100644 --- a/connectivity/netsocket/tests/TESTS/network/CMakeLists.txt +++ b/connectivity/netsocket/tests/TESTS/network/CMakeLists.txt @@ -1 +1,2 @@ -add_subdirectory(interface) \ No newline at end of file +add_subdirectory(interface) +add_subdirectory(wifi) \ No newline at end of file diff --git a/connectivity/netsocket/tests/TESTS/network/interface/main.cpp b/connectivity/netsocket/tests/TESTS/network/interface/main.cpp index b7799de2d4..3c474a3572 100644 --- a/connectivity/netsocket/tests/TESTS/network/interface/main.cpp +++ b/connectivity/netsocket/tests/TESTS/network/interface/main.cpp @@ -19,12 +19,6 @@ #error [NOT_SUPPORTED] network interface test cases require a RTOS to run. #else -#define WIFI 2 -#if !defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE) || \ - (MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == WIFI && !defined(MBED_CONF_NSAPI_DEFAULT_WIFI_SSID)) -#error [NOT_SUPPORTED] No network configuration found for this target. -#else - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity/unity.h" @@ -59,5 +53,4 @@ int main() return !Harness::run(specification); } -#endif // !defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE) || (MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == WIFI && !defined(MBED_CONF_NSAPI_DEFAULT_WIFI_SSID)) #endif // !defined(MBED_CONF_RTOS_PRESENT) diff --git a/connectivity/netsocket/tests/TESTS/network/interface/networkinterface_conn_disc_repeat.cpp b/connectivity/netsocket/tests/TESTS/network/interface/networkinterface_conn_disc_repeat.cpp index a717346c10..ce557b4f50 100644 --- a/connectivity/netsocket/tests/TESTS/network/interface/networkinterface_conn_disc_repeat.cpp +++ b/connectivity/netsocket/tests/TESTS/network/interface/networkinterface_conn_disc_repeat.cpp @@ -30,7 +30,7 @@ const int repeats = 5; void NETWORKINTERFACE_CONN_DISC_REPEAT() { - net = NetworkInterface::get_default_instance(); + net = get_network_interface(); for (int i = 0; i < repeats; i++) { nsapi_error_t err = net->connect(); diff --git a/connectivity/netsocket/tests/TESTS/network/interface/networkinterface_status.cpp b/connectivity/netsocket/tests/TESTS/network/interface/networkinterface_status.cpp index 829844b8a9..9adfc3e5c1 100644 --- a/connectivity/netsocket/tests/TESTS/network/interface/networkinterface_status.cpp +++ b/connectivity/netsocket/tests/TESTS/network/interface/networkinterface_status.cpp @@ -74,7 +74,7 @@ void NETWORKINTERFACE_STATUS() status_read_counter = 0; current_status = NSAPI_STATUS_ERROR_UNSUPPORTED; - net = NetworkInterface::get_default_instance(); + net = get_network_interface(); TEST_ASSERT_NOT_NULL_MESSAGE(net, "No NetworkInterface configured"); net->attach(status_cb); net->set_blocking(true); @@ -110,7 +110,7 @@ void NETWORKINTERFACE_STATUS_NONBLOCK() status_read_counter = 0; current_status = NSAPI_STATUS_ERROR_UNSUPPORTED; - net = NetworkInterface::get_default_instance(); + net = get_network_interface(); net->attach(status_cb); net->set_blocking(false); @@ -145,7 +145,7 @@ void NETWORKINTERFACE_STATUS_NONBLOCK() void NETWORKINTERFACE_STATUS_GET() { - net = NetworkInterface::get_default_instance(); + net = get_network_interface(); net->set_blocking(true); TEST_ASSERT_EQUAL(NSAPI_STATUS_DISCONNECTED, net->get_connection_status()); diff --git a/connectivity/netsocket/tests/TESTS/network/interface/networkinterface_tests.h b/connectivity/netsocket/tests/TESTS/network/interface/networkinterface_tests.h index d3d0293d2e..615a2711b5 100644 --- a/connectivity/netsocket/tests/TESTS/network/interface/networkinterface_tests.h +++ b/connectivity/netsocket/tests/TESTS/network/interface/networkinterface_tests.h @@ -18,6 +18,8 @@ #ifndef NETWORKINTERFACE_TESTS_H #define NETWORKINTERFACE_TESTS_H +#include "greentea_get_network_interface.h" + /* * Test cases */ diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/CMakeLists.txt b/connectivity/netsocket/tests/TESTS/network/wifi/CMakeLists.txt index e0de6668db..ba19268a03 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/CMakeLists.txt +++ b/connectivity/netsocket/tests/TESTS/network/wifi/CMakeLists.txt @@ -1,23 +1,23 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR) +# TODO Currently, on boards with multiple interfaces, this test may not run, as it is looking +# for the default wifi interface. As far as I can tell, there is no config definition that +# allows detecting if a board has wifi support other than +# MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE, so we are stuck with this limitation. +if(NOT "MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE=WIFI" IN_LIST MBED_CONFIG_DEFINITIONS) + set(TEST_SKIPPED "Requires wi-fi to be the default network interface") +endif() -set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../.. CACHE INTERNAL "") -set(TEST_TARGET mbed-connectivity-netsocket-network-wifi) - -include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake) - -project(${TEST_TARGET}) +# Options specific to this test +set(MBED_GREENTEA_WIFI_MAX_SCAN_SIZE 30 CACHE STRING "How many networks may appear in Wifi scan result") +set(MBED_GREENTEA_WIFI_SECURE_CHANNEL 1 CACHE STRING "Channel number that the wifi network is on. Used for channel-specific connection tests, if supported by the wifi driver.") list( APPEND TEST_SOURCE_LIST main.cpp - get_interface.cpp - get_security.cpp wifi-constructor.cpp - wifi_connect.cpp wifi_connect_disconnect_nonblock.cpp wifi_connect_disconnect_repeat.cpp wifi_connect_nocredentials.cpp @@ -25,7 +25,6 @@ list( wifi_connect_params_channel_fail.cpp wifi_connect_params_null.cpp wifi_connect_params_valid_secure.cpp - wifi_connect_secure.cpp wifi_connect_secure_fail.cpp wifi_get_rssi.cpp wifi_scan.cpp @@ -36,9 +35,17 @@ list( mbed_greentea_add_test( TEST_NAME - ${TEST_TARGET} + mbed-connectivity-network-wifi TEST_SOURCES ${TEST_SOURCE_LIST} TEST_REQUIRED_LIBS mbed-netsocket + TEST_SKIPPED + ${TEST_SKIPPED} ) + +if(TARGET test-mbed-connectivity-network-wifi) + target_compile_definitions(test-mbed-connectivity-network-wifi PRIVATE + MBED_GREENTEA_WIFI_MAX_SCAN_SIZE=${MBED_GREENTEA_WIFI_MAX_SCAN_SIZE} + MBED_GREENTEA_WIFI_SECURE_CHANNEL=${MBED_GREENTEA_WIFI_SECURE_CHANNEL}) +endif() \ No newline at end of file diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/get_interface.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/get_interface.cpp deleted file mode 100644 index b992f16536..0000000000 --- a/connectivity/netsocket/tests/TESTS/network/wifi/get_interface.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2017, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "wifi_tests.h" - -#define WIFI 2 -#if !defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE) || \ - MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE != WIFI -#error [NOT_SUPPORTED] No network configuration found for this target. -#else -#if !defined(MBED_CONF_APP_WIFI_SECURE_SSID) && !defined(MBED_CONF_APP_WIFI_UNSECURE_SSID) -#error [NOT_SUPPORTED] Requires parameters from mbed_app.json -#else - -#include "mbed.h" - -WiFiInterface *get_interface() -{ - static WiFiInterface *interface = NULL; - - if (interface) { - interface->disconnect(); - return interface; - } - - interface = WiFiInterface::get_default_instance(); - - return interface; -} -#endif //!defined(MBED_CONF_APP_WIFI_SECURE_SSID) && !defined(MBED_CONF_APP_WIFI_UNSECURE_SSID) -#endif //!defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE) || MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE != WIFI diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/get_security.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/get_security.cpp deleted file mode 100644 index 05a8c13b75..0000000000 --- a/connectivity/netsocket/tests/TESTS/network/wifi/get_security.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2017, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "mbed.h" -#include "nsapi_types.h" - -nsapi_security get_security() -{ -#if defined MBED_CONF_APP_WIFI_SECURE_PROTOCOL - static const char *SEC_WEP = "WEP"; - static const char *SEC_WPA = "WPA"; - static const char *SEC_WPA2 = "WPA2"; - static const char *SEC_WPA_WPA2 = "WPA/WPA2"; - static const char *SEC_WPA3 = "WPA3"; - static const char *SEC_WPA3_WPA2 = "WPA3/WPA2"; - - if (strcmp(MBED_CONF_APP_WIFI_SECURE_PROTOCOL, SEC_WEP) == 0) { - return NSAPI_SECURITY_WEP; - } - if (strcmp(MBED_CONF_APP_WIFI_SECURE_PROTOCOL, SEC_WPA) == 0) { - return NSAPI_SECURITY_WPA; - } - if (strcmp(MBED_CONF_APP_WIFI_SECURE_PROTOCOL, SEC_WPA2) == 0) { - return NSAPI_SECURITY_WPA2; - } - if (strcmp(MBED_CONF_APP_WIFI_SECURE_PROTOCOL, SEC_WPA_WPA2) == 0) { - return NSAPI_SECURITY_WPA_WPA2; - } - if (strcmp(MBED_CONF_APP_WIFI_SECURE_PROTOCOL, SEC_WPA3) == 0) { - return NSAPI_SECURITY_WPA3; - } - if (strcmp(MBED_CONF_APP_WIFI_SECURE_PROTOCOL, SEC_WPA3_WPA2) == 0) { - return NSAPI_SECURITY_WPA3_WPA2; - } -#elif defined MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY - return MBED_CONCAT(NSAPI_SECURITY_, MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY); -#endif - return NSAPI_SECURITY_NONE; -} diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/main.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/main.cpp index 78c597339e..3ef1f9439d 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/main.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/main.cpp @@ -15,36 +15,22 @@ * limitations under the License. */ -#define WIFI 2 -#if !defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE) || \ - MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE != WIFI -#error [NOT_SUPPORTED] No network configuration found for this target. -#else - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" #include "utest.h" #include "wifi_tests.h" -#if !defined(MBED_CONF_APP_WIFI_SECURE_SSID) +#if !defined(MBED_GREENTEA_WIFI_SECURE_SSID) #error [NOT_SUPPORTED] Requires secure AP #endif // Test for parameters -#if defined(MBED_CONF_APP_WIFI_SECURE_SSID) && \ - (!defined(MBED_CONF_APP_MAX_SCAN_SIZE) || \ - !defined(MBED_CONF_APP_WIFI_PASSWORD) || \ - !defined(MBED_CONF_APP_WIFI_SECURE_PROTOCOL)) +#if (!defined(MBED_GREENTEA_WIFI_MAX_SCAN_SIZE) || \ + !defined(MBED_GREENTEA_WIFI_SECURE_PASSWORD) || \ + !defined(MBED_GREENTEA_WIFI_SECURE_PROTOCOL)) #error [NOT_SUPPORTED] Requires parameters from mbed_app.json (for secure connections) -#else - -#if defined(MBED_CONF_APP_WIFI_UNSECURE_SSID) && \ - (!defined(MBED_CONF_APP_MAX_SCAN_SIZE) || \ - !defined(MBED_CONF_APP_WIFI_CH_UNSECURE)) -#error [NOT_SUPPORTED] Requires parameters from mbed_app.json (for unsecure connections) -#else - +#endif using namespace utest::v1; @@ -66,23 +52,15 @@ Case cases[] = { Case("WIFI-SET-CHANNEL", wifi_set_channel), Case("WIFI-CONNECT-PARAMS-NULL", wifi_connect_params_null), Case("WIFI-SCAN-NULL", wifi_scan_null), -#if defined(MBED_CONF_APP_WIFI_SECURE_SSID) || defined(MBED_CONF_APP_WIFI_UNSECURE_SSID) Case("WIFI-SCAN", wifi_scan), -#endif -#if defined(MBED_CONF_APP_WIFI_SECURE_SSID) Case("WIFI-GET-RSSI", wifi_get_rssi), Case("WIFI-CONNECT-DISCONNECT-REPEAT", wifi_connect_disconnect_repeat), Case("WIFI-CONNECT-PARAMS-VALID-SECURE", wifi_connect_params_valid_secure), Case("WIFI-CONNECT-PARAMS-CHANNEL", wifi_connect_params_channel), Case("WIFI-CONNECT-PARAMS-CHANNEL-FAIL", wifi_connect_params_channel_fail), - Case("WIFI-CONNECT-SECURE", wifi_connect_secure), Case("WIFI-CONNECT-SECURE-FAIL", wifi_connect_secure_fail), -#endif -#if defined(MBED_CONF_APP_WIFI_UNSECURE_SSID) - Case("WIFI-CONNECT", wifi_connect), //Most boards are not passing this test, but they should if they support non-blocking API. - //Case("WIFI_CONNECT_DISCONNECT_NONBLOCK", wifi_connect_disconnect_nonblock), -#endif + Case("WIFI_CONNECT_DISCONNECT_NONBLOCK", wifi_connect_disconnect_nonblock), }; Specification specification(test_setup, cases, greentea_continue_handlers); @@ -91,9 +69,4 @@ Specification specification(test_setup, cases, greentea_continue_handlers); int main() { return !Harness::run(specification); -} -#endif // defined(MBED_CONF_APP_WIFI_UNSECURE_SSID) && !defined(MBED_CONF_APP_* - -#endif // defined(MBED_CONF_APP_WIFI_SECURE_SSID) && (!defined(MBED_CONF_APP_* - -#endif //!defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE) || MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE != WIFI +} \ No newline at end of file diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/template_mbed_app.txt b/connectivity/netsocket/tests/TESTS/network/wifi/template_mbed_app.txt deleted file mode 100644 index 482143c635..0000000000 --- a/connectivity/netsocket/tests/TESTS/network/wifi/template_mbed_app.txt +++ /dev/null @@ -1,41 +0,0 @@ -{ - "config": { - "wifi-secure-ssid": { - "help": "WiFi SSID for secure network", - "optional_parameter": "if value is null, MBED_CONF_NSAPI_DEFAULT_WIFI_SSID is used", - "value": "\"SSID-SECURE\"" - }, - "wifi-unsecure-ssid": { - "help": "WiFi SSID for unsecure network", - "optional_parameter": "if value is null, non-secure tests are skipped", - "value": "\"SSID-UNSECURE\"" - }, - "wifi-password": { - "help": "WiFi Password", - "optional_parameter": "if value is null, MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD is used", - "value": "\"PASSWORD\"" - }, - "wifi-secure-protocol": { - "help": "WiFi security protocol, valid values are WEP, WPA, WPA2, WPA/WPA2", - "optional_parameter": "if value is null, MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY is used", - "value": "\"WPA2\"" - }, - "wifi-ch-secure": { - "help": "Channel number of secure SSID (if set_channel() is supported)", - "value": 1 - }, - "wifi-ch-unsecure": { - "help": "Channel number of unsecure SSID (if set_channel() is supported)", - "value": 2 - }, - "max-scan-size": { - "help": "How many networks may appear in Wifi scan result (default is 10)", - "value": 10 - } - }, - "target_overrides": { - "*": { - "target.network-default-interface-type": "WIFI" - } - } -} diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi-constructor.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi-constructor.cpp index d97d3a3fde..d31a88893b 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi-constructor.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi-constructor.cpp @@ -25,6 +25,6 @@ using namespace utest::v1; void wifi_constructor() { - WiFiInterface *wifi = get_interface(); + WiFiInterface *wifi = WiFiInterface::get_default_instance(); TEST_ASSERT(wifi); } diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect.cpp deleted file mode 100644 index fbd6f59c21..0000000000 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2017, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "mbed.h" -#include "greentea-client/test_env.h" -#include "unity.h" -#include "utest.h" -#include "wifi_tests.h" - -using namespace utest::v1; - -#if defined(MBED_CONF_APP_WIFI_UNSECURE_SSID) - -#define SSID_MAX_LEN 32 - -void wifi_connect(void) -{ - WiFiInterface *wifi = get_interface(); - TEST_ASSERT(wifi); - if (wifi == NULL) { - return; - } - - char ssid[SSID_MAX_LEN + 1] = MBED_CONF_APP_WIFI_UNSECURE_SSID; - - TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(ssid, NULL)); - TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->connect()); - TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->disconnect()); - - TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(ssid, "")); - TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->connect()); - TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->disconnect()); - - // Driver is expected to cache the credentials - memset(ssid, 0, SSID_MAX_LEN + 1); - - TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->connect()); - TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->disconnect()); -} - -#endif // defined(MBED_CONF_APP_WIFI_UNSECURE_SSID) diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_disconnect_nonblock.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_disconnect_nonblock.cpp index f1b68d9685..7f72ea7491 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_disconnect_nonblock.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_disconnect_nonblock.cpp @@ -23,9 +23,6 @@ using namespace utest::v1; -#if defined(MBED_CONF_APP_WIFI_UNSECURE_SSID) - -#define SSID_MAX_LEN 32 nsapi_connection_status_t status_connection; Semaphore sem_conn(0, 1); Semaphore sem_disconn(0, 1); @@ -50,9 +47,7 @@ void status_callback(nsapi_event_t e, intptr_t d) void wifi_connect_disconnect_nonblock(void) { - WiFiInterface *wifi = get_interface(); - char ssid[SSID_MAX_LEN + 1] = MBED_CONF_APP_WIFI_UNSECURE_SSID; - TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(ssid, NULL)); + WiFiInterface *wifi = get_wifi_interface(); wifi->attach(status_callback); TEST_SKIP_UNLESS(wifi->set_blocking(false) != NSAPI_ERROR_UNSUPPORTED); nsapi_error_t ret = wifi->connect(); @@ -61,20 +56,16 @@ void wifi_connect_disconnect_nonblock(void) TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, ret); TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_BUSY, ret2); TEST_ASSERT_TRUE(ret3 == NSAPI_ERROR_BUSY || ret3 == NSAPI_ERROR_IS_CONNECTED); - bool res = sem_connecting.try_acquire_for(30000); + TEST_ASSERT_TRUE(sem_connecting.try_acquire_for(30s)); TEST_ASSERT_EQUAL_INT(NSAPI_STATUS_CONNECTING, status_connection); - res = sem_conn.try_acquire_for(30000); - TEST_ASSERT_TRUE(res == true); + TEST_ASSERT_TRUE(sem_conn.try_acquire_for(30s)); TEST_ASSERT_TRUE(status_connection == NSAPI_STATUS_GLOBAL_UP || status_connection == NSAPI_STATUS_LOCAL_UP); ret = wifi->disconnect(); ret3 = wifi->disconnect(); TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, ret); TEST_ASSERT_TRUE(ret3 == NSAPI_ERROR_BUSY || ret3 == NSAPI_ERROR_NO_CONNECTION); - res = sem_disconn.try_acquire_for(30000); - TEST_ASSERT_TRUE(res == true); + TEST_ASSERT_TRUE(sem_disconn.try_acquire_for(30s)); TEST_ASSERT_EQUAL_INT(NSAPI_STATUS_DISCONNECTED, status_connection); wifi->set_blocking(true); wifi->attach(0); } - -#endif // defined(MBED_CONF_APP_WIFI_UNSECURE_SSID) diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_disconnect_repeat.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_disconnect_repeat.cpp index 898233da01..5c604f6593 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_disconnect_repeat.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_disconnect_repeat.cpp @@ -21,21 +21,25 @@ #include "utest.h" #include "wifi_tests.h" +#include "greentea_get_network_interface.h" + using namespace utest::v1; -#if defined(MBED_CONF_APP_WIFI_SECURE_SSID) +#if defined(MBED_GREENTEA_WIFI_SECURE_SSID) void wifi_connect_disconnect_repeat(void) { - WiFiInterface *wifi = get_interface(); + WiFiInterface *wifi = get_wifi_interface(); TEST_ASSERT(wifi); if (wifi == NULL) { return; } - nsapi_error_t error; - error = wifi->set_credentials(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, get_security()); - TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, error); + if (wifi->get_connection_status() != NSAPI_STATUS_DISCONNECTED) { + wifi->disconnect(); + } + + nsapi_error_t error; for (int i = 0; i < 10; i++) { printf("#%u connecting...\n", i); @@ -47,4 +51,4 @@ void wifi_connect_disconnect_repeat(void) } } -#endif // defined(MBED_CONF_APP_WIFI_SECURE_SSID) +#endif // defined(MBED_GREENTEA_WIFI_SECURE_SSID) diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_nocredentials.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_nocredentials.cpp index bae1a6ed9e..f00caf38f5 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_nocredentials.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_nocredentials.cpp @@ -25,7 +25,9 @@ using namespace utest::v1; void wifi_connect_nocredentials(void) { - WiFiInterface *wifi = get_interface(); + // Note: This test must execute first, before anyone calls set_credentials() + // on the wifi interface. + WiFiInterface *wifi = WiFiInterface::get_default_instance(); TEST_ASSERT(wifi); if (wifi == NULL) { return; diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_channel.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_channel.cpp index 6be5b7d0db..3600a111ad 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_channel.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_channel.cpp @@ -23,11 +23,11 @@ using namespace utest::v1; -#if defined(MBED_CONF_APP_WIFI_SECURE_SSID) +#if defined(MBED_GREENTEA_WIFI_SECURE_SSID) void wifi_connect_params_channel(void) { - WiFiInterface *wifi = get_interface(); + WiFiInterface *wifi = get_wifi_interface(); TEST_ASSERT(wifi); if (wifi == NULL) { return; @@ -38,7 +38,7 @@ void wifi_connect_params_channel(void) return; } - nsapi_error_t error = wifi->connect(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, get_security(), MBED_CONF_APP_WIFI_CH_SECURE); + nsapi_error_t error = wifi->connect(MBED_GREENTEA_WIFI_SECURE_SSID, MBED_GREENTEA_WIFI_SECURE_PASSWORD, get_wifi_security(), MBED_GREENTEA_WIFI_SECURE_CHANNEL); wifi->set_channel(0); @@ -47,4 +47,4 @@ void wifi_connect_params_channel(void) TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, error); } -#endif // defined(MBED_CONF_APP_WIFI_SECURE_SSID) +#endif // defined(MBED_GREENTEA_WIFI_SECURE_SSID) diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_channel_fail.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_channel_fail.cpp index fc27f34dd7..26cf55a1b9 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_channel_fail.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_channel_fail.cpp @@ -23,11 +23,11 @@ using namespace utest::v1; -#if defined(MBED_CONF_APP_WIFI_SECURE_SSID) +#if defined(MBED_GREENTEA_WIFI_SECURE_SSID) void wifi_connect_params_channel_fail(void) { - WiFiInterface *wifi = get_interface(); + WiFiInterface *wifi = get_wifi_interface(); TEST_ASSERT(wifi); if (wifi == NULL) { return; @@ -38,11 +38,11 @@ void wifi_connect_params_channel_fail(void) return; } - uint8_t wrong_channel = 1 + (MBED_CONF_APP_WIFI_CH_SECURE % 10); - nsapi_error_t error = wifi->connect(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, get_security(), wrong_channel); + uint8_t wrong_channel = 1 + (MBED_GREENTEA_WIFI_SECURE_CHANNEL % 10); + nsapi_error_t error = wifi->connect(MBED_GREENTEA_WIFI_SECURE_SSID, MBED_GREENTEA_WIFI_SECURE_PASSWORD, get_wifi_security(), wrong_channel); TEST_ASSERT(error == NSAPI_ERROR_CONNECTION_TIMEOUT || error == NSAPI_ERROR_NO_CONNECTION); wifi->set_channel(0); } -#endif // defined(MBED_CONF_APP_WIFI_SECURE_SSID) +#endif // defined(MBED_GREENTEA_WIFI_SECURE_SSID) diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_null.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_null.cpp index 8fbe4be3ea..6776d24358 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_null.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_null.cpp @@ -26,7 +26,7 @@ using namespace utest::v1; void wifi_connect_params_null(void) { nsapi_error_t error; - WiFiInterface *wifi = get_interface(); + WiFiInterface *wifi = get_wifi_interface(); TEST_ASSERT(wifi); if (wifi == NULL) { return; diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_valid_secure.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_valid_secure.cpp index 3264d90c5c..64a174b700 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_valid_secure.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_params_valid_secure.cpp @@ -23,17 +23,21 @@ using namespace utest::v1; -#if defined(MBED_CONF_APP_WIFI_SECURE_SSID) +#if defined(MBED_GREENTEA_WIFI_SECURE_SSID) void wifi_connect_params_valid_secure(void) { - WiFiInterface *wifi = get_interface(); + WiFiInterface *wifi = get_wifi_interface(); TEST_ASSERT(wifi); if (wifi == NULL) { return; } - if (wifi->connect(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, get_security()) == NSAPI_ERROR_OK) { + if (wifi->get_connection_status() != NSAPI_STATUS_DISCONNECTED) { + wifi->disconnect(); + } + + if (wifi->connect(MBED_GREENTEA_WIFI_SECURE_SSID, MBED_GREENTEA_WIFI_SECURE_PASSWORD, get_wifi_security()) == NSAPI_ERROR_OK) { if (wifi->disconnect() == NSAPI_ERROR_OK) { return; } @@ -42,4 +46,4 @@ void wifi_connect_params_valid_secure(void) TEST_FAIL(); } -#endif // defined(MBED_CONF_APP_WIFI_SECURE_SSID) +#endif // defined(MBED_GREENTEA_WIFI_SECURE_SSID) diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_secure.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_secure.cpp deleted file mode 100644 index 82f8e51261..0000000000 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_secure.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2017, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "mbed.h" -#include "greentea-client/test_env.h" -#include "unity.h" -#include "utest.h" -#include "wifi_tests.h" - -using namespace utest::v1; - -#if defined(MBED_CONF_APP_WIFI_SECURE_SSID) - -void wifi_connect_secure(void) -{ - WiFiInterface *wifi = get_interface(); - TEST_ASSERT(wifi); - if (wifi == NULL) { - return; - } - - // Driver shall cache the credentials - char ssid[] = MBED_CONF_APP_WIFI_SECURE_SSID; - char password[] = MBED_CONF_APP_WIFI_PASSWORD; - TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(ssid, password, get_security())); - ssid[0] = '\0'; - password[0] = '\0'; - TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->connect()); - TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->disconnect()); -} - -#endif // defined(MBED_CONF_APP_WIFI_SECURE_SSID) diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_secure_fail.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_secure_fail.cpp index 44d2793ad6..6ae2327d82 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_secure_fail.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_secure_fail.cpp @@ -23,17 +23,19 @@ using namespace utest::v1; -#if defined(MBED_CONF_APP_WIFI_SECURE_SSID) - void wifi_connect_secure_fail(void) { - WiFiInterface *wifi = get_interface(); + WiFiInterface *wifi = get_wifi_interface(); TEST_ASSERT(wifi); if (wifi == NULL) { return; } - TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(MBED_CONF_APP_WIFI_SECURE_SSID, "aaaaaaaa", get_security())); + if (wifi->get_connection_status() != NSAPI_STATUS_DISCONNECTED) { + wifi->disconnect(); + } + + TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(MBED_GREENTEA_WIFI_SECURE_SSID, "aaaaaaaa", get_wifi_security())); nsapi_error_t error; printf("Wifi connection with wrong password\n"); error = wifi->connect(); @@ -44,5 +46,3 @@ void wifi_connect_secure_fail(void) error == NSAPI_ERROR_NO_CONNECTION); } - -#endif // defined(MBED_CONF_APP_WIFI_SECURE_SSID) diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_get_rssi.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_get_rssi.cpp index d6400a6b26..f9bf35b9a3 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_get_rssi.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_get_rssi.cpp @@ -23,17 +23,19 @@ using namespace utest::v1; -#if defined(MBED_CONF_APP_WIFI_SECURE_SSID) +#if defined(MBED_GREENTEA_WIFI_SECURE_SSID) void wifi_get_rssi(void) { - WiFiInterface *wifi = get_interface(); + WiFiInterface *wifi = get_wifi_interface(); TEST_ASSERT(wifi); if (wifi == NULL) { return; } - TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, get_security())); + if (wifi->get_connection_status() != NSAPI_STATUS_DISCONNECTED) { + wifi->disconnect(); + } TEST_ASSERT_EQUAL_INT8(0, wifi->get_rssi()); @@ -44,4 +46,4 @@ void wifi_get_rssi(void) TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->disconnect()); } -#endif // defined(MBED_CONF_APP_WIFI_SECURE_SSID) +#endif // defined(MBED_GREENTEA_WIFI_SECURE_SSID) diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_scan.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_scan.cpp index 1ae8e139a2..bc41dffb36 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_scan.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_scan.cpp @@ -26,20 +26,19 @@ using namespace utest::v1; void wifi_scan(void) { - WiFiInterface *wifi = get_interface(); + WiFiInterface *wifi = get_wifi_interface(); TEST_ASSERT(wifi); if (wifi == NULL) { return; } - WiFiAccessPoint ap[MBED_CONF_APP_MAX_SCAN_SIZE]; + WiFiAccessPoint ap[MBED_GREENTEA_WIFI_MAX_SCAN_SIZE]; - int size = wifi->scan(ap, MBED_CONF_APP_MAX_SCAN_SIZE); + int size = wifi->scan(ap, MBED_GREENTEA_WIFI_MAX_SCAN_SIZE); printf("Scanned %u AP\n", size); TEST_ASSERT(size >= 1); bool secure_found = false; - bool unsecure_found = false; for (int i = 0; i < size; i++) { const char *ssid = ap[i].get_ssid(); @@ -47,19 +46,11 @@ void wifi_scan(void) int8_t rssi = ap[i].get_rssi(); printf("AP %u ssid %s security %u rssi %d\n", i, ssid, security, rssi); TEST_ASSERT_INT8_WITHIN(-10, -100, rssi); -#if defined(MBED_CONF_APP_WIFI_SECURE_SSID) - if (strcmp(MBED_CONF_APP_WIFI_SECURE_SSID, ssid) == 0) { + if (strcmp(MBED_GREENTEA_WIFI_SECURE_SSID, ssid) == 0) { secure_found = true; - TEST_ASSERT_EQUAL_INT(get_security(), security); + TEST_ASSERT_EQUAL_INT(get_wifi_security(), security); } -#endif -#if defined(MBED_CONF_APP_WIFI_UNSECURE_SSID) - if (strcmp(MBED_CONF_APP_WIFI_UNSECURE_SSID, ssid) == 0) { - unsecure_found = true; - TEST_ASSERT_EQUAL_INT(NSAPI_SECURITY_NONE, security); - } -#endif } - // Finding one SSID is enough - TEST_ASSERT_TRUE(secure_found || unsecure_found); + // We should be able to find the secure SSID + TEST_ASSERT_TRUE(secure_found); } diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_scan_null.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_scan_null.cpp index fc862e20cd..b66393e488 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_scan_null.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_scan_null.cpp @@ -25,7 +25,7 @@ using namespace utest::v1; void wifi_scan_null(void) { - WiFiInterface *wifi = get_interface(); + WiFiInterface *wifi = get_wifi_interface(); TEST_ASSERT(wifi); if (wifi == NULL) { return; diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_set_channel.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_set_channel.cpp index cddd90a4bf..6c79314756 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_set_channel.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_set_channel.cpp @@ -29,7 +29,7 @@ void wifi_set_channel(void) bool is_2Ghz = false; bool is_5Ghz = false; - WiFiInterface *wifi = get_interface(); + WiFiInterface *wifi = get_wifi_interface(); TEST_ASSERT(wifi); if (wifi == NULL) { return; diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_set_credential.cpp b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_set_credential.cpp index f7aae234b5..4d063a6883 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_set_credential.cpp +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_set_credential.cpp @@ -25,7 +25,7 @@ using namespace utest::v1; void wifi_set_credential(void) { - WiFiInterface *iface = get_interface(); + WiFiInterface *iface = WiFiInterface::get_default_instance(); TEST_ASSERT(iface); if (iface == NULL) { return; @@ -80,9 +80,9 @@ void wifi_set_credential(void) error = iface->set_credentials("OK", "12345678", NSAPI_SECURITY_WPA3_WPA2); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, error); - error = iface->set_credentials("OK", "kUjd0PHHeAqaDoyfcDDEOvbyiVbYMpUHDukGoR6EJZnO5iLzWsfwiM9JQqOngni", get_security()); + error = iface->set_credentials("OK", "kUjd0PHHeAqaDoyfcDDEOvbyiVbYMpUHDukGoR6EJZnO5iLzWsfwiM9JQqOngni", get_wifi_security()); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, error); - error = iface->set_credentials("OK", "kUjd0PHHeAqaDoyfcDDEOvbyiVbYMpUHDukGoR6EJZnO5iLzWsfwiM9JQqOngni8", get_security()); + error = iface->set_credentials("OK", "kUjd0PHHeAqaDoyfcDDEOvbyiVbYMpUHDukGoR6EJZnO5iLzWsfwiM9JQqOngni8", get_wifi_security()); TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, error); } diff --git a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_tests.h b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_tests.h index 60de5b6e77..1326f73675 100644 --- a/connectivity/netsocket/tests/TESTS/network/wifi/wifi_tests.h +++ b/connectivity/netsocket/tests/TESTS/network/wifi/wifi_tests.h @@ -18,36 +18,8 @@ #define WIFI_TESTS_H #ifdef MBED_CONF_NSAPI_PRESENT -#include "WiFiInterface.h" -#if !defined(MBED_CONF_APP_WIFI_SECURE_SSID) -#define MBED_CONF_APP_WIFI_SECURE_SSID MBED_CONF_NSAPI_DEFAULT_WIFI_SSID -#endif - -#if !defined(MBED_CONF_APP_WIFI_PASSWORD) -#define MBED_CONF_APP_WIFI_PASSWORD MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD -#endif - -#if !defined(MBED_CONF_APP_WIFI_SECURE_PROTOCOL) -#define MBED_CONF_APP_WIFI_SECURE_PROTOCOL MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY -#endif - -#if !defined(MBED_CONF_APP_WIFI_CH_SECURE) -#define MBED_CONF_APP_WIFI_CH_SECURE 1 -#endif - -#if !defined(MBED_CONF_APP_MAX_SCAN_SIZE) -#define MBED_CONF_APP_MAX_SCAN_SIZE 10 -#endif - -/** Get WiFiInterface based on provided - * app_json. */ -WiFiInterface *get_interface(void); - -/** - * Get security protocol to be used - */ -nsapi_security get_security(void); +#include "greentea_get_network_interface.h" /* * Test cases @@ -78,18 +50,12 @@ void wifi_connect_params_channel(void); /** Test WiFiInterface::connect(ssid, pass, security, channel) with valid parameters for secure network using wrong channel number. */ void wifi_connect_params_channel_fail(void); -/** Test WiFiInterface::connect() without parameters. Use set_credentials() for setting parameters. */ -void wifi_connect(void); - /** Test WiFiInterface::connect() and disconnect() in nonblocking mode. Use set_credentials() for setting parameters. */ void wifi_connect_disconnect_nonblock(void); /** Test WiFiInterface::connect() without parameters. Don't set parameters with set_credentials() */ void wifi_connect_nocredentials(void); -/** Test WiFiInterface::connect() without parameters. Use secure settings for set_credentials. */ -void wifi_connect_secure(void); - /** Test WiFiInterface::connect() failing with wrong password. */ void wifi_connect_secure_fail(void);