tests: bsim: Bluetooth: Audio: Add additional testing of discovery
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 <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
ec41dd9ba6
commit
954f2a09fb
@ -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
|
||||
|
||||
@ -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]);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
@ -99,7 +99,10 @@ 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;
|
||||
}
|
||||
@ -107,7 +110,7 @@ static void csip_discover_cb(struct bt_conn *conn,
|
||||
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(
|
||||
@ -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];
|
||||
|
||||
@ -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 */
|
||||
@ -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++],
|
||||
@ -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;
|
||||
}
|
||||
@ -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)",
|
||||
@ -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;
|
||||
@ -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) {
|
||||
@ -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 {
|
||||
@ -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;
|
||||
@ -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;
|
||||
@ -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;
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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;
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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;
|
||||
@ -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) {
|
||||
|
||||
@ -460,11 +460,25 @@ static void test_signal_interval(uint8_t index)
|
||||
printk("Client signal interval test success\n");
|
||||
}
|
||||
|
||||
static void discover_tbs(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
discovery_complete = false;
|
||||
|
||||
err = bt_tbs_client_discover(default_conn);
|
||||
if (err) {
|
||||
FAIL("Failed to discover TBS: %d", err);
|
||||
return;
|
||||
}
|
||||
|
||||
WAIT_FOR_COND(discovery_complete);
|
||||
}
|
||||
|
||||
static void test_main(void)
|
||||
{
|
||||
int err;
|
||||
int index = 0;
|
||||
int tbs_client_err;
|
||||
|
||||
err = bt_enable(bt_ready);
|
||||
|
||||
@ -490,12 +504,8 @@ static void test_main(void)
|
||||
|
||||
WAIT_FOR_COND(is_connected);
|
||||
|
||||
tbs_client_err = bt_tbs_client_discover(default_conn);
|
||||
if (tbs_client_err) {
|
||||
FAIL("Failed to discover TBS_CLIENT for connection %d", tbs_client_err);
|
||||
}
|
||||
|
||||
WAIT_FOR_COND(discovery_complete);
|
||||
discover_tbs();
|
||||
discover_tbs(); /* test that we can discover twice */
|
||||
|
||||
printk("GTBS %sfound\n", is_gtbs_found ? "" : "not ");
|
||||
|
||||
|
||||
@ -113,6 +113,23 @@ static struct bt_le_scan_cb scan_callbacks = {
|
||||
.recv = scan_recv,
|
||||
};
|
||||
|
||||
static void discover_tmas(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
UNSET_FLAG(flag_tmap_discovered);
|
||||
|
||||
/* Discover TMAS service on peer */
|
||||
err = bt_tmap_discover(default_conn, &tmap_callbacks);
|
||||
if (err != 0) {
|
||||
FAIL("Failed to initiate TMAS discovery: %d\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
printk("TMAP Central Starting Service Discovery...\n");
|
||||
WAIT_FOR_FLAG(flag_tmap_discovered);
|
||||
}
|
||||
|
||||
static void test_main(void)
|
||||
{
|
||||
int err;
|
||||
@ -141,15 +158,9 @@ static void test_main(void)
|
||||
|
||||
printk("Scanning successfully started\n");
|
||||
WAIT_FOR_FLAG(flag_connected);
|
||||
/* Discover TMAS service on peer */
|
||||
err = bt_tmap_discover(default_conn, &tmap_callbacks);
|
||||
if (err != 0) {
|
||||
FAIL("Failed to initiate TMAS discovery: %d\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
printk("TMAP Central Starting Service Discovery...\n");
|
||||
WAIT_FOR_FLAG(flag_tmap_discovered);
|
||||
discover_tmas();
|
||||
discover_tmas(); /* test that we can discover twice */
|
||||
|
||||
PASS("TMAP Client test passed\n");
|
||||
}
|
||||
|
||||
@ -811,6 +811,8 @@ static void test_discover(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
g_discovery_complete = false;
|
||||
|
||||
/* Invalid behavior */
|
||||
err = bt_vcp_vol_ctlr_discover(NULL, &vol_ctlr);
|
||||
if (err == 0) {
|
||||
@ -832,16 +834,6 @@ static void test_discover(void)
|
||||
}
|
||||
|
||||
WAIT_FOR_COND(g_discovery_complete);
|
||||
|
||||
/* Verify that we can discover again */
|
||||
g_discovery_complete = false;
|
||||
err = bt_vcp_vol_ctlr_discover(default_conn, &vol_ctlr);
|
||||
if (err != 0) {
|
||||
FAIL("Failed to discover VCP for the second time: %d\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
WAIT_FOR_COND(g_discovery_complete);
|
||||
}
|
||||
|
||||
static void test_included_get(void)
|
||||
@ -1169,6 +1161,7 @@ static void test_main(void)
|
||||
WAIT_FOR_FLAG(flag_connected);
|
||||
|
||||
test_discover();
|
||||
test_discover(); /* test that we can discover twice */
|
||||
test_included_get();
|
||||
test_conn_get();
|
||||
test_read_state();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user