Skip to content

connectivity-netsocket-tests-tests-network-wifi test suite configuration simplification #15031

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 2 commits into from
Sep 9, 2021
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
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

#include "wifi_tests.h"

#define WIFI 2
#if !defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE) || \
MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE != WIFI
Expand All @@ -25,7 +27,6 @@
#else

#include "mbed.h"
#include "WiFiInterface.h"

WiFiInterface *get_interface()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ nsapi_security get_security()
if (strcmp(MBED_CONF_APP_WIFI_SECURE_PROTOCOL, SEC_WPA3_WPA2) == 0) {
return NSAPI_SECURITY_WPA3_WPA2;
}
#elif defined MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY
return MBED_CONCAT(NSAPI_SECURITY_, MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY);
#endif
return NSAPI_SECURITY_NONE;
}
15 changes: 7 additions & 8 deletions connectivity/netsocket/tests/TESTS/network/wifi/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,21 @@
#include "utest.h"
#include "wifi_tests.h"

#if !defined(MBED_CONF_APP_WIFI_SECURE_SSID)
#error [NOT_SUPPORTED] Requires secure AP
#endif

// Test for parameters
#if defined(MBED_CONF_APP_WIFI_SECURE_SSID) && \
(!defined(MBED_CONF_APP_AP_MAC_SECURE) || \
!defined(MBED_CONF_APP_MAX_SCAN_SIZE) || \
!defined(MBED_CONF_APP_WIFI_CH_SECURE) || \
(!defined(MBED_CONF_APP_MAX_SCAN_SIZE) || \
!defined(MBED_CONF_APP_WIFI_PASSWORD) || \
!defined(MBED_CONF_APP_WIFI_SECURE_SSID) || \
!defined(MBED_CONF_APP_WIFI_SECURE_PROTOCOL))
#error [NOT_SUPPORTED] Requires parameters from mbed_app.json (for secure connections)
#else

#if defined(MBED_CONF_APP_WIFI_UNSECURE_SSID) && \
(!defined(MBED_CONF_APP_AP_MAC_UNSECURE) || \
!defined(MBED_CONF_APP_MAX_SCAN_SIZE) || \
!defined(MBED_CONF_APP_WIFI_CH_UNSECURE) || \
!defined(MBED_CONF_APP_WIFI_UNSECURE_SSID))
(!defined(MBED_CONF_APP_MAX_SCAN_SIZE) || \
!defined(MBED_CONF_APP_WIFI_CH_UNSECURE))
#error [NOT_SUPPORTED] Requires parameters from mbed_app.json (for unsecure connections)
#else

Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
{
"config": {
"wifi-secure-ssid": {
"help": "WiFi SSID for WPA2 secured network",
"help": "WiFi SSID for secure network",
"optional_parameter": "if value is null, MBED_CONF_NSAPI_DEFAULT_WIFI_SSID is used",
"value": "\"SSID-SECURE\""
},
"wifi-unsecure-ssid": {
"help": "WiFi SSID for unsecure netwrok",
"help": "WiFi SSID for unsecure network",
"optional_parameter": "if value is null, non-secure tests are skipped",
"value": "\"SSID-UNSECURE\""
},
"wifi-password": {
"help": "WiFi Password",
"optional_parameter": "if value is null, MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD is used",
"value": "\"PASSWORD\""
},
"wifi-secure-protocol": {
"help": "WiFi security protocol, valid values are WEP, WPA, WPA2, WPA/WPA2",
"value": "\"WPA/WPA2\""
"optional_parameter": "if value is null, MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY is used",
"value": "\"WPA2\""
},
"wifi-ch-secure": {
"help": "Channel number of secure SSID",
"help": "Channel number of secure SSID (if set_channel() is supported)",
"value": 1
},
"wifi-ch-unsecure": {
"help": "Channel number of unsecure SSID",
"help": "Channel number of unsecure SSID (if set_channel() is supported)",
"value": 2
},
"ap-mac-secure": {
"help": "BSSID of secure AP in form of AA:BB:CC:DD:EE:FF",
"value": "\"AA:AA:AA:AA:AA:AA\""
},
"ap-mac-unsecure": {
"help": "BSSID of unsecure AP in form of \"AA:BB:CC:DD:EE:FF\"",
"value": "\"BB:BB:BB:BB:BB:BB\""
},
"max-scan-size": {
"help": "How many networks may appear in Wifi scan result",
"help": "How many networks may appear in Wifi scan result (default is 10)",
"value": 10
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ void wifi_connect_disconnect_repeat(void)
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, error);

for (int i = 0; i < 10; i++) {
printf("#%u connecting...\n", i);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add separate commit for adding these debug messages (I would like to understand why are they being added)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@0xc0170 Done

error = wifi->connect();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, error);
printf("#%u diconnecting...\n", i);
error = wifi->disconnect();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ void wifi_connect_secure_fail(void)

TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(MBED_CONF_APP_WIFI_SECURE_SSID, "aaaaaaaa", get_security()));
nsapi_error_t error;
printf("Wifi connection with wrong password\n");
error = wifi->connect();
printf("=> %d => Wifi disconnection\n", error);
wifi->disconnect();
TEST_ASSERT(error == NSAPI_ERROR_AUTH_FAILURE ||
error == NSAPI_ERROR_CONNECTION_TIMEOUT ||
Expand Down
8 changes: 2 additions & 6 deletions connectivity/netsocket/tests/TESTS/network/wifi/wifi_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,17 @@ void wifi_scan(void)
WiFiAccessPoint ap[MBED_CONF_APP_MAX_SCAN_SIZE];

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

bool secure_found = false;
bool unsecure_found = false;

char secure_bssid[6];
char unsecure_bssid[6];
const char *coversion_string = "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx";
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");
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");

for (int i = 0; i < size; i++) {
const char *ssid = ap[i].get_ssid();
nsapi_security_t security = ap[i].get_security();
int8_t rssi = ap[i].get_rssi();
printf("AP %u ssid %s security %u rssi %d\n", i, ssid, security, rssi);
TEST_ASSERT_INT8_WITHIN(-10, -100, rssi);
#if defined(MBED_CONF_APP_WIFI_SECURE_SSID)
if (strcmp(MBED_CONF_APP_WIFI_SECURE_SSID, ssid) == 0) {
Expand Down
22 changes: 22 additions & 0 deletions connectivity/netsocket/tests/TESTS/network/wifi/wifi_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,29 @@
#ifndef WIFI_TESTS_H
#define WIFI_TESTS_H

#ifdef MBED_CONF_NSAPI_PRESENT
#include "WiFiInterface.h"

#if !defined(MBED_CONF_APP_WIFI_SECURE_SSID)
#define MBED_CONF_APP_WIFI_SECURE_SSID MBED_CONF_NSAPI_DEFAULT_WIFI_SSID
#endif

#if !defined(MBED_CONF_APP_WIFI_PASSWORD)
#define MBED_CONF_APP_WIFI_PASSWORD MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD
#endif

#if !defined(MBED_CONF_APP_WIFI_SECURE_PROTOCOL)
#define MBED_CONF_APP_WIFI_SECURE_PROTOCOL MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY
#endif

#if !defined(MBED_CONF_APP_WIFI_CH_SECURE)
#define MBED_CONF_APP_WIFI_CH_SECURE 1
#endif

#if !defined(MBED_CONF_APP_MAX_SCAN_SIZE)
#define MBED_CONF_APP_MAX_SCAN_SIZE 10
#endif

/** Get WiFiInterface based on provided
* app_json. */
WiFiInterface *get_interface(void);
Expand Down Expand Up @@ -82,3 +103,4 @@ void wifi_scan_null(void);
void wifi_scan(void);

#endif //WIFI_TESTS_H
#endif // MBED_CONF_NSAPI_PRESENT