summaryrefslogtreecommitdiff
path: root/spa/tests/test-buffer.c
blob: 9480de0aaee172b74a33f79a3781f9336ba13b4b (plain)
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
/* Simple Plugin API
 * Copyright © 2018 Collabora Ltd.
 *   @author George Kiagiadakis <george.kiagiadakis@collabora.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#include <spa/buffer/alloc.h>
#include <spa/buffer/buffer.h>
#include <spa/buffer/meta.h>

static void test_abi(void)
{
	/* buffer */
	spa_assert(SPA_DATA_Invalid == 0);
	spa_assert(SPA_DATA_MemPtr == 1);
	spa_assert(SPA_DATA_MemFd == 2);
	spa_assert(SPA_DATA_DmaBuf == 3);
	spa_assert(SPA_DATA_MemId == 4);
	spa_assert(SPA_DATA_LAST == 5);

	spa_assert(sizeof(struct spa_chunk) == 16);
	spa_assert(sizeof(struct spa_data) == 40);
	spa_assert(sizeof(struct spa_buffer) == 24);

	/* meta */
	spa_assert(SPA_META_Invalid == 0);
	spa_assert(SPA_META_Header == 1);
	spa_assert(SPA_META_VideoCrop == 2);
	spa_assert(SPA_META_VideoDamage == 3);
	spa_assert(SPA_META_Bitmap == 4);
	spa_assert(SPA_META_Cursor == 5);
	spa_assert(SPA_META_LAST == 6);

	spa_assert(sizeof(struct spa_meta) == 16);
	spa_assert(sizeof(struct spa_meta_header) == 24);
	spa_assert(sizeof(struct spa_meta_region) == 16);
	spa_assert(sizeof(struct spa_meta_bitmap) == 20);
	spa_assert(sizeof(struct spa_meta_cursor) == 28);

}

static void test_alloc(void)
{
	struct spa_buffer **buffers;
	struct spa_meta metas[4];
	struct spa_data datas[2];
	uint32_t aligns[2];
	uint32_t i, j;

	metas[0].type = SPA_META_Header;
	metas[0].size = sizeof(struct spa_meta_header);
	metas[1].type = SPA_META_VideoDamage;
	metas[1].size = sizeof(struct spa_meta_region) * 16;
#define CURSOR_META_SIZE(w,h,bpp) (sizeof(struct spa_meta_cursor) + \
                                   sizeof(struct spa_meta_bitmap) + w * h * bpp)
	metas[2].type = SPA_META_Cursor;
	metas[2].size = CURSOR_META_SIZE(64,64,4);
	metas[3].type = 101;
	metas[3].size = 11;

	datas[0].maxsize = 4000;
	datas[1].maxsize = 2011;

	aligns[0] = 32;
	aligns[1] = 16;

	buffers = spa_buffer_alloc_array(16, 0,
			SPA_N_ELEMENTS(metas), metas,
			SPA_N_ELEMENTS(datas), datas, aligns);

	fprintf(stderr, "buffers %p\n", buffers);

	for (i = 0; i < 16; i++) {
		struct spa_buffer *b = buffers[i];
		fprintf(stderr, "buffer %d %p\n", i, b);

		spa_assert(b->n_metas == SPA_N_ELEMENTS(metas));
		spa_assert(b->n_datas == SPA_N_ELEMENTS(datas));

		for (j = 0; j < SPA_N_ELEMENTS(metas); j++) {
			spa_assert(b->metas[j].type == metas[j].type);
			spa_assert(b->metas[j].size == metas[j].size);
			fprintf(stderr, " meta %d %p\n", j, b->metas[j].data);
			spa_assert(SPA_IS_ALIGNED(b->metas[j].data, 8));
		}

		for (j = 0; j < SPA_N_ELEMENTS(datas); j++) {
			spa_assert(b->datas[j].maxsize == datas[j].maxsize);
			fprintf(stderr, " data %d %p %p\n", j, b->datas[j].chunk, b->datas[j].data);
			spa_assert(SPA_IS_ALIGNED(b->datas[j].chunk, 8));
			spa_assert(SPA_IS_ALIGNED(b->datas[j].data, aligns[j]));
		}
	}
	free(buffers);
}

int main(int argc, char *argv[])
{
	test_abi();
	test_alloc();
	return 0;
}