1 // SPDX-License-Identifier: BSD-3-Clause
2 //
3 // Copyright(c) 2020 Intel Corporation. All rights reserved.
4 //
5
6 #include "../util.h"
7
8 #include <stdarg.h>
9 #include <stddef.h>
10 #include <setjmp.h>
11 #include <stdint.h>
12 #include <cmocka.h>
13 #include <sof/audio/component.h>
14 #include <sof/audio/module_adapter/module/generic.h>
15 #include "module_adapter.h"
16
module_adapter_test_setup(struct processing_module_test_data * test_data)17 int module_adapter_test_setup(struct processing_module_test_data *test_data)
18 {
19 struct processing_module_test_parameters *parameters = &test_data->parameters;
20 struct processing_module *mod;
21 struct comp_dev *dev;
22 uint32_t size;
23 int i;
24
25 /* allocate and set new device */
26 mod = test_malloc(sizeof(struct processing_module));
27 test_data->mod = mod;
28 dev = test_malloc(sizeof(struct comp_dev));
29 dev->frames = parameters->frames;
30 mod->dev = dev;
31 comp_set_drvdata(dev, mod);
32
33 test_data->sinks = test_calloc(test_data->num_sinks, sizeof(struct comp_buffer *));
34 test_data->sources = test_calloc(test_data->num_sources, sizeof(struct comp_buffer *));
35
36 test_data->input_buffers = test_calloc(test_data->num_sources,
37 sizeof(struct input_stream_buffer *));
38 test_data->output_buffers = test_calloc(test_data->num_sinks,
39 sizeof(struct output_stream_buffer *));
40
41 list_init(&dev->bsource_list);
42 list_init(&dev->bsink_list);
43
44 /* allocate sink buffers */
45 size = parameters->frames *
46 get_frame_bytes(parameters->sink_format, parameters->channels) *
47 parameters->buffer_size_ms;
48 for (i = 0; i < test_data->num_sinks; i++) {
49 test_data->sinks[i] = create_test_sink(dev, 0, parameters->sink_format,
50 parameters->channels, size);
51 test_data->output_buffers[i] = test_malloc(sizeof(struct output_stream_buffer));
52 test_data->output_buffers[i]->data = &test_data->sinks[i]->stream;
53 }
54
55 /* allocate source buffers */
56 size = parameters->frames * get_frame_bytes(parameters->source_format,
57 parameters->channels) * parameters->buffer_size_ms;
58 for (i = 0; i < test_data->num_sources; i++) {
59 test_data->sources[i] = create_test_source(dev, 0, parameters->source_format,
60 parameters->channels, size);
61 test_data->input_buffers[i] = test_malloc(sizeof(struct input_stream_buffer));
62 test_data->input_buffers[i]->data = &test_data->sources[i]->stream;
63 }
64
65 test_data->verify = parameters->verify;
66
67 return 0;
68 }
69
module_adapter_test_free(struct processing_module_test_data * test_data)70 void module_adapter_test_free(struct processing_module_test_data *test_data)
71 {
72 int i;
73
74 for (i = 0; i < test_data->num_sinks; i++) {
75 free_test_sink(test_data->sinks[i]);
76 test_free(test_data->output_buffers[i]);
77 }
78
79 for (i = 0; i < test_data->num_sources; i++) {
80 free_test_sink(test_data->sources[i]);
81 test_free(test_data->input_buffers[i]);
82 }
83
84 test_free(test_data->input_buffers);
85 test_free(test_data->output_buffers);
86 test_free(test_data->sinks);
87 test_free(test_data->sources);
88 test_free(test_data->mod->dev);
89 test_free(test_data->mod);
90 }
91