Skip to content

Commit b5ff195

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

1 file changed

Lines changed: 97 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)