|
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 |
3 | 4 | *
|
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. |
6 | 7 | * You may obtain a copy of the License at
|
7 | 8 | *
|
8 |
| - * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
9 | 10 | *
|
10 | 11 | * 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. |
13 | 14 | * See the License for the specific language governing permissions and
|
14 | 15 | * limitations under the License.
|
15 | 16 | */
|
16 | 17 |
|
17 |
| -#include "utest/utest.h" |
18 |
| -#include "unity/unity.h" |
19 |
| -#include "greentea-client/test_env.h" |
20 |
| - |
21 | 18 | #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 |
27 | 37 | #endif
|
28 | 38 |
|
29 | 39 | using namespace utest::v1;
|
30 | 40 |
|
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); |
178 | 44 | }
|
179 | 45 |
|
| 46 | +// Test cases |
180 | 47 | 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), |
185 | 64 | };
|
186 | 65 |
|
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); |
192 | 67 |
|
| 68 | +// Entry point into the tests |
193 | 69 | int main() {
|
194 |
| - Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); |
195 |
| - Harness::run(specification); |
| 70 | + return !Harness::run(specification); |
196 | 71 | }
|
0 commit comments