1 /* Simple Plugin API
2 * Copyright © 2018 Collabora Ltd.
3 * @author George Kiagiadakis <george.kiagiadakis@collabora.com>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25 #include "pwtest.h"
26
27 #include <spa/buffer/alloc.h>
28 #include <spa/buffer/buffer.h>
29 #include <spa/buffer/meta.h>
30
PWTEST(buffer_abi_types)31 PWTEST(buffer_abi_types)
32 {
33 /* buffer */
34 pwtest_int_eq(SPA_DATA_Invalid, 0);
35 pwtest_int_eq(SPA_DATA_MemPtr, 1);
36 pwtest_int_eq(SPA_DATA_MemFd, 2);
37 pwtest_int_eq(SPA_DATA_DmaBuf, 3);
38 pwtest_int_eq(SPA_DATA_MemId, 4);
39 pwtest_int_eq(_SPA_DATA_LAST, 5);
40
41 /* meta */
42 pwtest_int_eq(SPA_META_Invalid, 0);
43 pwtest_int_eq(SPA_META_Header, 1);
44 pwtest_int_eq(SPA_META_VideoCrop, 2);
45 pwtest_int_eq(SPA_META_VideoDamage, 3);
46 pwtest_int_eq(SPA_META_Bitmap, 4);
47 pwtest_int_eq(SPA_META_Cursor, 5);
48 pwtest_int_eq(SPA_META_Control, 6);
49 pwtest_int_eq(SPA_META_Busy, 7);
50 pwtest_int_eq(_SPA_META_LAST, 8);
51
52 return PWTEST_PASS;
53 }
54
PWTEST(buffer_abi_sizes)55 PWTEST(buffer_abi_sizes)
56 {
57 #if defined(__x86_64__) && defined(__LP64__)
58 pwtest_int_eq(sizeof(struct spa_chunk), 16U);
59 pwtest_int_eq(sizeof(struct spa_data), 40U);
60 pwtest_int_eq(sizeof(struct spa_buffer), 24U);
61
62 pwtest_int_eq(sizeof(struct spa_meta), 16U);
63 pwtest_int_eq(sizeof(struct spa_meta_header), 32U);
64 pwtest_int_eq(sizeof(struct spa_meta_region), 16U);
65 pwtest_int_eq(sizeof(struct spa_meta_bitmap), 20U);
66 pwtest_int_eq(sizeof(struct spa_meta_cursor), 28U);
67
68 return PWTEST_PASS;
69 #else
70 fprintf(stderr, "%zd\n", sizeof(struct spa_chunk));
71 fprintf(stderr, "%zd\n", sizeof(struct spa_data));
72 fprintf(stderr, "%zd\n", sizeof(struct spa_buffer));
73 fprintf(stderr, "%zd\n", sizeof(struct spa_meta));
74 fprintf(stderr, "%zd\n", sizeof(struct spa_meta_header));
75 fprintf(stderr, "%zd\n", sizeof(struct spa_meta_region));
76 fprintf(stderr, "%zd\n", sizeof(struct spa_meta_bitmap));
77 fprintf(stderr, "%zd\n", sizeof(struct spa_meta_cursor));
78 return PWTEST_SKIP;
79 #endif
80 }
81
PWTEST(buffer_alloc)82 PWTEST(buffer_alloc)
83 {
84 struct spa_buffer **buffers;
85 struct spa_meta metas[4];
86 struct spa_data datas[2];
87 uint32_t aligns[2];
88 uint32_t i, j;
89
90 metas[0].type = SPA_META_Header;
91 metas[0].size = sizeof(struct spa_meta_header);
92 metas[1].type = SPA_META_VideoDamage;
93 metas[1].size = sizeof(struct spa_meta_region) * 16;
94 #define CURSOR_META_SIZE(w,h,bpp) (sizeof(struct spa_meta_cursor) + \
95 sizeof(struct spa_meta_bitmap) + w * h * bpp)
96 metas[2].type = SPA_META_Cursor;
97 metas[2].size = CURSOR_META_SIZE(64,64,4);
98 metas[3].type = 101;
99 metas[3].size = 11;
100
101 datas[0].maxsize = 4000;
102 datas[1].maxsize = 2011;
103
104 aligns[0] = 32;
105 aligns[1] = 16;
106
107 buffers = spa_buffer_alloc_array(16, 0,
108 SPA_N_ELEMENTS(metas), metas,
109 SPA_N_ELEMENTS(datas), datas, aligns);
110
111 fprintf(stderr, "buffers %p\n", buffers);
112
113 for (i = 0; i < 16; i++) {
114 struct spa_buffer *b = buffers[i];
115 fprintf(stderr, "buffer %d %p\n", i, b);
116
117 pwtest_int_eq(b->n_metas, SPA_N_ELEMENTS(metas));
118 pwtest_int_eq(b->n_datas, SPA_N_ELEMENTS(datas));
119
120 for (j = 0; j < SPA_N_ELEMENTS(metas); j++) {
121 pwtest_int_eq(b->metas[j].type, metas[j].type);
122 pwtest_int_eq(b->metas[j].size, metas[j].size);
123 fprintf(stderr, " meta %d %p\n", j, b->metas[j].data);
124 pwtest_bool_true(SPA_IS_ALIGNED(b->metas[j].data, 8));
125 }
126
127 for (j = 0; j < SPA_N_ELEMENTS(datas); j++) {
128 pwtest_int_eq(b->datas[j].maxsize, datas[j].maxsize);
129 fprintf(stderr, " data %d %p %p\n", j, b->datas[j].chunk, b->datas[j].data);
130 pwtest_bool_true(SPA_IS_ALIGNED(b->datas[j].chunk, 8));
131 pwtest_bool_true(SPA_IS_ALIGNED(b->datas[j].data, aligns[j]));
132 }
133 }
134 free(buffers);
135
136 return PWTEST_PASS;
137 }
138
PWTEST_SUITE(spa_buffer)139 PWTEST_SUITE(spa_buffer)
140 {
141 pwtest_add(buffer_abi_types, PWTEST_NOARG);
142 pwtest_add(buffer_abi_sizes, PWTEST_NOARG);
143 pwtest_add(buffer_alloc, PWTEST_NOARG);
144
145 return PWTEST_PASS;
146 }
147
148