Skip to content

Commit a9db615

Browse files
committed
connectivity-netsocket-tests-tests-network-wifi update
Use default NSAPI configuration
1 parent be31d50 commit a9db615

File tree

8 files changed

+49
-28
lines changed

8 files changed

+49
-28
lines changed

connectivity/netsocket/tests/TESTS/network/wifi/get_interface.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18+
#include "wifi_tests.h"
19+
1820
#define WIFI 2
1921
#if !defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE) || \
2022
MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE != WIFI

connectivity/netsocket/tests/TESTS/network/wifi/get_security.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ nsapi_security get_security()
4747
if (strcmp(MBED_CONF_APP_WIFI_SECURE_PROTOCOL, SEC_WPA3_WPA2) == 0) {
4848
return NSAPI_SECURITY_WPA3_WPA2;
4949
}
50+
#elif defined MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY
51+
#define concat_(x,y) x##y
52+
#define concat(x,y) concat_(x,y)
53+
return concat(NSAPI_SECURITY_, MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY);
5054
#endif
5155
return NSAPI_SECURITY_NONE;
5256
}

connectivity/netsocket/tests/TESTS/network/wifi/main.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,21 @@
2727
#include "utest.h"
2828
#include "wifi_tests.h"
2929

30+
#if !defined(MBED_CONF_APP_WIFI_SECURE_SSID)
31+
#error [NOT_SUPPORTED] Requires secure AP
32+
#endif
33+
3034
// Test for parameters
3135
#if defined(MBED_CONF_APP_WIFI_SECURE_SSID) && \
32-
(!defined(MBED_CONF_APP_AP_MAC_SECURE) || \
33-
!defined(MBED_CONF_APP_MAX_SCAN_SIZE) || \
34-
!defined(MBED_CONF_APP_WIFI_CH_SECURE) || \
36+
(!defined(MBED_CONF_APP_MAX_SCAN_SIZE) || \
3537
!defined(MBED_CONF_APP_WIFI_PASSWORD) || \
36-
!defined(MBED_CONF_APP_WIFI_SECURE_SSID) || \
3738
!defined(MBED_CONF_APP_WIFI_SECURE_PROTOCOL))
3839
#error [NOT_SUPPORTED] Requires parameters from mbed_app.json (for secure connections)
3940
#else
4041

4142
#if defined(MBED_CONF_APP_WIFI_UNSECURE_SSID) && \
42-
(!defined(MBED_CONF_APP_AP_MAC_UNSECURE) || \
43-
!defined(MBED_CONF_APP_MAX_SCAN_SIZE) || \
44-
!defined(MBED_CONF_APP_WIFI_CH_UNSECURE) || \
45-
!defined(MBED_CONF_APP_WIFI_UNSECURE_SSID))
43+
(!defined(MBED_CONF_APP_MAX_SCAN_SIZE) || \
44+
!defined(MBED_CONF_APP_WIFI_CH_UNSECURE))
4645
#error [NOT_SUPPORTED] Requires parameters from mbed_app.json (for unsecure connections)
4746
#else
4847

connectivity/netsocket/tests/TESTS/network/wifi/template_mbed_app.txt

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,35 @@
11
{
22
"config": {
33
"wifi-secure-ssid": {
4-
"help": "WiFi SSID for WPA2 secured network",
4+
"help": "WiFi SSID for secure network",
5+
"optional_parameter": "if value is null, MBED_CONF_NSAPI_DEFAULT_WIFI_SSID is used",
56
"value": "\"SSID-SECURE\""
67
},
78
"wifi-unsecure-ssid": {
8-
"help": "WiFi SSID for unsecure netwrok",
9+
"help": "WiFi SSID for unsecure network",
10+
"optional_parameter": "if value is null, non-secure tests are skipped",
911
"value": "\"SSID-UNSECURE\""
1012
},
1113
"wifi-password": {
1214
"help": "WiFi Password",
15+
"optional_parameter": "if value is null, MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD is used",
1316
"value": "\"PASSWORD\""
1417
},
1518
"wifi-secure-protocol": {
1619
"help": "WiFi security protocol, valid values are WEP, WPA, WPA2, WPA/WPA2",
17-
"value": "\"WPA/WPA2\""
20+
"optional_parameter": "if value is null, MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY is used",
21+
"value": "\"WPA2\""
1822
},
1923
"wifi-ch-secure": {
20-
"help": "Channel number of secure SSID",
24+
"help": "Channel number of secure SSID (if set_channel() is supported)",
2125
"value": 1
2226
},
2327
"wifi-ch-unsecure": {
24-
"help": "Channel number of unsecure SSID",
28+
"help": "Channel number of unsecure SSID (if set_channel() is supported)",
2529
"value": 2
2630
},
27-
"ap-mac-secure": {
28-
"help": "BSSID of secure AP in form of AA:BB:CC:DD:EE:FF",
29-
"value": "\"AA:AA:AA:AA:AA:AA\""
30-
},
31-
"ap-mac-unsecure": {
32-
"help": "BSSID of unsecure AP in form of \"AA:BB:CC:DD:EE:FF\"",
33-
"value": "\"BB:BB:BB:BB:BB:BB\""
34-
},
3531
"max-scan-size": {
36-
"help": "How many networks may appear in Wifi scan result",
32+
"help": "How many networks may appear in Wifi scan result (default is 10)",
3733
"value": 10
3834
}
3935
},

connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_disconnect_repeat.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ void wifi_connect_disconnect_repeat(void)
3434
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, error);
3535

3636
for (int i = 0; i < 10; i++) {
37+
printf("#%u connecting...\n", i);
3738
error = wifi->connect();
3839
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, error);
40+
printf("#%u diconnecting...\n", i);
3941
error = wifi->disconnect();
4042
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, error);
4143
}

connectivity/netsocket/tests/TESTS/network/wifi/wifi_connect_secure_fail.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ void wifi_connect_secure_fail(void)
3131

3232
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(MBED_CONF_APP_WIFI_SECURE_SSID, "aaaaaaaa", get_security()));
3333
nsapi_error_t error;
34+
printf("Wifi connection with wrong password\n");
3435
error = wifi->connect();
36+
printf("=> %d => Wifi disconnection\n", error);
3537
wifi->disconnect();
3638
TEST_ASSERT(error == NSAPI_ERROR_AUTH_FAILURE ||
3739
error == NSAPI_ERROR_CONNECTION_TIMEOUT ||

connectivity/netsocket/tests/TESTS/network/wifi/wifi_scan.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,17 @@ void wifi_scan(void)
3131
WiFiAccessPoint ap[MBED_CONF_APP_MAX_SCAN_SIZE];
3232

3333
int size = wifi->scan(ap, MBED_CONF_APP_MAX_SCAN_SIZE);
34+
printf("Scanned %u AP\n", size);
3435
TEST_ASSERT(size >= 1);
3536

3637
bool secure_found = false;
3738
bool unsecure_found = false;
3839

39-
char secure_bssid[6];
40-
char unsecure_bssid[6];
41-
const char *coversion_string = "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx";
42-
TEST_ASSERT_EQUAL_INT_MESSAGE(6, sscanf(MBED_CONF_APP_AP_MAC_SECURE, coversion_string, &secure_bssid[0], &secure_bssid[1], &secure_bssid[2], &secure_bssid[3], &secure_bssid[4], &secure_bssid[5]), "Failed to convert ap-mac-secure from mbed_app.json");
43-
TEST_ASSERT_EQUAL_INT_MESSAGE(6, sscanf(MBED_CONF_APP_AP_MAC_UNSECURE, coversion_string, &unsecure_bssid[0], &unsecure_bssid[1], &unsecure_bssid[2], &unsecure_bssid[3], &unsecure_bssid[4], &unsecure_bssid[5]), "Failed to convert ap-mac-unsecure from mbed_app.json");
44-
4540
for (int i = 0; i < size; i++) {
4641
const char *ssid = ap[i].get_ssid();
4742
nsapi_security_t security = ap[i].get_security();
4843
int8_t rssi = ap[i].get_rssi();
44+
printf("AP %u ssid %s security %u rssi %d\n", i, ssid, security, rssi);
4945
TEST_ASSERT_INT8_WITHIN(-10, -100, rssi);
5046
#if defined(MBED_CONF_APP_WIFI_SECURE_SSID)
5147
if (strcmp(MBED_CONF_APP_WIFI_SECURE_SSID, ssid) == 0) {

connectivity/netsocket/tests/TESTS/network/wifi/wifi_tests.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,26 @@
1919

2020
#include "WiFiInterface.h"
2121

22+
#if !defined(MBED_CONF_APP_WIFI_SECURE_SSID)
23+
#define MBED_CONF_APP_WIFI_SECURE_SSID MBED_CONF_NSAPI_DEFAULT_WIFI_SSID
24+
#endif
25+
26+
#if !defined(MBED_CONF_APP_WIFI_PASSWORD)
27+
#define MBED_CONF_APP_WIFI_PASSWORD MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD
28+
#endif
29+
30+
#if !defined(MBED_CONF_APP_WIFI_SECURE_PROTOCOL)
31+
#define MBED_CONF_APP_WIFI_SECURE_PROTOCOL MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY
32+
#endif
33+
34+
#if !defined(MBED_CONF_APP_WIFI_CH_SECURE)
35+
#define MBED_CONF_APP_WIFI_CH_SECURE 1
36+
#endif
37+
38+
#if !defined(MBED_CONF_APP_MAX_SCAN_SIZE)
39+
#define MBED_CONF_APP_MAX_SCAN_SIZE 10
40+
#endif
41+
2242
/** Get WiFiInterface based on provided
2343
* app_json. */
2444
WiFiInterface *get_interface(void);

0 commit comments

Comments
 (0)