Skip to content

Greentea testing wifi connect nonblocked #11194

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 1 commit into from
Aug 21, 2019
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
40 changes: 34 additions & 6 deletions TESTS/network/wifi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,16 @@ Please refer to the following table for priorities of test cases. Priorities are
| 9 | WIFI_CONNECT_PARAMS_CHANNEL | | SHOULD |
| 10 | WIFI_CONNECT_PARAMS_CHANNEL_FAIL | | SHOULD |
| 11 | WIFI_CONNECT | | MUST |
| 12 | WIFI_CONNECT_SECURE | With security type: | |
| 12 | WIFI_CONNECT_NONBLOCK | | SHOULD |
| 13 | WIFI_CONNECT_SECURE | With security type: | |
| | | NSAPI_SECURITY_WEP | SHOULD |
| | | NSAPI_SECURITY_WPA | SHOULD |
| | | NSAPI_SECURITY_WPA2 | SHOULD |
| | | NSAPI_SECURITY_WPA_WPA2 | MUST |
| 13 | WIFI_CONNECT_SECURE_FAIL | | MUST |
| 14 | WIFI_CONNECT_DISCONNECT_REPEAT | | MUST |
| 15 | WIFI_SCAN_NULL | | SHOULD |
| 16 | WIFI_SCAN | | SHOULD |
| 14 | WIFI_CONNECT_SECURE_FAIL | | MUST |
| 15 | WIFI_CONNECT_DISCONNECT_REPEAT | | MUST |
| 16 | WIFI_SCAN_NULL | | SHOULD |
| 17 | WIFI_SCAN | | SHOULD |

Building test binaries
----------------------
Expand Down Expand Up @@ -372,7 +373,7 @@ Test `WiFiInterface::connect()` without parameters. Use `set_credentials()` for
2. `Call WiFiInterface::set_credentials( <ssid:unsecure>, NULL)`.
3. `Call WiFiInterface::connect()`.
4. `disconnect()`.
5. `Call WiFiInterface::set_credentials( <ssid:unsecure>, "")`.
5. `Call WiFiInterface::set_credentials( <ssid:unsecure>, "")`.
6. `Call WiFiInterface::connect()`.
7. `disconnect()`.
8. Trash the memory storing SSID.
Expand All @@ -384,6 +385,33 @@ Test `WiFiInterface::connect()` without parameters. Use `set_credentials()` for

`connect()` calls return `NSAPI_ERROR_OK`.

### WIFI_CONNECT_NONBLOCK

**Description:**

Test `WiFiInterface::connect()` and `WiFiInterface::disconnect()` in non-blocking mode. It checks that driver can connect and disconnect in nonblocking mode.

**Preconditions:**

1. Test enviroment is set up as specified in the "Test Environment" chapter.

**Test steps:**

1. Initialize the driver.
2. `Call WiFiInterface::set_credentials( <ssid:unsecure>, NULL)`.
3. `Call WiFiInterface::connect()`.
4. `Call WiFiInterface::set_blocking(false)`
5. `Call WiFiInterface::get_connection_status()`
6. `disconnect()`
7. `Call WiFiInterface::get_connection_status()`
8. `Call WiFiInterface::set_blocking(true)`

**Expected result:**

In case of drivers which do not support asynchronous mode `set_blocking(false)` call returns `NSAPI_ERROR_UNSUPPORTED` and skips test case, otherwise:
`connect()` call returns `NSAPI_ERROR_OK`. To confirm connection `get_connection_status()` calls return `NSAPI_STATUS_GLOBAL_UP` or `NSAPI_STATUS_LOCAL_UP`.
`disconnect()` call returns `NSAPI_ERROR_OK`. To confirm disconnection `get_connection_status()` calls return `NSAPI_STATUS_DISCONNECTED`.

### WIFI_CONNECT_SECURE

**Description:**
Expand Down
2 changes: 2 additions & 0 deletions TESTS/network/wifi/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ Case cases[] = {
Case("WIFI-GET-RSSI", wifi_get_rssi),
Case("WIFI-CONNECT-PARAMS-VALID-UNSECURE", wifi_connect_params_valid_unsecure),
Case("WIFI-CONNECT", wifi_connect),
//Most boards are not passing this test, but they should if they support non-blocking API.
//Case("WIFI-CONNECT-NONBLOCKING", wifi_connect_nonblock),
Copy link
Contributor

Choose a reason for hiding this comment

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

this should not be in here (can be added anytime).

Why is it commented out ? The implementation is being added in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

In fact, none of the Wi-Fi class implementations we checked is able to pass this test right now. We want the test to be available, however, in order to determine the expected behaviour and be able to ask Wi-Fi stack developers (Ublox, ST, etc.) to implement the missing functionality or at least return NSAPI_ERROR_UNSUPPORTED, so the test can be skipped.
We thought it would be easiest for someone starting the implementation with a test-driven-development to uncomment this line, run the test and try to make it pass.
Removing the test is also fine - most developers will probably be able to figure out how to run it ;-).
I would say, however, that leaving a commented test will not let us (and anyone developing a W-Fi driver) forget about this function.
@0xc0170 , how about we add a comment explaining the situation, like:

// Most boards are not passing this test, but they should if they support non-blocking API.

?

Copy link
Contributor

Choose a reason for hiding this comment

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

The comment would be better than it is now.

Case("WIFI-CONNECT-DISCONNECT-REPEAT", wifi_connect_disconnect_repeat),
#endif
#if defined(MBED_CONF_APP_WIFI_SECURE_SSID)
Expand Down
65 changes: 65 additions & 0 deletions TESTS/network/wifi/wifi_connect_nonblock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2019, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "mbed.h"
#include "greentea-client/test_env.h"
#include "unity.h"
#include "utest.h"
#include "wifi_tests.h"

using namespace utest::v1;

#if defined(MBED_CONF_APP_WIFI_UNSECURE_SSID)

#define SSID_MAX_LEN 32
nsapi_connection_status_t status_connection;
Semaphore sem_conn(0, 1);
Semaphore sem_disconn(0, 1);
void status_callback(nsapi_event_t e, intptr_t d)
{
if (d == NSAPI_STATUS_LOCAL_UP || d == NSAPI_STATUS_GLOBAL_UP) {
status_connection = (nsapi_connection_status_t)d;
sem_conn.release();
}

if (d == NSAPI_STATUS_DISCONNECTED) {
status_connection = (nsapi_connection_status_t)d;
sem_disconn.release();
}
}

void wifi_connect_nonblock(void)
{
WiFiInterface *wifi = get_interface();
char ssid[SSID_MAX_LEN + 1] = MBED_CONF_APP_WIFI_UNSECURE_SSID;
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(ssid, NULL));
wifi->attach(status_callback);
TEST_SKIP_UNLESS(wifi->set_blocking(false) != NSAPI_ERROR_UNSUPPORTED);
nsapi_error_t ret = wifi->connect();
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, ret);
bool res = sem_conn.try_acquire_for(30000);
TEST_ASSERT_TRUE(res == true);
TEST_ASSERT_TRUE(status_connection == NSAPI_STATUS_GLOBAL_UP || status_connection == NSAPI_STATUS_LOCAL_UP);
ret = wifi->disconnect();
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, ret);
res = sem_disconn.try_acquire_for(30000);
TEST_ASSERT_TRUE(res == true);
TEST_ASSERT_EQUAL_INT(NSAPI_STATUS_DISCONNECTED, status_connection);
wifi->set_blocking(true);
}

#endif // defined(MBED_CONF_APP_WIFI_UNSECURE_SSID)
3 changes: 3 additions & 0 deletions TESTS/network/wifi/wifi_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ void wifi_connect_params_channel_fail(void);
/** Test WiFiInterface::connect() without parameters. Use set_credentials() for setting parameters. */
void wifi_connect(void);

/** Test WiFiInterface::connect() in nonblocking mode. Use set_credentials() for setting parameters. */
void wifi_connect_nonblock(void);

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

Expand Down