Skip to content

Commit 2b034e7

Browse files
authored
Merge pull request #183 from dabekjakub/pipeline_test
New pipeline test
2 parents 31d8aa4 + 8dfedb6 commit 2b034e7

7 files changed

Lines changed: 447 additions & 0 deletions

File tree

test/cmocka/Makefile.am

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ check_PROGRAMS += rstrcmp
5555
rstrcmp_SOURCES = src/lib/lib/rstrcmp.c
5656
rstrcmp_LDADD = ../../src/lib/libcore.a $(LDADD)
5757

58+
#pipeline tests
59+
check_PROGRAMS += pipeline_new
60+
pipeline_new_SOURCES = ../../src/audio/pipeline.c src/audio/pipeline/pipeline_new.c src/audio/pipeline/pipeline_mocks.c src/audio/pipeline/pipeline_mocks_rzalloc.c
61+
62+
check_PROGRAMS += pipeline_new_allocation
63+
pipeline_new_allocation_SOURCES = ../../src/audio/pipeline.c src/audio/pipeline/pipeline_new_allocation.c src/audio/pipeline/pipeline_mocks.c src/audio/pipeline/pipeline_new_allocation_mocks.c
64+
5865
# volume tests
5966

6067
check_PROGRAMS += volume_process
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (c) 2018, Intel Corporation
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
* * Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* * Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
* * Neither the name of the Intel Corporation nor the
13+
* names of its contributors may be used to endorse or promote products
14+
* derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
*
28+
* Author: Jakub Dabek <jakub.dabek@linux.intel.com>
29+
*/
30+
31+
#include "pipeline_mocks.h"
32+
33+
void platform_dai_timestamp(struct comp_dev *dai,
34+
struct sof_ipc_stream_posn *posn)
35+
{
36+
(void)dai;
37+
(void)posn;
38+
}
39+
40+
void schedule_task(struct task *task, uint64_t start, uint64_t deadline)
41+
{
42+
(void)deadline;
43+
(void)start;
44+
(void)task;
45+
}
46+
47+
void schedule_task_complete(struct task *task)
48+
{
49+
(void)task;
50+
}
51+
52+
void schedule_task_idle(struct task *task, uint64_t deadline)
53+
{
54+
(void)deadline;
55+
(void)task;
56+
}
57+
58+
void rfree(void *ptr)
59+
{
60+
(void)ptr;
61+
}
62+
63+
void platform_host_timestamp(struct comp_dev *host,
64+
struct sof_ipc_stream_posn *posn)
65+
{
66+
(void)host;
67+
(void)posn;
68+
}
69+
70+
int ipc_stream_send_xrun(struct comp_dev *cdev,
71+
struct sof_ipc_stream_posn *posn)
72+
{
73+
return 0;
74+
}
75+
76+
void _trace_event(uint32_t event)
77+
{
78+
(void)event;
79+
}
80+
81+
void _trace_event_mbox_atomic(uint32_t event)
82+
{
83+
(void)event;
84+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2018, Intel Corporation
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
* * Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* * Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
* * Neither the name of the Intel Corporation nor the
13+
* names of its contributors may be used to endorse or promote products
14+
* derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
*
28+
* Author: Jakub Dabek <jakub.dabek@linux.intel.com>
29+
*/
30+
31+
#include <sof/audio/component.h>
32+
#include <sof/audio/pipeline.h>
33+
#include <sof/schedule.h>
34+
#include <stdarg.h>
35+
#include <stddef.h>
36+
#include <setjmp.h>
37+
#include <stdint.h>
38+
#include <cmocka.h>
39+
40+
int ipc_stream_send_xrun(struct comp_dev *cdev,
41+
struct sof_ipc_stream_posn *posn);
42+
43+
struct pipeline_new_setup_data {
44+
struct sof_ipc_pipe_new ipc_data;
45+
struct comp_dev *comp_data;
46+
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2018, Intel Corporation
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
* * Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* * Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
* * Neither the name of the Intel Corporation nor the
13+
* names of its contributors may be used to endorse or promote products
14+
* derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
*
28+
* Author: Jakub Dabek <jakub.dabek@linux.intel.com>
29+
*/
30+
31+
#include <sof/audio/component.h>
32+
#include <sof/audio/pipeline.h>
33+
#include <sof/schedule.h>
34+
#include <stdarg.h>
35+
#include <stddef.h>
36+
#include <setjmp.h>
37+
#include <stdint.h>
38+
#include <cmocka.h>
39+
#include <sof/alloc.h>
40+
41+
void *rzalloc(int zone, uint32_t caps, size_t bytes)
42+
{
43+
(void)zone;
44+
(void)caps;
45+
return calloc(bytes, 1);
46+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/*
2+
* Copyright (c) 2018, Intel Corporation
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
* * Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* * Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
* * Neither the name of the Intel Corporation nor the
13+
* names of its contributors may be used to endorse or promote products
14+
* derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
*
28+
* Author: Jakub Dabek <jakub.dabek@linux.intel.com>
29+
*/
30+
31+
#include <stdint.h>
32+
#include <sof/audio/component.h>
33+
#include <sof/audio/pipeline.h>
34+
#include <sof/schedule.h>
35+
#include "pipeline_mocks.h"
36+
#include <stdarg.h>
37+
#include <stddef.h>
38+
#include <setjmp.h>
39+
#include <cmocka.h>
40+
41+
static int setup(void **state)
42+
{
43+
struct pipeline_new_setup_data *pipeline_data = malloc(
44+
sizeof(struct pipeline_new_setup_data));
45+
46+
if (pipeline_data == NULL)
47+
return -1;
48+
49+
struct sof_ipc_pipe_new pipe_desc = { .core = 1, .priority = 2 };
50+
51+
pipeline_data->ipc_data = pipe_desc;
52+
53+
*state = pipeline_data;
54+
return 0;
55+
}
56+
57+
static int teardown(void **state)
58+
{
59+
free(*state);
60+
return 0;
61+
}
62+
63+
static void test_audio_pipeline_pipeline_new_creation(void **state)
64+
{
65+
struct pipeline_new_setup_data *test_data = *state;
66+
67+
/*Testing component*/
68+
struct pipeline *result = pipeline_new(&test_data->ipc_data,
69+
test_data->comp_data);
70+
71+
/*Pipeline should have been created so pointer can't be null*/
72+
assert_non_null(result);
73+
}
74+
75+
static void test_audio_pipeline_new_list_initialization(void **state)
76+
{
77+
struct pipeline_new_setup_data *test_data = *state;
78+
79+
/*Testing component*/
80+
struct pipeline *result = pipeline_new(&test_data->ipc_data,
81+
test_data->comp_data);
82+
83+
/*Check list initialization*/
84+
assert_ptr_equal(&result->comp_list, result->comp_list.next);
85+
assert_ptr_equal(&result->buffer_list, result->buffer_list.next);
86+
}
87+
88+
static void test_audio_pipeline_new_sheduler_init(void **state)
89+
{
90+
struct pipeline_new_setup_data *test_data = *state;
91+
92+
/*Testing component*/
93+
struct pipeline *result = pipeline_new(&test_data->ipc_data,
94+
test_data->comp_data);
95+
96+
/*Check if all parameters are passed to sheduler
97+
*(initialization)
98+
*/
99+
assert_int_equal(result->pipe_task.state, TASK_STATE_INIT);
100+
assert_int_equal(result->pipe_task.core, test_data->ipc_data.core);
101+
}
102+
103+
static void test_audio_pipeline_new_sheduler_config(void **state)
104+
{
105+
struct pipeline_new_setup_data *test_data = *state;
106+
107+
/*Testing component*/
108+
struct pipeline *result = pipeline_new(&test_data->ipc_data,
109+
test_data->comp_data);
110+
111+
/*Pipeline should end in pre init state untli sheduler runs
112+
*task that initializes it
113+
*/
114+
assert_int_equal(COMP_STATE_INIT, result->status);
115+
}
116+
117+
static void test_audio_pipeline_new_ipc_data_coppy(void **state)
118+
{
119+
struct pipeline_new_setup_data *test_data = *state;
120+
121+
/*Testing component*/
122+
struct pipeline *result = pipeline_new(&test_data->ipc_data,
123+
test_data->comp_data);
124+
125+
assert_memory_equal(&test_data->ipc_data, &result->ipc_pipe,
126+
sizeof(struct sof_ipc_pipe_new));
127+
}
128+
129+
int main(void)
130+
{
131+
132+
const struct CMUnitTest tests[] = {
133+
cmocka_unit_test(test_audio_pipeline_pipeline_new_creation),
134+
cmocka_unit_test(test_audio_pipeline_new_list_initialization),
135+
cmocka_unit_test(test_audio_pipeline_new_sheduler_init),
136+
cmocka_unit_test(test_audio_pipeline_new_sheduler_config),
137+
cmocka_unit_test(test_audio_pipeline_new_ipc_data_coppy),
138+
};
139+
140+
cmocka_set_message_output(CM_OUTPUT_TAP);
141+
142+
return cmocka_run_group_tests(tests, setup, teardown);
143+
}

0 commit comments

Comments
 (0)