Skip to content

Commit 4b31f8c

Browse files
Thalleycarlescufi
authored andcommitted
tests: Bluetooth: CSIP: Add no rank, size and lock char tests
Add tests for cases where the rank characteristic, the size characteristic and the lock characteristics are not set on the set members. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 5ce5940 commit 4b31f8c

File tree

5 files changed

+238
-49
lines changed

5 files changed

+238
-49
lines changed

tests/bsim/bluetooth/audio/src/csip_set_coordinator_test.c

Lines changed: 118 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@
99
#include <zephyr/bluetooth/audio/csip.h>
1010
#include "common.h"
1111

12+
static bool expect_rank = true;
13+
static bool expect_set_size = true;
14+
static bool expect_lockable = true;
15+
1216
extern enum bst_result_t bst_result;
1317
static volatile bool discovered;
1418
static volatile bool members_discovered;
19+
static volatile bool discover_timed_out;
1520
static volatile bool set_locked;
1621
static volatile bool set_unlocked;
1722
static volatile bool ordered_access_locked;
@@ -66,10 +71,32 @@ static void csip_discover_cb(struct bt_conn *conn,
6671
conn_index = bt_conn_index(conn);
6772

6873
for (size_t i = 0U; i < set_count; i++) {
74+
const uint8_t rank = member->insts[i].info.rank;
75+
const uint8_t set_size = member->insts[i].info.set_size;
76+
const uint8_t lockable = member->insts[i].info.lockable;
77+
6978
printk("CSIS[%zu]: %p\n", i, &member->insts[i]);
70-
printk("\tRank: %u\n", member->insts[i].info.rank);
71-
printk("\tSet Size: %u\n", member->insts[i].info.set_size);
72-
printk("\tLockable: %u\n", member->insts[i].info.lockable);
79+
printk("\tRank: %u\n", rank);
80+
printk("\tSet Size: %u\n", set_size);
81+
printk("\tLockable: %u\n", lockable);
82+
83+
if ((expect_rank && rank == 0U) || (!expect_rank && rank != 0U)) {
84+
FAIL("Unexpected rank: %u %u", expect_rank, rank);
85+
86+
return;
87+
}
88+
89+
if ((expect_set_size && set_size == 0U) || (!expect_set_size && set_size != 0U)) {
90+
FAIL("Unexpected set_size: %u %u", expect_set_size, set_size);
91+
92+
return;
93+
}
94+
95+
if (expect_lockable != lockable) {
96+
FAIL("Unexpected lockable: %u %u", expect_lockable, lockable);
97+
98+
return;
99+
}
73100
}
74101

75102
inst = &member->insts[0];
@@ -144,8 +171,11 @@ static bool csip_found(struct bt_data *data, void *user_data)
144171

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

147-
printk("Found member (%u / %u)\n",
148-
members_found, inst->info.set_size);
174+
if (inst->info.set_size == 0) {
175+
printk("Found member %u\n", members_found);
176+
} else {
177+
printk("Found member (%u / %u)\n", members_found, inst->info.set_size);
178+
}
149179

150180
/* Stop parsing */
151181
return false;
@@ -177,8 +207,11 @@ static struct bt_le_scan_cb csip_set_coordinator_scan_callbacks = {
177207

178208
static void discover_members_timer_handler(struct k_work *work)
179209
{
180-
FAIL("Could not find all members (%u / %u)\n",
181-
members_found, inst->info.set_size);
210+
if (inst->info.set_size > 0) {
211+
FAIL("Could not find all members (%u / %u)\n", members_found, inst->info.set_size);
212+
} else {
213+
discover_timed_out = true;
214+
}
182215
}
183216

184217
static void ordered_access(const struct bt_csip_set_coordinator_set_member **members,
@@ -282,9 +315,14 @@ static void test_main(void)
282315
return;
283316
}
284317

285-
WAIT_FOR_COND(members_found == inst->info.set_size);
318+
if (inst->info.set_size > 0) {
319+
WAIT_FOR_COND(members_found == inst->info.set_size);
320+
321+
(void)k_work_cancel_delayable(&discover_members_timer);
322+
} else {
323+
WAIT_FOR_COND(discover_timed_out);
324+
}
286325

287-
(void)k_work_cancel_delayable(&discover_members_timer);
288326
err = bt_le_scan_stop();
289327
if (err != 0) {
290328
FAIL("Scanning failed to stop (err %d)\n", err);
@@ -325,59 +363,73 @@ static void test_main(void)
325363
locked_members[i] = set_members[i];
326364
}
327365

328-
ordered_access(locked_members, connected_member_count, false);
329-
330-
printk("Locking set\n");
331-
err = bt_csip_set_coordinator_lock(locked_members, connected_member_count,
332-
&inst->info);
333-
if (err != 0) {
334-
FAIL("Failed to do set coordinator lock (%d)", err);
335-
return;
366+
if (inst->info.rank != 0U) {
367+
ordered_access(locked_members, connected_member_count, false);
336368
}
337369

338-
WAIT_FOR_COND(set_locked);
370+
if (inst->info.lockable) {
371+
printk("Locking set\n");
372+
err = bt_csip_set_coordinator_lock(locked_members, connected_member_count,
373+
&inst->info);
374+
if (err != 0) {
375+
FAIL("Failed to do set coordinator lock (%d)", err);
376+
return;
377+
}
339378

340-
ordered_access(locked_members, connected_member_count, true);
379+
WAIT_FOR_COND(set_locked);
380+
}
381+
382+
if (inst->info.rank != 0U) {
383+
ordered_access(locked_members, connected_member_count, inst->info.lockable);
384+
}
341385

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

344-
printk("Releasing set\n");
345-
err = bt_csip_set_coordinator_release(locked_members, connected_member_count,
346-
&inst->info);
347-
if (err != 0) {
348-
FAIL("Failed to do set coordinator release (%d)", err);
349-
return;
388+
if (inst->info.lockable) {
389+
printk("Releasing set\n");
390+
err = bt_csip_set_coordinator_release(locked_members, connected_member_count,
391+
&inst->info);
392+
if (err != 0) {
393+
FAIL("Failed to do set coordinator release (%d)", err);
394+
return;
395+
}
396+
397+
WAIT_FOR_COND(set_unlocked);
350398
}
351399

352-
WAIT_FOR_COND(set_unlocked);
400+
if (inst->info.rank != 0U) {
401+
ordered_access(locked_members, connected_member_count, false);
402+
}
353403

354-
ordered_access(locked_members, connected_member_count, false);
404+
if (inst->info.lockable) {
405+
/* Lock and unlock again */
406+
set_locked = false;
407+
set_unlocked = false;
355408

356-
/* Lock and unlock again */
357-
set_locked = false;
358-
set_unlocked = false;
409+
printk("Locking set\n");
410+
err = bt_csip_set_coordinator_lock(locked_members, connected_member_count,
411+
&inst->info);
412+
if (err != 0) {
413+
FAIL("Failed to do set coordinator lock (%d)", err);
414+
return;
415+
}
359416

360-
printk("Locking set\n");
361-
err = bt_csip_set_coordinator_lock(locked_members, connected_member_count,
362-
&inst->info);
363-
if (err != 0) {
364-
FAIL("Failed to do set coordinator lock (%d)", err);
365-
return;
417+
WAIT_FOR_COND(set_locked);
366418
}
367419

368-
WAIT_FOR_COND(set_locked);
369-
370420
k_sleep(K_MSEC(1000)); /* Simulate doing stuff */
371421

372-
printk("Releasing set\n");
373-
err = bt_csip_set_coordinator_release(locked_members, connected_member_count,
374-
&inst->info);
375-
if (err != 0) {
376-
FAIL("Failed to do set coordinator release (%d)", err);
377-
return;
378-
}
422+
if (inst->info.lockable) {
423+
printk("Releasing set\n");
424+
err = bt_csip_set_coordinator_release(locked_members, connected_member_count,
425+
&inst->info);
426+
if (err != 0) {
427+
FAIL("Failed to do set coordinator release (%d)", err);
428+
return;
429+
}
379430

380-
WAIT_FOR_COND(set_unlocked);
431+
WAIT_FOR_COND(set_unlocked);
432+
}
381433

382434
for (uint8_t i = 0; i < members_found; i++) {
383435
printk("Disconnecting member[%u] (%s)", i, addr);
@@ -393,17 +445,34 @@ static void test_main(void)
393445
PASS("All members disconnected\n");
394446
}
395447

448+
static void test_args(int argc, char *argv[])
449+
{
450+
for (int argn = 0; argn < argc; argn++) {
451+
const char *arg = argv[argn];
452+
453+
if (strcmp(arg, "no-size") == 0) {
454+
expect_set_size = false;
455+
} else if (strcmp(arg, "no-rank") == 0) {
456+
expect_rank = false;
457+
} else if (strcmp(arg, "no-lock") == 0) {
458+
expect_lockable = false;
459+
} else {
460+
FAIL("Invalid arg: %s", arg);
461+
}
462+
}
463+
}
464+
396465
static const struct bst_test_instance test_connect[] = {
397466

398467
{
399468
.test_id = "csip_set_coordinator",
400469
.test_post_init_f = test_init,
401470
.test_tick_f = test_tick,
402-
.test_main_f = test_main
471+
.test_main_f = test_main,
472+
.test_args_f = test_args,
403473
},
404474

405-
BSTEST_END_MARKER
406-
};
475+
BSTEST_END_MARKER};
407476

408477
struct bst_test_list *test_csip_set_coordinator_install(struct bst_test_list *tests)
409478
{

tests/bsim/bluetooth/audio/test_scripts/_csip.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ $dir_path/csip.sh
1111
$dir_path/csip_encrypted_sirk.sh
1212

1313
$dir_path/csip_forced_release.sh
14+
15+
$dir_path/csip_no_lock.sh
16+
17+
$dir_path/csip_no_rank.sh
18+
19+
$dir_path/csip_no_size.sh
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) 2023 Nordic Semiconductor ASA
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
# CSIP test where there is no lock characteristic on the Set Members
8+
9+
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source
10+
11+
VERBOSITY_LEVEL=2
12+
EXECUTE_TIMEOUT=20
13+
14+
cd ${BSIM_OUT_PATH}/bin
15+
16+
SIMULATION_ID="csip_no_lock"
17+
18+
Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \
19+
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=csip_set_coordinator \
20+
-RealEncryption=1 -rs=1 -argstest no-lock
21+
22+
Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \
23+
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=csip_set_member \
24+
-RealEncryption=1 -rs=2 -argstest rank 1 not-lockable
25+
26+
Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \
27+
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=2 -testid=csip_set_member \
28+
-RealEncryption=1 -rs=3 -argstest rank 2 not-lockable
29+
30+
Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \
31+
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=3 -testid=csip_set_member \
32+
-RealEncryption=1 -rs=4 -argstest rank 3 not-lockable
33+
34+
# Simulation time should be larger than the WAIT_TIME in common.h
35+
Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \
36+
-D=4 -sim_length=60e6 $@
37+
38+
wait_for_background_jobs
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) 2023 Nordic Semiconductor ASA
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
# CSIP test where there is no rank and no lock characteristic on the Set Members
8+
9+
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source
10+
11+
VERBOSITY_LEVEL=2
12+
EXECUTE_TIMEOUT=20
13+
14+
cd ${BSIM_OUT_PATH}/bin
15+
16+
SIMULATION_ID="csip_no_rank"
17+
18+
Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \
19+
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=csip_set_coordinator \
20+
-RealEncryption=1 -rs=1 -argstest no-rank no-lock
21+
22+
Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \
23+
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=csip_set_member \
24+
-RealEncryption=1 -rs=2 -argstest rank 0 not-lockable
25+
26+
Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \
27+
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=2 -testid=csip_set_member \
28+
-RealEncryption=1 -rs=3 -argstest rank 0 not-lockable
29+
30+
Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \
31+
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=3 -testid=csip_set_member \
32+
-RealEncryption=1 -rs=4 -argstest rank 0 not-lockable
33+
34+
# Simulation time should be larger than the WAIT_TIME in common.h
35+
Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \
36+
-D=4 -sim_length=60e6 $@
37+
38+
wait_for_background_jobs
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) 2023 Nordic Semiconductor ASA
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
# CSIP test where there is no set size characteristic on the Set Members
8+
9+
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source
10+
11+
VERBOSITY_LEVEL=2
12+
EXECUTE_TIMEOUT=20
13+
14+
cd ${BSIM_OUT_PATH}/bin
15+
16+
SIMULATION_ID="csip_no_size"
17+
18+
Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \
19+
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=csip_set_coordinator \
20+
-RealEncryption=1 -rs=1 -argstest no-size
21+
22+
Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \
23+
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=csip_set_member \
24+
-RealEncryption=1 -rs=2 -argstest rank 1 size 0
25+
26+
Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \
27+
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=2 -testid=csip_set_member \
28+
-RealEncryption=1 -rs=3 -argstest rank 2 size 0
29+
30+
Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \
31+
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=3 -testid=csip_set_member \
32+
-RealEncryption=1 -rs=4 -argstest rank 3s size 0
33+
34+
# Simulation time should be larger than the WAIT_TIME in common.h
35+
Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \
36+
-D=4 -sim_length=60e6 $@
37+
38+
wait_for_background_jobs

0 commit comments

Comments
 (0)