1#!/usr/bin/env bash
2# Copyright (c) 2025 Nordic Semiconductor ASA
3# SPDX-License-Identifier: Apache-2.0
4
5source ${ZEPHYR_BASE}/tests/bsim/sh_common.source
6
7VERBOSITY_LEVEL=2
8EXECUTE_TIMEOUT=60
9BSIM_EXE=./bs_${BOARD_TS}_tests_bsim_bluetooth_audio_prj_conf
10
11cd ${BSIM_OUT_PATH}/bin
12
13function Execute_ac() {
14    if [[ -n $ac_tx_preset ]]; then
15        ac_tx_preset_arg="${ac_tx_preset_arg_name} ${ac_tx_preset}"
16    else
17        ac_tx_preset_arg=""
18    fi
19
20    if [[ -n $ac_rx_preset ]]; then
21        ac_rx_preset_arg="source_preset ${ac_rx_preset}"
22    else
23        ac_rx_preset_arg=""
24    fi
25
26
27    sim_id="${ac_profile}_ac_${ac_config}_${ac_tx_preset}_${ac_rx_preset}"
28
29    printf "\n\n======== Running %s AC_%s with %s %s =========\n\n" \
30        "${ac_profile}" "${ac_config}" "${ac_tx_preset_arg}" "${ac_rx_preset_arg}"
31
32    let ac_device_count=1+${ac_acc_cnt}
33    ac_ini_name=${ac_ini_name}_${ac_config}
34
35    Execute ${BSIM_EXE} -v=${VERBOSITY_LEVEL} -s=${sim_id} -d=0 -testid=${ac_ini_name} \
36        -RealEncryption=1 -rs=23 -D=${ac_device_count} \
37        -argstest ${ac_tx_preset_arg} ${ac_rx_preset_arg}
38
39    for i in $(seq 1 $ac_acc_cnt); do
40        let rs=${i}*7 # ensure unique random seed value per acceptor
41
42        Execute ${BSIM_EXE} -v=${VERBOSITY_LEVEL} -s=${sim_id} -d=${i} -testid=${ac_acc_name} \
43            -RealEncryption=1 -rs=${rs} -D=${ac_device_count}
44    done
45
46    Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${sim_id} -D=${ac_device_count} \
47        -sim_length=60e6 $@
48
49    wait_for_background_jobs
50}
51
52function Execute_cap_unicast_ac() {
53    ac_profile="CAP" ac_ini_name=cap_initiator_ac ac_acc_name=cap_acceptor_unicast \
54        ac_tx_preset_arg_name=sink_preset Execute_ac $@
55}
56
57function Execute_cap_broadcast_ac() {
58    ac_profile="CAP" ac_ini_name=cap_initiator_ac ac_acc_name=cap_acceptor_broadcast \
59        ac_tx_preset_arg_name=preset Execute_ac $@
60}
61
62function Execute_gmap_unicast_ac() {
63    ac_profile="GMAP" ac_ini_name=gmap_ugg_ac ac_acc_name=gmap_ugt \
64        ac_tx_preset_arg_name=sink_preset Execute_ac $@
65}
66
67function Execute_gmap_broadcast_ac() {
68    ac_profile="GMAP" ac_ini_name=gmap_ugg_ac ac_acc_name=cap_acceptor_broadcast \
69        ac_tx_preset_arg_name=broadcast_preset Execute_ac $@
70}
71