|
| 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 | +#define SOF_TDFB_NUM_INPUT_PINS 1 |
| 17 | +#define SOF_TDFB_NUM_OUTPUT_PINS 1 |
| 18 | + |
| 19 | +#include <rtos/alloc.h> |
| 20 | + |
| 21 | +extern void sys_comp_module_tdfb_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 | + sys_comp_module_tdfb_interface_init(); |
| 38 | + return NULL; |
| 39 | +} |
| 40 | + |
| 41 | +SOF_DEFINE_UUID("tdfb_test", tdfb_test_uuid, |
| 42 | + 0xdd511749, 0xd9fa, 0x455c, |
| 43 | + 0xb3, 0xa7, 0x13, 0x58, 0x56, 0x93, 0xf1, 0xaf); |
| 44 | + |
| 45 | +struct custom_ipc4_config_tdfb { |
| 46 | + struct ipc4_base_module_cfg base; |
| 47 | + struct ipc4_base_module_cfg_ext base_ext; |
| 48 | + struct ipc4_input_pin_format in_pins[SOF_TDFB_NUM_INPUT_PINS]; |
| 49 | + struct ipc4_output_pin_format out_pins[SOF_TDFB_NUM_OUTPUT_PINS]; |
| 50 | +} __attribute__((packed, aligned(8))); |
| 51 | + |
| 52 | +/* Test TDFB initialization */ |
| 53 | +ZTEST(audio_tdfb, test_tdfb_init) |
| 54 | +{ |
| 55 | + struct comp_dev *comp; |
| 56 | + struct comp_ipc_config ipc_config; |
| 57 | + struct ipc_config_process spec; |
| 58 | + struct custom_ipc4_config_tdfb init_data; |
| 59 | + |
| 60 | + memset(&init_data, 0, sizeof(init_data)); |
| 61 | + init_data.base.audio_fmt.channels_count = 2; |
| 62 | + init_data.base.audio_fmt.sampling_frequency = 48000; |
| 63 | + init_data.base.audio_fmt.depth = 16; |
| 64 | + init_data.base.audio_fmt.valid_bit_depth = 16; |
| 65 | + init_data.base.audio_fmt.interleaving_style = IPC4_CHANNELS_INTERLEAVED; |
| 66 | + init_data.base.ibs = 2048; |
| 67 | + init_data.base.obs = 2048; |
| 68 | + |
| 69 | + init_data.base_ext.nb_input_pins = SOF_TDFB_NUM_INPUT_PINS; |
| 70 | + init_data.base_ext.nb_output_pins = SOF_TDFB_NUM_OUTPUT_PINS; |
| 71 | + init_data.in_pins[0].pin_index = 0; |
| 72 | + init_data.in_pins[0].ibs = 2048; |
| 73 | + init_data.in_pins[0].audio_fmt = init_data.base.audio_fmt; |
| 74 | + |
| 75 | + init_data.out_pins[0].pin_index = 0; |
| 76 | + init_data.out_pins[0].obs = 2048; |
| 77 | + init_data.out_pins[0].audio_fmt = init_data.base.audio_fmt; |
| 78 | + |
| 79 | + /* Setup basic IPC configuration */ |
| 80 | + memset(&ipc_config, 0, sizeof(ipc_config)); |
| 81 | + ipc_config.id = 1; |
| 82 | + ipc_config.pipeline_id = 1; |
| 83 | + ipc_config.core = 0; |
| 84 | + |
| 85 | + memset(&spec, 0, sizeof(spec)); |
| 86 | + spec.size = sizeof(init_data); |
| 87 | + spec.data = (unsigned char *)&init_data; |
| 88 | + |
| 89 | + struct list_item *clist; |
| 90 | + const struct comp_driver *drv = NULL; |
| 91 | + |
| 92 | + /* Find driver by UUID */ |
| 93 | + list_for_item(clist, &comp_drivers_get()->list) { |
| 94 | + struct comp_driver_info *info = container_of(clist, struct comp_driver_info, list); |
| 95 | + if (!info->drv->uid) continue; |
| 96 | + if (!memcmp(info->drv->uid, &tdfb_test_uuid, sizeof(struct sof_uuid))) { |
| 97 | + drv = info->drv; |
| 98 | + break; |
| 99 | + } |
| 100 | + } |
| 101 | + zassert_not_null(drv, "Driver for tdfb not found"); |
| 102 | + |
| 103 | + /* Initialize component via ops */ |
| 104 | + comp = drv->ops.create(drv, &ipc_config, &spec); |
| 105 | + zassert_not_null(comp, "tdfb allocation failed"); |
| 106 | + |
| 107 | + /* Verify component state */ |
| 108 | + zassert_equal(comp->state, COMP_STATE_READY, "Component is not in READY state"); |
| 109 | + zassert_equal(comp->ipc_config.id, 1, "IPC ID mismatch"); |
| 110 | + |
| 111 | + /* Free the component */ |
| 112 | + drv->ops.free(comp); |
| 113 | +} |
| 114 | + |
| 115 | +ZTEST_SUITE(audio_tdfb, NULL, setup, NULL, NULL, NULL); |
0 commit comments