Skip to content

Commit 446ad09

Browse files
Thalleykartben
authored andcommitted
Bluetooth: PACS: Test and fix PACS Kconfig combinations
Add unit tests for all possible PACS combinations and fix issues found. Signed-off-by: Emil Gydesen <[email protected]>
1 parent e7b6fd0 commit 446ad09

File tree

3 files changed

+130
-80
lines changed

3 files changed

+130
-80
lines changed

subsys/bluetooth/audio/pacs.c

Lines changed: 72 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,19 @@ LOG_MODULE_REGISTER(bt_pacs, CONFIG_BT_PACS_LOG_LEVEL);
5050
#define READ_BUF_SEM_TIMEOUT K_MSEC(50)
5151

5252
#if defined(CONFIG_BT_PAC_SRC)
53-
static uint32_t pacs_src_location;
5453
static sys_slist_t src_pac_list = SYS_SLIST_STATIC_INIT(&src_pac_list);
5554
static uint16_t src_supported_contexts;
55+
#if defined(CONFIG_BT_PAC_SRC_LOC)
56+
static uint32_t pacs_src_location;
57+
#endif /* CONFIG_BT_PAC_SRC_LOC */
5658
#endif /* CONFIG_BT_PAC_SRC */
5759

5860
#if defined(CONFIG_BT_PAC_SNK)
59-
static uint32_t pacs_snk_location;
6061
static sys_slist_t snk_pac_list = SYS_SLIST_STATIC_INIT(&snk_pac_list);
6162
static uint16_t snk_supported_contexts;
63+
#if defined(CONFIG_BT_PAC_SNK_LOC)
64+
static uint32_t pacs_snk_location;
65+
#endif /* CONFIG_BT_PAC_SNK_LOC */
6266
#endif /* CONFIG_BT_PAC_SNK */
6367

6468
static uint16_t src_available_contexts = BT_AUDIO_CONTEXT_TYPE_PROHIBITED;
@@ -616,131 +620,118 @@ static sys_slist_t *pacs_get_pac(enum bt_audio_dir dir)
616620
#define BT_PACS_SNK_PROP \
617621
BT_GATT_CHRC_READ \
618622
IF_ENABLED(CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE, (|BT_GATT_CHRC_NOTIFY))
619-
#define BT_PAC_SNK(_read) \
620-
BT_AUDIO_CHRC(BT_UUID_PACS_SNK, \
621-
BT_PACS_SNK_PROP, \
622-
BT_GATT_PERM_READ_ENCRYPT, \
623-
_read, NULL, NULL), \
623+
#define BT_PAC_SNK \
624+
BT_AUDIO_CHRC(BT_UUID_PACS_SNK, BT_PACS_SNK_PROP, BT_GATT_PERM_READ_ENCRYPT, snk_read, \
625+
NULL, NULL), \
624626
IF_ENABLED(CONFIG_BT_PAC_SNK_NOTIFIABLE, (BT_AUDIO_CCC(snk_cfg_changed),))
625627

626628
#define BT_PACS_SNK_LOC_PROP \
627629
BT_GATT_CHRC_READ \
628630
IF_ENABLED(CONFIG_BT_PAC_SNK_LOC_WRITEABLE, (|BT_GATT_CHRC_WRITE)) \
629631
IF_ENABLED(CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE, (|BT_GATT_CHRC_NOTIFY))
630632

631-
#define BT_PACS_SNK_LOC_PERM \
632-
BT_GATT_PERM_READ_ENCRYPT \
633+
#define BT_PACS_SNK_LOC_PERM \
634+
BT_GATT_PERM_READ_ENCRYPT \
633635
IF_ENABLED(CONFIG_BT_PAC_SNK_LOC_WRITEABLE, (|BT_GATT_PERM_WRITE_ENCRYPT))
634636

635-
#define BT_PACS_SNK_LOC(_read) \
636-
BT_AUDIO_CHRC(BT_UUID_PACS_SNK_LOC, \
637-
BT_PACS_SNK_LOC_PROP, \
638-
BT_PACS_SNK_LOC_PERM, \
639-
_read, \
640-
COND_CODE_1(CONFIG_BT_PAC_SNK_LOC_WRITEABLE, (snk_loc_write), (NULL)), \
641-
NULL), \
637+
/* declaration + value [+ cccd] */
638+
#define PACS_SNK_PAC_CHAR_ATTR_COUNT COND_CODE_1(IS_ENABLED(CONFIG_BT_PAC_SNK_NOTIFIABLE), (3), (2))
639+
#else
640+
#define BT_PAC_SNK
641+
#define PACS_SNK_PAC_CHAR_ATTR_COUNT 0
642+
#endif /* CONFIG_BT_PAC_SNK */
643+
644+
#if defined(CONFIG_BT_PAC_SNK_LOC)
645+
#define BT_PACS_SNK_LOC \
646+
BT_AUDIO_CHRC(BT_UUID_PACS_SNK_LOC, BT_PACS_SNK_LOC_PROP, BT_PACS_SNK_LOC_PERM, \
647+
snk_loc_read, \
648+
COND_CODE_1(CONFIG_BT_PAC_SNK_LOC_WRITEABLE, (snk_loc_write), (NULL)), NULL),\
642649
IF_ENABLED(CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE, (BT_AUDIO_CCC(snk_loc_cfg_changed),))
650+
651+
/* declaration + value [+ cccd] */
652+
#define PACS_SNK_PAC_LOC_CHAR_ATTR_COUNT \
653+
COND_CODE_1(IS_ENABLED(CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE), (3), (2))
643654
#else
644-
#define BT_PAC_SNK(_read)
645-
#define BT_PACS_SNK_LOC(_read)
646-
#endif
655+
#define BT_PACS_SNK_LOC
656+
#define PACS_SNK_PAC_LOC_CHAR_ATTR_COUNT 0
657+
#endif /* CONFIG_BT_PAC_SNK_LOC*/
647658

648659
#if defined(CONFIG_BT_PAC_SRC)
649660
#define BT_PACS_SRC_PROP \
650661
BT_GATT_CHRC_READ \
651662
IF_ENABLED(CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE, (|BT_GATT_CHRC_NOTIFY))
652-
#define BT_PAC_SRC(_read) \
653-
BT_AUDIO_CHRC(BT_UUID_PACS_SRC, \
654-
BT_PACS_SRC_PROP, \
655-
BT_GATT_PERM_READ_ENCRYPT, \
656-
_read, NULL, NULL), \
663+
#define BT_PAC_SRC \
664+
BT_AUDIO_CHRC(BT_UUID_PACS_SRC, BT_PACS_SRC_PROP, BT_GATT_PERM_READ_ENCRYPT, src_read, \
665+
NULL, NULL), \
657666
IF_ENABLED(CONFIG_BT_PAC_SRC_NOTIFIABLE, (BT_AUDIO_CCC(src_cfg_changed),))
658667

659668
#define BT_PACS_SRC_LOC_PROP \
660669
BT_GATT_CHRC_READ \
661670
IF_ENABLED(CONFIG_BT_PAC_SRC_LOC_WRITEABLE, (|BT_GATT_CHRC_WRITE)) \
662671
IF_ENABLED(CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE, (|BT_GATT_CHRC_NOTIFY))
663672

664-
#define BT_PACS_SRC_LOC_PERM \
665-
BT_GATT_PERM_READ_ENCRYPT \
673+
#define BT_PACS_SRC_LOC_PERM \
674+
BT_GATT_PERM_READ_ENCRYPT \
666675
IF_ENABLED(CONFIG_BT_PAC_SRC_LOC_WRITEABLE, (|BT_GATT_PERM_WRITE_ENCRYPT))
667676

668-
#define BT_PACS_SRC_LOC(_read) \
669-
BT_AUDIO_CHRC(BT_UUID_PACS_SRC_LOC, \
670-
BT_PACS_SRC_LOC_PROP, \
671-
BT_PACS_SRC_LOC_PERM, \
672-
_read, \
673-
COND_CODE_1(CONFIG_BT_PAC_SRC_LOC_WRITEABLE, (src_loc_write), (NULL)), \
674-
NULL), \
677+
/* declaration + value [+ cccd] */
678+
#define PACS_SRC_PAC_CHAR_ATTR_COUNT COND_CODE_1(IS_ENABLED(CONFIG_BT_PAC_SRC_NOTIFIABLE), (3), (2))
679+
#else
680+
#define BT_PAC_SRC
681+
#define PACS_SRC_PAC_CHAR_ATTR_COUNT 0
682+
#endif
683+
684+
#if defined(CONFIG_BT_PAC_SRC_LOC)
685+
#define BT_PACS_SRC_LOC \
686+
BT_AUDIO_CHRC(BT_UUID_PACS_SRC_LOC, BT_PACS_SRC_LOC_PROP, BT_PACS_SRC_LOC_PERM, \
687+
src_loc_read, \
688+
COND_CODE_1(CONFIG_BT_PAC_SRC_LOC_WRITEABLE, (src_loc_write), (NULL)), NULL),\
675689
IF_ENABLED(CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE, (BT_AUDIO_CCC(src_loc_cfg_changed),))
690+
691+
/* declaration + value [+ cccd] */
692+
#define PACS_SRC_PAC_LOC_CHAR_ATTR_COUNT \
693+
COND_CODE_1(IS_ENABLED(CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE), (3), (2))
676694
#else
677-
#define BT_PAC_SRC(_read)
678-
#define BT_PACS_SRC_LOC(_read)
695+
#define BT_PACS_SRC_LOC
696+
#define PACS_SRC_PAC_LOC_CHAR_ATTR_COUNT 0
679697
#endif
680698

681-
#define BT_PAC_AVAILABLE_CONTEXT(_read) \
682-
BT_AUDIO_CHRC(BT_UUID_PACS_AVAILABLE_CONTEXT, \
683-
BT_GATT_CHRC_READ|BT_GATT_CHRC_NOTIFY, \
684-
BT_GATT_PERM_READ_ENCRYPT, \
685-
_read, NULL, NULL), \
699+
#define BT_PAC_AVAILABLE_CONTEXT \
700+
BT_AUDIO_CHRC(BT_UUID_PACS_AVAILABLE_CONTEXT, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \
701+
BT_GATT_PERM_READ_ENCRYPT, available_contexts_read, NULL, NULL), \
686702
BT_AUDIO_CCC(available_context_cfg_changed),
687703

688704
#define BT_PACS_SUPPORTED_CONTEXT_PROP \
689705
BT_GATT_CHRC_READ \
690706
IF_ENABLED(CONFIG_BT_PACS_SUPPORTED_CONTEXT_NOTIFIABLE, (|BT_GATT_CHRC_NOTIFY))
691707

692-
#define BT_PAC_SUPPORTED_CONTEXT(_read) \
693-
BT_AUDIO_CHRC(BT_UUID_PACS_SUPPORTED_CONTEXT, \
694-
BT_PACS_SUPPORTED_CONTEXT_PROP, \
695-
BT_GATT_PERM_READ_ENCRYPT, \
696-
_read, NULL, NULL), \
697-
IF_ENABLED(CONFIG_BT_PACS_SUPPORTED_CONTEXT_NOTIFIABLE, \
708+
#define BT_PAC_SUPPORTED_CONTEXT \
709+
BT_AUDIO_CHRC(BT_UUID_PACS_SUPPORTED_CONTEXT, BT_PACS_SUPPORTED_CONTEXT_PROP, \
710+
BT_GATT_PERM_READ_ENCRYPT, supported_context_read, NULL, NULL), \
711+
IF_ENABLED(CONFIG_BT_PACS_SUPPORTED_CONTEXT_NOTIFIABLE, \
698712
(BT_AUDIO_CCC(supported_context_cfg_changed),))
699713

700-
#define BT_PACS_SERVICE_DEFINITION() { \
701-
BT_GATT_PRIMARY_SERVICE(BT_UUID_PACS), \
702-
BT_PAC_SNK(snk_read) \
703-
BT_PACS_SNK_LOC(snk_loc_read) \
704-
BT_PAC_SRC(src_read) \
705-
BT_PACS_SRC_LOC(src_loc_read) \
706-
BT_PAC_AVAILABLE_CONTEXT(available_contexts_read) \
707-
BT_PAC_SUPPORTED_CONTEXT(supported_context_read) \
714+
#define BT_PACS_SERVICE_DEFINITION() { \
715+
BT_GATT_PRIMARY_SERVICE(BT_UUID_PACS), \
716+
BT_PAC_SNK \
717+
BT_PACS_SNK_LOC \
718+
BT_PAC_SRC \
719+
BT_PACS_SRC_LOC \
720+
BT_PAC_AVAILABLE_CONTEXT \
721+
BT_PAC_SUPPORTED_CONTEXT \
708722
}
709723

710724
static const struct bt_gatt_attr _pacs_attrs[] = BT_PACS_SERVICE_DEFINITION();
711725
static struct bt_gatt_attr pacs_attrs[] = BT_PACS_SERVICE_DEFINITION();
712726
static struct bt_gatt_service pacs_svc = (struct bt_gatt_service)BT_GATT_SERVICE(pacs_attrs);
713727

714-
#if defined(CONFIG_BT_PAC_SNK)
715-
/* declaration + value [+ cccd] */
716-
#define PACS_SNK_PAC_CHAR_ATTR_COUNT COND_CODE_1(IS_ENABLED(CONFIG_BT_PAC_SNK_NOTIFIABLE), (3), (2))
717-
/* declaration + value [+ cccd] */
718-
#define PACS_SNK_PAC_LOC_CHAR_ATTR_COUNT \
719-
COND_CODE_1(IS_ENABLED(CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE), (3), (2))
720-
#else
721-
#define PACS_SNK_PAC_CHAR_ATTR_COUNT 0
722-
#define PACS_SNK_PAC_LOC_CHAR_ATTR_COUNT 0
723-
#endif /* CONFIG_BT_PAC_SNK */
724-
725-
#if defined(CONFIG_BT_PAC_SRC)
726-
/* declaration + value [+ cccd] */
727-
#define PACS_SRC_PAC_CHAR_ATTR_COUNT COND_CODE_1(IS_ENABLED(CONFIG_BT_PAC_SRC_NOTIFIABLE), (3), (2))
728-
/* declaration + value [+ cccd] */
729-
#define PACS_SRC_PAC_LOC_CHAR_ATTR_COUNT \
730-
COND_CODE_1(IS_ENABLED(CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE), (3), (2))
731-
#else
732-
#define PACS_SRC_PAC_CHAR_ATTR_COUNT 0
733-
#define PACS_SRC_PAC_LOC_CHAR_ATTR_COUNT 0
734-
#endif /* CONFIG_BT_PAC_SNK */
735-
736728
static void configure_pacs_char(const struct bt_bap_pacs_register_param *param)
737729
{
738730
const uint8_t first_attr_offset = 1U;
739731
struct bt_gatt_attr *svc_attrs =
740732
&pacs_svc.attrs[first_attr_offset]; /* first attribute is the service */
741733
uint8_t attrs_to_rem = 0U;
742734
uint8_t first_to_rem = 0U;
743-
uint8_t src_pac_offset;
744735

745736
/* Remove the Sink PAC and Location */
746737
#if defined(CONFIG_BT_PAC_SNK_LOC)
@@ -764,8 +755,9 @@ static void configure_pacs_char(const struct bt_bap_pacs_register_param *param)
764755
pacs_svc.attr_count -= attrs_to_rem;
765756
}
766757

758+
#if defined(CONFIG_BT_PAC_SRC)
767759
/* Set first_to_rem to the start of Source PAC Char, for cleaner offset calc */
768-
src_pac_offset =
760+
const uint8_t src_pac_offset =
769761
(PACS_SNK_PAC_CHAR_ATTR_COUNT + PACS_SNK_PAC_LOC_CHAR_ATTR_COUNT) - attrs_to_rem;
770762
attrs_to_rem = 0U;
771763

@@ -776,12 +768,11 @@ static void configure_pacs_char(const struct bt_bap_pacs_register_param *param)
776768
attrs_to_rem = PACS_SRC_PAC_LOC_CHAR_ATTR_COUNT;
777769
}
778770
#endif /* CONFIG_BT_PAC_SRC_LOC */
779-
#if defined(CONFIG_BT_PAC_SRC)
771+
780772
if (!param->src_pac) {
781773
first_to_rem = src_pac_offset;
782774
attrs_to_rem = PACS_SRC_PAC_CHAR_ATTR_COUNT + PACS_SRC_PAC_LOC_CHAR_ATTR_COUNT;
783775
}
784-
#endif /* CONFIG_BT_PAC_SRC */
785776

786777
if (attrs_to_rem > 0U) {
787778
for (uint8_t i = first_to_rem + attrs_to_rem;
@@ -790,6 +781,7 @@ static void configure_pacs_char(const struct bt_bap_pacs_register_param *param)
790781
}
791782
pacs_svc.attr_count -= attrs_to_rem;
792783
}
784+
#endif /* CONFIG_BT_PAC_SRC */
793785
}
794786

795787
static bool valid_pacs_register_param(const struct bt_bap_pacs_register_param *param)

tests/bluetooth/audio/pacs/src/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,25 @@ ZTEST_SUITE(pacs_test_suite, NULL, NULL, NULL, pacs_test_suite_after, NULL);
4545
static ZTEST(pacs_test_suite, test_pacs_register)
4646
{
4747
const struct bt_bap_pacs_register_param pacs_params[] = {
48+
#if defined(CONFIG_BT_PAC_SNK)
4849
/* valid snk_pac combinations */
4950
PACS_REGISTER_PARAM(true, true, true, true),
5051
PACS_REGISTER_PARAM(true, true, true, false),
5152
PACS_REGISTER_PARAM(true, true, false, false),
5253
PACS_REGISTER_PARAM(true, false, true, true),
5354
PACS_REGISTER_PARAM(true, false, true, false),
5455
PACS_REGISTER_PARAM(true, false, false, false),
56+
#endif /* CONFIG_BT_PAC_SNK */
5557

58+
#if defined(CONFIG_BT_PAC_SRC)
5659
/* valid src_pac combinations */
5760
PACS_REGISTER_PARAM(true, true, true, true),
5861
PACS_REGISTER_PARAM(true, false, true, true),
5962
PACS_REGISTER_PARAM(false, false, true, true),
6063
PACS_REGISTER_PARAM(true, true, true, false),
6164
PACS_REGISTER_PARAM(true, false, true, false),
6265
PACS_REGISTER_PARAM(false, false, true, false),
66+
#endif /* CONFIG_BT_PAC_SRC */
6367
};
6468

6569
for (size_t i = 0U; i < ARRAY_SIZE(pacs_params); i++) {

tests/bluetooth/audio/pacs/testcase.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,57 @@ common:
55
tests:
66
bluetooth.audio.pacs.test_default:
77
type: unit
8+
extra_configs:
9+
- CONFIG_BT_PAC_SNK=y
10+
- CONFIG_BT_PAC_SNK_LOC=y
11+
- CONFIG_BT_PAC_SRC=y
12+
- CONFIG_BT_PAC_SRC_LOC=y
13+
bluetooth.audio.pacs.test_snk_pac_snk_loc_src_pac:
14+
type: unit
15+
extra_configs:
16+
- CONFIG_BT_PAC_SNK=y
17+
- CONFIG_BT_PAC_SNK_LOC=y
18+
- CONFIG_BT_PAC_SRC=y
19+
- CONFIG_BT_PAC_SRC_LOC=n
20+
bluetooth.audio.pacs.test_snk_pac_snk_loc:
21+
type: unit
22+
extra_configs:
23+
- CONFIG_BT_PAC_SNK=y
24+
- CONFIG_BT_PAC_SNK_LOC=y
25+
- CONFIG_BT_PAC_SRC=n
26+
- CONFIG_BT_PAC_SRC_LOC=n
27+
bluetooth.audio.pacs.test_snk_pac:
28+
type: unit
29+
extra_configs:
30+
- CONFIG_BT_PAC_SNK=y
31+
- CONFIG_BT_PAC_SNK_LOC=n
32+
- CONFIG_BT_PAC_SRC=n
33+
- CONFIG_BT_PAC_SRC_LOC=n
34+
bluetooth.audio.pacs.test_snk_pac_src_pac_src_loc:
35+
type: unit
36+
extra_configs:
37+
- CONFIG_BT_PAC_SNK=y
38+
- CONFIG_BT_PAC_SNK_LOC=n
39+
- CONFIG_BT_PAC_SRC=y
40+
- CONFIG_BT_PAC_SRC_LOC=y
41+
bluetooth.audio.pacs.test_snk_pac_src_pac:
42+
type: unit
43+
extra_configs:
44+
- CONFIG_BT_PAC_SNK=y
45+
- CONFIG_BT_PAC_SNK_LOC=n
46+
- CONFIG_BT_PAC_SRC=y
47+
- CONFIG_BT_PAC_SRC_LOC=n
48+
bluetooth.audio.pacs.test_src_pac_src_loc:
49+
type: unit
50+
extra_configs:
51+
- CONFIG_BT_PAC_SNK=n
52+
- CONFIG_BT_PAC_SNK_LOC=n
53+
- CONFIG_BT_PAC_SRC=y
54+
- CONFIG_BT_PAC_SRC_LOC=y
55+
bluetooth.audio.pacs.test_src_pac:
56+
type: unit
57+
extra_configs:
58+
- CONFIG_BT_PAC_SNK=n
59+
- CONFIG_BT_PAC_SNK_LOC=n
60+
- CONFIG_BT_PAC_SRC=y
61+
- CONFIG_BT_PAC_SRC_LOC=n

0 commit comments

Comments
 (0)