Skip to content

Commit 0ca1ddc

Browse files
singalsukv2019i
authored andcommitted
Test: Cmocka: Convert mux to module adapter
This patch converts the demux_copy, mux_copy, and mux_get_processing_function tests to module adapter API. The main change is in component new preparations with UUID reference. Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent 75f6bc6 commit 0ca1ddc

4 files changed

Lines changed: 146 additions & 84 deletions

File tree

test/cmocka/src/audio/mux/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ add_library(
1414
${PROJECT_SOURCE_DIR}/src/audio/component.c
1515
${PROJECT_SOURCE_DIR}/src/audio/data_blob.c
1616
${PROJECT_SOURCE_DIR}/src/audio/buffer.c
17+
${PROJECT_SOURCE_DIR}/src/math/numbers.c
1718
${PROJECT_SOURCE_DIR}/src/ipc/ipc3/helper.c
1819
${PROJECT_SOURCE_DIR}/src/ipc/ipc-helper.c
1920
${PROJECT_SOURCE_DIR}/test/cmocka/src/notifier_mocks.c
21+
${PROJECT_SOURCE_DIR}/src/audio/module_adapter/module_adapter.c
22+
${PROJECT_SOURCE_DIR}/src/audio/module_adapter/module/generic.c
2023
)
2124
sof_append_relative_path_definitions(audio_mux)
2225

test/cmocka/src/audio/mux/demux_copy.c

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "../../util.h"
99

10+
#include <sof/audio/module_adapter/module/generic.h>
1011
#include <sof/audio/component_ext.h>
1112
#include <sof/audio/format.h>
1213
#include <sof/audio/mux.h>
@@ -20,12 +21,14 @@
2021
#include <cmocka.h>
2122

2223
struct test_data {
23-
uint32_t format;
24-
uint8_t mask[MUX_MAX_STREAMS][PLATFORM_MAX_CHANNELS];
25-
void *outputs[MUX_MAX_STREAMS];
2624
struct comp_dev *dev;
27-
struct comp_buffer *source;
25+
struct processing_module *mod;
26+
struct comp_data *cd;
2827
struct comp_buffer *sinks[MUX_MAX_STREAMS];
28+
struct comp_buffer *source;
29+
void *outputs[MUX_MAX_STREAMS];
30+
uint32_t format;
31+
uint8_t mask[MUX_MAX_STREAMS][PLATFORM_MAX_CHANNELS];
2932
};
3033

3134
static int16_t input_16b[PLATFORM_MAX_CHANNELS] = {
@@ -82,27 +85,33 @@ static uint8_t masks[][MUX_MAX_STREAMS][PLATFORM_MAX_CHANNELS] = {
8285
static int setup_group(void **state)
8386
{
8487
sys_comp_init(sof_get());
85-
sys_comp_mux_init();
86-
88+
sys_comp_module_demux_interface_init();
8789
return 0;
8890
}
8991

9092
static struct sof_ipc_comp_process *create_demux_comp_ipc(struct test_data *td)
9193
{
94+
struct sof_ipc_comp_process *ipc;
95+
struct sof_mux_config *mux;
9296
size_t ipc_size = sizeof(struct sof_ipc_comp_process);
93-
size_t mux_size = sizeof(struct sof_mux_config)
94-
+ MUX_MAX_STREAMS * sizeof(struct mux_stream_data);
95-
struct sof_ipc_comp_process *ipc = calloc(1, ipc_size + mux_size);
96-
struct sof_mux_config *mux = (struct sof_mux_config *)&ipc->data;
97+
size_t mux_size = sizeof(struct sof_mux_config) +
98+
MUX_MAX_STREAMS * sizeof(struct mux_stream_data);
99+
const struct sof_uuid uuid = {
100+
.a = 0xc4b26868, .b = 0x1430, .c = 0x470e,
101+
.d = {0xa0, 0x89, 0x15, 0xd1, 0xc7, 0x7f, 0x85, 0x1a}
102+
};
97103
int i, j;
98104

99-
ipc->comp.hdr.size = sizeof(struct sof_ipc_comp_process);
105+
ipc = calloc(1, ipc_size + mux_size + SOF_UUID_SIZE);
106+
memcpy_s(ipc + 1, SOF_UUID_SIZE, &uuid, SOF_UUID_SIZE);
107+
mux = (struct sof_mux_config *)((char *)(ipc + 1) + SOF_UUID_SIZE);
108+
ipc->comp.hdr.size = ipc_size + SOF_UUID_SIZE;
100109
ipc->comp.type = SOF_COMP_DEMUX;
101110
ipc->config.hdr.size = sizeof(struct sof_ipc_comp_config);
102111
ipc->size = mux_size;
112+
ipc->comp.ext_data_length = SOF_UUID_SIZE;
103113

104114
mux->num_streams = MUX_MAX_STREAMS;
105-
106115
for (i = 0; i < MUX_MAX_STREAMS; ++i) {
107116
mux->streams[i].pipeline_id = i;
108117
for (j = 0; j < PLATFORM_MAX_CHANNELS; ++j)
@@ -147,26 +156,26 @@ static void prepare_source(struct test_data *td, size_t sample_size)
147156
static int setup_test_case(void **state)
148157
{
149158
struct test_data *td = *((struct test_data **)state);
150-
struct sof_ipc_comp_process *ipc = create_demux_comp_ipc(td);
151-
size_t sample_size = td->format == SOF_IPC_FRAME_S16_LE ?
152-
sizeof(int16_t) : sizeof(int32_t);
153-
int ret = 0;
159+
struct comp_dev *dev;
160+
struct processing_module *mod;
161+
struct sof_ipc_comp_process *ipc;
162+
size_t sample_size = td->format == SOF_IPC_FRAME_S16_LE ? sizeof(int16_t) : sizeof(int32_t);
154163

155-
td->dev = comp_new((struct sof_ipc_comp *)ipc);
164+
ipc = create_demux_comp_ipc(td);
165+
dev = comp_new((struct sof_ipc_comp *)ipc);
156166
free(ipc);
157-
158-
if (!td->dev)
167+
if (!dev)
159168
return -EINVAL;
160169

161-
prepare_sinks(td, sample_size);
170+
mod = comp_get_drvdata(dev);
171+
td->dev = dev;
172+
td->mod = mod;
173+
td->cd = module_get_private_data(mod);
162174

175+
prepare_sinks(td, sample_size);
163176
prepare_source(td, sample_size);
164177

165-
ret = comp_prepare(td->dev);
166-
if (ret)
167-
return ret;
168-
169-
return 0;
178+
return comp_prepare(td->dev);
170179
}
171180

172181
static int teardown_test_case(void **state)
@@ -273,13 +282,14 @@ static char *get_test_name(int mask_index, const char *format_name)
273282

274283
int main(void)
275284
{
276-
int i, j;
277285
struct CMUnitTest tests[ARRAY_SIZE(valid_formats) * ARRAY_SIZE(masks)];
286+
struct test_data *td;
287+
int i, j, ti, ret;
278288

279289
for (i = 0; i < ARRAY_SIZE(valid_formats); ++i) {
280290
for (j = 0; j < ARRAY_SIZE(masks); ++j) {
281-
int ti = i * ARRAY_SIZE(masks) + j;
282-
struct test_data *td = malloc(sizeof(struct test_data));
291+
ti = i * ARRAY_SIZE(masks) + j;
292+
td = malloc(sizeof(struct test_data));
283293

284294
td->format = valid_formats[i];
285295

@@ -320,6 +330,10 @@ int main(void)
320330
}
321331

322332
cmocka_set_message_output(CM_OUTPUT_TAP);
333+
ret = cmocka_run_group_tests(tests, setup_group, NULL);
334+
335+
for (ti = 0; ti < ARRAY_SIZE(valid_formats) * ARRAY_SIZE(masks); ti++)
336+
free(tests[ti].initial_state);
323337

324-
return cmocka_run_group_tests(tests, setup_group, NULL);
338+
return ret;
325339
}

test/cmocka/src/audio/mux/mux_copy.c

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "../../util.h"
99

10+
#include <sof/audio/module_adapter/module/generic.h>
1011
#include <sof/audio/component_ext.h>
1112
#include <sof/audio/format.h>
1213
#include <sof/audio/mux.h>
@@ -20,12 +21,14 @@
2021
#include <cmocka.h>
2122

2223
struct test_data {
23-
uint32_t format;
24-
uint8_t mask[MUX_MAX_STREAMS][PLATFORM_MAX_CHANNELS];
25-
void *output;
2624
struct comp_dev *dev;
25+
struct processing_module *mod;
26+
struct comp_data *cd;
2727
struct comp_buffer *sources[MUX_MAX_STREAMS];
2828
struct comp_buffer *sink;
29+
void *output;
30+
uint32_t format;
31+
uint8_t mask[MUX_MAX_STREAMS][PLATFORM_MAX_CHANNELS];
2932
};
3033

3134
static int16_t input_16b[MUX_MAX_STREAMS][PLATFORM_MAX_CHANNELS] = {
@@ -100,27 +103,33 @@ static uint8_t masks[][MUX_MAX_STREAMS][PLATFORM_MAX_CHANNELS] = {
100103
static int setup_group(void **state)
101104
{
102105
sys_comp_init(sof_get());
103-
sys_comp_mux_init();
104-
106+
sys_comp_module_mux_interface_init();
105107
return 0;
106108
}
107109

108110
static struct sof_ipc_comp_process *create_mux_comp_ipc(struct test_data *td)
109111
{
112+
struct sof_ipc_comp_process *ipc;
113+
struct sof_mux_config *mux;
110114
size_t ipc_size = sizeof(struct sof_ipc_comp_process);
111-
size_t mux_size = sizeof(struct sof_mux_config)
112-
+ MUX_MAX_STREAMS * sizeof(struct mux_stream_data);
113-
struct sof_ipc_comp_process *ipc = calloc(1, ipc_size + mux_size);
114-
struct sof_mux_config *mux = (struct sof_mux_config *)&ipc->data;
115+
size_t mux_size = sizeof(struct sof_mux_config) +
116+
MUX_MAX_STREAMS * sizeof(struct mux_stream_data);
117+
const struct sof_uuid uuid = {
118+
.a = 0xc607ff4d, .b = 0x9cb6, .c = 0x49dc,
119+
.d = {0xb6, 0x78, 0x7d, 0xa3, 0xc6, 0x3e, 0xa5, 0x57}
120+
};
115121
int i, j;
116122

117-
ipc->comp.hdr.size = sizeof(struct sof_ipc_comp_process);
123+
ipc = calloc(1, ipc_size + mux_size + SOF_UUID_SIZE);
124+
memcpy_s(ipc + 1, SOF_UUID_SIZE, &uuid, SOF_UUID_SIZE);
125+
mux = (struct sof_mux_config *)((char *)(ipc + 1) + SOF_UUID_SIZE);
126+
ipc->comp.hdr.size = ipc_size + SOF_UUID_SIZE;
118127
ipc->comp.type = SOF_COMP_MUX;
119128
ipc->config.hdr.size = sizeof(struct sof_ipc_comp_config);
120129
ipc->size = mux_size;
130+
ipc->comp.ext_data_length = SOF_UUID_SIZE;
121131

122132
mux->num_streams = MUX_MAX_STREAMS;
123-
124133
for (i = 0; i < MUX_MAX_STREAMS; ++i) {
125134
mux->streams[i].pipeline_id = i;
126135
for (j = 0; j < PLATFORM_MAX_CHANNELS; ++j)
@@ -169,26 +178,27 @@ static void prepare_sources(struct test_data *td, size_t sample_size)
169178
static int setup_test_case(void **state)
170179
{
171180
struct test_data *td = *((struct test_data **)state);
172-
struct sof_ipc_comp_process *ipc = create_mux_comp_ipc(td);
173-
size_t sample_size = td->format == SOF_IPC_FRAME_S16_LE ?
174-
sizeof(int16_t) : sizeof(int32_t);
175-
int ret = 0;
181+
struct comp_dev *dev;
182+
struct processing_module *mod;
183+
struct sof_ipc_comp_process *ipc;
184+
size_t sample_size = td->format == SOF_IPC_FRAME_S16_LE ? sizeof(int16_t) : sizeof(int32_t);
176185

177-
td->dev = comp_new((struct sof_ipc_comp *)ipc);
186+
ipc = create_mux_comp_ipc(td);
187+
dev = comp_new((struct sof_ipc_comp *)ipc);
178188
free(ipc);
179-
180-
if (!td->dev)
189+
if (!dev)
181190
return -EINVAL;
182191

183-
prepare_sink(td, sample_size);
192+
mod = comp_get_drvdata(dev);
193+
td->dev = dev;
194+
td->mod = mod;
195+
td->cd = module_get_private_data(mod);
184196

197+
prepare_sink(td, sample_size);
185198
prepare_sources(td, sample_size);
186199

187-
ret = comp_prepare(td->dev);
188-
if (ret)
189-
return ret;
200+
return comp_prepare(td->dev);
190201

191-
return 0;
192202
}
193203

194204
static int teardown_test_case(void **state)
@@ -200,9 +210,7 @@ static int teardown_test_case(void **state)
200210
free_test_source(td->sources[i]);
201211

202212
free_test_sink(td->sink);
203-
204213
comp_free(td->dev);
205-
206214
return 0;
207215
}
208216

@@ -292,13 +300,14 @@ static char *get_test_name(int mask_index, const char *format_name)
292300

293301
int main(void)
294302
{
295-
int i, j;
303+
struct test_data *td;
296304
struct CMUnitTest tests[ARRAY_SIZE(valid_formats) * ARRAY_SIZE(masks)];
305+
int i, j, ti, ret;
297306

298307
for (i = 0; i < ARRAY_SIZE(valid_formats); ++i) {
299308
for (j = 0; j < ARRAY_SIZE(masks); ++j) {
300-
int ti = i * ARRAY_SIZE(masks) + j;
301-
struct test_data *td = malloc(sizeof(struct test_data));
309+
ti = i * ARRAY_SIZE(masks) + j;
310+
td = malloc(sizeof(struct test_data));
302311

303312
td->format = valid_formats[i];
304313

@@ -339,6 +348,10 @@ int main(void)
339348
}
340349

341350
cmocka_set_message_output(CM_OUTPUT_TAP);
351+
ret = cmocka_run_group_tests(tests, setup_group, NULL);
352+
353+
for (ti = 0; ti < ARRAY_SIZE(valid_formats) * ARRAY_SIZE(masks); ti++)
354+
free(tests[ti].initial_state);
342355

343-
return cmocka_run_group_tests(tests, setup_group, NULL);
356+
return ret;
344357
}

0 commit comments

Comments
 (0)