Skip to content

Commit b9a3686

Browse files
committed
test: audio: add unit test for nxp
Add the ztest framework test cases for the nxp module, validating component instantiation and evaluation configuration structs bindings. Contains fixes to eap_stub.c mitigating uninitialized trace string pointer dereference. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent 4da8d95 commit b9a3686

2 files changed

Lines changed: 98 additions & 0 deletions

File tree

src/audio/nxp/eap_stub.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
LVM_ReturnStatus_en LVM_GetVersionInfo(LVM_VersionInfo_st *pVersion)
1010
{
11+
if (pVersion) {
12+
pVersion->pPlatform = "stub_platform";
13+
pVersion->pVersionNumber = "0.0.0_stub";
14+
}
1115
return LVM_SUCCESS;
1216
}
1317

zephyr/test/audio/test_nxp.c

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_nxp_eap_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_NXP_EAP) || defined(CONFIG_COMP_NXP_EAP_STUB)
35+
sys_comp_module_nxp_eap_interface_init();
36+
#endif
37+
return NULL;
38+
}
39+
40+
extern const struct sof_uuid nxp_eap_uuid;
41+
42+
struct custom_ipc4_config_nxp_eap {
43+
struct ipc4_base_module_cfg base;
44+
} __attribute__((packed, aligned(8)));
45+
46+
ZTEST(audio_nxp_eap, test_nxp_eap_init)
47+
{
48+
#ifndef CONFIG_COMP_NXP_EAP
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_nxp_eap 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 = 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, &nxp_eap_uuid, sizeof(struct sof_uuid))) {
81+
drv = info->drv;
82+
break;
83+
}
84+
}
85+
zassert_not_null(drv, "Driver for nxp_eap not found");
86+
87+
comp = drv->ops.create(drv, &ipc_config, &spec);
88+
zassert_not_null(comp, "nxp_eap 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_nxp_eap, NULL, setup, NULL, NULL, NULL);

0 commit comments

Comments
 (0)