|
| 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 | +#include "test_audio_helper.h" |
| 19 | + |
| 20 | +extern void sys_comp_module_up_down_mixer_interface_init(void); |
| 21 | + |
| 22 | +static void *setup(void) |
| 23 | +{ |
| 24 | + struct sof *sof = sof_get(); |
| 25 | + |
| 26 | + sys_comp_init(sof); |
| 27 | + |
| 28 | + if (!sof->ipc) { |
| 29 | + sof->ipc = rzalloc(SOF_MEM_FLAG_COHERENT, sizeof(*sof->ipc)); |
| 30 | + sof->ipc->comp_data = rzalloc(SOF_MEM_FLAG_COHERENT, 4096); |
| 31 | + k_spinlock_init(&sof->ipc->lock); |
| 32 | + list_init(&sof->ipc->msg_list); |
| 33 | + list_init(&sof->ipc->comp_list); |
| 34 | + } |
| 35 | + |
| 36 | + sys_comp_module_up_down_mixer_interface_init(); |
| 37 | + return NULL; |
| 38 | +} |
| 39 | + |
| 40 | +/* UUID extracted from native registries */ |
| 41 | +SOF_DEFINE_UUID("up_down_mixer_test", up_down_mixer_test_uuid, |
| 42 | + 0x42f8060c, 0x832f, 0x4dbf, |
| 43 | + 0xb2, 0x47, 0x51, 0xe9, 0x61, 0x99, 0x7b, 0x34); |
| 44 | + |
| 45 | +struct custom_ipc4_config_up_down { |
| 46 | + struct ipc4_base_module_cfg base; |
| 47 | + uint32_t out_channel_config; |
| 48 | + uint32_t coefficients_select; |
| 49 | + int32_t coefficients[8]; |
| 50 | + uint32_t channel_map; |
| 51 | +} __attribute__((packed, aligned(8))); |
| 52 | + |
| 53 | +/* Test UP_DOWN_MIXER initialization */ |
| 54 | +static struct comp_dev *test_up_down_mixer_create(void) |
| 55 | +{ |
| 56 | + struct comp_dev *comp; |
| 57 | + struct comp_ipc_config ipc_config; |
| 58 | + struct ipc_config_process spec; |
| 59 | + struct custom_ipc4_config_up_down mixer_init_data; |
| 60 | + |
| 61 | + memset(&mixer_init_data, 0, sizeof(mixer_init_data)); |
| 62 | + memset(&mixer_init_data.base.audio_fmt, 0, sizeof(mixer_init_data.base.audio_fmt)); |
| 63 | + mixer_init_data.base.ibs = 4096; |
| 64 | + mixer_init_data.base.obs = 4096; |
| 65 | + mixer_init_data.base.audio_fmt.channels_count = 2; |
| 66 | + mixer_init_data.base.audio_fmt.sampling_frequency = 48000; |
| 67 | + mixer_init_data.base.audio_fmt.depth = 32; |
| 68 | + mixer_init_data.base.audio_fmt.valid_bit_depth = 32; |
| 69 | + mixer_init_data.base.audio_fmt.interleaving_style = IPC4_CHANNELS_INTERLEAVED; |
| 70 | + mixer_init_data.out_channel_config = IPC4_CHANNEL_CONFIG_STEREO; /* Stereo out */ |
| 71 | + mixer_init_data.coefficients_select = 0; /* DEFAULT_COEFFICIENTS */ |
| 72 | + |
| 73 | + /* Setup basic IPC configuration */ |
| 74 | + memset(&ipc_config, 0, sizeof(ipc_config)); |
| 75 | + ipc_config.id = 1; |
| 76 | + ipc_config.pipeline_id = 1; |
| 77 | + ipc_config.core = 0; |
| 78 | + |
| 79 | + memset(&spec, 0, sizeof(spec)); |
| 80 | + spec.size = sizeof(mixer_init_data); |
| 81 | + spec.data = (unsigned char *)&mixer_init_data; |
| 82 | + |
| 83 | + struct list_item *clist; |
| 84 | + const struct comp_driver *drv = NULL; |
| 85 | + |
| 86 | + /* Find driver by UUID */ |
| 87 | + list_for_item(clist, &comp_drivers_get()->list) { |
| 88 | + struct comp_driver_info *info = container_of(clist, struct comp_driver_info, list); |
| 89 | + if (!info->drv->uid) continue; |
| 90 | + if (!memcmp(info->drv->uid, &up_down_mixer_test_uuid, sizeof(struct sof_uuid))) { |
| 91 | + drv = info->drv; |
| 92 | + break; |
| 93 | + } |
| 94 | + } |
| 95 | + zassert_not_null(drv, "Driver for UP_DOWN_MIXER not found"); |
| 96 | + |
| 97 | + /* Initialize component via ops */ |
| 98 | + comp = drv->ops.create(drv, &ipc_config, &spec); |
| 99 | + zassert_not_null(comp, "Component allocation failed"); |
| 100 | + |
| 101 | + return comp; |
| 102 | +} |
| 103 | + |
| 104 | +/* Test up_down_mixer initialization */ |
| 105 | +ZTEST(audio_up_down_mixer, test_up_down_mixer_init) |
| 106 | +{ |
| 107 | + struct comp_dev *comp = test_up_down_mixer_create(); |
| 108 | + |
| 109 | + /* Verify component state */ |
| 110 | + zassert_equal(comp->state, COMP_STATE_READY, "Component is not in READY state"); |
| 111 | + zassert_equal(comp->ipc_config.id, 1, "IPC ID mismatch"); |
| 112 | + |
| 113 | + /* Free the component */ |
| 114 | + comp->drv->ops.free(comp); |
| 115 | +} |
| 116 | +ZTEST(audio_up_down_mixer, test_up_down_mixer_config) |
| 117 | +{ |
| 118 | + struct comp_dev *comp = test_up_down_mixer_create(); |
| 119 | + |
| 120 | + int ret = 0; |
| 121 | + if (comp->drv->ops.set_large_config) { |
| 122 | + uint32_t val = 0; |
| 123 | + ret = comp->drv->ops.set_large_config(comp, 0, true, true, |
| 124 | + sizeof(val), (uint8_t *)&val); |
| 125 | + } |
| 126 | + |
| 127 | + comp->drv->ops.free(comp); |
| 128 | +} |
| 129 | + |
| 130 | +ZTEST(audio_up_down_mixer, test_up_down_mixer_process) |
| 131 | +{ |
| 132 | + struct comp_dev *comp = test_up_down_mixer_create(); |
| 133 | + |
| 134 | + struct sof_ipc_stream_params params = {0}; |
| 135 | + params.buffer_fmt = SOF_IPC_BUFFER_INTERLEAVED; |
| 136 | + params.channels = 2; |
| 137 | + params.rate = 48000; |
| 138 | + params.sample_container_bytes = 4; |
| 139 | + params.sample_valid_bytes = 4; |
| 140 | + |
| 141 | + test_audio_helper_setup_buffers(comp, 4096, ¶ms); |
| 142 | + test_audio_helper_process(comp); |
| 143 | + test_audio_helper_free_buffers(comp); |
| 144 | + |
| 145 | + comp->drv->ops.free(comp); |
| 146 | +} |
| 147 | + |
| 148 | + |
| 149 | +ZTEST_SUITE(audio_up_down_mixer, NULL, setup, NULL, NULL, NULL); |
0 commit comments