Skip to content

Commit fb8a650

Browse files
mrajwatlauda
authored andcommitted
CMOCKA-KPB: create dummy source && sink buffers
Signed-off-by: Marcin Rajwa <marcin.rajwa@linux.intel.com>
1 parent 3ff3b61 commit fb8a650

1 file changed

Lines changed: 46 additions & 13 deletions

File tree

test/cmocka/src/audio/kpb/kpb_buffer.c

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,9 @@ enum kpb_test_buff_type {
5353

5454
/*! Parameters for test case */
5555
struct test_case {
56-
int no_buffers;
57-
int lp_buff_size;
58-
int hp_buff_size;
59-
int source_period_bytes;
60-
int sink_period_bytes;
56+
size_t period_bytes;
57+
size_t history_buffer_size;
58+
6159
};
6260

6361
/* Dummy IPC structure, used to create KPB component */
@@ -87,14 +85,19 @@ struct comp_buffer *sink;
8785
/* Dummy memory buffers and data pointers */
8886
void *source_data;
8987
void *sink_data;
90-
void *his_buf_lp;
91-
void *his_buf_hp;
88+
89+
/* Local function declarations */
90+
static struct comp_buffer *mock_comp_buffer(void **state,
91+
enum kpb_test_buff_type buff_type);
9292

9393
/* Initialize KPB for test */
9494
static int buffering_test_setup(void **state)
9595
{
96-
(void)state;
9796

97+
struct test_case *test_case_data = (struct test_case *)*state;
98+
unsigned char *r_ptr;
99+
int i;
100+
char pattern = 0xAB;
98101
/* Dummy IPC structue to create new KPB component */
99102
struct sof_ipc_comp_kpb_mock kpb = {
100103
.comp = {
@@ -124,11 +127,44 @@ static int buffering_test_setup(void **state)
124127
kpb_dev_mock->private)->config.sampling_freq,
125128
KPB_SAMPLNG_FREQUENCY);
126129

130+
/* Create source and sink buffers */
131+
source_data = test_malloc(test_case_data->history_buffer_size);
132+
sink_data = test_malloc(test_case_data->history_buffer_size);
133+
134+
source = mock_comp_buffer(state, KPB_SOURCE_BUFFER);
135+
sink = mock_comp_buffer(state, KPB_SINK_BUFFER);
136+
127137
return 0;
128138
}
129139

140+
static struct comp_buffer *mock_comp_buffer(void **state,
141+
enum kpb_test_buff_type buff_type)
142+
{
143+
struct test_case *test_case_data = (struct test_case *)*state;
144+
struct comp_buffer *buffer = test_malloc(sizeof(struct comp_buffer));
145+
146+
switch (buff_type) {
147+
case KPB_SOURCE_BUFFER:
148+
buffer->avail = test_case_data->period_bytes;
149+
buffer->r_ptr = source_data;
150+
break;
151+
case KPB_SINK_BUFFER:
152+
buffer->free = test_case_data->period_bytes;
153+
buffer->w_ptr = sink_data;
154+
break;
155+
}
156+
157+
buffer->cb = NULL;
158+
159+
return buffer;
160+
}
130161
static int buffering_test_teardown(void **state)
131162
{
163+
test_free(source_data);
164+
test_free(sink_data);
165+
test_free(source);
166+
test_free(sink);
167+
132168
return 0;
133169
}
134170

@@ -168,11 +204,8 @@ int main(void)
168204
{
169205
struct CMUnitTest tests[2];
170206
struct test_case internal_buffering = {
171-
.no_buffers = 2,
172-
.lp_buff_size = 100,
173-
.hp_buff_size = 20,
174-
.source_period_bytes = 120,
175-
.sink_period_bytes = 120,
207+
.period_bytes = 100,
208+
.history_buffer_size = KPB_MAX_BUFFER_SIZE,
176209
};
177210

178211
tests[0].name = "Dummy, always successful test";

0 commit comments

Comments
 (0)