Skip to content

Commit b8dd55c

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

1 file changed

Lines changed: 110 additions & 0 deletions

File tree

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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 "../../../src/audio/stft_process/stft_process.h"
16+
17+
#include <rtos/alloc.h>
18+
19+
extern void sys_comp_module_stft_process_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_stft_process_interface_init();
36+
return NULL;
37+
}
38+
39+
SOF_DEFINE_UUID("stft_process_test", stft_process_test_uuid,
40+
0x0d116ea6, 0x9150, 0x46de,
41+
0x98, 0xb8, 0xb2, 0xb3, 0xa7, 0x91, 0xda, 0x29);
42+
43+
struct custom_ipc4_config_stft_process {
44+
struct ipc4_base_module_cfg base;
45+
struct sof_stft_process_config config;
46+
} __attribute__((packed, aligned(8)));
47+
48+
/* Test STFT Process initialization */
49+
ZTEST(audio_stft_process, test_stft_process_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_stft_process 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.config.size = sizeof(struct sof_stft_process_config);
66+
init_data.config.sample_frequency = 48000;
67+
init_data.config.window_gain_comp = 0;
68+
init_data.config.channel = 2;
69+
init_data.config.frame_length = 400;
70+
init_data.config.frame_shift = 160;
71+
init_data.config.pad = STFT_PAD_END;
72+
init_data.config.window = STFT_HANN_WINDOW;
73+
74+
/* Setup basic IPC configuration */
75+
memset(&ipc_config, 0, sizeof(ipc_config));
76+
ipc_config.id = 1;
77+
ipc_config.pipeline_id = 1;
78+
ipc_config.core = 0;
79+
80+
memset(&spec, 0, sizeof(spec));
81+
spec.size = sizeof(init_data);
82+
spec.data = (unsigned char *)&init_data;
83+
84+
struct list_item *clist;
85+
const struct comp_driver *drv = NULL;
86+
87+
/* Find driver by UUID */
88+
list_for_item(clist, &comp_drivers_get()->list) {
89+
struct comp_driver_info *info = container_of(clist, struct comp_driver_info, list);
90+
if (!info->drv->uid) continue;
91+
if (!memcmp(info->drv->uid, &stft_process_test_uuid, sizeof(struct sof_uuid))) {
92+
drv = info->drv;
93+
break;
94+
}
95+
}
96+
zassert_not_null(drv, "Driver for stft_process not found");
97+
98+
/* Initialize component via ops */
99+
comp = drv->ops.create(drv, &ipc_config, &spec);
100+
zassert_not_null(comp, "stft_process allocation failed");
101+
102+
/* Verify component state */
103+
zassert_equal(comp->state, COMP_STATE_READY, "Component is not in READY state");
104+
zassert_equal(comp->ipc_config.id, 1, "IPC ID mismatch");
105+
106+
/* Free the component */
107+
drv->ops.free(comp);
108+
}
109+
110+
ZTEST_SUITE(audio_stft_process, NULL, setup, NULL, NULL, NULL);

0 commit comments

Comments
 (0)