tests: Bluetooth: Increase coverage for sync establishment
We didn't have test coverage for the scenario where the host
starts scanning automatically.
Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
diff --git a/tests/bsim/bluetooth/host/adv/periodic/src/per_adv_syncer.c b/tests/bsim/bluetooth/host/adv/periodic/src/per_adv_syncer.c
index 274a6ca..df126e3 100644
--- a/tests/bsim/bluetooth/host/adv/periodic/src/per_adv_syncer.c
+++ b/tests/bsim/bluetooth/host/adv/periodic/src/per_adv_syncer.c
@@ -253,6 +253,33 @@
PASS("Periodic advertising syncer passed\n");
}
+static void main_per_adv_syncer_app_not_scanning(void)
+{
+ int err;
+ struct bt_le_per_adv_sync *sync = NULL;
+
+ common_init();
+ start_scan();
+
+ printk("Waiting for periodic advertising...\n");
+ WAIT_FOR_FLAG(flag_per_adv);
+ printk("Found periodic advertising.\n");
+
+ printk("Stopping scan\n");
+ err = bt_le_scan_stop();
+ if (err != 0) {
+ FAIL("Failed to stop scan: %d", err);
+ return;
+ }
+
+ create_pa_sync(&sync);
+
+ printk("Waiting for periodic sync lost...\n");
+ WAIT_FOR_FLAG(flag_per_adv_sync_lost);
+
+ PASS("Periodic advertising syncer passed\n");
+}
+
static void main_per_adv_conn_syncer(void)
{
struct bt_le_per_adv_sync *sync = NULL;
@@ -342,6 +369,15 @@
.test_main_f = main_per_adv_syncer
},
{
+ .test_id = "per_adv_syncer_app_not_scanning",
+ .test_descr = "Basic periodic advertising sync test but where "
+ "the app stopped scanning before creating sync."
+ "Expect the host to start scanning automatically.",
+ .test_post_init_f = test_init,
+ .test_tick_f = test_tick,
+ .test_main_f = main_per_adv_syncer_app_not_scanning
+ },
+ {
.test_id = "per_adv_conn_syncer",
.test_descr = "Periodic advertising sync test, but where there "
"is a connection between the advertiser and the "
diff --git a/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_app_not_scanning.sh b/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_app_not_scanning.sh
new file mode 100755
index 0000000..7362b53
--- /dev/null
+++ b/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_app_not_scanning.sh
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+# Copyright (c) 2024 Nordic Semiconductor ASA
+# SPDX-License-Identifier: Apache-2.0
+
+# Periodic advertising sync test where the host starts scanning
+# automatically because the application didn't start it.
+
+source ${ZEPHYR_BASE}/tests/bsim/sh_common.source
+
+simulation_id="per_adv_not_scanning"
+verbosity_level=2
+
+cd ${BSIM_OUT_PATH}/bin
+
+Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_host_adv_periodic_prj_conf \
+ -v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=0 \
+ -testid=per_adv_advertiser -rs=23
+
+Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_host_adv_periodic_prj_conf \
+ -v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=0 \
+ -testid=per_adv_syncer_app_not_scanning -rs=6
+
+Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \
+ -D=2 -sim_length=20e6 $@
+
+wait_for_background_jobs