Skip to content

Commit e4869a9

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

1 file changed

Lines changed: 94 additions & 0 deletions

File tree

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
16+
#include <rtos/alloc.h>
17+
18+
extern void sys_comp_module_sound_dose_interface_init(void);
19+
20+
static void *setup(void)
21+
{
22+
struct sof *sof = sof_get();
23+
24+
sys_comp_init(sof);
25+
26+
if (!sof->ipc) {
27+
sof->ipc = rzalloc(SOF_MEM_FLAG_COHERENT, sizeof(*sof->ipc));
28+
sof->ipc->comp_data = rzalloc(SOF_MEM_FLAG_COHERENT, 4096);
29+
k_spinlock_init(&sof->ipc->lock);
30+
list_init(&sof->ipc->msg_list);
31+
list_init(&sof->ipc->comp_list);
32+
}
33+
34+
#if defined(CONFIG_COMP_SOUND_DOSE)
35+
sys_comp_module_sound_dose_interface_init();
36+
#endif
37+
return NULL;
38+
}
39+
40+
extern const struct sof_uuid sound_dose_uuid;
41+
42+
struct custom_ipc4_config_sound_dose {
43+
struct ipc4_base_module_cfg base;
44+
} __attribute__((packed, aligned(8)));
45+
46+
ZTEST(audio_sound_dose, test_sound_dose_init)
47+
{
48+
#ifndef CONFIG_COMP_SOUND_DOSE
49+
ztest_test_skip();
50+
#endif
51+
struct comp_dev *comp;
52+
struct comp_ipc_config ipc_config;
53+
struct ipc_config_process spec;
54+
struct custom_ipc4_config_sound_dose init_data;
55+
56+
memset(&init_data, 0, sizeof(init_data));
57+
init_data.base.audio_fmt.channels_count = 1;
58+
init_data.base.audio_fmt.sampling_frequency = 16000;
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 = 1024;
63+
init_data.base.obs = 1024;
64+
65+
memset(&ipc_config, 0, sizeof(ipc_config));
66+
ipc_config.id = 1;
67+
ipc_config.pipeline_id = 1;
68+
ipc_config.core = 0;
69+
70+
memset(&spec, 0, sizeof(spec));
71+
spec.size = sizeof(init_data);
72+
spec.data = (unsigned char *)&init_data;
73+
74+
struct list_item *clist;
75+
const struct comp_driver *drv = NULL;
76+
77+
list_for_item(clist, &comp_drivers_get()->list) {
78+
struct comp_driver_info *info = container_of(clist, struct comp_driver_info, list);
79+
if (!info->drv->uid) continue;
80+
if (!memcmp(info->drv->uid, &sound_dose_uuid, sizeof(struct sof_uuid))) {
81+
drv = info->drv;
82+
break;
83+
}
84+
}
85+
zassert_not_null(drv, "Driver for sound_dose missing");
86+
87+
comp = drv->ops.create(drv, &ipc_config, &spec);
88+
zassert_not_null(comp, "sound_dose allocation failed");
89+
zassert_equal(comp->state, COMP_STATE_READY, "Component is not in READY state");
90+
91+
drv->ops.free(comp);
92+
}
93+
94+
ZTEST_SUITE(audio_sound_dose, NULL, setup, NULL, NULL, NULL);

0 commit comments

Comments
 (0)