Skip to content

Commit 42532d7

Browse files
Merge pull request #5161 from SeppoTakalo/wifi_tests
Implement functional Wifi tests
2 parents d6136b9 + 429b068 commit 42532d7

20 files changed

+846
-186
lines changed

TESTS/network/wifi/get_interface.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2017, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "mbed.h"
19+
20+
// Pick the correct driver based on mbed_app.json
21+
#define INTERNAL 1
22+
#define WIFI_ESP8266 2
23+
#define X_NUCLEO_IDW01M1 3
24+
25+
#if MBED_CONF_APP_WIFI_DRIVER == INTERNAL
26+
27+
#if TARGET_UBLOX_EVK_ODIN_W2
28+
#include "OdinWiFiInterface.h"
29+
#define DRIVER OdinWiFiInterface
30+
31+
#elif TARGET_REALTEK_RTL8195AM
32+
#include "RTWInterface.h"
33+
#define DRIVER RTWInterface
34+
#else
35+
#error [NOT_SUPPORTED] Unsupported Wifi driver
36+
#endif
37+
38+
#elif MBED_CONF_APP_WIFI_DRIVER == WIFI_ESP8266
39+
#include "ESP8266Interface.h"
40+
#define DRIVER ESP8266Interface
41+
42+
#elif MBED_CONF_APP_WIFI_DRIVER == X_NUCLEO_IDW01M1
43+
#include "SpwfSAInterface.h"
44+
#define DRIVER SpwfSAInterface
45+
#else
46+
#error [NOT_SUPPORTED] Unsupported Wifi driver
47+
#endif
48+
49+
WiFiInterface *get_interface()
50+
{
51+
static WiFiInterface *interface = NULL;
52+
53+
if (interface)
54+
delete interface;
55+
56+
#if MBED_CONF_APP_WIFI_DRIVER == INTERNAL
57+
interface = new DRIVER();
58+
#else
59+
interface = new DRIVER(MBED_CONF_APP_WIFI_TX, MBED_CONF_APP_WIFI_RX);
60+
#endif
61+
return interface;
62+
}

TESTS/network/wifi/main.cpp

Lines changed: 49 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -1,196 +1,71 @@
1-
/* mbed Microcontroller Library
2-
* Copyright (c) 2016 ARM Limited
1+
/*
2+
* Copyright (c) 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
*/
1617

17-
#include "utest/utest.h"
18-
#include "unity/unity.h"
19-
#include "greentea-client/test_env.h"
20-
2118
#include "mbed.h"
22-
23-
#if TARGET_UBLOX_EVK_ODIN_W2
24-
#include "OdinWiFiInterface.h"
25-
#else
26-
#error [NOT_SUPPORTED] Only built in WiFi modules are supported at this time.
19+
#include "greentea-client/test_env.h"
20+
#include "unity.h"
21+
#include "utest.h"
22+
#include "wifi_tests.h"
23+
24+
// Test for parameters
25+
#if !defined(MBED_CONF_APP_AP_MAC_SECURE) || \
26+
!defined(MBED_CONF_APP_AP_MAC_UNSECURE) || \
27+
!defined(MBED_CONF_APP_MAX_SCAN_SIZE) || \
28+
!defined(MBED_CONF_APP_WIFI_CH_SECURE) || \
29+
!defined(MBED_CONF_APP_WIFI_CH_UNSECURE) || \
30+
!defined(MBED_CONF_APP_WIFI_DRIVER) || \
31+
!defined(MBED_CONF_APP_WIFI_PASSWORD) || \
32+
!defined(MBED_CONF_APP_WIFI_RX) || \
33+
!defined(MBED_CONF_APP_WIFI_SECURE_SSID) || \
34+
!defined(MBED_CONF_APP_WIFI_TX) || \
35+
!defined(MBED_CONF_APP_WIFI_UNSECURE_SSID)
36+
#error [NOT_SUPPORTED] Requires parameters from mbed_app.json
2737
#endif
2838

2939
using namespace utest::v1;
3040

31-
/**
32-
* WiFi tests require following macros to be defined:
33-
* - MBED_CONF_APP_WIFI_SSID - SSID of a network the test will try connecting to
34-
* - MBED_CONF_APP_WIFI_PASSWORD - Passphrase that will be used to connecting to the network
35-
* - WIFI_TEST_NETWORKS - List of network that presence will be asserted e.g. "net1", "net2", "net3"
36-
*/
37-
#if !defined(MBED_CONF_APP_WIFI_SSID) || !defined(MBED_CONF_APP_WIFI_PASSWORD) || !defined(MBED_CONF_APP_WIFI_NETWORKS)
38-
#error [NOT_SUPPORTED] MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD and MBED_CONF_APP_WIFI_NETWORKS have to be defined for this test.
39-
#endif
40-
41-
const char *networks[] = {MBED_CONF_APP_WIFI_NETWORKS, NULL};
42-
43-
WiFiInterface *wifi;
44-
45-
/* In normal circumstances the WiFi object could be global, but the delay introduced by WiFi initialization is an issue
46-
for the tests. It causes Greentea to timeout on syncing with the board. To solve it we defer the actual object
47-
creation till we actually need it.
48-
*/
49-
WiFiInterface *get_wifi()
50-
{
51-
if (wifi == NULL) {
52-
/* We don't really care about freeing this, as its lifetime is through the full test suit run. */
53-
#if TARGET_UBLOX_EVK_ODIN_W2
54-
wifi = new OdinWiFiInterface;
55-
#endif
56-
}
57-
58-
return wifi;
59-
}
60-
61-
void check_wifi(const char *ssid, bool *net_stat)
62-
{
63-
int i = 0;
64-
while(networks[i]) {
65-
if (strcmp(networks[i], ssid) == 0) {
66-
net_stat[i] = true;
67-
break;
68-
}
69-
i++;
70-
}
71-
}
72-
73-
void wifi_scan()
74-
{
75-
int count;
76-
WiFiAccessPoint *aps;
77-
const int net_len = sizeof(networks)/sizeof(networks[0]);
78-
bool net_stat[net_len - 1];
79-
80-
memset(net_stat, 0, sizeof(net_stat));
81-
82-
count = get_wifi()->scan(NULL, 0);
83-
TEST_ASSERT_MESSAGE(count >= 0, "WiFi interface returned error");
84-
TEST_ASSERT_MESSAGE(count > 0, "Scan result empty");
85-
86-
aps = new WiFiAccessPoint[count];
87-
count = get_wifi()->scan(aps, count);
88-
for(int i = 0; i < count; i++) {
89-
check_wifi(aps[i].get_ssid(), net_stat);
90-
}
91-
92-
delete[] aps;
93-
94-
for (unsigned i = 0; i < sizeof(net_stat); i++) {
95-
TEST_ASSERT_MESSAGE(net_stat[i] == true, "Not all required WiFi network detected");
96-
}
97-
}
98-
99-
void wifi_connect()
100-
{
101-
int ret;
102-
103-
ret = get_wifi()->connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2);
104-
TEST_ASSERT_MESSAGE(ret == 0, "Connect failed");
105-
106-
ret = get_wifi()->disconnect();
107-
TEST_ASSERT_MESSAGE(ret == 0, "Disconnect failed");
108-
}
109-
110-
void wifi_connect_scan()
111-
{
112-
int ret;
113-
int count;
114-
WiFiAccessPoint *aps;
115-
const int net_len = sizeof(networks)/sizeof(networks[0]);
116-
bool net_stat[net_len - 1];
117-
118-
memset(net_stat, 0, sizeof(net_stat));
119-
120-
ret = get_wifi()->connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2);
121-
TEST_ASSERT_MESSAGE(ret == 0, "Connect failed");
122-
123-
count = get_wifi()->scan(NULL, 0);
124-
TEST_ASSERT_MESSAGE(count >= 0, "WiFi interface returned error");
125-
TEST_ASSERT_MESSAGE(count > 0, "Scan result empty");
126-
127-
aps = new WiFiAccessPoint[count];
128-
count = get_wifi()->scan(aps, count);
129-
for(int i = 0; i < count; i++) {
130-
check_wifi(aps[i].get_ssid(), net_stat);
131-
}
132-
133-
delete[] aps;
134-
135-
ret = get_wifi()->disconnect();
136-
TEST_ASSERT_MESSAGE(ret == 0, "Disconnect failed");
137-
138-
for (unsigned i = 0; i < sizeof(net_stat); i++) {
139-
TEST_ASSERT_MESSAGE(net_stat[i] == true, "Not all required WiFi network detected");
140-
}
141-
}
142-
143-
void wifi_http()
144-
{
145-
TCPSocket socket;
146-
int ret;
147-
148-
ret = get_wifi()->connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2);
149-
TEST_ASSERT_MESSAGE(ret == 0, "Connect failed");
150-
151-
// Open a socket on the network interface, and create a TCP connection to www.arm.com
152-
ret = socket.open(get_wifi());
153-
TEST_ASSERT_MESSAGE(ret == 0, "Socket open failed");
154-
ret = socket.connect("www.arm.com", 80);
155-
TEST_ASSERT_MESSAGE(ret == 0, "Socket connect failed");
156-
157-
// Send a simple http request
158-
char sbuffer[] = "GET / HTTP/1.1\r\nHost: www.arm.com\r\n\r\n";
159-
int scount = socket.send(sbuffer, sizeof sbuffer);
160-
TEST_ASSERT_MESSAGE(scount >= 0, "Socket send failed");
161-
162-
// Recieve a simple http response and check if it's not empty
163-
char rbuffer[64];
164-
int rcount = socket.recv(rbuffer, sizeof rbuffer);
165-
TEST_ASSERT_MESSAGE(rcount >= 0, "Socket recv error");
166-
TEST_ASSERT_MESSAGE(rcount > 0, "No data received");
167-
168-
ret = socket.close();
169-
TEST_ASSERT_MESSAGE(ret == 0, "Socket close failed");
170-
171-
ret = get_wifi()->disconnect();
172-
TEST_ASSERT_MESSAGE(ret == 0, "Disconnect failed");
173-
}
174-
175-
status_t greentea_failure_handler(const Case *const source, const failure_t reason) {
176-
greentea_case_failure_abort_handler(source, reason);
177-
return STATUS_CONTINUE;
41+
utest::v1::status_t test_setup(const size_t number_of_cases) {
42+
GREENTEA_SETUP(240, "default_auto");
43+
return verbose_test_setup_handler(number_of_cases);
17844
}
17945

46+
// Test cases
18047
Case cases[] = {
181-
Case("Scan test", wifi_scan, greentea_failure_handler),
182-
Case("Connect test", wifi_connect, greentea_failure_handler),
183-
Case("Scan while connected test", wifi_connect_scan, greentea_failure_handler),
184-
Case("HTTP test", wifi_http, greentea_failure_handler),
48+
Case("WIFI-CONSTRUCTOR", wifi_constructor),
49+
Case("WIFI-SET-CREDENTIAL", wifi_set_credential),
50+
Case("WIFI-SET-CHANNEL", wifi_set_channel),
51+
Case("WIFI-GET-RSSI", wifi_get_rssi),
52+
Case("WIFI-CONNECT-PARAMS-NULL", wifi_connect_params_null),
53+
Case("WIFI-CONNECT-PARAMS-VALID-UNSECURE", wifi_connect_params_valid_unsecure),
54+
Case("WIFI-CONNECT-PARAMS-VALID-SECURE", wifi_connect_params_valid_secure),
55+
Case("WIFI-CONNECT-PARAMS-CHANNEL", wifi_connect_params_channel),
56+
Case("WIFI-CONNECT-PARAMS-CHANNEL-FAIL", wifi_connect_params_channel_fail),
57+
Case("WIFI-CONNECT-NOCREDENTIALS", wifi_connect_nocredentials),
58+
Case("WIFI-CONNECT", wifi_connect),
59+
Case("WIFI-CONNECT-SECURE", wifi_connect_secure),
60+
Case("WIFI-CONNECT-SECURE-FAIL", wifi_connect_secure_fail),
61+
Case("WIFI-CONNECT-DISCONNECT-REPEAT", wifi_connect_disconnect_repeat),
62+
Case("WIFI-SCAN-NULL", wifi_scan_null),
63+
Case("WIFI-SCAN", wifi_scan),
18564
};
18665

187-
status_t greentea_test_setup(const size_t number_of_cases) {
188-
GREENTEA_SETUP(90, "default_auto");
189-
return greentea_test_setup_handler(number_of_cases);
190-
}
191-
66+
Specification specification(test_setup, cases);
19267

68+
// Entry point into the tests
19369
int main() {
194-
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
195-
Harness::run(specification);
70+
return !Harness::run(specification);
19671
}
Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,48 @@
11
{
22
"config": {
3-
"wifi-ssid": {
4-
"help": "WiFi SSID",
5-
"value": "\"SSID\""
3+
"wifi-secure-ssid": {
4+
"help": "WiFi SSID for WPA2 secured network",
5+
"value": "\"SSID-SECURE\""
6+
},
7+
"wifi-unsecure-ssid": {
8+
"help": "WiFi SSID for unsecure netwrok",
9+
"value": "\"SSID-UNSECURE\""
610
},
711
"wifi-password": {
812
"help": "WiFi Password",
9-
"value": "\"PASS\""
13+
"value": "\"PASSWORD\""
1014
},
11-
"wifi-networks": {
12-
"help": "WiFi SSIDs which presence will be asserted in the test",
13-
"value": "\"SSID1\",\"SSID2\",\"SSID3\""
14-
}
15-
},
16-
"target_overrides": {
17-
"UBLOX_EVK_ODIN_W2": {
18-
"target.device_has": ["EMAC"]
15+
"wifi-ch-secure": {
16+
"help": "Channel number of secure SSID",
17+
"value": 1
18+
},
19+
"wifi-ch-unsecure": {
20+
"help": "Channel number of unsecure SSID",
21+
"value": 2
22+
},
23+
"wifi-driver": {
24+
"help": "Wifi driver to use, valid values are INTERNAL, WIFI_ESP8266 and X_NUCLEO_IDW01M1",
25+
"value": "INTERNAL"
26+
},
27+
"wifi-tx": {
28+
"help": "TX pin for serial connection to external device",
29+
"value": "D1"
30+
},
31+
"wifi-rx": {
32+
"help": "RX pin for serial connection to external device",
33+
"value": "D0"
34+
},
35+
"ap-mac-secure": {
36+
"help": "BSSID of secure AP in form of AA:BB:CC:DD:EE:FF",
37+
"value": "\"AA:AA:AA:AA:AA:AA\""
38+
},
39+
"ap-mac-unsecure": {
40+
"help": "BSSID of unsecure AP in form of \"AA:BB:CC:DD:EE:FF\"",
41+
"value": "\"BB:BB:BB:BB:BB:BB\""
42+
},
43+
"max-scan-size": {
44+
"help": "How many networks may appear in Wifi scan result",
45+
"value": 10
1946
}
2047
}
2148
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2017, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "mbed.h"
19+
#include "greentea-client/test_env.h"
20+
#include "unity.h"
21+
#include "utest.h"
22+
#include "wifi_tests.h"
23+
24+
using namespace utest::v1;
25+
26+
void wifi_constructor() {
27+
WiFiInterface *wifi = get_interface();
28+
TEST_ASSERT(wifi);
29+
}

0 commit comments

Comments
 (0)