forked from thesofproject/sof
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer_copy.c
More file actions
171 lines (126 loc) · 3.98 KB
/
buffer_copy.c
File metadata and controls
171 lines (126 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2018 Intel Corporation. All rights reserved.
//
// Author: Slawomir Blauciak <slawomir.blauciak@linux.intel.com>
#include <sof/audio/component.h>
#include <sof/audio/buffer.h>
#include <sof/ipc/driver.h>
#include <sof/ipc/msg.h>
#include <sof/ipc/topology.h>
#include <sof/ipc/schedule.h>
#include <stdio.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <math.h>
#include <stdint.h>
#include <cmocka.h>
static void test_audio_buffer_copy_underrun(void **state)
{
int copy_bytes;
(void)state;
struct sof_ipc_buffer test_buf_desc = {
.size = 256
};
struct comp_buffer *src = buffer_new(&test_buf_desc, false);
struct comp_buffer *snk = buffer_new(&test_buf_desc, false);
assert_non_null(src);
assert_non_null(snk);
comp_update_buffer_produce(src, 10);
copy_bytes =
audio_stream_can_copy_bytes(&src->stream, &snk->stream, 16);
assert_int_equal(audio_stream_get_avail_bytes(&src->stream), 10);
assert_int_equal(copy_bytes, -1);
buffer_free(src);
buffer_free(snk);
}
static void test_audio_buffer_copy_overrun(void **state)
{
int copy_bytes;
(void)state;
struct sof_ipc_buffer test_buf_desc = {
.size = 256
};
struct comp_buffer *src = buffer_new(&test_buf_desc, false);
struct comp_buffer *snk = buffer_new(&test_buf_desc, false);
assert_non_null(src);
assert_non_null(snk);
comp_update_buffer_produce(src, 16);
comp_update_buffer_produce(snk, 246);
copy_bytes =
audio_stream_can_copy_bytes(&src->stream, &snk->stream, 16);
assert_int_equal(audio_stream_get_avail_bytes(&src->stream), 16);
assert_int_equal(audio_stream_get_free_bytes(&snk->stream), 10);
assert_int_equal(copy_bytes, 1);
buffer_free(src);
buffer_free(snk);
}
static void test_audio_buffer_copy_success(void **state)
{
int copy_bytes;
(void)state;
struct sof_ipc_buffer test_buf_desc = {
.size = 256
};
struct comp_buffer *src = buffer_new(&test_buf_desc, false);
struct comp_buffer *snk = buffer_new(&test_buf_desc, false);
assert_non_null(src);
assert_non_null(snk);
comp_update_buffer_produce(src, 10);
copy_bytes = audio_stream_can_copy_bytes(&src->stream, &snk->stream, 0);
assert_int_equal(audio_stream_get_avail_bytes(&src->stream), 10);
assert_int_equal(copy_bytes, 0);
buffer_free(src);
buffer_free(snk);
}
static void test_audio_buffer_copy_fit_space_constraint(void **state)
{
int copy_bytes;
(void)state;
struct sof_ipc_buffer test_buf_desc = {
.size = 256
};
struct comp_buffer *src = buffer_new(&test_buf_desc, false);
struct comp_buffer *snk = buffer_new(&test_buf_desc, false);
assert_non_null(src);
assert_non_null(snk);
comp_update_buffer_produce(src, 16);
comp_update_buffer_produce(snk, 246);
copy_bytes = audio_stream_get_copy_bytes(&src->stream, &snk->stream);
assert_int_equal(audio_stream_get_avail_bytes(&src->stream), 16);
assert_int_equal(audio_stream_get_free_bytes(&snk->stream), 10);
assert_int_equal(copy_bytes, 10);
buffer_free(src);
buffer_free(snk);
}
static void test_audio_buffer_copy_fit_no_space_constraint(void **state)
{
int copy_bytes;
(void)state;
struct sof_ipc_buffer test_buf_desc = {
.size = 256
};
struct comp_buffer *src = buffer_new(&test_buf_desc, false);
struct comp_buffer *snk = buffer_new(&test_buf_desc, false);
assert_non_null(src);
assert_non_null(snk);
comp_update_buffer_produce(src, 16);
copy_bytes = audio_stream_get_copy_bytes(&src->stream, &snk->stream);
assert_int_equal(audio_stream_get_avail_bytes(&src->stream), 16);
assert_int_equal(copy_bytes, 16);
buffer_free(src);
buffer_free(snk);
}
int main(void)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_audio_buffer_copy_underrun),
cmocka_unit_test(test_audio_buffer_copy_overrun),
cmocka_unit_test(test_audio_buffer_copy_success),
cmocka_unit_test(test_audio_buffer_copy_fit_space_constraint),
cmocka_unit_test(test_audio_buffer_copy_fit_no_space_constraint)
};
cmocka_set_message_output(CM_OUTPUT_TAP);
return cmocka_run_group_tests(tests, NULL, NULL);
}