Commit c7ffce3e authored by Lucas Mathias Balling's avatar Lucas Mathias Balling Committed by Carles Cufi
Browse files

tests: Bluetooth: LLCP unittests for Periodic Sync Procedure

Added LLCP PDU Periodic Sync Indication unittests

Signed-off-by: default avatarLucas Mathias Balling <lutb@demant.com>
parent 39fcf021
Loading
Loading
Loading
Loading
+6 −0
Changes for tests/bluetooth/controller/common/include/helper_pdu.h: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -62,6 +62,8 @@ void helper_pdu_encode_cis_terminate_ind(struct pdu_data *pdu, void *param);
void helper_pdu_encode_sca_req(struct pdu_data *pdu, void *param);
void helper_pdu_encode_sca_rsp(struct pdu_data *pdu, void *param);

void helper_pdu_encode_periodic_sync_ind(struct pdu_data *pdu, void *param);

void helper_pdu_verify_ping_req(const char *file, uint32_t line, struct pdu_data *pdu, void *param);
void helper_pdu_verify_ping_rsp(const char *file, uint32_t line, struct pdu_data *pdu, void *param);

@@ -155,6 +157,9 @@ void helper_pdu_verify_cis_terminate_ind(const char *file, uint32_t line, struct
void helper_pdu_verify_sca_req(const char *file, uint32_t line, struct pdu_data *pdu, void *param);
void helper_pdu_verify_sca_rsp(const char *file, uint32_t line, struct pdu_data *pdu, void *param);

void helper_pdu_verify_periodic_sync_ind(const char *file, uint32_t line, struct pdu_data *pdu,
					 void *param);

void helper_node_verify_peer_sca_update(const char *file, uint32_t line, struct node_rx_pdu *rx,
				   void *param);

@@ -193,6 +198,7 @@ enum helper_pdu_opcode {
	LL_CIS_RSP,
	LL_CIS_IND,
	LL_CIS_TERMINATE_IND,
	LL_PERIODIC_SYNC_IND,
	LL_ZERO,
};

+70 −0
Changes for tests/bluetooth/controller/common/src/helper_pdu.c: 70 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -504,6 +504,33 @@ void helper_pdu_encode_sca_rsp(struct pdu_data *pdu, void *param)
	pdu->llctrl.clock_accuracy_rsp.sca = p->sca;
}

void helper_pdu_encode_periodic_sync_ind(struct pdu_data *pdu, void *param)
{
	struct pdu_data_llctrl_periodic_sync_ind *p = param;

	pdu->ll_id = PDU_DATA_LLID_CTRL;
	pdu->len = offsetof(struct pdu_data_llctrl, periodic_sync_ind) +
		sizeof(struct pdu_data_llctrl_periodic_sync_ind);
	pdu->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_PERIODIC_SYNC_IND;

	pdu->llctrl.periodic_sync_ind.id = sys_cpu_to_le16(p->id);

	memcpy(&pdu->llctrl.periodic_sync_ind.sync_info, &p->sync_info,
			sizeof(struct pdu_adv_sync_info));

	pdu->llctrl.periodic_sync_ind.conn_event_count = sys_cpu_to_le16(p->conn_event_count);
	pdu->llctrl.periodic_sync_ind.last_pa_event_counter =
							sys_cpu_to_le16(p->last_pa_event_counter);
	pdu->llctrl.periodic_sync_ind.sid = p->sid;
	pdu->llctrl.periodic_sync_ind.addr_type = p->addr_type;
	pdu->llctrl.periodic_sync_ind.sca = p->sca;
	pdu->llctrl.periodic_sync_ind.phy = p->phy;

	memcpy(pdu->llctrl.periodic_sync_ind.adv_addr, p->adv_addr, sizeof(p->adv_addr));

	pdu->llctrl.periodic_sync_ind.sync_conn_event_count = p->sync_conn_event_count;
}

void helper_pdu_verify_version_ind(const char *file, uint32_t line, struct pdu_data *pdu,
				   void *param)
{
@@ -1253,3 +1280,46 @@ void helper_pdu_verify_sca_rsp(const char *file, uint32_t line, struct pdu_data
	zassert_equal(pdu->llctrl.opcode, PDU_DATA_LLCTRL_TYPE_CLOCK_ACCURACY_RSP,
		      "Not a LL_CLOCK_ACCURACY_RSP.\nCalled at %s:%d\n", file, line);
}

void helper_pdu_verify_periodic_sync_ind(const char *file, uint32_t line, struct pdu_data *pdu,
					 void *param)
{
	struct pdu_data_llctrl_periodic_sync_ind *p = param;

	zassert_equal(pdu->ll_id, PDU_DATA_LLID_CTRL, "Not a Control PDU.\nCalled at %s:%d\n", file,
		      line);
	zassert_equal(pdu->llctrl.opcode, PDU_DATA_LLCTRL_TYPE_PERIODIC_SYNC_IND,
		      "Not a LL_PERIODIC_SYNC_IND.\nCalled at %s:%d\n", file, line);

	zassert_equal(pdu->llctrl.periodic_sync_ind.id, p->id,
		      "id mismatch.\nCalled at %s:%d\n", file, line);

	zassert_equal(pdu->llctrl.periodic_sync_ind.conn_event_count, p->conn_event_count,
		      "conn_event_count mismatch.\nCalled at %s:%d\n", file, line);

	zassert_equal(pdu->llctrl.periodic_sync_ind.last_pa_event_counter, p->last_pa_event_counter,
		      "last_pa_event_counter mismatch.\nCalled at %s:%d\n", file, line);

	zassert_equal(pdu->llctrl.periodic_sync_ind.sid, p->sid,
		      "sid mismatch.\nCalled at %s:%d\n", file, line);

	zassert_equal(pdu->llctrl.periodic_sync_ind.addr_type, p->addr_type,
		      "addr_type mismatch.\nCalled at %s:%d\n", file, line);

	zassert_equal(pdu->llctrl.periodic_sync_ind.sca, p->sca,
		      "sca mismatch.\nCalled at %s:%d\n", file, line);

	zassert_equal(pdu->llctrl.periodic_sync_ind.phy, p->phy,
		      "phy mismatch.\nCalled at %s:%d\n", file, line);

	zassert_equal(pdu->llctrl.periodic_sync_ind.sync_conn_event_count, p->sync_conn_event_count,
		      "sync_conn_event_count mismatch.\nCalled at %s:%d\n", file, line);

	zassert_mem_equal(&pdu->llctrl.periodic_sync_ind.sync_info, &p->sync_info,
			   sizeof(struct pdu_adv_sync_info),
			  "sync_info mismatch.\nCalled at %s:%d\n", file, line);

	zassert_mem_equal(pdu->llctrl.periodic_sync_ind.adv_addr, p->adv_addr,
			  sizeof(p->adv_addr),
			  "adv_addr mismatch.\nCalled at %s:%d\n", file, line);
}
+4 −0
Changes for tests/bluetooth/controller/common/src/helper_util.c: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@ helper_pdu_encode_func_t *const helper_pdu_encode[] = {
	[LL_CIS_RSP] = helper_pdu_encode_cis_rsp,
	[LL_CIS_IND] = helper_pdu_encode_cis_ind,
	[LL_CIS_TERMINATE_IND] = helper_pdu_encode_cis_terminate_ind,
	[LL_PERIODIC_SYNC_IND] = helper_pdu_encode_periodic_sync_ind,
	[LL_ZERO] = helper_pdu_encode_zero,
};

@@ -134,6 +135,7 @@ helper_pdu_verify_func_t *const helper_pdu_verify[] = {
	[LL_CIS_RSP] = helper_pdu_verify_cis_rsp,
	[LL_CIS_IND] = helper_pdu_verify_cis_ind,
	[LL_CIS_TERMINATE_IND] = helper_pdu_verify_cis_terminate_ind,
	[LL_PERIODIC_SYNC_IND] = helper_pdu_verify_periodic_sync_ind,
};

helper_pdu_ntf_verify_func_t *const helper_pdu_ntf_verify[] = {
@@ -170,6 +172,7 @@ helper_pdu_ntf_verify_func_t *const helper_pdu_ntf_verify[] = {
	[LL_CIS_RSP] = NULL,
	[LL_CIS_IND] = NULL,
	[LL_CIS_TERMINATE_IND] = NULL,
	[LL_PERIODIC_SYNC_IND] = NULL,
};

helper_node_encode_func_t *const helper_node_encode[] = {
@@ -203,6 +206,7 @@ helper_node_encode_func_t *const helper_node_encode[] = {
	[LL_CIS_RSP] = NULL,
	[LL_CIS_IND] = NULL,
	[LL_CIS_TERMINATE_IND] = NULL,
	[LL_PERIODIC_SYNC_IND] = NULL,
};

helper_node_verify_func_t *const helper_node_verify[] = {
+21 −0
Changes for tests/bluetooth/controller/ctrl_isoal/src/isoal_test_common.c: 21 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -20,6 +20,11 @@
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/sys/byteorder.h>

#include "hal/cpu.h"
#include "hal/ccm.h"
#include "hal/cntr.h"
#include "hal/ticker.h"

#include "util/memq.h"

#include "pdu_df.h"
@@ -35,6 +40,8 @@
#include "isoal_test_common.h"
#include "isoal_test_debug.h"

#define ULL_TIME_WRAPPING_POINT_US	(HAL_TICKER_TICKS_TO_US_64BIT(HAL_TICKER_CNTR_MASK))
#define ULL_TIME_SPAN_FULL_US		(ULL_TIME_WRAPPING_POINT_US + 1)

/**
 * Intializes a RX PDU buffer
@@ -270,3 +277,17 @@ void init_test_data_buffer(uint8_t *buf, uint16_t size)
		buf[i] = (uint8_t)(i & 0x00FF);
	}
}

/**
 * @brief Wraps given time within the range of 0 to ULL_TIME_WRAPPING_POINT_US
 * @param  time_now  Current time value
 * @param  time_diff Time difference (signed)
 * @return           Wrapped time after difference
 */
uint32_t ull_get_wrapped_time_us(uint32_t time_now_us, int32_t time_diff_us)
{
	uint32_t result = ((uint64_t)time_now_us + ULL_TIME_SPAN_FULL_US + time_diff_us) %
				((uint64_t)ULL_TIME_SPAN_FULL_US);

	return result;
}
+16 −0
Changes for tests/bluetooth/controller/ctrl_periodic_sync/CMakeLists.txt: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)

project(bluetooth_ull_llcp_periodic_sync)
find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE})

add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/controller/common common)
add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/controller/uut uut)

target_link_libraries(testbinary PRIVATE uut common)

target_sources(testbinary
  PRIVATE
    src/main.c
)
Loading