Skip to content

Commit ac7b851

Browse files
authored
Merge pull request #11409 from dmaziec1/esp8266-nonblocking
esp8266 nonblocking connect/disconnect
2 parents 0c59bea + f5ccbe7 commit ac7b851

File tree

6 files changed

+204
-63
lines changed

6 files changed

+204
-63
lines changed

TESTS/network/wifi/README.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ 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_NONBLOCK | | SHOULD |
65+
| 12 | WIFI_CONNECT_DISCONNECT_NONBLOCK | | SHOULD |
6666
| 13 | WIFI_CONNECT_SECURE | With security type: | |
6767
| | | NSAPI_SECURITY_WEP | SHOULD |
6868
| | | NSAPI_SECURITY_WPA | SHOULD |
@@ -385,7 +385,7 @@ Test `WiFiInterface::connect()` without parameters. Use `set_credentials()` for
385385

386386
`connect()` calls return `NSAPI_ERROR_OK`.
387387

388-
### WIFI_CONNECT_NONBLOCK
388+
### WIFI_CONNECT_DISCONNECT_NONBLOCK
389389

390390
**Description:**
391391

@@ -399,18 +399,24 @@ Test `WiFiInterface::connect()` and `WiFiInterface::disconnect()` in non-blockin
399399

400400
1. Initialize the driver.
401401
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)`
402+
3. `Call WiFiInterface::set_blocking(false)`
403+
4. `Call WiFiInterface::connect()`.
404+
5. `Cal WiFiInterface::set_credentials(const char *ssid, const char *pass, nsapi_security_t security)`
405+
6. `Call WiFiInterface::connect()`.
406+
7. `disconnect()`
407+
8. `disconnect()`
408+
9. `Call WiFiInterface::set_blocking(true)`
408409

409410
**Expected result:**
410411

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`.
412+
1. Drivers which do not support asynchronous mode `set_blocking(false)` call returns `NSAPI_ERROR_UNSUPPORTED` and skips test case.
413+
2. `connect()` call returns `NSAPI_ERROR_OK`.
414+
3. `set_credentials(...)` call returns `NSAPI_ERROR_BUSY`.
415+
4. Second `connect()` call returns `NSAPI_ERROR_BUSY` or `NSAPI_ERROR_IS_CONNECTED`.
416+
5. Attached callback informs about connection status. Callback reports status `NSAPI_STATUS_CONNECTING` and `NSAPI_STATUS_CONNECTED`.
417+
6. `disconnect()` call returns `NSAPI_ERROR_OK`.
418+
7. Second `disconnect()` call returns `NSAPI_ERROR_BUSY` or `NSAPI_ERROR_IS_CONNECTED`.
419+
8. To confirm disconnection callback reports `NSAPI_STATUS_DISCONNECTED`.
414420

415421
### WIFI_CONNECT_SECURE
416422

TESTS/network/wifi/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Case cases[] = {
7575
Case("WIFI-CONNECT-PARAMS-VALID-UNSECURE", wifi_connect_params_valid_unsecure),
7676
Case("WIFI-CONNECT", wifi_connect),
7777
//Most boards are not passing this test, but they should if they support non-blocking API.
78-
//Case("WIFI-CONNECT-NONBLOCKING", wifi_connect_nonblock),
78+
//Case("WIFI_CONNECT_DISCONNECT_NONBLOCK", wifi_connect_disconnect_nonblock),
7979
Case("WIFI-CONNECT-DISCONNECT-REPEAT", wifi_connect_disconnect_repeat),
8080
#endif
8181
#if defined(MBED_CONF_APP_WIFI_SECURE_SSID)

TESTS/network/wifi/wifi_connect_nonblock.cpp renamed to TESTS/network/wifi/wifi_connect_disconnect_nonblock.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ using namespace utest::v1;
2929
nsapi_connection_status_t status_connection;
3030
Semaphore sem_conn(0, 1);
3131
Semaphore sem_disconn(0, 1);
32+
Semaphore sem_connecting(0, 1);
3233
void status_callback(nsapi_event_t e, intptr_t d)
3334
{
3435
if (d == NSAPI_STATUS_LOCAL_UP || d == NSAPI_STATUS_GLOBAL_UP) {
@@ -40,26 +41,40 @@ void status_callback(nsapi_event_t e, intptr_t d)
4041
status_connection = (nsapi_connection_status_t)d;
4142
sem_disconn.release();
4243
}
44+
45+
if (d == NSAPI_STATUS_CONNECTING) {
46+
status_connection = (nsapi_connection_status_t)d;
47+
sem_connecting.release();
48+
}
4349
}
4450

45-
void wifi_connect_nonblock(void)
51+
void wifi_connect_disconnect_nonblock(void)
4652
{
4753
WiFiInterface *wifi = get_interface();
4854
char ssid[SSID_MAX_LEN + 1] = MBED_CONF_APP_WIFI_UNSECURE_SSID;
4955
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(ssid, NULL));
5056
wifi->attach(status_callback);
5157
TEST_SKIP_UNLESS(wifi->set_blocking(false) != NSAPI_ERROR_UNSUPPORTED);
5258
nsapi_error_t ret = wifi->connect();
59+
nsapi_error_t ret2 = wifi->set_credentials("1234", "1234", NSAPI_SECURITY_WPA_WPA2);
60+
nsapi_error_t ret3 = wifi->connect();
5361
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, ret);
54-
bool res = sem_conn.try_acquire_for(30000);
62+
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_BUSY, ret2);
63+
TEST_ASSERT_TRUE(ret3 == NSAPI_ERROR_BUSY || ret3 == NSAPI_ERROR_IS_CONNECTED);
64+
bool res = sem_connecting.try_acquire_for(30000);
65+
TEST_ASSERT_EQUAL_INT(NSAPI_STATUS_CONNECTING, status_connection);
66+
res = sem_conn.try_acquire_for(30000);
5567
TEST_ASSERT_TRUE(res == true);
5668
TEST_ASSERT_TRUE(status_connection == NSAPI_STATUS_GLOBAL_UP || status_connection == NSAPI_STATUS_LOCAL_UP);
5769
ret = wifi->disconnect();
70+
ret3 = wifi->disconnect();
5871
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, ret);
72+
TEST_ASSERT_TRUE(ret3 == NSAPI_ERROR_BUSY || ret3 == NSAPI_ERROR_NO_CONNECTION);
5973
res = sem_disconn.try_acquire_for(30000);
6074
TEST_ASSERT_TRUE(res == true);
6175
TEST_ASSERT_EQUAL_INT(NSAPI_STATUS_DISCONNECTED, status_connection);
6276
wifi->set_blocking(true);
77+
wifi->attach(0);
6378
}
6479

6580
#endif // defined(MBED_CONF_APP_WIFI_UNSECURE_SSID)

TESTS/network/wifi/wifi_tests.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ 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);
66+
/** Test WiFiInterface::connect() and disconnect() in nonblocking mode. Use set_credentials() for setting parameters. */
67+
void wifi_connect_disconnect_nonblock(void);
6868

6969
/** Test WiFiInterface::connect() without parameters. Don't set parameters with set_credentials() */
7070
void wifi_connect_nocredentials(void);

0 commit comments

Comments
 (0)