Bluetooth: tests: Add Hearing Access Service bsim tests
This extends the bsim tests with the HAS client/server and server standalone test cases. Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
This commit is contained in:
parent
db59647c0a
commit
29f043707f
5 changed files with 238 additions and 0 deletions
|
@ -90,6 +90,11 @@ CONFIG_BT_OTS_CLIENT=y
|
|||
CONFIG_BT_BASS=y
|
||||
CONFIG_BT_BASS_CLIENT=y
|
||||
|
||||
# Hearing Access
|
||||
CONFIG_BT_HAS=y
|
||||
CONFIG_BT_HAS_CLIENT=y
|
||||
CONFIG_BT_HAS_HEARING_AID_MONAURAL=y
|
||||
|
||||
# DEBUGGING
|
||||
CONFIG_BT_DEBUG_LOG=y
|
||||
CONFIG_BT_DEBUG_VCS=y
|
||||
|
@ -117,6 +122,8 @@ CONFIG_BT_AUDIO_DEBUG_STREAM=y
|
|||
CONFIG_BT_AUDIO_DEBUG_CAPABILITIES=y
|
||||
CONFIG_BT_DEBUG_BASS=y
|
||||
CONFIG_BT_DEBUG_BASS_CLIENT=y
|
||||
CONFIG_BT_DEBUG_HAS=y
|
||||
CONFIG_BT_DEBUG_HAS_CLIENT=y
|
||||
|
||||
# LOGGING
|
||||
CONFIG_TEST_LOGGING_DEFAULTS=n
|
||||
|
|
127
tests/bluetooth/bsim_bt/bsim_test_audio/src/has_client_test.c
Normal file
127
tests/bluetooth/bsim_bt/bsim_test_audio/src/has_client_test.c
Normal file
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Codecoup
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_BT_HAS_CLIENT
|
||||
#include "bluetooth/audio/has.h"
|
||||
|
||||
#include "common.h"
|
||||
|
||||
extern enum bst_result_t bst_result;
|
||||
|
||||
CREATE_FLAG(g_is_connected);
|
||||
CREATE_FLAG(g_service_discovered);
|
||||
CREATE_FLAG(g_preset_switched);
|
||||
|
||||
static struct bt_conn *g_conn;
|
||||
static struct bt_has *g_has;
|
||||
|
||||
static void discover_cb(struct bt_conn *conn, int err, struct bt_has *has,
|
||||
enum bt_has_hearing_aid_type type, enum bt_has_capabilities caps)
|
||||
{
|
||||
if (err) {
|
||||
FAIL("Failed to discover HAS (err %d)\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
printk("HAS discovered type %d caps %d\n", type, caps);
|
||||
|
||||
g_has = has;
|
||||
SET_FLAG(g_service_discovered);
|
||||
}
|
||||
|
||||
static void preset_switch_cb(struct bt_has *has, uint8_t index)
|
||||
{
|
||||
printk("Active preset index %d\n", index);
|
||||
|
||||
SET_FLAG(g_preset_switched);
|
||||
}
|
||||
|
||||
static const struct bt_has_client_cb has_cb = {
|
||||
.discover = discover_cb,
|
||||
.preset_switch = preset_switch_cb,
|
||||
};
|
||||
|
||||
static void connected(struct bt_conn *conn, uint8_t err)
|
||||
{
|
||||
if (err > 0) {
|
||||
char addr[BT_ADDR_LE_STR_LEN];
|
||||
|
||||
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
|
||||
|
||||
FAIL("Failed to connect to %s (err %u)\n", addr, err);
|
||||
return;
|
||||
}
|
||||
|
||||
g_conn = conn;
|
||||
SET_FLAG(g_is_connected);
|
||||
}
|
||||
|
||||
BT_CONN_CB_DEFINE(conn_callbacks) = {
|
||||
.connected = connected,
|
||||
.disconnected = disconnected,
|
||||
};
|
||||
|
||||
static void test_main(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = bt_enable(NULL);
|
||||
if (err < 0) {
|
||||
FAIL("Bluetooth discover failed (err %d)\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
printk("Bluetooth initialized\n");
|
||||
|
||||
err = bt_has_client_cb_register(&has_cb);
|
||||
if (err < 0) {
|
||||
FAIL("Failed to register callbacks (err %d)\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found);
|
||||
if (err < 0) {
|
||||
FAIL("Scanning failed to start (err %d)\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
printk("Scanning successfully started\n");
|
||||
|
||||
WAIT_FOR_COND(g_is_connected);
|
||||
|
||||
err = bt_has_client_discover(g_conn);
|
||||
if (err < 0) {
|
||||
FAIL("Failed to discover HAS (err %d)\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
WAIT_FOR_COND(g_service_discovered);
|
||||
WAIT_FOR_COND(g_preset_switched);
|
||||
|
||||
PASS("HAS main PASS\n");
|
||||
}
|
||||
|
||||
static const struct bst_test_instance test_has[] = {
|
||||
{
|
||||
.test_id = "has_client",
|
||||
.test_post_init_f = test_init,
|
||||
.test_tick_f = test_tick,
|
||||
.test_main_f = test_main,
|
||||
},
|
||||
BSTEST_END_MARKER
|
||||
};
|
||||
|
||||
struct bst_test_list *test_has_client_install(struct bst_test_list *tests)
|
||||
{
|
||||
return bst_add_tests(tests, test_has);
|
||||
}
|
||||
#else
|
||||
struct bst_test_list *test_has_client_install(struct bst_test_list *tests)
|
||||
{
|
||||
return tests;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BT_HAS_CLIENT */
|
58
tests/bluetooth/bsim_bt/bsim_test_audio/src/has_test.c
Normal file
58
tests/bluetooth/bsim_bt/bsim_test_audio/src/has_test.c
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Codecoup
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_BT_HAS
|
||||
#include <bluetooth/gatt.h>
|
||||
#include <bluetooth/audio/has.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
extern enum bst_result_t bst_result;
|
||||
|
||||
static void test_main(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = bt_enable(NULL);
|
||||
if (err) {
|
||||
FAIL("Bluetooth enable failed (err %d)\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
printk("Bluetooth initialized\n");
|
||||
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, AD_SIZE, NULL, 0);
|
||||
if (err) {
|
||||
FAIL("Advertising failed to start (err %d)\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
printk("Advertising successfully started\n");
|
||||
|
||||
PASS("HAS passed\n");
|
||||
}
|
||||
|
||||
static const struct bst_test_instance test_has[] = {
|
||||
{
|
||||
.test_id = "has",
|
||||
.test_post_init_f = test_init,
|
||||
.test_tick_f = test_tick,
|
||||
.test_main_f = test_main,
|
||||
},
|
||||
BSTEST_END_MARKER,
|
||||
};
|
||||
|
||||
struct bst_test_list *test_has_install(struct bst_test_list *tests)
|
||||
{
|
||||
return bst_add_tests(tests, test_has);
|
||||
}
|
||||
#else
|
||||
struct bst_test_list *test_has_install(struct bst_test_list *tests)
|
||||
{
|
||||
return tests;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BT_HAS */
|
|
@ -24,6 +24,8 @@ extern struct bst_test_list *test_broadcast_sink_install(struct bst_test_list *t
|
|||
extern struct bst_test_list *test_bass_install(struct bst_test_list *tests);
|
||||
extern struct bst_test_list *test_bass_client_install(struct bst_test_list *tests);
|
||||
extern struct bst_test_list *test_bass_broadcaster_install(struct bst_test_list *tests);
|
||||
extern struct bst_test_list *test_has_install(struct bst_test_list *tests);
|
||||
extern struct bst_test_list *test_has_client_install(struct bst_test_list *tests);
|
||||
|
||||
bst_test_install_t test_installers[] = {
|
||||
test_vcs_install,
|
||||
|
@ -44,6 +46,8 @@ bst_test_install_t test_installers[] = {
|
|||
test_bass_install,
|
||||
test_bass_client_install,
|
||||
test_bass_broadcaster_install,
|
||||
test_has_install,
|
||||
test_has_client_install,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
|
42
tests/bluetooth/bsim_bt/bsim_test_audio/test_scripts/has.sh
Executable file
42
tests/bluetooth/bsim_bt/bsim_test_audio/test_scripts/has.sh
Executable file
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Copyright (c) 2022 Codecoup
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
SIMULATION_ID="has"
|
||||
VERBOSITY_LEVEL=2
|
||||
PROCESS_IDS=""; EXIT_CODE=0
|
||||
|
||||
function Execute(){
|
||||
if [ ! -f $1 ]; then
|
||||
echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\
|
||||
compile it?)\e[39m"
|
||||
exit 1
|
||||
fi
|
||||
timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!"
|
||||
}
|
||||
|
||||
: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}"
|
||||
|
||||
#Give a default value to BOARD if it does not have one yet:
|
||||
BOARD="${BOARD:-nrf52_bsim}"
|
||||
|
||||
cd ${BSIM_OUT_PATH}/bin
|
||||
|
||||
printf "\n\n======== Running HAS main (API) test =========\n\n"
|
||||
|
||||
Execute ./bs_${BOARD}_tests_bluetooth_bsim_bt_bsim_test_audio_prj_conf \
|
||||
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=has -rs=24
|
||||
|
||||
Execute ./bs_${BOARD}_tests_bluetooth_bsim_bt_bsim_test_audio_prj_conf \
|
||||
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=has_client -rs=46
|
||||
|
||||
Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \
|
||||
-D=2 -sim_length=60e6 $@
|
||||
|
||||
for PROCESS_ID in $PROCESS_IDS; do
|
||||
wait $PROCESS_ID || let "EXIT_CODE=$?"
|
||||
done
|
||||
|
||||
exit $EXIT_CODE #the last exit code != 0
|
Loading…
Add table
Add a link
Reference in a new issue