Skip to content

Commit 58f35ea

Browse files
PavelVPVaescolar
authored andcommitted
tests: Bluetooth: Mesh: Remove device synchronization API
This API was creating more problems than solving. We should not use back channel in bsim tests unless there is no other way to communicate between devices. To synchronize devices we should use k_sleep. This addresses #55821 Signed-off-by: Pavel Vasilyev <[email protected]>
1 parent ec6433e commit 58f35ea

File tree

4 files changed

+4
-114
lines changed

4 files changed

+4
-114
lines changed

tests/bluetooth/bsim/mesh/src/mesh_test.c

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -503,81 +503,6 @@ void bt_mesh_test_ra_cb_setup(void (*cb)(uint8_t *, size_t))
503503
ra_cb = cb;
504504
}
505505

506-
void bt_mesh_test_sync_init(struct bt_mesh_test_sync_ctx *ctx)
507-
{
508-
ctx->chan_id = bs_open_back_channel(get_device_nbr(),
509-
ctx->dev_nmbr,
510-
ctx->chan_nmbr, ctx->cnt);
511-
}
512-
513-
static bool wait_for_sync(uint32_t channel_id, int *wait, uint8_t msg_len)
514-
{
515-
int size;
516-
517-
while (true) {
518-
size = bs_bc_is_msg_received(channel_id);
519-
520-
if (size < 0) {
521-
FAIL("Sync channel error: %d", size);
522-
} else if (size > 0) {
523-
ASSERT_EQUAL(size, msg_len);
524-
return true;
525-
} else if (*wait <= 0) {
526-
return false;
527-
}
528-
529-
k_sleep(K_MSEC(100));
530-
*wait -= 100;
531-
}
532-
}
533-
534-
bool bt_mesh_test_sync_multi(struct bt_mesh_test_sync_ctx *ctx, uint32_t channel, uint16_t wait_sec)
535-
{
536-
const uint32_t barrier_msg = 0xC0FFEE;
537-
uint32_t recv_msg;
538-
int wait = wait_sec * MSEC_PER_SEC;
539-
540-
for (int i = 0; i < ctx->cnt; i++) {
541-
if (ctx->chan_nmbr[i] != channel) {
542-
continue;
543-
}
544-
545-
if (!wait_for_sync(ctx->chan_id[i], &wait, sizeof(barrier_msg))) {
546-
return false;
547-
}
548-
549-
bs_bc_receive_msg(ctx->chan_id[i], (uint8_t *)&recv_msg, sizeof(recv_msg));
550-
ASSERT_EQUAL(barrier_msg, recv_msg);
551-
}
552-
553-
for (int i = 0; i < ctx->cnt; i++) {
554-
if (ctx->chan_nmbr[i] != channel) {
555-
continue;
556-
}
557-
558-
bs_bc_send_msg(ctx->chan_id[i], (uint8_t *)&barrier_msg, sizeof(barrier_msg));
559-
}
560-
561-
return true;
562-
}
563-
564-
bool bt_mesh_test_sync(uint32_t channel_id, uint16_t wait_sec)
565-
{
566-
const uint32_t barrier_msg = 0xC0FFEE;
567-
uint32_t recv_msg;
568-
int wait = wait_sec * MSEC_PER_SEC;
569-
570-
bs_bc_send_msg(channel_id, (uint8_t *)&barrier_msg, sizeof(barrier_msg));
571-
572-
if (!wait_for_sync(channel_id, &wait, sizeof(barrier_msg))) {
573-
return false;
574-
}
575-
576-
bs_bc_receive_msg(channel_id, (uint8_t *)&recv_msg, sizeof(recv_msg));
577-
ASSERT_EQUAL(barrier_msg, recv_msg);
578-
return true;
579-
}
580-
581506
uint16_t bt_mesh_test_own_addr_get(uint16_t start_addr)
582507
{
583508
return start_addr + get_device_nbr();

tests/bluetooth/bsim/mesh/src/mesh_test.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,6 @@ int bt_mesh_test_send_ra(uint16_t addr, uint8_t *data, size_t len,
156156
void *cb_data);
157157
void bt_mesh_test_ra_cb_setup(void (*cb)(uint8_t *, size_t));
158158

159-
void bt_mesh_test_sync_init(struct bt_mesh_test_sync_ctx *ctx);
160-
bool bt_mesh_test_sync_multi(struct bt_mesh_test_sync_ctx *ctx, uint32_t channel,
161-
uint16_t wait_sec);
162-
bool bt_mesh_test_sync(uint32_t channel_id, uint16_t wait_sec);
163-
164159
uint16_t bt_mesh_test_own_addr_get(uint16_t start_addr);
165160

166161
#if defined(CONFIG_BT_MESH_SAR_CFG)

tests/bluetooth/bsim/mesh/src/test_blob.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -950,13 +950,6 @@ static void test_srv_trans_complete(void)
950950
static void test_cli_trans_resume(void)
951951
{
952952
int err;
953-
struct bt_mesh_test_sync_ctx sync = {
954-
.chan_nmbr = (uint32_t[]){ SYNC_CHAN },
955-
.dev_nmbr = (uint32_t[]){ SRV1_DEV },
956-
.cnt = 1
957-
};
958-
959-
bt_mesh_test_sync_init(&sync);
960953

961954
bt_mesh_test_cfg_set(NULL, 800);
962955
bt_mesh_device_setup(&prov, &cli_comp);
@@ -1002,8 +995,6 @@ static void test_cli_trans_resume(void)
1002995

1003996
ASSERT_TRUE(blob_cli.state == BT_MESH_BLOB_CLI_STATE_SUSPENDED);
1004997

1005-
/* Sync with the server device to enable scanning again. */
1006-
ASSERT_TRUE(bt_mesh_test_sync(sync.chan_id[0], 3));
1007998
/* Initiate resumption of BLOB transfer */
1008999
err = bt_mesh_blob_cli_resume(&blob_cli);
10091000
if (err) {
@@ -1021,14 +1012,6 @@ static void test_cli_trans_resume(void)
10211012

10221013
static void test_srv_trans_resume(void)
10231014
{
1024-
struct bt_mesh_test_sync_ctx sync = {
1025-
.chan_nmbr = (uint32_t[]){ SYNC_CHAN },
1026-
.dev_nmbr = (uint32_t[]){ 0 },
1027-
.cnt = 1
1028-
};
1029-
1030-
bt_mesh_test_sync_init(&sync);
1031-
10321015
bt_mesh_test_cfg_set(NULL, 800);
10331016
bt_mesh_device_setup(&prov, &srv_comp);
10341017
blob_srv_prov_and_conf(bt_mesh_test_own_addr_get(BLOB_CLI_ADDR));
@@ -1059,8 +1042,8 @@ static void test_srv_trans_resume(void)
10591042

10601043
ASSERT_TRUE(blob_srv.phase == BT_MESH_BLOB_XFER_PHASE_SUSPENDED);
10611044

1062-
/* Wait for BLOB client to suspend */
1063-
ASSERT_TRUE(bt_mesh_test_sync(sync.chan_id[0], 400));
1045+
/* Wait for BLOB client to suspend. Measured experimentally. */
1046+
k_sleep(K_SECONDS(140));
10641047

10651048
bt_mesh_scan_enable();
10661049

tests/bluetooth/bsim/mesh/src/test_transport.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,14 @@ static void test_tx_va(void)
152152
{
153153
uint16_t virtual_addr;
154154
int err;
155-
struct bt_mesh_test_sync_ctx sync = {
156-
.chan_nmbr = (uint32_t[]){ SYNC_CHAN },
157-
.dev_nmbr = (uint32_t[]){ SRV1_DEV },
158-
.cnt = 1
159-
};
160155

161-
bt_mesh_test_sync_init(&sync);
162156
bt_mesh_test_setup();
163157

164158
err = bt_mesh_va_add(test_va_uuid, &virtual_addr);
165159
ASSERT_OK_MSG(err, "Virtual addr add failed (err %d)", err);
166160

167-
ASSERT_TRUE(bt_mesh_test_sync(sync.chan_id[0], 4));
161+
/* Wait for the receiver to subscribe on address. */
162+
k_sleep(K_SECONDS(1));
168163

169164
for (int i = 0; i < ARRAY_SIZE(test_vector); i++) {
170165
err = bt_mesh_test_send(virtual_addr, test_vector[i].len,
@@ -438,21 +433,13 @@ static void test_rx_va(void)
438433
uint16_t virtual_addr;
439434
uint8_t status;
440435
int err;
441-
struct bt_mesh_test_sync_ctx sync = {
442-
.chan_nmbr = (uint32_t[]){ SYNC_CHAN },
443-
.dev_nmbr = (uint32_t[]){ CLI_DEV },
444-
.cnt = 1
445-
};
446436

447-
bt_mesh_test_sync_init(&sync);
448437
bt_mesh_test_setup();
449438

450439
err = bt_mesh_cfg_cli_mod_sub_va_add(0, cfg->addr, cfg->addr, test_va_uuid,
451440
TEST_MOD_ID, &virtual_addr, &status);
452441
ASSERT_OK_MSG(err || status, "Sub add failed (err %d, status %u)", err, status);
453442

454-
ASSERT_TRUE(bt_mesh_test_sync(sync.chan_id[0], 4));
455-
456443
for (int i = 0; i < ARRAY_SIZE(test_vector); i++) {
457444
err = bt_mesh_test_recv(test_vector[i].len, virtual_addr,
458445
K_SECONDS(20));

0 commit comments

Comments
 (0)