From f3f42d363bb806db02a1bdbff2cd711f6701238c Mon Sep 17 00:00:00 2001 From: Jonathan Rico Date: Mon, 11 Mar 2024 09:10:20 +0100 Subject: [PATCH] Bluetooth: shell: add bsim runner script Spawns n instances of the bt-shell in separate xterm windows. Assumes in-tree build of the shell, can optionally specify another .exe image. Also add snippet for that use-case (`-S xterm-native-shell`). Signed-off-by: Jonathan Rico --- tests/bluetooth/shell/run-bsim.sh | 43 +++++++++++++++++++ .../snippets/xterm-native-shell/snippet.yml | 4 ++ .../xterm-native-shell.conf | 4 ++ .../xterm-native-shell.overlay | 25 +++++++++++ 4 files changed, 76 insertions(+) create mode 100755 tests/bluetooth/shell/run-bsim.sh create mode 100644 tests/bluetooth/shell/snippets/xterm-native-shell/snippet.yml create mode 100644 tests/bluetooth/shell/snippets/xterm-native-shell/xterm-native-shell.conf create mode 100644 tests/bluetooth/shell/snippets/xterm-native-shell/xterm-native-shell.overlay diff --git a/tests/bluetooth/shell/run-bsim.sh b/tests/bluetooth/shell/run-bsim.sh new file mode 100755 index 00000000000..88d5e37dc98 --- /dev/null +++ b/tests/bluetooth/shell/run-bsim.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +# Copyright (c) 2024 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +set -e +set -u + +if [ $# -eq 0 ]; then + echo "Usage: run.sh [exe_image]" + shift +fi + +if [ $# -gt 2 ]; then + echo "Too many args" + shift +fi + +echo "Starting simulation. Hit Ctrl-C to exit." + +# Build it with e.g. +# cd $ZEPHYR_BASE/tests/bluetooth/shell +# west build -d build -b nrf52_bsim -S xterm-native-shell $ZEPHYR_BASE/tests/bluetooth/shell +default_image=${ZEPHYR_BASE}/tests/bluetooth/shell/build/zephyr/zephyr.exe + +num_devices=$1 +image="${2:-"${default_image}"}" + +# Cleanup all existing sims +$BSIM_OUT_PATH/components/common/stop_bsim.sh + +# Force sim to real-time +pushd $BSIM_OUT_PATH/components/device_handbrake +./bs_device_handbrake -s=shell-sim -r=10 -d=0 & +popd + +for dev_id in $(seq 1 ${num_devices}); do + echo "Start device $dev_id" + $image -s=shell-sim -d=$dev_id -RealEncryption=1 -rs=$dev_id -attach_uart -wait_uart & +done + +# Start the PHY +pushd $BSIM_OUT_PATH/bin +$BSIM_OUT_PATH/bin/bs_2G4_phy_v1 -s=shell-sim -D=$((num_devices+=1)) diff --git a/tests/bluetooth/shell/snippets/xterm-native-shell/snippet.yml b/tests/bluetooth/shell/snippets/xterm-native-shell/snippet.yml new file mode 100644 index 00000000000..836aa14542d --- /dev/null +++ b/tests/bluetooth/shell/snippets/xterm-native-shell/snippet.yml @@ -0,0 +1,4 @@ +name: xterm-native-shell +append: + EXTRA_CONF_FILE: xterm-native-shell.conf + EXTRA_DTC_OVERLAY_FILE: xterm-native-shell.overlay diff --git a/tests/bluetooth/shell/snippets/xterm-native-shell/xterm-native-shell.conf b/tests/bluetooth/shell/snippets/xterm-native-shell/xterm-native-shell.conf new file mode 100644 index 00000000000..b29c9b615a6 --- /dev/null +++ b/tests/bluetooth/shell/snippets/xterm-native-shell/xterm-native-shell.conf @@ -0,0 +1,4 @@ +CONFIG_NATIVE_UART_0_ON_OWN_PTY=y +CONFIG_UART_NATIVE_WAIT_PTS_READY_ENABLE=y +CONFIG_SHELL_BACKEND_SERIAL_RX_RING_BUFFER_SIZE=8192 +CONFIG_LOG_PRINTK=n diff --git a/tests/bluetooth/shell/snippets/xterm-native-shell/xterm-native-shell.overlay b/tests/bluetooth/shell/snippets/xterm-native-shell/xterm-native-shell.overlay new file mode 100644 index 00000000000..c47dd06bc38 --- /dev/null +++ b/tests/bluetooth/shell/snippets/xterm-native-shell/xterm-native-shell.overlay @@ -0,0 +1,25 @@ +/ { + chosen { + zephyr,console = &uart0; + zephyr,shell-uart = &uart0; + }; +}; + +/* Use the PTY driver instead of the UART peripheral emulation that is now the + * default on nrf52_bsim. */ + +&uart1 { + status = "okay"; + compatible = "zephyr,native-posix-uart"; + /delete-property/ pinctrl-0; + /delete-property/ pinctrl-1; + /delete-property/ pinctrl-names; +}; + +&uart0 { + status = "okay"; + compatible = "zephyr,native-posix-uart"; + /delete-property/ pinctrl-0; + /delete-property/ pinctrl-1; + /delete-property/ pinctrl-names; +};