Skip to content

Commit 8e81d01

Browse files
juhaylinenSeppo Takalo
authored andcommitted
Update Greentea WiFi tests
Use similar network interface configuration as used in netsocket tests Improve test coverage
1 parent f04f7c1 commit 8e81d01

File tree

7 files changed

+32
-50
lines changed

7 files changed

+32
-50
lines changed

TESTS/network/wifi/get_interface.cpp

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

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_IDW0XX1 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
18+
#ifndef MBED_CONF_APP_OBJECT_CONSTRUCTION
19+
#error [NOT_SUPPORTED] No network interface found for this target.
3620
#endif
3721

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_IDW0XX1
43-
#include "SpwfSAInterface.h"
44-
#define DRIVER SpwfSAInterface
45-
#else
46-
#error [NOT_SUPPORTED] Unsupported Wifi driver
47-
#endif
22+
#include "mbed.h"
23+
#include MBED_CONF_APP_HEADER_FILE
4824

4925
WiFiInterface *get_interface()
5026
{
@@ -55,10 +31,7 @@ WiFiInterface *get_interface()
5531
return interface;
5632
}
5733

58-
#if MBED_CONF_APP_WIFI_DRIVER == INTERNAL
59-
interface = new DRIVER();
60-
#else
61-
interface = new DRIVER(MBED_CONF_APP_WIFI_TX, MBED_CONF_APP_WIFI_RX);
62-
#endif
34+
interface = MBED_CONF_APP_OBJECT_CONSTRUCTION;
35+
6336
return interface;
6437
}

TESTS/network/wifi/main.cpp

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

18+
#ifndef MBED_CONF_APP_OBJECT_CONSTRUCTION
19+
#error [NOT_SUPPORTED] No network interface found for this target.
20+
#endif
21+
1822
#include "mbed.h"
1923
#include "greentea-client/test_env.h"
2024
#include "unity.h"
@@ -26,11 +30,8 @@
2630
#if !defined(MBED_CONF_APP_AP_MAC_SECURE) || \
2731
!defined(MBED_CONF_APP_MAX_SCAN_SIZE) || \
2832
!defined(MBED_CONF_APP_WIFI_CH_SECURE) || \
29-
!defined(MBED_CONF_APP_WIFI_DRIVER) || \
3033
!defined(MBED_CONF_APP_WIFI_PASSWORD) || \
31-
!defined(MBED_CONF_APP_WIFI_RX) || \
3234
!defined(MBED_CONF_APP_WIFI_SECURE_SSID) || \
33-
!defined(MBED_CONF_APP_WIFI_TX) || \
3435
!defined MBED_CONF_APP_WIFI_SECURE_PROTOCOL
3536
#error [NOT_SUPPORTED] Requires parameters from mbed_app.json (for secure connections)
3637
#endif
@@ -40,10 +41,7 @@
4041
#if !defined(MBED_CONF_APP_AP_MAC_UNSECURE) || \
4142
!defined(MBED_CONF_APP_MAX_SCAN_SIZE) || \
4243
!defined(MBED_CONF_APP_WIFI_CH_UNSECURE) || \
43-
!defined(MBED_CONF_APP_WIFI_DRIVER) || \
4444
!defined(MBED_CONF_APP_WIFI_PASSWORD) || \
45-
!defined(MBED_CONF_APP_WIFI_RX) || \
46-
!defined(MBED_CONF_APP_WIFI_TX) || \
4745
!defined(MBED_CONF_APP_WIFI_UNSECURE_SSID)
4846
#error [NOT_SUPPORTED] Requires parameters from mbed_app.json (for unsecure connections)
4947
#endif

TESTS/network/wifi/template_mbed_app.txt

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,12 @@
2424
"help": "Channel number of unsecure SSID",
2525
"value": 2
2626
},
27-
"wifi-driver": {
28-
"help": "Wifi driver to use, valid values are INTERNAL, WIFI_ESP8266 and X_NUCLEO_IDW0XX1",
29-
"value": "INTERNAL"
27+
"header-file": {
28+
"help" : "String for including your driver header file",
29+
"value" : "\"WIFI_INTERFACE.h\""
3030
},
31-
"wifi-tx": {
32-
"help": "TX pin for serial connection to external device",
33-
"value": "D1"
34-
},
35-
"wifi-rx": {
36-
"help": "RX pin for serial connection to external device",
37-
"value": "D0"
31+
"object-construction" : {
32+
"value" : "new WIFI_INTERFACE()"
3833
},
3934
"ap-mac-secure": {
4035
"help": "BSSID of secure AP in form of AA:BB:CC:DD:EE:FF",

TESTS/network/wifi/wifi_connect_params_null.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ void wifi_connect_params_null(void)
2727
{
2828
WiFiInterface *wifi = get_interface();
2929
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_PARAMETER, wifi->connect(NULL, NULL));
30+
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_PARAMETER, wifi->connect("", ""));
3031
}

TESTS/network/wifi/wifi_connect_params_valid_unsecure.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ void wifi_connect_params_valid_unsecure(void)
2929
{
3030
WiFiInterface *wifi = get_interface();
3131
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->connect(MBED_CONF_APP_WIFI_UNSECURE_SSID, NULL));
32+
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->disconnect());
33+
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->connect(MBED_CONF_APP_WIFI_UNSECURE_SSID, ""));
34+
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->disconnect());
3235
}
3336

3437
#endif // defined(MBED_CONF_APP_WIFI_UNSECURE_SSID)

TESTS/network/wifi/wifi_set_channel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void wifi_set_channel(void)
5151

5252
if (is_2Ghz) {
5353
error = wifi->set_channel(0);
54-
TEST_ASSERT(error == NSAPI_ERROR_PARAMETER);
54+
TEST_ASSERT(error == NSAPI_ERROR_OK);
5555
error = wifi->set_channel(1);
5656
TEST_ASSERT(error == NSAPI_ERROR_OK);
5757
error = wifi->set_channel(13);

TESTS/network/wifi/wifi_set_credential.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,27 @@ void wifi_set_credential(void)
3131
error = iface->set_credentials(NULL, NULL, NSAPI_SECURITY_NONE);
3232
TEST_ASSERT(error == NSAPI_ERROR_PARAMETER);
3333

34+
error = iface->set_credentials("", "", NSAPI_SECURITY_NONE);
35+
TEST_ASSERT(error == NSAPI_ERROR_PARAMETER);
36+
3437
error = iface->set_credentials("OK", NULL, NSAPI_SECURITY_NONE);
3538
TEST_ASSERT(error == NSAPI_ERROR_OK);
3639

40+
error = iface->set_credentials("OK", "", NSAPI_SECURITY_NONE);
41+
TEST_ASSERT(error == NSAPI_ERROR_OK);
42+
3743
error = iface->set_credentials("OK", NULL, NSAPI_SECURITY_WEP);
3844
TEST_ASSERT(error == NSAPI_ERROR_PARAMETER);
3945

46+
error = iface->set_credentials("OK", "", NSAPI_SECURITY_WEP);
47+
TEST_ASSERT(error == NSAPI_ERROR_PARAMETER);
48+
4049
error = iface->set_credentials("OK", NULL, NSAPI_SECURITY_WPA_WPA2);
4150
TEST_ASSERT(error == NSAPI_ERROR_PARAMETER);
4251

52+
error = iface->set_credentials("OK", "", NSAPI_SECURITY_WPA_WPA2);
53+
TEST_ASSERT(error == NSAPI_ERROR_PARAMETER);
54+
4355
error = iface->set_credentials("OK", NULL, NSAPI_SECURITY_NONE);
4456
TEST_ASSERT(error == NSAPI_ERROR_OK);
4557

0 commit comments

Comments
 (0)