Skip to content

Add configurable network driver tests #4795

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Sep 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,64 +1,57 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
/*
* Copyright (c) 2013-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.
* 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
* 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.
* 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.
*/
#if !FEATURE_LWIP
#error [NOT_SUPPORTED] LWIP not supported for this target
#endif
#if DEVICE_EMAC
#error [NOT_SUPPORTED] Not supported for WiFi targets
#endif

#ifndef MBED_CONF_APP_CONNECT_STATEMENT
#error [NOT_SUPPORTED] No network configuration found for this target.
#endif

#include "mbed.h"
#include "greentea-client/test_env.h"
#include "unity.h"
#include "utest.h"

#include "EthernetInterface.h"
#include MBED_CONF_APP_HEADER_FILE

using namespace utest::v1;


// Bringing the network up and down
template <int COUNT>
void test_bring_up_down() {
EthernetInterface eth;
NetworkInterface* net = MBED_CONF_APP_OBJECT_CONSTRUCTION;

for (int i = 0; i < COUNT; i++) {
int err = eth.connect();
int err = MBED_CONF_APP_CONNECT_STATEMENT;
TEST_ASSERT_EQUAL(0, err);

printf("MBED: IP Address %s\r\n", eth.get_ip_address());
printf("MBED: Netmask %s\r\n", eth.get_netmask());
printf("MBED: Gateway %s\r\n", eth.get_gateway());
TEST_ASSERT(eth.get_ip_address());
TEST_ASSERT(eth.get_netmask());
TEST_ASSERT(eth.get_gateway());
printf("MBED: IP Address %s\r\n", net->get_ip_address());
TEST_ASSERT(net->get_ip_address());

UDPSocket udp;
err = udp.open(&eth);
err = udp.open(net);
TEST_ASSERT_EQUAL(0, err);
err = udp.close();
TEST_ASSERT_EQUAL(0, err);

TCPSocket tcp;
err = tcp.open(&eth);
err = tcp.open(net);
TEST_ASSERT_EQUAL(0, err);
err = tcp.close();
TEST_ASSERT_EQUAL(0, err);

err = eth.disconnect();
err = net->disconnect();
TEST_ASSERT_EQUAL(0, err);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
/*
* Copyright (c) 2013-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.
* 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
* 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.
* 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.
*/
#if !FEATURE_LWIP
#error [NOT_SUPPORTED] LWIP not supported for this target
#endif
#if DEVICE_EMAC
#error [NOT_SUPPORTED] Not supported for WiFi targets
#endif

#ifndef MBED_CONF_APP_CONNECT_STATEMENT
#error [NOT_SUPPORTED] No network configuration found for this target.
#endif

#include "mbed.h"
#include "greentea-client/test_env.h"
#include "unity.h"
#include "utest.h"
#include "EthernetInterface.h"
#include MBED_CONF_APP_HEADER_FILE

using namespace utest::v1;

Expand All @@ -34,20 +33,23 @@ using namespace utest::v1;
#define MBED_DNS_TEST_HOST "connector.mbed.com"
#endif


// Address info from stack
const char *ip_literal;
nsapi_version_t ip_pref;
const char *ip_pref_repr;

// Network setup
EthernetInterface net;
NetworkInterface *net;

void net_bringup() {
int err = net.connect();
net = MBED_CONF_APP_OBJECT_CONSTRUCTION;
int err = MBED_CONF_APP_CONNECT_STATEMENT;
TEST_ASSERT_EQUAL(0, err);
printf("MBED: Connected to network\n");
printf("MBED: IP Address: %s\n", net.get_ip_address());
printf("MBED: IP Address: %s\n", net->get_ip_address());

ip_literal = net.get_ip_address();
ip_literal = net->get_ip_address();
ip_pref = SocketAddress(ip_literal).get_ip_version();
ip_pref_repr = (ip_pref == NSAPI_IPv4) ? "ipv4" :
(ip_pref == NSAPI_IPv6) ? "ipv6" : "unspec";
Expand All @@ -57,7 +59,7 @@ void net_bringup() {
// DNS tests
void test_dns_query() {
SocketAddress addr;
int err = net.gethostbyname(MBED_DNS_TEST_HOST, &addr);
int err = net->gethostbyname(MBED_DNS_TEST_HOST, &addr);
printf("DNS: query \"%s\" => \"%s\"\n",
MBED_DNS_TEST_HOST, addr.get_ip_address());

Expand All @@ -68,7 +70,7 @@ void test_dns_query() {

void test_dns_query_pref() {
SocketAddress addr;
int err = net.gethostbyname(MBED_DNS_TEST_HOST, &addr, ip_pref);
int err = net->gethostbyname(MBED_DNS_TEST_HOST, &addr, ip_pref);
printf("DNS: query %s \"%s\" => \"%s\"\n",
ip_pref_repr, MBED_DNS_TEST_HOST, addr.get_ip_address());

Expand All @@ -80,7 +82,7 @@ void test_dns_query_pref() {

void test_dns_literal() {
SocketAddress addr;
int err = net.gethostbyname(ip_literal, &addr);
int err = net->gethostbyname(ip_literal, &addr);
printf("DNS: literal \"%s\" => \"%s\"\n",
ip_literal, addr.get_ip_address());

Expand All @@ -92,7 +94,7 @@ void test_dns_literal() {

void test_dns_literal_pref() {
SocketAddress addr;
int err = net.gethostbyname(ip_literal, &addr, ip_pref);
int err = net->gethostbyname(ip_literal, &addr, ip_pref);
printf("DNS: literal %s \"%s\" => \"%s\"\n",
ip_pref_repr, ip_literal, addr.get_ip_address());

Expand Down
20 changes: 13 additions & 7 deletions TESTS/netsocket/ip_parsing/main.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
/*
* Copyright (c) 2013-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.
* 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
* 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.
* 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_CONF_APP_CONNECT_STATEMENT
#error [NOT_SUPPORTED] No network configuration found for this target.
#endif

#include "mbed.h"
#include "greentea-client/test_env.h"
#include "unity.h"
Expand Down
Loading