|
| 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/audio/pipeline.h> |
| 14 | +#include <sof/ipc/topology.h> |
| 15 | +#include <ipc4/base-config.h> |
| 16 | + |
| 17 | +#include <rtos/alloc.h> |
| 18 | + |
| 19 | +extern void sys_comp_module_src_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_src_interface_init(); |
| 36 | + return NULL; |
| 37 | +} |
| 38 | + |
| 39 | +/* Simple UUID for testing */ |
| 40 | +SOF_DEFINE_UUID("src_test", src_test_uuid, 0xe61bb28d, 0x149a, 0x4c1f, |
| 41 | + 0xb7, 0x09, 0x46, 0x82, 0x3e, 0xf5, 0xf5, 0xae); |
| 42 | + |
| 43 | +struct custom_ipc4_config_src { |
| 44 | + struct ipc4_base_module_cfg base; |
| 45 | + uint32_t sink_rate; |
| 46 | +}; |
| 47 | + |
| 48 | +/* Test src initialization via module_adapter or directly */ |
| 49 | +ZTEST(audio_src, test_src_init) |
| 50 | +{ |
| 51 | + struct comp_dev *comp; |
| 52 | + struct comp_ipc_config ipc_config; |
| 53 | + struct ipc_config_process spec; |
| 54 | + struct custom_ipc4_config_src src_init_data; |
| 55 | + |
| 56 | + memset(&src_init_data, 0, sizeof(src_init_data)); |
| 57 | + memset(&src_init_data.base.audio_fmt, 0, sizeof(src_init_data.base.audio_fmt)); |
| 58 | + src_init_data.base.audio_fmt.channels_count = 2; |
| 59 | + src_init_data.base.audio_fmt.sampling_frequency = 48000; |
| 60 | + src_init_data.base.audio_fmt.depth = 16; |
| 61 | + src_init_data.base.audio_fmt.valid_bit_depth = 16; |
| 62 | + src_init_data.base.audio_fmt.interleaving_style = IPC4_CHANNELS_INTERLEAVED; |
| 63 | + src_init_data.sink_rate = 48000; |
| 64 | + |
| 65 | + /* Setup basic IPC configuration */ |
| 66 | + memset(&ipc_config, 0, sizeof(ipc_config)); |
| 67 | + ipc_config.id = 1; |
| 68 | + ipc_config.pipeline_id = 1; |
| 69 | + ipc_config.core = 0; |
| 70 | + |
| 71 | + memset(&spec, 0, sizeof(spec)); |
| 72 | + spec.size = sizeof(src_init_data); |
| 73 | + spec.data = (unsigned char *)&src_init_data; |
| 74 | + |
| 75 | + struct list_item *clist; |
| 76 | + const struct comp_driver *drv = NULL; |
| 77 | + |
| 78 | + /* Find src driver by UUID */ |
| 79 | + list_for_item(clist, &comp_drivers_get()->list) { |
| 80 | + struct comp_driver_info *info = container_of(clist, struct comp_driver_info, list); |
| 81 | + if (!info->drv->uid) continue; |
| 82 | + if (!memcmp(info->drv->uid, &src_test_uuid, sizeof(struct sof_uuid))) { |
| 83 | + drv = info->drv; |
| 84 | + break; |
| 85 | + } |
| 86 | + } |
| 87 | + zassert_not_null(drv, "Driver for src not found"); |
| 88 | + |
| 89 | + /* Initialize src component via ops */ |
| 90 | + comp = drv->ops.create(drv, &ipc_config, &spec); |
| 91 | + zassert_not_null(comp, "SRC allocation failed"); |
| 92 | + |
| 93 | + /* Verify component state */ |
| 94 | + zassert_equal(comp->state, COMP_STATE_READY, "Component is not in READY state"); |
| 95 | + zassert_equal(comp->ipc_config.id, 1, "IPC ID mismatch"); |
| 96 | + |
| 97 | + /* Free the component */ |
| 98 | + drv->ops.free(comp); |
| 99 | +} |
| 100 | + |
| 101 | +/* Test src parameters parsing */ |
| 102 | +ZTEST(audio_src, test_src_params) |
| 103 | +{ |
| 104 | + struct comp_dev *comp; |
| 105 | + struct comp_ipc_config ipc_config; |
| 106 | + struct ipc_config_process spec; |
| 107 | + struct sof_ipc_stream_params params; |
| 108 | + struct custom_ipc4_config_src src_init_data; |
| 109 | + int ret; |
| 110 | + |
| 111 | + memset(&src_init_data, 0, sizeof(src_init_data)); |
| 112 | + memset(&src_init_data.base.audio_fmt, 0, sizeof(src_init_data.base.audio_fmt)); |
| 113 | + src_init_data.base.audio_fmt.channels_count = 2; |
| 114 | + src_init_data.base.audio_fmt.sampling_frequency = 48000; |
| 115 | + src_init_data.base.audio_fmt.depth = 16; |
| 116 | + src_init_data.base.audio_fmt.valid_bit_depth = 16; |
| 117 | + src_init_data.base.audio_fmt.interleaving_style = IPC4_CHANNELS_INTERLEAVED; |
| 118 | + src_init_data.sink_rate = 44100; |
| 119 | + |
| 120 | + memset(&ipc_config, 0, sizeof(ipc_config)); |
| 121 | + ipc_config.id = 1; |
| 122 | + ipc_config.pipeline_id = 1; |
| 123 | + |
| 124 | + memset(&spec, 0, sizeof(spec)); |
| 125 | + spec.size = sizeof(src_init_data); |
| 126 | + spec.data = (unsigned char *)&src_init_data; |
| 127 | + |
| 128 | + struct list_item *clist; |
| 129 | + const struct comp_driver *drv = NULL; |
| 130 | + |
| 131 | + list_for_item(clist, &comp_drivers_get()->list) { |
| 132 | + struct comp_driver_info *info = container_of(clist, struct comp_driver_info, list); |
| 133 | + if (!info->drv->uid) continue; |
| 134 | + if (!memcmp(info->drv->uid, &src_test_uuid, sizeof(struct sof_uuid))) { |
| 135 | + drv = info->drv; |
| 136 | + break; |
| 137 | + } |
| 138 | + } |
| 139 | + zassert_not_null(drv, "Driver for src not found"); |
| 140 | + |
| 141 | + comp = drv->ops.create(drv, &ipc_config, &spec); |
| 142 | + |
| 143 | + memset(¶ms, 0, sizeof(params)); |
| 144 | + params.channels = 2; |
| 145 | + params.rate = 48000; |
| 146 | + params.sample_container_bytes = 2; |
| 147 | + params.sample_valid_bytes = 2; |
| 148 | + params.buffer_fmt = SOF_IPC_BUFFER_INTERLEAVED; |
| 149 | + |
| 150 | + /* Configure parameters */ |
| 151 | + ret = drv->ops.params(comp, ¶ms); |
| 152 | + /* Assuming parameters evaluate successfully relative to core formats */ |
| 153 | + zassert_true(ret >= 0, "SRC parameter setup failed"); |
| 154 | + |
| 155 | + drv->ops.free(comp); |
| 156 | +} |
| 157 | + |
| 158 | +ZTEST_SUITE(audio_src, NULL, setup, NULL, NULL, NULL); |
0 commit comments