tests: Bluetooth: audio: Unit test bt_audio_codec_cfg_get_* helpers
This adds unit tests for bt_audio_codec_cfg_get_* functio helpers. Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
This commit is contained in:
parent
dd3cffcd20
commit
9a9855f711
5 changed files with 133 additions and 0 deletions
17
tests/bluetooth/audio/codec/CMakeLists.txt
Normal file
17
tests/bluetooth/audio/codec/CMakeLists.txt
Normal file
|
@ -0,0 +1,17 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
project(bluetooth_codec)
|
||||
find_package(Zephyr COMPONENTS unittest HINTS $ENV{ZEPHYR_BASE})
|
||||
|
||||
add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/audio/codec/uut uut)
|
||||
|
||||
target_link_libraries(testbinary PRIVATE uut)
|
||||
|
||||
target_include_directories(testbinary PRIVATE include)
|
||||
|
||||
target_sources(testbinary
|
||||
PRIVATE
|
||||
src/main.c
|
||||
)
|
15
tests/bluetooth/audio/codec/prj.conf
Normal file
15
tests/bluetooth/audio/codec/prj.conf
Normal file
|
@ -0,0 +1,15 @@
|
|||
CONFIG_ZTEST=y
|
||||
CONFIG_ZTEST_NEW_API=y
|
||||
|
||||
CONFIG_BT=y
|
||||
CONFIG_BT_AUDIO=y
|
||||
CONFIG_BT_BAP_UNICAST_SERVER=y
|
||||
|
||||
CONFIG_LOG=y
|
||||
CONFIG_BT_AUDIO_LOG_LEVEL_DBG=y
|
||||
CONFIG_BT_AUDIO_CODEC_LOG_LEVEL_DBG=y
|
||||
|
||||
CONFIG_ASSERT=y
|
||||
CONFIG_ASSERT_LEVEL=2
|
||||
CONFIG_ASSERT_VERBOSE=y
|
||||
CONFIG_ASSERT_ON_ERRORS=y
|
73
tests/bluetooth/audio/codec/src/main.c
Normal file
73
tests/bluetooth/audio/codec/src/main.c
Normal file
|
@ -0,0 +1,73 @@
|
|||
/* main.c - Application main entry point */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2023 Codecoup
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/fff.h>
|
||||
#include <zephyr/bluetooth/audio/audio.h>
|
||||
#include <zephyr/bluetooth/audio/bap_lc3_preset.h>
|
||||
|
||||
DEFINE_FFF_GLOBALS;
|
||||
|
||||
ZTEST_SUITE(audio_codec_test_suite, NULL, NULL, NULL, NULL, NULL);
|
||||
|
||||
ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_freq)
|
||||
{
|
||||
const struct bt_bap_lc3_preset preset =
|
||||
BT_BAP_LC3_UNICAST_PRESET_16_2_1(BT_AUDIO_LOCATION_FRONT_LEFT,
|
||||
BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
|
||||
int ret;
|
||||
|
||||
ret = bt_audio_codec_cfg_get_freq(&preset.codec_cfg);
|
||||
zassert_equal(ret, 16000u, "unexpected return value %d", ret);
|
||||
}
|
||||
|
||||
ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_frame_duration_us)
|
||||
{
|
||||
const struct bt_bap_lc3_preset preset =
|
||||
BT_BAP_LC3_UNICAST_PRESET_48_2_2(BT_AUDIO_LOCATION_FRONT_LEFT,
|
||||
BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
|
||||
int ret;
|
||||
|
||||
ret = bt_audio_codec_cfg_get_frame_duration_us(&preset.codec_cfg);
|
||||
zassert_equal(ret, 10000u, "unexpected return value %d", ret);
|
||||
}
|
||||
|
||||
ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_chan_allocation_val)
|
||||
{
|
||||
const struct bt_bap_lc3_preset preset =
|
||||
BT_BAP_LC3_UNICAST_PRESET_8_1_1(BT_AUDIO_LOCATION_FRONT_LEFT,
|
||||
BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
|
||||
enum bt_audio_location chan_allocation = BT_AUDIO_LOCATION_FRONT_RIGHT;
|
||||
int err;
|
||||
|
||||
err = bt_audio_codec_cfg_get_chan_allocation_val(&preset.codec_cfg, &chan_allocation);
|
||||
zassert_false(err, "unexpected error %d", err);
|
||||
zassert_equal(chan_allocation, BT_AUDIO_LOCATION_FRONT_LEFT,
|
||||
"unexpected return value %d", chan_allocation);
|
||||
}
|
||||
|
||||
ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_octets_per_frame)
|
||||
{
|
||||
const struct bt_bap_lc3_preset preset =
|
||||
BT_BAP_LC3_UNICAST_PRESET_32_2_2(BT_AUDIO_LOCATION_FRONT_LEFT,
|
||||
BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
|
||||
int ret;
|
||||
|
||||
ret = bt_audio_codec_cfg_get_octets_per_frame(&preset.codec_cfg);
|
||||
zassert_equal(ret, 80u, "unexpected return value %d", ret);
|
||||
}
|
||||
|
||||
ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_frame_blocks_per_sdu)
|
||||
{
|
||||
const struct bt_bap_lc3_preset preset =
|
||||
BT_BAP_LC3_UNICAST_PRESET_48_5_1(BT_AUDIO_LOCATION_FRONT_LEFT,
|
||||
BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
|
||||
int ret;
|
||||
|
||||
ret = bt_audio_codec_cfg_get_frame_blocks_per_sdu(&preset.codec_cfg, true);
|
||||
zassert_equal(ret, 1u, "unexpected return value %d", ret);
|
||||
}
|
7
tests/bluetooth/audio/codec/testcase.yaml
Normal file
7
tests/bluetooth/audio/codec/testcase.yaml
Normal file
|
@ -0,0 +1,7 @@
|
|||
common:
|
||||
tags:
|
||||
- bluetooth
|
||||
- bluetooth_audio
|
||||
tests:
|
||||
bluetooth.audio.codec.test:
|
||||
type: unit
|
21
tests/bluetooth/audio/codec/uut/CMakeLists.txt
Normal file
21
tests/bluetooth/audio/codec/uut/CMakeLists.txt
Normal file
|
@ -0,0 +1,21 @@
|
|||
#
|
||||
# Copyright (c) 2023 Codecoup
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# CMakeLists.txt file for creating of uut library.
|
||||
#
|
||||
|
||||
add_library(uut STATIC
|
||||
${ZEPHYR_BASE}/subsys/bluetooth/audio/audio.c
|
||||
${ZEPHYR_BASE}/subsys/bluetooth/audio/codec.c
|
||||
${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c
|
||||
${ZEPHYR_BASE}/subsys/logging/log_minimal.c
|
||||
${ZEPHYR_BASE}/subsys/net/buf_simple.c
|
||||
)
|
||||
|
||||
add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/audio/mocks mocks)
|
||||
|
||||
target_link_libraries(uut PUBLIC test_interface mocks)
|
||||
|
||||
target_compile_options(uut PRIVATE -std=c11 -include ztest.h)
|
Loading…
Add table
Add a link
Reference in a new issue