Skip to content

Commit

Permalink
tests: bsim: Bluetooth: Audio: Add additional testing of discovery
Browse files Browse the repository at this point in the history
Expand the babblesim tests for LE audio to verify that all the
discovery functions can be called multiple times without error.

HAS is an exception as that has an existing separate check
that disallows discovery multiple times.

Signed-off-by: Emil Gydesen <[email protected]>
  • Loading branch information
Thalley authored and MaureenHelm committed Feb 2, 2024
1 parent ec41dd9 commit 954f2a0
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 86 deletions.
2 changes: 2 additions & 0 deletions tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1022,8 +1022,10 @@ static void test_main(void)
exchange_mtu();

discover_sinks();
discover_sinks(); /* test that we can discover twice */

discover_sources();
discover_sources(); /* test that we can discover twice */

/* Run the stream setup multiple time to ensure states are properly
* set and reset
Expand Down
1 change: 1 addition & 0 deletions tests/bsim/bluetooth/audio/src/cap_commander_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ static void test_main_cap_commander_capture_and_render(void)

/* TODO: We should use CSIP to find set members */
discover_cas(connected_conns[i]);
discover_cas(connected_conns[i]); /* test that we can discover twice */

if (IS_ENABLED(CONFIG_BT_VCP_VOL_CTLR)) {
discover_vcs(connected_conns[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ static void test_main_cap_initiator_unicast(void)
WAIT_FOR_FLAG(flag_mtu_exchanged);

discover_cas(default_conn);
discover_cas(default_conn); /* test that we can discover twice */

discover_sink(default_conn);
discover_source(default_conn);
Expand Down
89 changes: 47 additions & 42 deletions tests/bsim/bluetooth/audio/src/csip_set_coordinator_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static volatile bool set_locked;
static volatile bool set_unlocked;
static volatile bool ordered_access_locked;
static volatile bool ordered_access_unlocked;
static const struct bt_csip_set_coordinator_csis_inst *inst;
static const struct bt_csip_set_coordinator_csis_inst *primary_inst;

static uint8_t members_found;
static struct k_work_delayable discover_members_timer;
Expand Down Expand Up @@ -99,15 +99,18 @@ static void csip_discover_cb(struct bt_conn *conn,
}
}

inst = &member->insts[0];
if (primary_inst == NULL) {
primary_inst = &member->insts[0];
}

set_members[conn_index] = member;
discovered = true;
}

static void csip_lock_changed_cb(struct bt_csip_set_coordinator_csis_inst *inst,
bool locked)
{
printk("Inst %p %s\n", inst, locked ? "locked" : "released");
printk("inst %p %s\n", inst, locked ? "locked" : "released");
}

static void csip_set_coordinator_ordered_access_cb(
Expand Down Expand Up @@ -156,7 +159,7 @@ static bool is_discovered(const bt_addr_le_t *addr)

static bool csip_found(struct bt_data *data, void *user_data)
{
if (bt_csip_set_coordinator_is_set_member(inst->info.set_sirk, data)) {
if (bt_csip_set_coordinator_is_set_member(primary_inst->info.set_sirk, data)) {
const bt_addr_le_t *addr = user_data;
char addr_str[BT_ADDR_LE_STR_LEN];

Expand All @@ -171,10 +174,11 @@ static bool csip_found(struct bt_data *data, void *user_data)

bt_addr_le_copy(&addr_found[members_found++], addr);

if (inst->info.set_size == 0) {
if (primary_inst->info.set_size == 0) {
printk("Found member %u\n", members_found);
} else {
printk("Found member (%u / %u)\n", members_found, inst->info.set_size);
printk("Found member (%u / %u)\n", members_found,
primary_inst->info.set_size);
}

/* Stop parsing */
Expand All @@ -189,7 +193,7 @@ static void csip_set_coordinator_scan_recv(const struct bt_le_scan_recv_info *in
{
/* We're only interested in connectable events */
if (info->adv_props & BT_GAP_ADV_PROP_CONNECTABLE) {
if (inst == NULL) {
if (primary_inst == NULL) {
/* Scanning for the first device */
if (members_found == 0) {
bt_addr_le_copy(&addr_found[members_found++],
Expand All @@ -207,8 +211,9 @@ static struct bt_le_scan_cb csip_set_coordinator_scan_callbacks = {

static void discover_members_timer_handler(struct k_work *work)
{
if (inst->info.set_size > 0) {
FAIL("Could not find all members (%u / %u)\n", members_found, inst->info.set_size);
if (primary_inst->info.set_size > 0) {
FAIL("Could not find all members (%u / %u)\n", members_found,
primary_inst->info.set_size);
} else {
discover_timed_out = true;
}
Expand All @@ -228,8 +233,7 @@ static void ordered_access(const struct bt_csip_set_coordinator_set_member **mem
ordered_access_unlocked = false;
}

err = bt_csip_set_coordinator_ordered_access(members, count,
&inst->info,
err = bt_csip_set_coordinator_ordered_access(members, count, &primary_inst->info,
csip_set_coordinator_oap_cb);
if (err != 0) {
FAIL("Failed to do CSIP set coordinator ordered access (%d)",
Expand All @@ -244,6 +248,21 @@ static void ordered_access(const struct bt_csip_set_coordinator_set_member **mem
}
}

static void discover_csis(struct bt_conn *conn)
{
int err;

discovered = false;

err = bt_csip_set_coordinator_discover(conns[bt_conn_index(conn)]);
if (err != 0) {
FAIL("Failed to initialize set coordinator for connection %d\n", err);
return;
}

WAIT_FOR_COND(discovered);
}

static void test_main(void)
{
int err;
Expand Down Expand Up @@ -293,14 +312,8 @@ static void test_main(void)
WAIT_FOR_FLAG(flag_connected);
connected_member_count++;

err = bt_csip_set_coordinator_discover(conns[0]);
if (err != 0) {
FAIL("Failed to initialize set coordinator for connection %d\n",
err);
return;
}

WAIT_FOR_COND(discovered);
discover_csis(conns[0]);
discover_csis(conns[0]); /* test that we can discover twice */

err = bt_le_scan_start(BT_LE_SCAN_ACTIVE, NULL);
if (err != 0) {
Expand All @@ -315,8 +328,8 @@ static void test_main(void)
return;
}

if (inst->info.set_size > 0) {
WAIT_FOR_COND(members_found == inst->info.set_size);
if (primary_inst->info.set_size > 0) {
WAIT_FOR_COND(members_found == primary_inst->info.set_size);

(void)k_work_cancel_delayable(&discover_members_timer);
} else {
Expand Down Expand Up @@ -347,30 +360,22 @@ static void test_main(void)
WAIT_FOR_FLAG(flag_connected);
connected_member_count++;

discovered = false;
printk("Doing discovery on member[%u]", i);
err = bt_csip_set_coordinator_discover(conns[i]);
if (err != 0) {
FAIL("Failed to initialize set coordinator for connection %d\n",
err);
return;
}

WAIT_FOR_COND(discovered);
discover_csis(conns[i]);
}

for (size_t i = 0; i < ARRAY_SIZE(locked_members); i++) {
locked_members[i] = set_members[i];
}

if (inst->info.rank != 0U) {
if (primary_inst->info.rank != 0U) {
ordered_access(locked_members, connected_member_count, false);
}

if (inst->info.lockable) {
if (primary_inst->info.lockable) {
printk("Locking set\n");
err = bt_csip_set_coordinator_lock(locked_members, connected_member_count,
&inst->info);
&primary_inst->info);
if (err != 0) {
FAIL("Failed to do set coordinator lock (%d)", err);
return;
Expand All @@ -379,16 +384,16 @@ static void test_main(void)
WAIT_FOR_COND(set_locked);
}

if (inst->info.rank != 0U) {
ordered_access(locked_members, connected_member_count, inst->info.lockable);
if (primary_inst->info.rank != 0U) {
ordered_access(locked_members, connected_member_count, primary_inst->info.lockable);
}

k_sleep(K_MSEC(1000)); /* Simulate doing stuff */

if (inst->info.lockable) {
if (primary_inst->info.lockable) {
printk("Releasing set\n");
err = bt_csip_set_coordinator_release(locked_members, connected_member_count,
&inst->info);
&primary_inst->info);
if (err != 0) {
FAIL("Failed to do set coordinator release (%d)", err);
return;
Expand All @@ -397,18 +402,18 @@ static void test_main(void)
WAIT_FOR_COND(set_unlocked);
}

if (inst->info.rank != 0U) {
if (primary_inst->info.rank != 0U) {
ordered_access(locked_members, connected_member_count, false);
}

if (inst->info.lockable) {
if (primary_inst->info.lockable) {
/* Lock and unlock again */
set_locked = false;
set_unlocked = false;

printk("Locking set\n");
err = bt_csip_set_coordinator_lock(locked_members, connected_member_count,
&inst->info);
&primary_inst->info);
if (err != 0) {
FAIL("Failed to do set coordinator lock (%d)", err);
return;
Expand All @@ -419,10 +424,10 @@ static void test_main(void)

k_sleep(K_MSEC(1000)); /* Simulate doing stuff */

if (inst->info.lockable) {
if (primary_inst->info.lockable) {
printk("Releasing set\n");
err = bt_csip_set_coordinator_release(locked_members, connected_member_count,
&inst->info);
&primary_inst->info);
if (err != 0) {
FAIL("Failed to do set coordinator release (%d)", err);
return;
Expand Down
1 change: 1 addition & 0 deletions tests/bsim/bluetooth/audio/src/gmap_ugg_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,7 @@ static void test_gmap_ugg_unicast_ac(const struct gmap_unicast_ac_param *param)
}

discover_gmas(connected_conns[i]);
discover_gmas(connected_conns[i]); /* test that we can discover twice */
}

gmap_ac_unicast(param, &unicast_group);
Expand Down
1 change: 1 addition & 0 deletions tests/bsim/bluetooth/audio/src/gmap_ugt_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ static void test_main(void)
WAIT_FOR_FLAG(flag_connected);

discover_gmas(default_conn);
discover_gmas(default_conn); /* test that we can discover twice */

WAIT_FOR_FLAG(flag_disconnected);

Expand Down
23 changes: 16 additions & 7 deletions tests/bsim/bluetooth/audio/src/has_client_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,21 @@ static bool test_preset_prev(uint8_t active_index_expected)
return g_active_index == active_index_expected;
}

static void discover_has(void)
{
int err;

g_service_discovered = false;

err = bt_has_client_discover(default_conn);
if (err < 0) {
FAIL("Failed to discover HAS (err %d)\n", err);
return;
}

WAIT_FOR_COND(g_service_discovered);
}

static void test_main(void)
{
int err;
Expand Down Expand Up @@ -188,13 +203,7 @@ static void test_main(void)

WAIT_FOR_FLAG(flag_connected);

err = bt_has_client_discover(default_conn);
if (err < 0) {
FAIL("Failed to discover HAS (err %d)\n", err);
return;
}

WAIT_FOR_COND(g_service_discovered);
discover_has();
WAIT_FOR_COND(g_preset_switched);

err = bt_has_client_presets_read(g_has, BT_HAS_PRESET_INDEX_FIRST, 255);
Expand Down
24 changes: 17 additions & 7 deletions tests/bsim/bluetooth/audio/src/ias_client_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ static void test_alert_stop(struct bt_conn *conn)
}
}

static void discover_ias(void)
{
int err;

UNSET_FLAG(g_service_discovered);

err = bt_ias_discover(default_conn);
if (err < 0) {
FAIL("Failed to discover IAS (err %d)\n", err);
return;
}

WAIT_FOR_FLAG(g_service_discovered);
}

static void test_main(void)
{
int err;
Expand Down Expand Up @@ -95,13 +110,8 @@ static void test_main(void)

WAIT_FOR_FLAG(flag_connected);

err = bt_ias_discover(default_conn);
if (err < 0) {
FAIL("Failed to discover IAS (err %d)\n", err);
return;
}

WAIT_FOR_FLAG(g_service_discovered);
discover_ias();
discover_ias(); /* test that we can discover twice */

/* Set alert levels with a delay to let the server handle any changes it want */
test_alert_high(default_conn);
Expand Down
1 change: 1 addition & 0 deletions tests/bsim/bluetooth/audio/src/mcc_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2454,6 +2454,7 @@ void test_main(void)
WAIT_FOR_FLAG(flag_conn_updated);

test_discover();
test_discover(); /* test that we can discover twice */

reset_test_iteration(i);

Expand Down
22 changes: 17 additions & 5 deletions tests/bsim/bluetooth/audio/src/micp_mic_ctlr_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,21 @@ static int test_aics(void)
return 0;
}

static void discover_mics(struct bt_micp_mic_ctlr **mic_ctlr)
{
int err;

g_discovery_complete = false;

err = bt_micp_mic_ctlr_discover(default_conn, mic_ctlr);
if (err != 0) {
FAIL("Failed to discover MICS %d", err);
return;
}

WAIT_FOR_COND(g_discovery_complete);
}

static void test_main(void)
{
int err;
Expand Down Expand Up @@ -371,11 +386,8 @@ static void test_main(void)
printk("Scanning successfully started\n");
WAIT_FOR_FLAG(flag_connected);

err = bt_micp_mic_ctlr_discover(default_conn, &mic_ctlr);
if (err != 0) {
FAIL("Failed to discover MICS %d", err);
}
WAIT_FOR_COND(g_discovery_complete);
discover_mics(&mic_ctlr);
discover_mics(&mic_ctlr); /* test that we can discover twice */

err = bt_micp_mic_ctlr_included_get(mic_ctlr, &micp_included);
if (err != 0) {
Expand Down
Loading

0 comments on commit 954f2a0

Please sign in to comment.