Skip to content

Commit 590ce2c

Browse files
authored
Merge pull request #11194 from dmaziec1/Wifi_test_connect_nonblock
Greentea testing wifi connect nonblocked
2 parents 399b517 + 8f4a865 commit 590ce2c

File tree

4 files changed

+104
-6
lines changed

4 files changed

+104
-6
lines changed

TESTS/network/wifi/README.md

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,16 @@ Please refer to the following table for priorities of test cases. Priorities are
6262
| 9 | WIFI_CONNECT_PARAMS_CHANNEL | | SHOULD |
6363
| 10 | WIFI_CONNECT_PARAMS_CHANNEL_FAIL | | SHOULD |
6464
| 11 | WIFI_CONNECT | | MUST |
65-
| 12 | WIFI_CONNECT_SECURE | With security type: | |
65+
| 12 | WIFI_CONNECT_NONBLOCK | | SHOULD |
66+
| 13 | WIFI_CONNECT_SECURE | With security type: | |
6667
| | | NSAPI_SECURITY_WEP | SHOULD |
6768
| | | NSAPI_SECURITY_WPA | SHOULD |
6869
| | | NSAPI_SECURITY_WPA2 | SHOULD |
6970
| | | NSAPI_SECURITY_WPA_WPA2 | MUST |
70-
| 13 | WIFI_CONNECT_SECURE_FAIL | | MUST |
71-
| 14 | WIFI_CONNECT_DISCONNECT_REPEAT | | MUST |
72-
| 15 | WIFI_SCAN_NULL | | SHOULD |
73-
| 16 | WIFI_SCAN | | SHOULD |
71+
| 14 | WIFI_CONNECT_SECURE_FAIL | | MUST |
72+
| 15 | WIFI_CONNECT_DISCONNECT_REPEAT | | MUST |
73+
| 16 | WIFI_SCAN_NULL | | SHOULD |
74+
| 17 | WIFI_SCAN | | SHOULD |
7475

7576
Building test binaries
7677
----------------------
@@ -372,7 +373,7 @@ Test `WiFiInterface::connect()` without parameters. Use `set_credentials()` for
372373
2. `Call WiFiInterface::set_credentials( <ssid:unsecure>, NULL)`.
373374
3. `Call WiFiInterface::connect()`.
374375
4. `disconnect()`.
375-
5. `Call WiFiInterface::set_credentials( <ssid:unsecure>, "")`.
376+
5. `Call WiFiInterface::set_credentials( <ssid:unsecure>, "")`.
376377
6. `Call WiFiInterface::connect()`.
377378
7. `disconnect()`.
378379
8. Trash the memory storing SSID.
@@ -384,6 +385,33 @@ Test `WiFiInterface::connect()` without parameters. Use `set_credentials()` for
384385

385386
`connect()` calls return `NSAPI_ERROR_OK`.
386387

388+
### WIFI_CONNECT_NONBLOCK
389+
390+
**Description:**
391+
392+
Test `WiFiInterface::connect()` and `WiFiInterface::disconnect()` in non-blocking mode. It checks that driver can connect and disconnect in nonblocking mode.
393+
394+
**Preconditions:**
395+
396+
1. Test enviroment is set up as specified in the "Test Environment" chapter.
397+
398+
**Test steps:**
399+
400+
1. Initialize the driver.
401+
2. `Call WiFiInterface::set_credentials( <ssid:unsecure>, NULL)`.
402+
3. `Call WiFiInterface::connect()`.
403+
4. `Call WiFiInterface::set_blocking(false)`
404+
5. `Call WiFiInterface::get_connection_status()`
405+
6. `disconnect()`
406+
7. `Call WiFiInterface::get_connection_status()`
407+
8. `Call WiFiInterface::set_blocking(true)`
408+
409+
**Expected result:**
410+
411+
In case of drivers which do not support asynchronous mode `set_blocking(false)` call returns `NSAPI_ERROR_UNSUPPORTED` and skips test case, otherwise:
412+
`connect()` call returns `NSAPI_ERROR_OK`. To confirm connection `get_connection_status()` calls return `NSAPI_STATUS_GLOBAL_UP` or `NSAPI_STATUS_LOCAL_UP`.
413+
`disconnect()` call returns `NSAPI_ERROR_OK`. To confirm disconnection `get_connection_status()` calls return `NSAPI_STATUS_DISCONNECTED`.
414+
387415
### WIFI_CONNECT_SECURE
388416

389417
**Description:**

TESTS/network/wifi/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ Case cases[] = {
7474
Case("WIFI-GET-RSSI", wifi_get_rssi),
7575
Case("WIFI-CONNECT-PARAMS-VALID-UNSECURE", wifi_connect_params_valid_unsecure),
7676
Case("WIFI-CONNECT", wifi_connect),
77+
//Most boards are not passing this test, but they should if they support non-blocking API.
78+
//Case("WIFI-CONNECT-NONBLOCKING", wifi_connect_nonblock),
7779
Case("WIFI-CONNECT-DISCONNECT-REPEAT", wifi_connect_disconnect_repeat),
7880
#endif
7981
#if defined(MBED_CONF_APP_WIFI_SECURE_SSID)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2019, 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+
#if defined(MBED_CONF_APP_WIFI_UNSECURE_SSID)
27+
28+
#define SSID_MAX_LEN 32
29+
nsapi_connection_status_t status_connection;
30+
Semaphore sem_conn(0, 1);
31+
Semaphore sem_disconn(0, 1);
32+
void status_callback(nsapi_event_t e, intptr_t d)
33+
{
34+
if (d == NSAPI_STATUS_LOCAL_UP || d == NSAPI_STATUS_GLOBAL_UP) {
35+
status_connection = (nsapi_connection_status_t)d;
36+
sem_conn.release();
37+
}
38+
39+
if (d == NSAPI_STATUS_DISCONNECTED) {
40+
status_connection = (nsapi_connection_status_t)d;
41+
sem_disconn.release();
42+
}
43+
}
44+
45+
void wifi_connect_nonblock(void)
46+
{
47+
WiFiInterface *wifi = get_interface();
48+
char ssid[SSID_MAX_LEN + 1] = MBED_CONF_APP_WIFI_UNSECURE_SSID;
49+
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(ssid, NULL));
50+
wifi->attach(status_callback);
51+
TEST_SKIP_UNLESS(wifi->set_blocking(false) != NSAPI_ERROR_UNSUPPORTED);
52+
nsapi_error_t ret = wifi->connect();
53+
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, ret);
54+
bool res = sem_conn.try_acquire_for(30000);
55+
TEST_ASSERT_TRUE(res == true);
56+
TEST_ASSERT_TRUE(status_connection == NSAPI_STATUS_GLOBAL_UP || status_connection == NSAPI_STATUS_LOCAL_UP);
57+
ret = wifi->disconnect();
58+
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, ret);
59+
res = sem_disconn.try_acquire_for(30000);
60+
TEST_ASSERT_TRUE(res == true);
61+
TEST_ASSERT_EQUAL_INT(NSAPI_STATUS_DISCONNECTED, status_connection);
62+
wifi->set_blocking(true);
63+
}
64+
65+
#endif // defined(MBED_CONF_APP_WIFI_UNSECURE_SSID)

TESTS/network/wifi/wifi_tests.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ void wifi_connect_params_channel_fail(void);
6363
/** Test WiFiInterface::connect() without parameters. Use set_credentials() for setting parameters. */
6464
void wifi_connect(void);
6565

66+
/** Test WiFiInterface::connect() in nonblocking mode. Use set_credentials() for setting parameters. */
67+
void wifi_connect_nonblock(void);
68+
6669
/** Test WiFiInterface::connect() without parameters. Don't set parameters with set_credentials() */
6770
void wifi_connect_nocredentials(void);
6871

0 commit comments

Comments
 (0)