Skip to content

Commit 3a90ea1

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

1 file changed

Lines changed: 99 additions & 0 deletions

File tree

zephyr/test/audio/test_rtnr.c

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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_rtnr_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+
sys_comp_module_rtnr_interface_init();
35+
return NULL;
36+
}
37+
38+
SOF_DEFINE_UUID("rtnr_test", rtnr_test_uuid,
39+
0x5c7ca334, 0xe15d, 0x11eb,
40+
0xba, 0x80, 0x02, 0x42, 0xac, 0x13, 0x00, 0x04);
41+
42+
struct custom_ipc4_config_rtnr {
43+
struct ipc4_base_module_cfg base;
44+
} __attribute__((packed, aligned(8)));
45+
46+
/* Test RTNR initialization */
47+
ZTEST(audio_rtnr, test_rtnr_init)
48+
{
49+
struct comp_dev *comp;
50+
struct comp_ipc_config ipc_config;
51+
struct ipc_config_process spec;
52+
struct custom_ipc4_config_rtnr init_data;
53+
54+
memset(&init_data, 0, sizeof(init_data));
55+
init_data.base.audio_fmt.channels_count = 2;
56+
init_data.base.audio_fmt.sampling_frequency = 48000;
57+
init_data.base.audio_fmt.depth = 16;
58+
init_data.base.audio_fmt.valid_bit_depth = 16;
59+
init_data.base.audio_fmt.interleaving_style = IPC4_CHANNELS_INTERLEAVED;
60+
init_data.base.ibs = 2048;
61+
init_data.base.obs = 2048;
62+
63+
/* Setup basic IPC configuration */
64+
memset(&ipc_config, 0, sizeof(ipc_config));
65+
ipc_config.id = 1;
66+
ipc_config.pipeline_id = 1;
67+
ipc_config.core = 0;
68+
69+
memset(&spec, 0, sizeof(spec));
70+
spec.size = sizeof(init_data);
71+
spec.data = (unsigned char *)&init_data;
72+
73+
struct list_item *clist;
74+
const struct comp_driver *drv = NULL;
75+
76+
/* Find driver by UUID */
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, &rtnr_test_uuid, sizeof(struct sof_uuid))) {
81+
drv = info->drv;
82+
break;
83+
}
84+
}
85+
zassert_not_null(drv, "Driver for RTNR not found");
86+
87+
/* Initialize component via ops */
88+
comp = drv->ops.create(drv, &ipc_config, &spec);
89+
zassert_not_null(comp, "RTNR allocation failed");
90+
91+
/* Verify component state */
92+
zassert_equal(comp->state, COMP_STATE_READY, "Component is not in READY state");
93+
zassert_equal(comp->ipc_config.id, 1, "IPC ID mismatch");
94+
95+
/* Free the component */
96+
drv->ops.free(comp);
97+
}
98+
99+
ZTEST_SUITE(audio_rtnr, NULL, setup, NULL, NULL, NULL);

0 commit comments

Comments
 (0)