Skip to content

Commit

Permalink
buf: make unit test using newly added buffer API
Browse files Browse the repository at this point in the history
Unit test should also - if possible - use buffer API
There are, however, some parts of testing that still
use direct access to comp_buffer internals.

Signed-off-by: Marcin Szkudlinski <[email protected]>
  • Loading branch information
marcinszkudlinski authored and lgirdwood committed Feb 26, 2025
1 parent ad7e28f commit 5f4449d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
33 changes: 14 additions & 19 deletions test/cmocka/src/audio/pipeline/pipeline_connect_upstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ static void test_audio_pipeline_complete_connect_upstream_ignore_source
*/
list_item_append(&result.sched_comp->bsource_list,
&test_data->b1->sink_list);
test_data->b1->sink = result.sched_comp;
test_data->b1->source = test_data->second;
comp_buffer_set_sink_component(test_data->b1, result.sched_comp);
comp_buffer_set_source_component(test_data->b1, test_data->second);
list_item_append(&test_data->b1->source_list,
&test_data->second->bsink_list);
list_item_append(&test_data->second->bsource_list,
&test_data->b2->sink_list);
test_data->b2->sink = test_data->second;
comp_buffer_set_sink_component(test_data->b2, test_data->second);

/*Testing component*/
pipeline_complete(&result, test_data->first, test_data->second);
Expand All @@ -156,14 +156,11 @@ static void test_audio_pipeline_complete_connect_downstream_full(void **state)
/*Connecting first comp to second*/
comp = &test_data->second->ipc_config;
comp->pipeline_id = PIPELINE_ID_SAME;
list_item_append(&result.sched_comp->bsink_list,
&test_data->b1->source_list);
test_data->b1->source = result.sched_comp;
list_item_append(&test_data->b1->source_list,
&result.sched_comp->bsink_list);
test_data->b1->sink = test_data->second;
list_item_append(&test_data->b1->sink_list,
&test_data->second->bsource_list);
list_item_append(&result.sched_comp->bsink_list, &test_data->b1->source_list);
comp_buffer_set_source_component(test_data->b1, result.sched_comp);
list_item_append(&test_data->b1->source_list, &result.sched_comp->bsink_list);
comp_buffer_set_sink_component(test_data->b1, test_data->second);
list_item_append(&test_data->b1->sink_list, &test_data->second->bsource_list);

test_data->first->frames = 0;
test_data->second->frames = 0;
Expand All @@ -189,8 +186,8 @@ static void test_audio_pipeline_complete_connect_upstream_full(void **state)
comp->pipeline_id = PIPELINE_ID_SAME;
list_item_append(&result.sched_comp->bsource_list,
&test_data->b1->sink_list);
test_data->b1->sink = test_data->first;
test_data->b1->source = test_data->second;
comp_buffer_set_sink_component(test_data->b1, test_data->first);
comp_buffer_set_source_component(test_data->b1, test_data->second);

/*Testing component*/
pipeline_complete(&result, test_data->first, test_data->second);
Expand All @@ -212,12 +209,10 @@ static void test_audio_pipeline_complete_connect_upstream_other_pipeline
/*Connecting first comp to second*/
comp = &test_data->second->ipc_config;
comp->pipeline_id = PIPELINE_ID_DIFFERENT;
list_item_append(&result.sched_comp->bsource_list,
&test_data->b1->sink_list);
test_data->b1->sink = test_data->first;
test_data->b1->source = test_data->second;
list_item_append(&test_data->second->bsource_list,
&test_data->b1->source_list);
list_item_append(&result.sched_comp->bsource_list, &test_data->b1->sink_list);
comp_buffer_set_sink_component(test_data->b1, test_data->first);
comp_buffer_set_source_component(test_data->b1, test_data->second);
list_item_append(&test_data->second->bsource_list, &test_data->b1->source_list);

/*Testing component*/
pipeline_complete(&result, test_data->first, test_data->second);
Expand Down
22 changes: 11 additions & 11 deletions test/cmocka/src/audio/pipeline/pipeline_connection_mocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ void cleanup_test_data(struct pipeline_connect_data *data)
{
list_init(&data->first->bsource_list);
list_init(&data->second->bsource_list);
list_init(&data->b1->sink_list);
list_init(&data->b1->source_list);
comp_buffer_reset_sink_list(data->b1);
comp_buffer_reset_source_list(data->b1);
list_init(&data->first->bsink_list);
list_init(&data->second->bsink_list);
list_init(&data->b2->sink_list);
list_init(&data->b2->source_list);
comp_buffer_reset_sink_list(data->b2);
comp_buffer_reset_source_list(data->b2);
}

struct pipeline_connect_data *get_standard_connect_objects(void)
Expand Down Expand Up @@ -70,17 +70,17 @@ struct pipeline_connect_data *get_standard_connect_objects(void)

struct comp_buffer *buffer = calloc(sizeof(struct comp_buffer), 1);

buffer->source = first;
buffer->sink = second;
list_init(&buffer->sink_list);
list_init(&buffer->source_list);
comp_buffer_set_source_component(buffer, first);
comp_buffer_set_sink_component(buffer, second);
comp_buffer_reset_sink_list(buffer);
comp_buffer_reset_source_list(buffer);
pipeline_connect_data->b1 = buffer;

struct comp_buffer *buffer_2 = calloc(sizeof(struct comp_buffer), 1);

buffer_2->source = second;
list_init(&buffer_2->sink_list);
list_init(&buffer_2->source_list);
comp_buffer_set_source_component(buffer_2, second);
comp_buffer_reset_sink_list(buffer_2);
comp_buffer_reset_source_list(buffer_2);
pipeline_connect_data->b2 = buffer_2;

pipeline_connect_data->p = *pipe;
Expand Down
2 changes: 1 addition & 1 deletion test/cmocka/src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static inline struct comp_buffer *create_test_sink(struct comp_dev *dev,

static inline void free_test_sink(struct comp_buffer *buffer)
{
free(buffer->sink);
free(comp_buffer_get_sink_component(buffer));
buffer_free(buffer);
}

Expand Down

0 comments on commit 5f4449d

Please sign in to comment.