mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #9875 from tymoteuszblochmobica/testfix
Apply proper network interface verification. Only run for platforms which have two interfaces and prevent crashes otherwise.pull/9930/head
commit
355f09bbac
|
@ -24,7 +24,12 @@
|
||||||
#error [NOT_SUPPORTED] Requires parameters from mbed_app.json
|
#error [NOT_SUPPORTED] Requires parameters from mbed_app.json
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "mbed.h"
|
#if !defined(DEVICE_EMAC) || \
|
||||||
|
(!defined(MBED_CONF_APP_WIFI_SECURE_SSID) && !defined(MBED_CONF_APP_WIFI_UNSECURE_SSID))
|
||||||
|
#error [NOT_SUPPORTED] Both Wifi and Ethernet devices are required for multihoming tests.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "greentea-client/test_env.h"
|
#include "greentea-client/test_env.h"
|
||||||
#include "unity/unity.h"
|
#include "unity/unity.h"
|
||||||
#include "utest.h"
|
#include "utest.h"
|
||||||
|
@ -34,7 +39,8 @@
|
||||||
using namespace utest::v1;
|
using namespace utest::v1;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
NetworkInterface *net;
|
EthInterface *eth;
|
||||||
|
WiFiInterface *wifi;
|
||||||
}
|
}
|
||||||
|
|
||||||
char interface_name[MBED_CONF_MULTIHOMING_MAX_INTERFACES_NUM][INTERFACE_NAME_LEN];
|
char interface_name[MBED_CONF_MULTIHOMING_MAX_INTERFACES_NUM][INTERFACE_NAME_LEN];
|
||||||
|
@ -48,26 +54,27 @@ mbed_stats_socket_t udp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
|
||||||
#define SSID_MAX_LEN 32
|
#define SSID_MAX_LEN 32
|
||||||
#define PWD_MAX_LEN 64
|
#define PWD_MAX_LEN 64
|
||||||
|
|
||||||
WiFiInterface *wifi;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
NetworkInterface *get_interface()
|
NetworkInterface *get_interface(int interface_index)
|
||||||
{
|
{
|
||||||
return net;
|
if (interface_index == ETH_INTERFACE) {
|
||||||
|
return eth;
|
||||||
|
} else if (interface_index == WIFI_INTERFACE) {
|
||||||
|
return wifi;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _ifup()
|
static void _ifup()
|
||||||
{
|
{
|
||||||
|
eth = EthInterface::get_default_instance();
|
||||||
#if DEVICE_EMAC
|
nsapi_error_t err = eth->connect();
|
||||||
net = EthInterface::get_default_instance();
|
eth->get_interface_name(interface_name[interface_num]);
|
||||||
nsapi_error_t err = net->connect();
|
|
||||||
net->get_interface_name(interface_name[0]);
|
|
||||||
interface_num++;
|
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
|
||||||
printf("MBED: IP address is '%s' interface name %s\n", net->get_ip_address(), interface_name[0]);
|
printf("MBED: IP address is '%s' interface name %s\n", eth->get_ip_address(), interface_name[interface_num]);
|
||||||
#endif
|
interface_num++;
|
||||||
#if defined(MBED_CONF_APP_WIFI_SECURE_SSID) || defined(MBED_CONF_APP_WIFI_UNSECURE_SSID)
|
|
||||||
wifi = WiFiInterface::get_default_instance();
|
wifi = WiFiInterface::get_default_instance();
|
||||||
|
|
||||||
if (wifi) {
|
if (wifi) {
|
||||||
|
@ -88,27 +95,29 @@ static void _ifup()
|
||||||
TEST_FAIL_MESSAGE("Wifi connection error!");
|
TEST_FAIL_MESSAGE("Wifi connection error!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
wifi->get_interface_name(interface_name[1]);
|
wifi->get_interface_name(interface_name[interface_num]);
|
||||||
interface_num++;
|
|
||||||
printf("MAC: %s\n", wifi->get_mac_address());
|
printf("MAC: %s\n", wifi->get_mac_address());
|
||||||
printf("IP: %s\n", wifi->get_ip_address());
|
printf("IP: %s\n", wifi->get_ip_address());
|
||||||
printf("Netmask: %s\n", wifi->get_netmask());
|
printf("Netmask: %s\n", wifi->get_netmask());
|
||||||
printf("Gateway: %s\n", wifi->get_gateway());
|
printf("Gateway: %s\n", wifi->get_gateway());
|
||||||
printf("RSSI: %d\n\n", wifi->get_rssi());
|
printf("RSSI: %d\n\n", wifi->get_rssi());
|
||||||
printf("Wifi interface name: %s\n\n", interface_name[1]);
|
printf("Wifi interface name: %s\n\n", interface_name[interface_num]);
|
||||||
|
interface_num++;
|
||||||
} else {
|
} else {
|
||||||
TEST_FAIL_MESSAGE("ERROR: No WiFiInterface found!");
|
TEST_FAIL_MESSAGE("ERROR: No WiFiInterface found!");
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _ifdown()
|
static void _ifdown()
|
||||||
{
|
{
|
||||||
interface_num = 0;
|
interface_num = 0;
|
||||||
net->disconnect();
|
if (eth != NULL) {
|
||||||
|
eth->disconnect();
|
||||||
|
}
|
||||||
#if defined(MBED_CONF_APP_WIFI_SECURE_SSID) || defined(MBED_CONF_APP_WIFI_UNSECURE_SSID)
|
#if defined(MBED_CONF_APP_WIFI_SECURE_SSID) || defined(MBED_CONF_APP_WIFI_UNSECURE_SSID)
|
||||||
|
if (wifi != NULL) {
|
||||||
wifi->disconnect();
|
wifi->disconnect();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
printf("MBED: ifdown\n");
|
printf("MBED: ifdown\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,9 +55,15 @@ void MULTIHOMING_ASYNCHRONOUS_DNS()
|
||||||
|
|
||||||
for (unsigned int i = 0; i < MBED_CONF_APP_DNS_TEST_HOSTS_NUM; i++) {
|
for (unsigned int i = 0; i < MBED_CONF_APP_DNS_TEST_HOSTS_NUM; i++) {
|
||||||
|
|
||||||
|
for (unsigned int interface_index = 0; interface_index < MBED_CONF_MULTIHOMING_MAX_INTERFACES_NUM; interface_index++) {
|
||||||
|
NetworkInterface *interface = get_interface(interface_index);
|
||||||
|
if (interface == NULL) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
for (unsigned int j = 0; j < interface_num; j++) {
|
for (unsigned int j = 0; j < interface_num; j++) {
|
||||||
|
|
||||||
nsapi_error_t err = get_interface()->gethostbyname_async(dns_test_hosts[i],
|
nsapi_error_t err = interface->gethostbyname_async(dns_test_hosts[i],
|
||||||
mbed::Callback<void(nsapi_error_t, SocketAddress *)>(hostbyname_cb, (void *) &data), NSAPI_UNSPEC, interface_name[j]);
|
mbed::Callback<void(nsapi_error_t, SocketAddress *)>(hostbyname_cb, (void *) &data), NSAPI_UNSPEC, interface_name[j]);
|
||||||
TEST_ASSERT(err >= 0);
|
TEST_ASSERT(err >= 0);
|
||||||
|
|
||||||
|
@ -83,7 +89,7 @@ void MULTIHOMING_ASYNCHRONOUS_DNS()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,9 +44,16 @@ void MULTIHOMING_SYNCHRONOUS_DNS()
|
||||||
|
|
||||||
for (unsigned int i = 0; i < MBED_CONF_APP_DNS_TEST_HOSTS_NUM; i++) {
|
for (unsigned int i = 0; i < MBED_CONF_APP_DNS_TEST_HOSTS_NUM; i++) {
|
||||||
SocketAddress address;
|
SocketAddress address;
|
||||||
|
|
||||||
|
for (unsigned int interface_index = 0; interface_index < MBED_CONF_MULTIHOMING_MAX_INTERFACES_NUM; interface_index++) {
|
||||||
|
NetworkInterface *interface = get_interface(interface_index);
|
||||||
|
if (interface == NULL) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
for (unsigned int j = 0; j < interface_num; j++) {
|
for (unsigned int j = 0; j < interface_num; j++) {
|
||||||
|
|
||||||
nsapi_error_t err = get_interface()->gethostbyname(dns_test_hosts[i], &address, NSAPI_UNSPEC, interface_name[j]);
|
nsapi_error_t err = interface->gethostbyname(dns_test_hosts[i], &address, NSAPI_UNSPEC, interface_name[j]);
|
||||||
printf("DNS: query interface_name %s %d \n", interface_name[j], j);
|
printf("DNS: query interface_name %s %d \n", interface_name[j], j);
|
||||||
|
|
||||||
if (err == NSAPI_ERROR_OK) {
|
if (err == NSAPI_ERROR_OK) {
|
||||||
|
@ -65,8 +72,7 @@ void MULTIHOMING_SYNCHRONOUS_DNS()
|
||||||
printf("DNS: query \"%s\" => %d, unexpected answer\n", dns_test_hosts[i], err);
|
printf("DNS: query \"%s\" => %d, unexpected answer\n", dns_test_hosts[i], err);
|
||||||
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_NO_MEMORY || err == NSAPI_ERROR_DNS_FAILURE || err == NSAPI_ERROR_TIMEOUT);
|
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_NO_MEMORY || err == NSAPI_ERROR_DNS_FAILURE || err == NSAPI_ERROR_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "mbed.h"
|
||||||
|
|
||||||
#ifndef MULTIHOMING_TESTS_H
|
#ifndef MULTIHOMING_TESTS_H
|
||||||
#define MULTIHOMING_TESTS_H
|
#define MULTIHOMING_TESTS_H
|
||||||
|
|
||||||
|
@ -22,7 +24,7 @@
|
||||||
#define INTERFACE_NAME_LEN 6
|
#define INTERFACE_NAME_LEN 6
|
||||||
|
|
||||||
#ifndef MBED_CONF_MULTIHOMING_MAX_INTERFACES_NUM
|
#ifndef MBED_CONF_MULTIHOMING_MAX_INTERFACES_NUM
|
||||||
#define MBED_CONF_MULTIHOMING_MAX_INTERFACES_NUM 3
|
#define MBED_CONF_MULTIHOMING_MAX_INTERFACES_NUM 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MBED_CONF_APP_DNS_TEST_HOSTS_NUM
|
#ifndef MBED_CONF_APP_DNS_TEST_HOSTS_NUM
|
||||||
|
@ -36,6 +38,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define ETH_INTERFACE 0
|
||||||
|
#define WIFI_INTERFACE 1
|
||||||
|
|
||||||
|
|
||||||
struct dns_application_data {
|
struct dns_application_data {
|
||||||
|
@ -53,7 +57,7 @@ extern int interface_num;
|
||||||
const char dns_test_hosts[MBED_CONF_APP_DNS_TEST_HOSTS_NUM][DNS_TEST_HOST_LEN] = MBED_CONF_APP_DNS_TEST_HOSTS;
|
const char dns_test_hosts[MBED_CONF_APP_DNS_TEST_HOSTS_NUM][DNS_TEST_HOST_LEN] = MBED_CONF_APP_DNS_TEST_HOSTS;
|
||||||
|
|
||||||
|
|
||||||
NetworkInterface *get_interface();
|
NetworkInterface *get_interface(int interface_index);
|
||||||
void drop_bad_packets(UDPSocket &sock, int orig_timeout);
|
void drop_bad_packets(UDPSocket &sock, int orig_timeout);
|
||||||
void fill_tx_buffer_ascii(char *buff, size_t len);
|
void fill_tx_buffer_ascii(char *buff, size_t len);
|
||||||
|
|
||||||
|
|
|
@ -54,13 +54,18 @@ static void _sigio_handler(osThreadId id)
|
||||||
|
|
||||||
void MULTIHOMING_UDPSOCKET_ECHOTEST()
|
void MULTIHOMING_UDPSOCKET_ECHOTEST()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
for (unsigned int interface_index = 0; interface_index < MBED_CONF_MULTIHOMING_MAX_INTERFACES_NUM; interface_index++) {
|
||||||
|
NetworkInterface *interface = get_interface(interface_index);
|
||||||
|
if (interface == NULL) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
SocketAddress udp_addr;
|
SocketAddress udp_addr;
|
||||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
interface->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||||
udp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
udp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||||
|
|
||||||
UDPSocket sock;
|
UDPSocket sock;
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(interface));
|
||||||
|
|
||||||
for (unsigned int j = 0; j < interface_num; j++) {
|
for (unsigned int j = 0; j < interface_num; j++) {
|
||||||
int recvd;
|
int recvd;
|
||||||
int sent;
|
int sent;
|
||||||
|
@ -98,6 +103,7 @@ void MULTIHOMING_UDPSOCKET_ECHOTEST()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void udpsocket_echotest_nonblock_receiver(void *receive_bytes)
|
void udpsocket_echotest_nonblock_receiver(void *receive_bytes)
|
||||||
|
@ -127,12 +133,15 @@ void MULTIHOMING_UDPSOCKET_ECHOTEST_NONBLOCK()
|
||||||
TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state);
|
TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
for (unsigned int interface_index = 0; interface_index < MBED_CONF_MULTIHOMING_MAX_INTERFACES_NUM; interface_index++) {
|
||||||
|
NetworkInterface *interface = get_interface(interface_index);
|
||||||
|
if (interface == NULL) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
SocketAddress udp_addr;
|
SocketAddress udp_addr;
|
||||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
interface->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||||
udp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
udp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||||
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(interface));
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
|
||||||
sock.set_blocking(false);
|
sock.set_blocking(false);
|
||||||
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));
|
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));
|
||||||
for (unsigned int j = 0; j < interface_num; j++) {
|
for (unsigned int j = 0; j < interface_num; j++) {
|
||||||
|
@ -206,4 +215,5 @@ void MULTIHOMING_UDPSOCKET_ECHOTEST_NONBLOCK()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue