-
Notifications
You must be signed in to change notification settings - Fork 3k
Add greentea tests for network interface status and connect/disconnect #7882
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2018, 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. | ||
*/ | ||
|
||
#define WIFI 2 | ||
#if !defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE) || \ | ||
(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == WIFI && !defined(MBED_CONF_NSAPI_DEFAULT_WIFI_SSID)) | ||
#error [NOT_SUPPORTED] No network configuration found for this target. | ||
#endif | ||
|
||
#include "mbed.h" | ||
#include "greentea-client/test_env.h" | ||
#include "unity/unity.h" | ||
#include "utest.h" | ||
#include "utest/utest_stack_trace.h" | ||
#include "networkinterface_tests.h" | ||
|
||
using namespace utest::v1; | ||
|
||
// Test setup | ||
utest::v1::status_t test_setup(const size_t number_of_cases) | ||
{ | ||
GREENTEA_SETUP(480, "default_auto"); | ||
return verbose_test_setup_handler(number_of_cases); | ||
} | ||
|
||
Case cases[] = { | ||
Case("NETWORKINTERFACE_STATUS", NETWORKINTERFACE_STATUS), | ||
Case("NETWORKINTERFACE_STATUS_NONBLOCK", NETWORKINTERFACE_STATUS_NONBLOCK), | ||
Case("NETWORKINTERFACE_STATUS_GET", NETWORKINTERFACE_STATUS_GET), | ||
Case("NETWORKINTERFACE_CONN_DISC_REPEAT", NETWORKINTERFACE_CONN_DISC_REPEAT), | ||
}; | ||
|
||
Specification specification(test_setup, cases); | ||
|
||
int main() | ||
{ | ||
return !Harness::run(specification); | ||
} |
43 changes: 43 additions & 0 deletions
43
TESTS/network/interface/networkinterface_conn_disc_repeat.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) 2018, 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 "networkinterface_tests.h" | ||
#include "unity/unity.h" | ||
#include "utest.h" | ||
|
||
using namespace utest::v1; | ||
|
||
namespace | ||
{ | ||
NetworkInterface* net; | ||
const int repeats = 5; | ||
} | ||
|
||
void NETWORKINTERFACE_CONN_DISC_REPEAT() | ||
{ | ||
net = NetworkInterface::get_default_instance(); | ||
|
||
for (int i = 0; i < repeats; i++) { | ||
nsapi_error_t err = net->connect(); | ||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err); | ||
|
||
err = net->disconnect(); | ||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/* | ||
* Copyright (c) 2018, 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 "networkinterface_tests.h" | ||
#include "unity/unity.h" | ||
#include "utest.h" | ||
|
||
using namespace utest::v1; | ||
|
||
namespace | ||
{ | ||
NetworkInterface* net; | ||
rtos::Semaphore status_semaphore; | ||
int status_write_counter = 0; | ||
int status_read_counter = 0; | ||
const int repeats = 5; | ||
const int status_buffer_size = 100; | ||
nsapi_connection_status_t current_status = NSAPI_STATUS_ERROR_UNSUPPORTED; | ||
nsapi_connection_status_t statuses[status_buffer_size]; | ||
} | ||
|
||
void status_cb(nsapi_event_t event, intptr_t value) | ||
{ | ||
TEST_ASSERT_EQUAL(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, event); | ||
|
||
statuses[status_write_counter] = static_cast<nsapi_connection_status_t>(value); | ||
status_write_counter++; | ||
if (status_write_counter >= status_buffer_size) { | ||
TEST_ASSERT(0); | ||
} | ||
|
||
status_semaphore.release(); | ||
} | ||
|
||
nsapi_connection_status_t wait_status_callback() | ||
{ | ||
nsapi_connection_status_t status; | ||
|
||
while (true) { | ||
status_semaphore.wait(); | ||
|
||
status = statuses[status_read_counter]; | ||
status_read_counter++; | ||
|
||
if (status != current_status) { | ||
current_status = status; | ||
return status; | ||
} | ||
} | ||
} | ||
|
||
void NETWORKINTERFACE_STATUS() | ||
{ | ||
nsapi_connection_status_t status; | ||
|
||
status_write_counter = 0; | ||
status_read_counter = 0; | ||
current_status = NSAPI_STATUS_ERROR_UNSUPPORTED; | ||
|
||
net = NetworkInterface::get_default_instance(); | ||
net->attach(status_cb); | ||
net->set_blocking(true); | ||
|
||
for (int i = 0; i < repeats; i++) { | ||
nsapi_error_t err = net->connect(); | ||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err); | ||
|
||
status = wait_status_callback(); | ||
TEST_ASSERT_EQUAL(NSAPI_STATUS_CONNECTING, status); | ||
|
||
status = wait_status_callback(); | ||
if (status == NSAPI_STATUS_LOCAL_UP) { | ||
status = wait_status_callback(); | ||
} | ||
TEST_ASSERT_EQUAL(NSAPI_STATUS_GLOBAL_UP, status); | ||
|
||
net->disconnect(); | ||
|
||
status = wait_status_callback(); | ||
TEST_ASSERT_EQUAL(NSAPI_STATUS_DISCONNECTED, status); | ||
} | ||
|
||
net->attach(NULL); | ||
} | ||
|
||
void NETWORKINTERFACE_STATUS_NONBLOCK() | ||
{ | ||
nsapi_connection_status_t status; | ||
|
||
status_write_counter = 0; | ||
status_read_counter = 0; | ||
current_status = NSAPI_STATUS_ERROR_UNSUPPORTED; | ||
|
||
net = NetworkInterface::get_default_instance(); | ||
net->attach(status_cb); | ||
net->set_blocking(false); | ||
|
||
for (int i = 0; i < repeats; i++) { | ||
nsapi_error_t err = net->connect(); | ||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err); | ||
|
||
status = wait_status_callback(); | ||
TEST_ASSERT_EQUAL(NSAPI_STATUS_CONNECTING, status); | ||
|
||
status = wait_status_callback(); | ||
if (status == NSAPI_STATUS_LOCAL_UP) { | ||
status = wait_status_callback(); | ||
} | ||
TEST_ASSERT_EQUAL(NSAPI_STATUS_GLOBAL_UP, status); | ||
|
||
net->disconnect(); | ||
|
||
status = wait_status_callback(); | ||
TEST_ASSERT_EQUAL(NSAPI_STATUS_DISCONNECTED, status); | ||
} | ||
|
||
net->attach(NULL); | ||
net->set_blocking(true); | ||
} | ||
|
||
void NETWORKINTERFACE_STATUS_GET() | ||
{ | ||
nsapi_connection_status_t status; | ||
|
||
net = NetworkInterface::get_default_instance(); | ||
net->set_blocking(true); | ||
|
||
TEST_ASSERT_EQUAL(NSAPI_STATUS_DISCONNECTED, net->get_connection_status()); | ||
|
||
for (int i = 0; i < repeats; i++) { | ||
nsapi_error_t err = net->connect(); | ||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err); | ||
|
||
while (net->get_connection_status() != NSAPI_STATUS_GLOBAL_UP) { | ||
wait(0.5); | ||
} | ||
|
||
net->disconnect(); | ||
|
||
TEST_ASSERT_EQUAL(NSAPI_STATUS_DISCONNECTED, net->get_connection_status()); | ||
} | ||
|
||
net->attach(NULL); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2018, 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. | ||
*/ | ||
|
||
#ifndef NETWORKINTERFACE_TESTS_H | ||
#define NETWORKINTERFACE_TESTS_H | ||
|
||
/* | ||
* Test cases | ||
*/ | ||
void NETWORKINTERFACE_STATUS(); | ||
void NETWORKINTERFACE_STATUS_NONBLOCK(); | ||
void NETWORKINTERFACE_STATUS_GET(); | ||
void NETWORKINTERFACE_CONN_DISC_REPEAT(); | ||
|
||
#endif //NETWORKINTERFACE_TESTS_H |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are these in capital letters? I assumed these are macros that somehow get overwritten somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the naming convention for our socket and network tests. Test case names are in capital letters. Used in socket and dns tests already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it?
https://github.com/ARMmbed/mbed-os/blob/fef021810ed8fe892df3b5be34ef4ddda2d3321c/TESTS/network/emac/emac_tests.h
https://github.com/ARMmbed/mbed-os/blob/fef021810ed8fe892df3b5be34ef4ddda2d3321c/TESTS/network/wifi/wifi_tests.h
they are all lower case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, older tests not using that yet. @SeppoTakalo should we update also those?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the exact same name as test plan has.
Test cases are anyway a bit special, so having exception to common API guidelines is acceptable.
Having testcases in small letters has a added benefit that it is clearly visible separation from test suite (binary name)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0xc0170 I think we would be changing the emac/wifi tests to match socket/dns tests in an another pull requests. Can this pull request proceed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, entering needs: CI now.
It would be (I would still challenge we are entering the ground where preprocessor can replace it and leads to failures. I would avoid naming anything else with capital letters but macros) but this is not the case for test cases for our tests. I found this only in these tests not anywhere else so do not see why it would be different (we can update the test plan to match the implementation). If this is something up for the change, should be documented (test cases are upper case because..) and followed?
cc @ARMmbed/mbed-os-test