mirror of https://github.com/ARMmbed/mbed-os.git
Make network tests properly support boards with wifi again (#317)
* Make network tests properly support boards with wifi again * Style fixes * Style fix againpull/15530/head
parent
5354079bfb
commit
42df56c391
|
@ -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)
|
|
@ -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
|
|
@ -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:
|
||||
|
|
|
@ -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<void(nsapi_error_t, SocketAddress *)>(getaddrinfo_cb, (void *) &data[i]));
|
||||
nsapi_error_t err = get_network_interface()->getaddrinfo_async(hosts[i], &hints, mbed::Callback<void(nsapi_error_t, SocketAddress *)>(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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "nsapi_dns.h"
|
||||
#include "mbed_trace.h"
|
||||
#include "greentea_get_network_interface.h"
|
||||
|
||||
#define TRACE_GROUP "GRNT"
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)++;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "../test_params.h"
|
||||
#include "mbed_trace.h"
|
||||
#include "greentea_get_network_interface.h"
|
||||
|
||||
#define TRACE_GROUP "GRNT"
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "UDPSocket.h"
|
||||
#include "unity/unity.h"
|
||||
#include "utest.h"
|
||||
#include "greentea_get_network_interface.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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()));
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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()));
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
add_subdirectory(interface)
|
||||
add_subdirectory(wifi)
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#ifndef NETWORKINTERFACE_TESTS_H
|
||||
#define NETWORKINTERFACE_TESTS_H
|
||||
|
||||
#include "greentea_get_network_interface.h"
|
||||
|
||||
/*
|
||||
* Test cases
|
||||
*/
|
||||
|
|
|
@ -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()
|
|
@ -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
|
|
@ -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 <cstring>
|
||||
#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;
|
||||
}
|
|
@ -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);
|
||||
|
@ -92,8 +70,3 @@ 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
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,6 +25,6 @@ using namespace utest::v1;
|
|||
|
||||
void wifi_constructor()
|
||||
{
|
||||
WiFiInterface *wifi = get_interface();
|
||||
WiFiInterface *wifi = WiFiInterface::get_default_instance();
|
||||
TEST_ASSERT(wifi);
|
||||
}
|
||||
|
|
|
@ -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)
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue