Skip to content

Commit e3cb228

Browse files
Merge pull request #4795 from sarahmarshy/test-configs
Add configurable network driver tests
2 parents c063e25 + fbe8dfa commit e3cb228

File tree

27 files changed

+934
-632
lines changed

27 files changed

+934
-632
lines changed

features/FEATURE_LWIP/TESTS/mbedmicro-net/connectivity/main.cpp renamed to TESTS/netsocket/connectivity/main.cpp

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,57 @@
1-
/* mbed Microcontroller Library
2-
* Copyright (c) 2017 ARM Limited
1+
/*
2+
* Copyright (c) 2013-2017, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
34
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
67
* You may obtain a copy of the License at
78
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9+
* http://www.apache.org/licenses/LICENSE-2.0
910
*
1011
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1314
* See the License for the specific language governing permissions and
1415
* limitations under the License.
1516
*/
16-
#if !FEATURE_LWIP
17-
#error [NOT_SUPPORTED] LWIP not supported for this target
18-
#endif
19-
#if DEVICE_EMAC
20-
#error [NOT_SUPPORTED] Not supported for WiFi targets
21-
#endif
17+
18+
#ifndef MBED_CONF_APP_CONNECT_STATEMENT
19+
#error [NOT_SUPPORTED] No network configuration found for this target.
20+
#endif
2221

2322
#include "mbed.h"
2423
#include "greentea-client/test_env.h"
2524
#include "unity.h"
2625
#include "utest.h"
27-
28-
#include "EthernetInterface.h"
26+
#include MBED_CONF_APP_HEADER_FILE
2927

3028
using namespace utest::v1;
3129

32-
3330
// Bringing the network up and down
3431
template <int COUNT>
3532
void test_bring_up_down() {
36-
EthernetInterface eth;
33+
NetworkInterface* net = MBED_CONF_APP_OBJECT_CONSTRUCTION;
3734

3835
for (int i = 0; i < COUNT; i++) {
39-
int err = eth.connect();
36+
int err = MBED_CONF_APP_CONNECT_STATEMENT;
4037
TEST_ASSERT_EQUAL(0, err);
4138

42-
printf("MBED: IP Address %s\r\n", eth.get_ip_address());
43-
printf("MBED: Netmask %s\r\n", eth.get_netmask());
44-
printf("MBED: Gateway %s\r\n", eth.get_gateway());
45-
TEST_ASSERT(eth.get_ip_address());
46-
TEST_ASSERT(eth.get_netmask());
47-
TEST_ASSERT(eth.get_gateway());
39+
printf("MBED: IP Address %s\r\n", net->get_ip_address());
40+
TEST_ASSERT(net->get_ip_address());
4841

4942
UDPSocket udp;
50-
err = udp.open(&eth);
43+
err = udp.open(net);
5144
TEST_ASSERT_EQUAL(0, err);
5245
err = udp.close();
5346
TEST_ASSERT_EQUAL(0, err);
5447

5548
TCPSocket tcp;
56-
err = tcp.open(&eth);
49+
err = tcp.open(net);
5750
TEST_ASSERT_EQUAL(0, err);
5851
err = tcp.close();
5952
TEST_ASSERT_EQUAL(0, err);
6053

61-
err = eth.disconnect();
54+
err = net->disconnect();
6255
TEST_ASSERT_EQUAL(0, err);
6356
}
6457
}

features/FEATURE_LWIP/TESTS/mbedmicro-net/gethostbyname/main.cpp renamed to TESTS/netsocket/gethostbyname/main.cpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
1-
/* mbed Microcontroller Library
2-
* Copyright (c) 2017 ARM Limited
1+
/*
2+
* Copyright (c) 2013-2017, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
34
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
67
* You may obtain a copy of the License at
78
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9+
* http://www.apache.org/licenses/LICENSE-2.0
910
*
1011
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1314
* See the License for the specific language governing permissions and
1415
* limitations under the License.
1516
*/
16-
#if !FEATURE_LWIP
17-
#error [NOT_SUPPORTED] LWIP not supported for this target
18-
#endif
19-
#if DEVICE_EMAC
20-
#error [NOT_SUPPORTED] Not supported for WiFi targets
21-
#endif
17+
18+
#ifndef MBED_CONF_APP_CONNECT_STATEMENT
19+
#error [NOT_SUPPORTED] No network configuration found for this target.
20+
#endif
2221

2322
#include "mbed.h"
2423
#include "greentea-client/test_env.h"
2524
#include "unity.h"
2625
#include "utest.h"
27-
#include "EthernetInterface.h"
26+
#include MBED_CONF_APP_HEADER_FILE
2827

2928
using namespace utest::v1;
3029

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

36+
3737
// Address info from stack
3838
const char *ip_literal;
3939
nsapi_version_t ip_pref;
4040
const char *ip_pref_repr;
4141

4242
// Network setup
43-
EthernetInterface net;
43+
NetworkInterface *net;
44+
4445
void net_bringup() {
45-
int err = net.connect();
46+
net = MBED_CONF_APP_OBJECT_CONSTRUCTION;
47+
int err = MBED_CONF_APP_CONNECT_STATEMENT;
4648
TEST_ASSERT_EQUAL(0, err);
4749
printf("MBED: Connected to network\n");
48-
printf("MBED: IP Address: %s\n", net.get_ip_address());
50+
printf("MBED: IP Address: %s\n", net->get_ip_address());
4951

50-
ip_literal = net.get_ip_address();
52+
ip_literal = net->get_ip_address();
5153
ip_pref = SocketAddress(ip_literal).get_ip_version();
5254
ip_pref_repr = (ip_pref == NSAPI_IPv4) ? "ipv4" :
5355
(ip_pref == NSAPI_IPv6) ? "ipv6" : "unspec";
@@ -57,7 +59,7 @@ void net_bringup() {
5759
// DNS tests
5860
void test_dns_query() {
5961
SocketAddress addr;
60-
int err = net.gethostbyname(MBED_DNS_TEST_HOST, &addr);
62+
int err = net->gethostbyname(MBED_DNS_TEST_HOST, &addr);
6163
printf("DNS: query \"%s\" => \"%s\"\n",
6264
MBED_DNS_TEST_HOST, addr.get_ip_address());
6365

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

6971
void test_dns_query_pref() {
7072
SocketAddress addr;
71-
int err = net.gethostbyname(MBED_DNS_TEST_HOST, &addr, ip_pref);
73+
int err = net->gethostbyname(MBED_DNS_TEST_HOST, &addr, ip_pref);
7274
printf("DNS: query %s \"%s\" => \"%s\"\n",
7375
ip_pref_repr, MBED_DNS_TEST_HOST, addr.get_ip_address());
7476

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

8183
void test_dns_literal() {
8284
SocketAddress addr;
83-
int err = net.gethostbyname(ip_literal, &addr);
85+
int err = net->gethostbyname(ip_literal, &addr);
8486
printf("DNS: literal \"%s\" => \"%s\"\n",
8587
ip_literal, addr.get_ip_address());
8688

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

9395
void test_dns_literal_pref() {
9496
SocketAddress addr;
95-
int err = net.gethostbyname(ip_literal, &addr, ip_pref);
97+
int err = net->gethostbyname(ip_literal, &addr, ip_pref);
9698
printf("DNS: literal %s \"%s\" => \"%s\"\n",
9799
ip_pref_repr, ip_literal, addr.get_ip_address());
98100

TESTS/netsocket/ip_parsing/main.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
/* mbed Microcontroller Library
2-
* Copyright (c) 2017 ARM Limited
1+
/*
2+
* Copyright (c) 2013-2017, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
34
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
67
* You may obtain a copy of the License at
78
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9+
* http://www.apache.org/licenses/LICENSE-2.0
910
*
1011
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1314
* See the License for the specific language governing permissions and
1415
* limitations under the License.
1516
*/
17+
18+
#ifndef MBED_CONF_APP_CONNECT_STATEMENT
19+
#error [NOT_SUPPORTED] No network configuration found for this target.
20+
#endif
21+
1622
#include "mbed.h"
1723
#include "greentea-client/test_env.h"
1824
#include "unity.h"

0 commit comments

Comments
 (0)