|
| 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/multiband_drc/user/multiband_drc.h" |
| 16 | + |
| 17 | +#include <rtos/alloc.h> |
| 18 | + |
| 19 | +extern void sys_comp_module_multiband_drc_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_multiband_drc_interface_init(); |
| 36 | + return NULL; |
| 37 | +} |
| 38 | + |
| 39 | +SOF_DEFINE_UUID("multiband_drc_test", multiband_drc_test_uuid, |
| 40 | + 0x0d9f2256, 0x8e4f, 0x47b3, |
| 41 | + 0x84, 0x48, 0x23, 0x9a, 0x33, 0x4f, 0x11, 0x91); |
| 42 | + |
| 43 | +struct custom_ipc4_config_multiband_drc { |
| 44 | + struct ipc4_base_module_cfg base; |
| 45 | + struct sof_multiband_drc_config config; |
| 46 | + struct sof_drc_params drc_coef[2]; |
| 47 | +} __attribute__((packed, aligned(8))); |
| 48 | + |
| 49 | +/* Test Multiband_DRC initialization */ |
| 50 | +ZTEST(audio_multiband_drc, test_multiband_drc_init) |
| 51 | +{ |
| 52 | + struct comp_dev *comp; |
| 53 | + struct comp_ipc_config ipc_config; |
| 54 | + struct ipc_config_process spec; |
| 55 | + struct custom_ipc4_config_multiband_drc init_data; |
| 56 | + |
| 57 | + memset(&init_data, 0, sizeof(init_data)); |
| 58 | + init_data.base.audio_fmt.channels_count = 2; |
| 59 | + init_data.base.audio_fmt.sampling_frequency = 48000; |
| 60 | + init_data.base.audio_fmt.depth = 16; |
| 61 | + init_data.base.audio_fmt.valid_bit_depth = 16; |
| 62 | + init_data.base.audio_fmt.interleaving_style = IPC4_CHANNELS_INTERLEAVED; |
| 63 | + init_data.base.ibs = 2048; |
| 64 | + init_data.base.obs = 2048; |
| 65 | + |
| 66 | + /* Setup Multiband_DRC specific parameters */ |
| 67 | + init_data.config.size = sizeof(struct sof_multiband_drc_config) + sizeof(struct sof_drc_params) * 2; |
| 68 | + init_data.config.num_bands = 2; |
| 69 | + init_data.config.enable_emp_deemp = 0; |
| 70 | + |
| 71 | + /* Setup basic IPC configuration */ |
| 72 | + memset(&ipc_config, 0, sizeof(ipc_config)); |
| 73 | + ipc_config.id = 1; |
| 74 | + ipc_config.pipeline_id = 1; |
| 75 | + ipc_config.core = 0; |
| 76 | + |
| 77 | + memset(&spec, 0, sizeof(spec)); |
| 78 | + spec.size = sizeof(init_data); |
| 79 | + spec.data = (unsigned char *)&init_data; |
| 80 | + |
| 81 | + struct list_item *clist; |
| 82 | + const struct comp_driver *drv = NULL; |
| 83 | + |
| 84 | + /* Find driver by UUID */ |
| 85 | + list_for_item(clist, &comp_drivers_get()->list) { |
| 86 | + struct comp_driver_info *info = container_of(clist, struct comp_driver_info, list); |
| 87 | + if (!info->drv->uid) continue; |
| 88 | + if (!memcmp(info->drv->uid, &multiband_drc_test_uuid, sizeof(struct sof_uuid))) { |
| 89 | + drv = info->drv; |
| 90 | + break; |
| 91 | + } |
| 92 | + } |
| 93 | + zassert_not_null(drv, "Driver for Multiband DRC not found"); |
| 94 | + |
| 95 | + /* Initialize component via ops */ |
| 96 | + comp = drv->ops.create(drv, &ipc_config, &spec); |
| 97 | + zassert_not_null(comp, "Multiband DRC allocation failed"); |
| 98 | + |
| 99 | + /* Verify component state */ |
| 100 | + zassert_equal(comp->state, COMP_STATE_READY, "Component is not in READY state"); |
| 101 | + zassert_equal(comp->ipc_config.id, 1, "IPC ID mismatch"); |
| 102 | + |
| 103 | + /* Free the component */ |
| 104 | + drv->ops.free(comp); |
| 105 | +} |
| 106 | + |
| 107 | +ZTEST_SUITE(audio_multiband_drc, NULL, setup, NULL, NULL, NULL); |
0 commit comments