From e5004d926158ec923fcdf6014ecb0c900961a508 Mon Sep 17 00:00:00 2001 From: Herman Berget Date: Thu, 7 Apr 2022 15:47:43 +0200 Subject: [PATCH] Bluetooth: Tests: Wait for sync from other devices only The sync mechanism using Babblesim backchannels picked up self-sent messages. Use the device number as data to disambiguate messages from other devices. Signed-off-by: Herman Berget --- .../bsim_bt/bsim_test_gatt_caching/src/common.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/bluetooth/bsim_bt/bsim_test_gatt_caching/src/common.c b/tests/bluetooth/bsim_bt/bsim_test_gatt_caching/src/common.c index 5b5f463d6c2..a7083921905 100644 --- a/tests/bluetooth/bsim_bt/bsim_test_gatt_caching/src/common.c +++ b/tests/bluetooth/bsim_bt/bsim_test_gatt_caching/src/common.c @@ -21,6 +21,7 @@ void test_init(void) } #define CHANNEL_ID 0 +#define MSG_SIZE 1 void backchannel_init(void) { @@ -39,8 +40,7 @@ void backchannel_init(void) void backchannel_sync_send(void) { - /* Dummy message */ - uint8_t sync_msg[] = { 'A' }; + uint8_t sync_msg[MSG_SIZE] = { get_device_nbr() }; printk("Sending sync\n"); bs_bc_send_msg(CHANNEL_ID, sync_msg, ARRAY_SIZE(sync_msg)); @@ -48,7 +48,17 @@ void backchannel_sync_send(void) void backchannel_sync_wait(void) { - while (!bs_bc_is_msg_received(CHANNEL_ID)) { + uint8_t sync_msg[MSG_SIZE]; + + while (true) { + if (bs_bc_is_msg_received(CHANNEL_ID) > 0) { + bs_bc_receive_msg(CHANNEL_ID, sync_msg, ARRAY_SIZE(sync_msg)); + if (sync_msg[0] != get_device_nbr()) { + /* Received a message from another device, exit */ + break; + } + } + k_sleep(K_MSEC(1)); }