Skip to content

Commit 6db7778

Browse files
ppryga-nordiccfriedt
authored andcommitted
tests: Bluetooth: df: Add test to verify correctness of relase of PDUs
Add unit tests that will ensure the CTE disable operation does not cause breaking of LLL operations by too early release of chained PDUs. The tests verify if numbers of PDUs in free PDUs fifo and free PDUs memory pool are correct. Signed-off-by: Piotr Pryga <[email protected]>
1 parent bd65231 commit 6db7778

File tree

6 files changed

+278
-31
lines changed

6 files changed

+278
-31
lines changed

subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,3 +1542,15 @@ static inline bool isr_rx_ci_adva_check(uint8_t tx_addr, uint8_t *addr,
15421542
return (tx_addr == ci->rx_addr) &&
15431543
!memcmp(addr, ci->connect_ind.adv_addr, BDADDR_SIZE);
15441544
}
1545+
1546+
#if defined(CONFIG_ZTEST)
1547+
uint32_t lll_adv_free_pdu_fifo_count_get(void)
1548+
{
1549+
return MFIFO_AVAIL_COUNT_GET(pdu_free);
1550+
}
1551+
1552+
uint32_t lll_adv_pdu_mem_free_count_get(void)
1553+
{
1554+
return mem_free_count_get(mem_pdu.free);
1555+
}
1556+
#endif /* CONFIG_ZTEST */

subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_internal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,8 @@ bool lll_adv_connect_ind_check(struct lll_adv *lll, struct pdu_adv *ci,
7878
uint8_t tx_addr, uint8_t *addr,
7979
uint8_t rx_addr, uint8_t *tgt_addr,
8080
uint8_t devmatch_ok, uint8_t *rl_idx);
81+
82+
#if defined(CONFIG_ZTEST)
83+
uint32_t lll_adv_free_pdu_fifo_count_get(void);
84+
uint32_t lll_adv_pdu_mem_free_count_get(void);
85+
#endif /* CONFIG_ZTEST */

tests/bluetooth/df/connectionless_cte_chains/src/common.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ void common_release_adv_set(struct ll_adv_set *adv_set)
108108
if (sync) {
109109
sync->is_started = 0U;
110110
}
111+
112+
lll_adv_data_reset(&sync->lll.data);
111113
}
112114
adv_set->lll.sync = NULL;
113115
if (adv_set->df_cfg->is_enabled) {
@@ -196,8 +198,14 @@ void common_release_per_adv_chain(struct ll_adv_set *adv_set)
196198

197199
lll_sync = adv_set->lll.sync;
198200
pdu = lll_adv_sync_data_peek(lll_sync, NULL);
201+
if (pdu != NULL) {
202+
lll_adv_pdu_linked_release_all(pdu);
203+
}
199204

200-
lll_adv_pdu_linked_release_all(pdu);
205+
pdu = (void *)lll_sync->data.pdu[lll_sync->data.first];
206+
if (pdu != NULL) {
207+
lll_adv_pdu_linked_release_all(pdu);
208+
}
201209
}
202210

203211
/*
@@ -443,6 +451,17 @@ void common_validate_chain_with_cte(struct ll_adv_set *adv, uint8_t cte_count,
443451
}
444452
}
445453

454+
/*
455+
* @brief Helper function to cleanup after test case end.
456+
*
457+
* @param adv Pointer to advertising set
458+
*/
459+
void common_teardown(struct ll_adv_set *adv)
460+
{
461+
common_release_per_adv_chain(adv);
462+
common_release_adv_set(adv);
463+
lll_adv_init();
464+
}
446465
/*
447466
* @brief Helper function to add payload data to extended advertising PDU.
448467
*

tests/bluetooth/df/connectionless_cte_chains/src/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ void common_prepare_df_cfg(struct ll_adv_set *adv, uint8_t cte_count);
1919
void common_validate_per_adv_chain(struct ll_adv_set *adv, uint8_t pdu_count);
2020
void common_validate_chain_with_cte(struct ll_adv_set *adv, uint8_t cte_count,
2121
uint8_t ad_data_pdu_count);
22+
void common_teardown(struct ll_adv_set *adv);

tests/bluetooth/df/connectionless_cte_chains/src/test_add_cte_to_chain.c

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "lll/lll_adv_types.h"
2424
#include "lll_adv.h"
2525
#include "lll/lll_adv_pdu.h"
26+
#include "lll/lll_adv_internal.h"
2627
#include "lll_adv_sync.h"
2728
#include "lll/lll_df_types.h"
2829

@@ -62,9 +63,7 @@ void test_add_number_of_cte_to_sigle_pdu_chain(void)
6263
/* Validate result */
6364
common_validate_chain_with_cte(adv, TEST_CTE_COUNT, TEST_PER_ADV_SINGLE_PDU);
6465

65-
/* Teardown */
66-
common_release_per_adv_chain(adv);
67-
common_release_adv_set(adv);
66+
common_teardown(adv);
6867
}
6968

7069
void test_add_cte_for_each_pdu_in_chain(void)
@@ -90,9 +89,7 @@ void test_add_cte_for_each_pdu_in_chain(void)
9089
/* Validate result */
9190
common_validate_chain_with_cte(adv, TEST_CTE_COUNT, TEST_CTE_COUNT);
9291

93-
/* Teardown */
94-
common_release_per_adv_chain(adv);
95-
common_release_adv_set(adv);
92+
common_teardown(adv);
9693
}
9794

9895
void test_add_cte_for_not_all_pdu_in_chain(void)
@@ -118,9 +115,44 @@ void test_add_cte_for_not_all_pdu_in_chain(void)
118115
/* Validate result */
119116
common_validate_chain_with_cte(adv, TEST_CTE_COUNT, TEST_PER_ADV_CHAIN_LENGTH);
120117

121-
/* Teardown */
122-
common_release_per_adv_chain(adv);
123-
common_release_adv_set(adv);
118+
common_teardown(adv);
119+
}
120+
121+
void test_add_cte_to_not_all_pdus_in_chain_enqueued_to_lll(void)
122+
{
123+
struct pdu_adv *pdu_prev, *pdu_new;
124+
struct ll_adv_set *adv;
125+
uint8_t handle;
126+
uint8_t upd;
127+
int err;
128+
129+
/* Setup for test */
130+
adv = common_create_adv_set(TEST_ADV_SET_HANDLE);
131+
/* Use the same number for PDUs in a chain as for CTE request */
132+
common_prepare_df_cfg(adv, TEST_CTE_COUNT);
133+
common_create_per_adv_chain(adv, TEST_PER_ADV_CHAIN_LENGTH);
134+
common_validate_per_adv_chain(adv, TEST_PER_ADV_CHAIN_LENGTH);
135+
136+
/* Swap PDU double buffer and get new latest PDU data */
137+
pdu_new = lll_adv_sync_data_latest_get(adv->lll.sync, NULL, &upd);
138+
zassert_not_equal(pdu_new, NULL,
139+
"Unexpected value of new PDU pointer after PDU double buffer swap");
140+
141+
pdu_prev = lll_adv_sync_data_peek(adv->lll.sync, NULL);
142+
zassert_equal(pdu_prev, pdu_new,
143+
"Unexpected value of previous PDU pointer after PDU double buffer swap");
144+
145+
handle = ull_adv_handle_get(adv);
146+
147+
err = ll_df_set_cl_cte_tx_enable(handle, true);
148+
zassert_equal(err, 0,
149+
"Unexpected error while enabling CTE for periodic avertising chain, err: %d",
150+
err);
151+
152+
/* Validate result */
153+
common_validate_chain_with_cte(adv, TEST_CTE_COUNT, TEST_PER_ADV_CHAIN_LENGTH);
154+
155+
common_teardown(adv);
124156
}
125157

126158
void test_add_cte_for_single_pdu_chain(void)
@@ -146,9 +178,7 @@ void test_add_cte_for_single_pdu_chain(void)
146178
/* Validate result */
147179
common_validate_chain_with_cte(adv, TEST_CTE_SINGLE, TEST_PER_ADV_SINGLE_PDU);
148180

149-
/* Teardown */
150-
common_release_per_adv_chain(adv);
151-
common_release_adv_set(adv);
181+
common_teardown(adv);
152182
}
153183

154184
void run_add_cte_to_per_adv_chain_tests(void)
@@ -157,6 +187,7 @@ void run_add_cte_to_per_adv_chain_tests(void)
157187
ztest_unit_test(test_add_number_of_cte_to_sigle_pdu_chain),
158188
ztest_unit_test(test_add_cte_for_each_pdu_in_chain),
159189
ztest_unit_test(test_add_cte_for_not_all_pdu_in_chain),
190+
ztest_unit_test(test_add_cte_to_not_all_pdus_in_chain_enqueued_to_lll),
160191
ztest_unit_test(test_add_cte_for_single_pdu_chain));
161192
ztest_run_test_suite(test_add_cte_to_per_adv_chain);
162193
}

0 commit comments

Comments
 (0)