1#!/usr/bin/env bash
2# Copyright (c) 2023 Nordic Semiconductor
3# SPDX-License-Identifier: Apache-2.0
4
5source ${ZEPHYR_BASE}/tests/bsim/sh_common.source
6
7simulation_id="conn_stress"
8process_ids=""; exit_code=0
9
10# We don't use the `Execute` fn from `bsim/sh_common.source` as
11# `wait_for_background_jobs` will terminate the script if there's an error, and
12# this test will fail often. We still want to run the packet conversion scripts,
13# especially if the test was not successful.
14function Execute(){
15  if [ ! -f $1 ]; then
16    echo -e "ERR! \e[91m`pwd`/`basename $1` cannot be found (did you forget to\
17 compile it?)\e[39m"
18    exit 1
19  fi
20  timeout 60 $@ & process_ids="$process_ids $!"
21
22  echo "Running $@"
23}
24
25test_path="bsim_bluetooth_host_misc_conn_stress"
26bsim_central_exe_name="bs_${BOARD_TS}_${test_path}_central_prj_conf"
27bsim_peripheral_exe_name="bs_${BOARD_TS}_${test_path}_peripheral_prj_conf"
28
29# terminate running simulations (if any)
30${BSIM_COMPONENTS_PATH}/common/stop_bsim.sh $simulation_id
31
32cd ${BSIM_OUT_PATH}/bin
33
34bsim_args="-RealEncryption=1 -v=2 -s=${simulation_id}"
35test_args="-argstest notify_size=220 conn_interval=32"
36
37nr_of_units=12
38
39for device in `seq 1 $nr_of_units`; do
40    let rs=$device*100
41
42    Execute "./${bsim_peripheral_exe_name}" ${bsim_args} \
43        -d=$device -rs=$rs -testid=peripheral ${test_args}
44done
45
46Execute ./bs_2G4_phy_v1 -dump -v=2 -s=${simulation_id} -D=13 -sim_length=1000e6 &
47
48Execute "./${bsim_central_exe_name}" ${bsim_args} -d=0 -rs=001 -testid=central ${test_args}
49
50for process_id in $process_ids; do
51  wait $process_id || let "exit_code=$?"
52done
53
54for i in `seq -w 0 $nr_of_units`; do
55    ${BSIM_OUT_PATH}/components/ext_2G4_phy_v1/dump_post_process/csv2pcap -o \
56    ${BSIM_OUT_PATH}/results/${simulation_id}/Trace_$i.pcap \
57    ${BSIM_OUT_PATH}/results/${simulation_id}/d_2G4_$i.Tx.csv
58
59    ${BSIM_OUT_PATH}/components/ext_2G4_phy_v1/dump_post_process/csv2pcap -o \
60    ${BSIM_OUT_PATH}/results/${simulation_id}/Trace_Rx_$i.pcap \
61    ${BSIM_OUT_PATH}/results/${simulation_id}/d_2G4_$i.Rx.csv
62
63    echo "${BSIM_OUT_PATH}/results/${simulation_id}/Trace_$i.pcap"
64    echo "${BSIM_OUT_PATH}/results/${simulation_id}/Trace_Rx_$i.pcap"
65done
66
67exit $exit_code
68