Skip to content

Commit b294d60

Browse files
author
Dominika Maziec
committed
Greentea testing wifi connect nonblocked
1 parent f8dc035 commit b294d60

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

TESTS/network/wifi/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ 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+
//Case("WIFI-CONNECT-NONBLOCKING", wifi_connect_nonblock),
7778
Case("WIFI-CONNECT-DISCONNECT-REPEAT", wifi_connect_disconnect_repeat),
7879
#endif
7980
#if defined(MBED_CONF_APP_WIFI_SECURE_SSID)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (c) 2017, 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+
30+
void wifi_connect_nonblock(void)
31+
{
32+
WiFiInterface *wifi = get_interface();
33+
34+
TEST_SKIP_UNLESS(wifi-> set_blocking(false) != NSAPI_ERROR_UNSUPPORTED)
35+
36+
char ssid[SSID_MAX_LEN + 1] = MBED_CONF_APP_WIFI_UNSECURE_SSID;
37+
38+
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(ssid, NULL));
39+
40+
nsapi_error_t ret = wifi->connect();
41+
42+
TEST_ASSERT_TRUE((ret == NSAPI_ERROR_OK) || (ret == NSAPI_ERROR_WOULD_BLOCK));
43+
44+
nsapi_error_t connection_status;
45+
if (ret == NSAPI_ERROR_OK) {
46+
connection_status = wifi->get_connection_status();
47+
TEST_ASSERT_TRUE(
48+
(connection_status == NSAPI_STATUS_GLOBAL_UP)
49+
|| (connection_status == NSAPI_STATUS_LOCAL_UP))
50+
} else {
51+
while ((connection_status != NSAPI_STATUS_GLOBAL_UP)
52+
&& (connection_status != NSAPI_STATUS_LOCAL_UP)) {
53+
connection_status = wifi->get_connection_status();
54+
}
55+
}
56+
57+
ret = wifi->disconnect();
58+
TEST_ASSERT_TRUE((ret == NSAPI_ERROR_OK) || (ret == NSAPI_ERROR_WOULD_BLOCK));
59+
60+
if (ret == NSAPI_ERROR_OK) {
61+
connection_status = wifi->get_connection_status();
62+
TEST_ASSERT_EQUAL_INT(NSAPI_STATUS_DISCONNECTED, connection_status);
63+
} else {
64+
while (connection_status != NSAPI_STATUS_DISCONNECTED) {
65+
connection_status = wifi->get_connection_status();
66+
}
67+
}
68+
69+
wifi->set_blocking(true);
70+
}
71+
72+
#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)