Skip to content

Commit 457a20c

Browse files
PavelVPVmmahadevan108
authored andcommitted
test: bsim: bluetooth: mesh: Wait until adv is actually sent
k_sleep may not be enough to let advertiser send the message. Instead we should rely on the bt_mesh_send_cb. Signed-off-by: Pavel Vasilyev <[email protected]>
1 parent 4c5c434 commit 457a20c

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,11 +569,17 @@ uint16_t bt_mesh_test_own_addr_get(uint16_t start_addr)
569569
}
570570

571571
void bt_mesh_test_send_over_adv(void *data, size_t len)
572+
{
573+
bt_mesh_test_send_over_adv_cb(data, len, NULL, NULL);
574+
}
575+
576+
void bt_mesh_test_send_over_adv_cb(void *data, size_t len, const struct bt_mesh_send_cb *cb,
577+
void *cb_data)
572578
{
573579
struct bt_mesh_adv *adv = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL,
574580
BT_MESH_TRANSMIT(0, 20), K_NO_WAIT);
575581
net_buf_simple_add_mem(&adv->b, data, len);
576-
bt_mesh_adv_send(adv, NULL, NULL);
582+
bt_mesh_adv_send(adv, cb, cb_data);
577583
}
578584

579585
int bt_mesh_test_wait_for_packet(bt_le_scan_cb_t scan_cb, struct k_sem *observer_sem, uint16_t wait)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ void bt_mesh_test_ra_cb_setup(void (*cb)(uint8_t *, size_t));
204204
uint16_t bt_mesh_test_own_addr_get(uint16_t start_addr);
205205

206206
void bt_mesh_test_send_over_adv(void *data, size_t len);
207+
void bt_mesh_test_send_over_adv_cb(void *data, size_t len, const struct bt_mesh_send_cb *cb,
208+
void *cb_data);
207209
/* Wait for a packet (i. e. an advertisement or a GATT frame) sent by a device.
208210
* `scan_cb` is triggered if the packet is received, and must release `observer_sem` when finished.
209211
*/

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,29 @@ static void dut_pub_common(bool disable_bt)
318318
ASSERT_OK(bt_mesh_suspend());
319319
}
320320

321+
static void send_start(uint16_t duration, int err, void *cb_data)
322+
{
323+
if (err) {
324+
FAIL("Failed to send message (err %d)", err);
325+
}
326+
}
327+
328+
static void send_end(int err, void *cb_data)
329+
{
330+
k_sem_give((struct k_sem *)cb_data);
331+
}
332+
321333
static void dut_gatt_common(bool disable_bt)
322334
{
335+
struct k_sem send_sem;
336+
337+
k_sem_init(&send_sem, 0, 1);
338+
339+
const struct bt_mesh_send_cb send_cb = {
340+
.start = send_start,
341+
.end = send_end,
342+
};
343+
323344
bt_mesh_test_cfg_set(NULL, WAIT_TIME);
324345
bt_mesh_device_setup(&prov, &comp);
325346
ASSERT_OK_MSG(bt_mesh_prov_enable(BT_MESH_PROV_GATT), "Failed to enable GATT provisioner");
@@ -336,8 +357,9 @@ static void dut_gatt_common(bool disable_bt)
336357

337358
/* Send a mesh message to notify Tester that DUT is about to be suspended. */
338359
dut_status = DUT_SUSPENDED;
339-
bt_mesh_test_send_over_adv(&dut_status, sizeof(enum dut_mesh_status));
340-
k_sleep(K_MSEC(150));
360+
bt_mesh_test_send_over_adv_cb(&dut_status, sizeof(enum dut_mesh_status), &send_cb,
361+
&send_sem);
362+
ASSERT_OK(k_sem_take(&send_sem, K_MSEC(200)));
341363

342364
ASSERT_OK_MSG(bt_mesh_suspend(), "Failed to suspend Mesh.");
343365

0 commit comments

Comments
 (0)