Skip to content
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

[test] fix listening network tests #2416

Merged
merged 1 commit into from Mar 31, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 26 additions & 2 deletions user/tests/wiring/no_fixture/ble_provisioning.cpp
Expand Up @@ -20,10 +20,15 @@

#if HAL_PLATFORM_BLE

// Dot not enter listening mode based on the flag
// Do not enter listening mode based on the flag
test(LISTENING_00_DISABLE_LISTENING_MODE) {
System.enableFeature(FEATURE_DISABLE_LISTENING_MODE);
Network.listen();
SCOPE_GUARD({
System.disableFeature(FEATURE_DISABLE_LISTENING_MODE);
Network.listen(false);
delay(1000);
});
delay(1000); // Time for system thread to enter listening mode, if any
assertFalse(Network.listening());
}
Expand All @@ -32,6 +37,10 @@ test(LISTENING_00_DISABLE_LISTENING_MODE) {
test(LISTENING_01_ENABLE_LISTENING_MODE) {
System.disableFeature(FEATURE_DISABLE_LISTENING_MODE);
Network.listen();
SCOPE_GUARD({
Network.listen(false);
delay(1000);
});
delay(1000); // Time for system thread to enter listening mode
assertTrue(Network.listening());
Network.listen(false);
Expand All @@ -43,16 +52,27 @@ test(LISTENING_01_ENABLE_LISTENING_MODE) {
// device-os should exit listening mode
test(LISTENING_02_DISABLE_FLAG_WHILE_IN_LISTENING_MODE) {
Network.listen();
SCOPE_GUARD({
Network.listen(false);
delay(1000);
});
delay(1000); // Time for system thread to enter listening mode
assertTrue(Network.listening());
System.enableFeature(FEATURE_DISABLE_LISTENING_MODE);
SCOPE_GUARD({
System.disableFeature(FEATURE_DISABLE_LISTENING_MODE);
});
delay(1500); // Time for system thread to process the flag
assertFalse(Network.listening());
}

test(LISTENING_03_ENABLE_BLE_PROV_MODE_WHEN_FLAG_SET) {
System.enableFeature(FEATURE_DISABLE_LISTENING_MODE);
BLE.provisioningMode(true);
SCOPE_GUARD({
BLE.provisioningMode(false);
System.disableFeature(FEATURE_DISABLE_LISTENING_MODE);
});
delay(100);
assertTrue(BLE.getProvisioningStatus());
assertTrue(BLE.advertising());
Expand All @@ -75,16 +95,20 @@ test(LISTENING_04_ENABLE_BLE_PROV_MODE_WHEN_FLAG_CLEARED) {
}

test(LISTENING_05_ENABLE_BLE_PROV_AFTER_LISTENING_MODE) {
// 15 min gives the device time to go through a 10 min timeout & power cycle
const system_tick_t WAIT_TIMEOUT = 15 * 60 * 1000;
SCOPE_GUARD({
System.disableFeature(FEATURE_DISABLE_LISTENING_MODE);
});
Network.listen();
delay(1000); // Time for system thread to enter listening mode
assertTrue(Network.listening());
SCOPE_GUARD({
Network.listen(false);
delay(1000);
// Make sure we restore cloud connection after exiting this test because we entered listening mode
Particle.connect();
waitFor(Particle.connected, HAL_PLATFORM_MAX_CLOUD_CONNECT_TIME);
waitFor(Particle.connected, WAIT_TIMEOUT);
assertTrue(Particle.connected());
});
System.enableFeature(FEATURE_DISABLE_LISTENING_MODE);
Expand Down
10 changes: 10 additions & 0 deletions user/tests/wiring/no_fixture/network.cpp
Expand Up @@ -19,6 +19,11 @@
#include "unit-test/unit-test.h"

test(NETWORK_00_UDP_begin_does_not_leak_sockets_without_calling_stop) {
// 15 min gives the device time to go through a 10 min timeout & power cycle
const system_tick_t WAIT_TIMEOUT = 15 * 60 * 1000;
Network.on();
Network.connect();
waitFor(Network.ready, WAIT_TIMEOUT);
// Arbitrary number that is large enough to showcase the issue
#if PLATFORM_ID == PLATFORM_ELECTRON_PRODUCTION
// There is a limited number of sockets available on Electrons, since we are using
Expand All @@ -41,6 +46,11 @@ test(NETWORK_00_UDP_begin_does_not_leak_sockets_without_calling_stop) {
}

test(NETWORK_01_UDP_sockets_can_be_read_with_timeout) {
// 15 min gives the device time to go through a 10 min timeout & power cycle
const system_tick_t WAIT_TIMEOUT = 15 * 60 * 1000;
Network.on();
Network.connect();
waitFor(Network.ready, WAIT_TIMEOUT);
auto udp = std::make_unique<UDP>();
assertTrue((bool)udp);

Expand Down