Skip to content

Commit 73bae69

Browse files
committed
test: audio: add unit test for smart_amp
Add the ztest framework test cases for the smart_amp module, validating component instantiation and evaluation configuration structs bindings. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent 146ac0a commit 73bae69

1 file changed

Lines changed: 104 additions & 0 deletions

File tree

zephyr/test/audio/test_smart_amp.c

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
/*
3+
* Copyright(c) 2026 Intel Corporation.
4+
*/
5+
6+
#include <zephyr/kernel.h>
7+
#include <zephyr/ztest.h>
8+
#include <string.h>
9+
#include <rtos/sof.h>
10+
#include <sof/list.h>
11+
#include <sof/audio/component.h>
12+
#include <sof/audio/component_ext.h>
13+
#include <sof/ipc/topology.h>
14+
#include <ipc4/base-config.h>
15+
#include <user/smart_amp.h>
16+
17+
#include <rtos/alloc.h>
18+
19+
extern void sys_comp_module_smart_amp_interface_init(void);
20+
21+
static void *setup(void)
22+
{
23+
struct sof *sof = sof_get();
24+
25+
sys_comp_init(sof);
26+
27+
if (!sof->ipc) {
28+
sof->ipc = rzalloc(SOF_MEM_FLAG_COHERENT, sizeof(*sof->ipc));
29+
sof->ipc->comp_data = rzalloc(SOF_MEM_FLAG_COHERENT, 4096);
30+
k_spinlock_init(&sof->ipc->lock);
31+
list_init(&sof->ipc->msg_list);
32+
list_init(&sof->ipc->comp_list);
33+
}
34+
35+
sys_comp_module_smart_amp_interface_init();
36+
return NULL;
37+
}
38+
39+
SOF_DEFINE_UUID("smart_amp_test", passthru_smart_amp_test_uuid,
40+
0x64a794f0, 0x55d3, 0x4bca,
41+
0x9d, 0x5b, 0x7b, 0x58, 0x8b, 0xad, 0xd0, 0x37);
42+
43+
struct custom_ipc4_config_smart_amp {
44+
struct ipc4_base_module_cfg base;
45+
struct sof_smart_amp_config smart_amp;
46+
} __attribute__((packed, aligned(8)));
47+
48+
/* Test smart_amp initialization */
49+
ZTEST(audio_smart_amp, test_smart_amp_init)
50+
{
51+
struct comp_dev *comp;
52+
struct comp_ipc_config ipc_config;
53+
struct ipc_config_process spec;
54+
struct custom_ipc4_config_smart_amp init_data;
55+
56+
memset(&init_data, 0, sizeof(init_data));
57+
init_data.base.audio_fmt.channels_count = 2;
58+
init_data.base.audio_fmt.sampling_frequency = 48000;
59+
init_data.base.audio_fmt.depth = 16;
60+
init_data.base.audio_fmt.valid_bit_depth = 16;
61+
init_data.base.audio_fmt.interleaving_style = IPC4_CHANNELS_INTERLEAVED;
62+
init_data.base.ibs = 2048;
63+
init_data.base.obs = 2048;
64+
65+
init_data.smart_amp.size = sizeof(struct sof_smart_amp_config);
66+
init_data.smart_amp.feedback_channels = 2;
67+
68+
/* Setup basic IPC configuration */
69+
memset(&ipc_config, 0, sizeof(ipc_config));
70+
ipc_config.id = 1;
71+
ipc_config.pipeline_id = 1;
72+
ipc_config.core = 0;
73+
74+
memset(&spec, 0, sizeof(spec));
75+
spec.size = sizeof(init_data);
76+
spec.data = (unsigned char *)&init_data;
77+
78+
struct list_item *clist;
79+
const struct comp_driver *drv = NULL;
80+
81+
/* Find driver by UUID */
82+
list_for_item(clist, &comp_drivers_get()->list) {
83+
struct comp_driver_info *info = container_of(clist, struct comp_driver_info, list);
84+
if (!info->drv->uid) continue;
85+
if (!memcmp(info->drv->uid, &passthru_smart_amp_test_uuid, sizeof(struct sof_uuid))) {
86+
drv = info->drv;
87+
break;
88+
}
89+
}
90+
zassert_not_null(drv, "Driver for smart_amp not found");
91+
92+
/* Initialize component via ops */
93+
comp = drv->ops.create(drv, &ipc_config, &spec);
94+
zassert_not_null(comp, "smart_amp allocation failed");
95+
96+
/* Verify component state */
97+
zassert_equal(comp->state, COMP_STATE_READY, "Component is not in READY state");
98+
zassert_equal(comp->ipc_config.id, 1, "IPC ID mismatch");
99+
100+
/* Free the component */
101+
drv->ops.free(comp);
102+
}
103+
104+
ZTEST_SUITE(audio_smart_amp, NULL, setup, NULL, NULL, NULL);

0 commit comments

Comments
 (0)