-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests bsim: Add tests for unicast client/server samples
Add a test based on the unicase client/server samples which runs them together and after waiting for a predefined amount of time, checks how many audio packets has the client received, and if over a threshold, passes the test. Signed-off-by: Alberto Escolar Piedras <[email protected]>
- Loading branch information
Showing
15 changed files
with
268 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2023 Nordic Semiconductor ASA | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# Compile all the applications needed by the bsim tests in these subfolders | ||
|
||
#set -x #uncomment this line for debugging | ||
set -ue | ||
|
||
: "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" | ||
: "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root\ | ||
directory}" | ||
|
||
WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_out}" | ||
|
||
BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" | ||
|
||
mkdir -p ${WORK_DIR} | ||
|
||
source ${ZEPHYR_BASE}/tests/bsim/compile.source | ||
|
||
if [ "${BOARD}" == "nrf5340bsim_nrf5340_cpuapp" ]; then | ||
app=samples/bluetooth/unicast_audio_server sysbuild=1 compile | ||
else | ||
app=samples/bluetooth/unicast_audio_server conf_overlay=overlay-bt_ll_sw_split.conf \ | ||
exe_name=bs_${BOARD}_${app}_prj_conf sysbuild=1 compile | ||
fi | ||
app=tests/bsim/bluetooth/audio_samples/unicast_audio_client sysbuild=1 compile | ||
|
||
wait_for_background_jobs |
24 changes: 24 additions & 0 deletions
24
tests/bsim/bluetooth/audio_samples/unicast_audio_client/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
|
||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(unicast_audio_client_self_tets) | ||
|
||
set(unicast_client_path ${ZEPHYR_BASE}/samples/bluetooth/unicast_audio_client) | ||
|
||
target_sources(app PRIVATE | ||
${unicast_client_path}/src/main.c | ||
) | ||
|
||
target_sources(app PRIVATE | ||
src/unicast_client_sample_test.c | ||
src/test_main.c | ||
) | ||
|
||
zephyr_library_include_directories(${ZEPHYR_BASE}/samples/bluetooth) | ||
|
||
zephyr_include_directories( | ||
${BSIM_COMPONENTS_PATH}/libUtilv1/src/ | ||
${BSIM_COMPONENTS_PATH}/libPhyComv1/src/ | ||
) |
10 changes: 10 additions & 0 deletions
10
tests/bsim/bluetooth/audio_samples/unicast_audio_client/Kconfig.sysbuild
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright (c) 2023 Nordic Semiconductor ASA | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
source "${ZEPHYR_BASE}/samples/bluetooth/unicast_audio_client/Kconfig.sysbuild" | ||
|
||
config NATIVE_SIMULATOR_PRIMARY_MCU_INDEX | ||
int | ||
# Let's pass the test arguments to the application MCU test | ||
# otherwise by default they would have gone to the net core. | ||
default 0 if $(BOARD) = "nrf5340bsim_nrf5340_cpuapp" |
16 changes: 16 additions & 0 deletions
16
tests/bsim/bluetooth/audio_samples/unicast_audio_client/boards/nrf52_bsim.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# This file content is just a copy of the equivalent one in the unicast client sample | ||
# together with its overlay-bt_ll_sw_split.conf | ||
|
||
# For LC3 the following configs are needed | ||
CONFIG_FPU=y | ||
CONFIG_LIBLC3=y | ||
# LC3 lib requires floating point support in the c-lib. | ||
CONFIG_REQUIRES_FULL_LIBC=y | ||
|
||
CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=1650 | ||
CONFIG_BT_CTLR_ISO_TX_BUFFERS=4 | ||
CONFIG_BT_CTLR_ISO_TX_BUFFER_SIZE=155 | ||
CONFIG_BT_CTLR_ISOAL_SOURCES=2 | ||
CONFIG_BT_CTLR_ISOAL_SINKS=1 | ||
CONFIG_BT_CTLR_ADVANCED_FEATURES=y | ||
CONFIG_BT_CTLR_CONN_ISO_LOW_LATENCY_POLICY=y |
14 changes: 14 additions & 0 deletions
14
.../bsim/bluetooth/audio_samples/unicast_audio_client/boards/nrf5340bsim_nrf5340_cpuapp.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# This file content is just a copy of the equivalent one in the unicast client sample | ||
|
||
# For LC3 the following configs are needed | ||
CONFIG_FPU=y | ||
CONFIG_LIBLC3=y | ||
# LC3 lib requires floating point support in the c-lib. | ||
CONFIG_REQUIRES_FULL_LIBC=y | ||
|
||
CONFIG_BT_BUF_EVT_RX_SIZE=255 | ||
CONFIG_BT_BUF_ACL_RX_SIZE=255 | ||
CONFIG_BT_BUF_ACL_TX_SIZE=251 | ||
CONFIG_BT_BUF_CMD_TX_SIZE=255 | ||
|
||
CONFIG_BT_TINYCRYPT_ECC=y |
16 changes: 16 additions & 0 deletions
16
.../bsim/bluetooth/audio_samples/unicast_audio_client/boards/nrf5340bsim_nrf5340_cpunet.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# This file content is just a copy of the equivalent one in the unicast client sample | ||
# together with its overlay-bt_ll_sw_split.conf | ||
|
||
# For LC3 the following configs are needed | ||
CONFIG_FPU=y | ||
CONFIG_LIBLC3=y | ||
# LC3 lib requires floating point support in the c-lib. | ||
CONFIG_REQUIRES_FULL_LIBC=y | ||
|
||
CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=1650 | ||
CONFIG_BT_CTLR_ISO_TX_BUFFERS=4 | ||
CONFIG_BT_CTLR_ISO_TX_BUFFER_SIZE=155 | ||
CONFIG_BT_CTLR_ISOAL_SOURCES=2 | ||
CONFIG_BT_CTLR_ISOAL_SINKS=1 | ||
CONFIG_BT_CTLR_ADVANCED_FEATURES=y | ||
CONFIG_BT_CTLR_CONN_ISO_LOW_LATENCY_POLICY=y |
16 changes: 16 additions & 0 deletions
16
tests/bsim/bluetooth/audio_samples/unicast_audio_client/prj.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# This file content is just a copy of the unicast client sample prj.conf | ||
|
||
CONFIG_BT=y | ||
CONFIG_LOG=y | ||
CONFIG_BT_CENTRAL=y | ||
CONFIG_BT_AUDIO=y | ||
CONFIG_BT_BAP_UNICAST_CLIENT=y | ||
CONFIG_BT_ISO_TX_BUF_COUNT=4 | ||
# Support an ISO channel per ASE | ||
CONFIG_BT_ISO_MAX_CHAN=4 | ||
CONFIG_BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT=4 | ||
CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT=2 | ||
CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT=2 | ||
CONFIG_BT_KEYS_OVERWRITE_OLDEST=y | ||
|
||
CONFIG_BT_EXT_ADV=y |
14 changes: 14 additions & 0 deletions
14
tests/bsim/bluetooth/audio_samples/unicast_audio_client/src/test_main.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright (c) 2023 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "bstests.h" | ||
|
||
extern struct bst_test_list *test_unicast_client_sample_install(struct bst_test_list *tests); | ||
|
||
bst_test_install_t test_installers[] = { | ||
test_unicast_client_sample_install, | ||
NULL | ||
}; |
77 changes: 77 additions & 0 deletions
77
tests/bsim/bluetooth/audio_samples/unicast_audio_client/src/unicast_client_sample_test.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (c) 2023 Nordic Semiconductor ASA | ||
* Copyright (c) 2017-2019 Oticon A/S | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "bs_types.h" | ||
#include "bs_tracing.h" | ||
#include "bs_utils.h" | ||
#include "time_machine.h" | ||
#include "bstests.h" | ||
|
||
#define WAIT_TIME 10 /* Seconds */ | ||
|
||
#define PASS_THRESHOLD 100 /* Audio packets */ | ||
|
||
extern enum bst_result_t bst_result; | ||
|
||
#define FAIL(...) \ | ||
do { \ | ||
bst_result = Failed; \ | ||
bs_trace_error_time_line(__VA_ARGS__); \ | ||
} while (0) | ||
|
||
#define PASS(...) \ | ||
do { \ | ||
bst_result = Passed; \ | ||
bs_trace_info_time(1, __VA_ARGS__); \ | ||
} while (0) | ||
|
||
static void test_unicast_client_sample_init(void) | ||
{ | ||
/* We set an absolute deadline in 30 seconds */ | ||
bst_ticker_set_next_tick_absolute(WAIT_TIME*1e6); | ||
bst_result = In_progress; | ||
} | ||
|
||
static void test_unicast_client_sample_tick(bs_time_t HW_device_time) | ||
{ | ||
/* | ||
* If in WAIT_TIME seconds we did not get enough packets through | ||
* we consider the test failed | ||
*/ | ||
|
||
extern uint64_t unicast_audio_recv_ctr; | ||
|
||
bs_trace_info_time(2, "%"PRIu64" packets received, expected >= %i\n", | ||
unicast_audio_recv_ctr, PASS_THRESHOLD); | ||
|
||
if (unicast_audio_recv_ctr >= PASS_THRESHOLD) { | ||
PASS("unicast_client PASSED\n"); | ||
bs_trace_exit("Done, disconnecting from simulation\n"); | ||
} else { | ||
FAIL("unicast_client FAILED (Did not pass after %i seconds)\n", | ||
WAIT_TIME); | ||
} | ||
} | ||
|
||
static const struct bst_test_instance test_sample[] = { | ||
{ | ||
.test_id = "unicast_client", | ||
.test_descr = "Test based on the unicast client sample. " | ||
"It expects to be connected to a compatible unicast server, " | ||
"waits for " STR(WAIT_TIME) " seconds, and checks how " | ||
"many audio packets have been received correctly", | ||
.test_post_init_f = test_unicast_client_sample_init, | ||
.test_tick_f = test_unicast_client_sample_tick, | ||
}, | ||
BSTEST_END_MARKER | ||
}; | ||
|
||
struct bst_test_list *test_unicast_client_sample_install(struct bst_test_list *tests) | ||
{ | ||
tests = bst_add_tests(tests, test_sample); | ||
return tests; | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/bsim/bluetooth/audio_samples/unicast_audio_client/sysbuild.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright (c) 2023 Nordic Semiconductor ASA | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
include(${ZEPHYR_BASE}/samples/bluetooth/unicast_audio_client/sysbuild.cmake) | ||
|
||
if (NOT ("${SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX}" STREQUAL "")) | ||
set_property(TARGET ${NET_APP} APPEND_STRING PROPERTY CONFIG | ||
"CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX=${SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX}\n" | ||
) | ||
set_property(TARGET ${DEFAULT_IMAGE} APPEND_STRING PROPERTY CONFIG | ||
"CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX=${SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX}\n" | ||
) | ||
endif() |
29 changes: 29 additions & 0 deletions
29
tests/bsim/bluetooth/audio_samples/unicast_audio_client/tests_scripts/unicast_client.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2023 Nordic Semiconductor ASA | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# Simple selfchecking test for the unicast client/server samples, | ||
# It relies on the bs_tests hooks to register a test timer callback, which after a deadline | ||
# will check how many audio packets the unicast client has received, and if over a threshold | ||
# it considers the test passed | ||
|
||
simulation_id="unicast_samples_test" | ||
verbosity_level=2 | ||
|
||
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source | ||
|
||
EXECUTE_TIMEOUT=100 | ||
|
||
cd ${BSIM_OUT_PATH}/bin | ||
|
||
Execute ./bs_${BOARD}_samples_bluetooth_unicast_audio_server_prj_conf \ | ||
-v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=1 | ||
|
||
Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_samples_unicast_audio_client_prj_conf \ | ||
-v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=1 \ | ||
-testid=unicast_client | ||
|
||
Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ | ||
-D=2 -sim_length=20e6 $@ | ||
|
||
wait_for_background_jobs #Wait for all programs in background and return != 0 if any fails |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters