Skip to content

Commit

Permalink
[test]: make the ble scanning tests self contained
Browse files Browse the repository at this point in the history
  • Loading branch information
XuGuohui committed Aug 22, 2024
1 parent e3f9b10 commit 1c0a9fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
13 changes: 12 additions & 1 deletion user/tests/wiring/ble_central_peripheral/ble_central/central.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ constexpr uint16_t PEER_DESIRED_ATT_MTU = 123;

Thread* scanThread = nullptr;
volatile unsigned scanResults = 0;
String nameInSr;

test(BLE_000_Central_Cloud_Connect) {
subscribeEvents(BLE_ROLE_PERIPHERAL);
Expand Down Expand Up @@ -608,6 +609,12 @@ test(BLE_33_Central_Can_Connect_While_Scanning) {
BLE.scanWithFilter(BleScanFilter().allowDuplicates(true), +[](const BleScanResult *result, void *param) -> void {
auto scanResults = (volatile unsigned int*)param;
(*scanResults)++;
if (result->scanResponse().length() > 0 && nameInSr.length() == 0) {
nameInSr = result->scanResponse().deviceName();
if (nameInSr != "ble-test") {
nameInSr = String();
}
}
}, param);
}, (void*)&scanResults);

Expand All @@ -625,12 +632,14 @@ test(BLE_33_Central_Can_Connect_While_Scanning) {
});
});
scanResults = 0;
nameInSr = String();
delay(2000);
assertMoreOrEqual((unsigned)scanResults, 1);
assertTrue(nameInSr == "ble-test");
assertTrue(peer.connected());
}

test(BLE_34_Central_Can_Connect_While_Scanning_After_Disconnect) {
test(BLE_34_Central_Is_Still_Scanning_After_Disconnect) {
SCOPE_GUARD({
if (BLE.scanning() && scanThread) {
assertEqual(0, BLE.stopScanning());
Expand All @@ -641,8 +650,10 @@ test(BLE_34_Central_Can_Connect_While_Scanning_After_Disconnect) {
assertTrue(BLE.scanning());
assertFalse(BLE.connected());
scanResults = 0;
nameInSr = String();
delay(5000);
assertMoreOrEqual((unsigned)scanResults, 1);
assertTrue(nameInSr == "ble-test");
}

test(BLE_35_Central_Can_Connect_While_Peripheral_Is_Scanning_Prepare) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,16 @@ test(BLE_33_Central_Can_Connect_While_Scanning) {
assertTrue(waitFor([]{ return !BLE.connected(); }, 10000));
assertFalse(BLE.connected());
});
BleAdvertisingData advData;
advData.appendServiceUUID(serviceUuid);
BleAdvertisingData srData;
srData.appendLocalName("ble-test");
int ret = BLE.advertise(&advData, &srData);
assertEqual(ret, 0);
assertTrue(BLE.advertising());
}

test(BLE_34_Central_Can_Connect_While_Scanning_After_Disconnect) {
test(BLE_34_Central_Is_Still_Scanning_After_Disconnect) {
}

test(BLE_35_Central_Can_Connect_While_Peripheral_Is_Scanning_Prepare) {
Expand Down

0 comments on commit 1c0a9fe

Please sign in to comment.