|
| 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_tone_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_tone_interface_init(); |
| 36 | + return NULL; |
| 37 | +} |
| 38 | + |
| 39 | +/* TONE_UUID extracted from native registries */ |
| 40 | +SOF_DEFINE_UUID("tone_test", tone_test_uuid, 0x04e3f894, 0x2c5c, 0x4f2e, |
| 41 | + 0x8d, 0xc1, 0x69, 0x4e, 0xea, 0xab, 0x53, 0xfa); |
| 42 | + |
| 43 | +struct custom_ipc4_config_tone { |
| 44 | + struct ipc4_base_module_cfg base; |
| 45 | +} __attribute__((packed, aligned(4))); |
| 46 | + |
| 47 | +/* Test TONE initialization */ |
| 48 | +ZTEST(audio_tone, test_tone_init) |
| 49 | +{ |
| 50 | + struct comp_dev *comp; |
| 51 | + struct comp_ipc_config ipc_config; |
| 52 | + struct ipc_config_process spec; |
| 53 | + struct custom_ipc4_config_tone tone_init_data; |
| 54 | + |
| 55 | + memset(&tone_init_data, 0, sizeof(tone_init_data)); |
| 56 | + memset(&tone_init_data.base.audio_fmt, 0, sizeof(tone_init_data.base.audio_fmt)); |
| 57 | + tone_init_data.base.audio_fmt.channels_count = 2; |
| 58 | + tone_init_data.base.audio_fmt.sampling_frequency = 48000; |
| 59 | + tone_init_data.base.audio_fmt.depth = 32; |
| 60 | + tone_init_data.base.audio_fmt.valid_bit_depth = 32; |
| 61 | + tone_init_data.base.audio_fmt.interleaving_style = IPC4_CHANNELS_INTERLEAVED; |
| 62 | + |
| 63 | + /* Setup basic IPC configuration */ |
| 64 | + memset(&ipc_config, 0, sizeof(ipc_config)); |
| 65 | + ipc_config.id = 1; |
| 66 | + ipc_config.pipeline_id = 1; |
| 67 | + ipc_config.core = 0; |
| 68 | + |
| 69 | + memset(&spec, 0, sizeof(spec)); |
| 70 | + spec.size = sizeof(tone_init_data); |
| 71 | + spec.data = (unsigned char *)&tone_init_data; |
| 72 | + |
| 73 | + struct list_item *clist; |
| 74 | + const struct comp_driver *drv = NULL; |
| 75 | + |
| 76 | + /* Find TONE driver by UUID */ |
| 77 | + list_for_item(clist, &comp_drivers_get()->list) { |
| 78 | + struct comp_driver_info *info = container_of(clist, struct comp_driver_info, list); |
| 79 | + if (!info->drv->uid) continue; |
| 80 | + if (!memcmp(info->drv->uid, &tone_test_uuid, sizeof(struct sof_uuid))) { |
| 81 | + drv = info->drv; |
| 82 | + break; |
| 83 | + } |
| 84 | + } |
| 85 | + zassert_not_null(drv, "Driver for TONE not found"); |
| 86 | + |
| 87 | + /* Initialize TONE component via ops */ |
| 88 | + comp = drv->ops.create(drv, &ipc_config, &spec); |
| 89 | + zassert_not_null(comp, "TONE allocation failed"); |
| 90 | + |
| 91 | + /* Verify component state */ |
| 92 | + zassert_equal(comp->state, COMP_STATE_READY, "Component is not in READY state"); |
| 93 | + zassert_equal(comp->ipc_config.id, 1, "IPC ID mismatch"); |
| 94 | + |
| 95 | + /* Free the component */ |
| 96 | + drv->ops.free(comp); |
| 97 | +} |
| 98 | + |
| 99 | +/* Test TONE parameters parsing */ |
| 100 | +ZTEST(audio_tone, test_tone_params) |
| 101 | +{ |
| 102 | + struct comp_dev *comp; |
| 103 | + struct comp_ipc_config ipc_config; |
| 104 | + struct ipc_config_process spec; |
| 105 | + struct sof_ipc_stream_params params; |
| 106 | + struct custom_ipc4_config_tone tone_init_data; |
| 107 | + int ret; |
| 108 | + |
| 109 | + memset(&tone_init_data, 0, sizeof(tone_init_data)); |
| 110 | + memset(&tone_init_data.base.audio_fmt, 0, sizeof(tone_init_data.base.audio_fmt)); |
| 111 | + tone_init_data.base.audio_fmt.channels_count = 2; |
| 112 | + tone_init_data.base.audio_fmt.sampling_frequency = 48000; |
| 113 | + tone_init_data.base.audio_fmt.depth = 32; |
| 114 | + tone_init_data.base.audio_fmt.valid_bit_depth = 32; |
| 115 | + tone_init_data.base.audio_fmt.interleaving_style = IPC4_CHANNELS_INTERLEAVED; |
| 116 | + |
| 117 | + memset(&ipc_config, 0, sizeof(ipc_config)); |
| 118 | + ipc_config.id = 1; |
| 119 | + ipc_config.pipeline_id = 1; |
| 120 | + |
| 121 | + memset(&spec, 0, sizeof(spec)); |
| 122 | + spec.size = sizeof(tone_init_data); |
| 123 | + spec.data = (unsigned char *)&tone_init_data; |
| 124 | + |
| 125 | + struct list_item *clist; |
| 126 | + const struct comp_driver *drv = NULL; |
| 127 | + |
| 128 | + list_for_item(clist, &comp_drivers_get()->list) { |
| 129 | + struct comp_driver_info *info = container_of(clist, struct comp_driver_info, list); |
| 130 | + if (!info->drv->uid) continue; |
| 131 | + if (!memcmp(info->drv->uid, &tone_test_uuid, sizeof(struct sof_uuid))) { |
| 132 | + drv = info->drv; |
| 133 | + break; |
| 134 | + } |
| 135 | + } |
| 136 | + zassert_not_null(drv, "Driver for TONE not found"); |
| 137 | + |
| 138 | + comp = drv->ops.create(drv, &ipc_config, &spec); |
| 139 | + |
| 140 | + memset(¶ms, 0, sizeof(params)); |
| 141 | + params.channels = 2; |
| 142 | + params.rate = 48000; |
| 143 | + params.sample_container_bytes = 4; |
| 144 | + params.sample_valid_bytes = 4; |
| 145 | + params.buffer_fmt = SOF_IPC_BUFFER_INTERLEAVED; |
| 146 | + |
| 147 | + /* Configure parameters */ |
| 148 | + ret = drv->ops.params(comp, ¶ms); |
| 149 | + zassert_true(ret >= 0, "TONE parameter setup failed"); |
| 150 | + |
| 151 | + drv->ops.free(comp); |
| 152 | +} |
| 153 | + |
| 154 | +ZTEST_SUITE(audio_tone, NULL, setup, NULL, NULL, NULL); |
0 commit comments