1037b3c26Smrg/*
2037b3c26Smrg * Copyright (C) 2015 Etnaviv Project
3037b3c26Smrg *
4037b3c26Smrg * Permission is hereby granted, free of charge, to any person obtaining a
5037b3c26Smrg * copy of this software and associated documentation files (the "Software"),
6037b3c26Smrg * to deal in the Software without restriction, including without limitation
7037b3c26Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8037b3c26Smrg * and/or sell copies of the Software, and to permit persons to whom the
9037b3c26Smrg * Software is furnished to do so, subject to the following conditions:
10037b3c26Smrg *
11037b3c26Smrg * The above copyright notice and this permission notice (including the next
12037b3c26Smrg * paragraph) shall be included in all copies or substantial portions of the
13037b3c26Smrg * Software.
14037b3c26Smrg *
15037b3c26Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16037b3c26Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17037b3c26Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18037b3c26Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19037b3c26Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20037b3c26Smrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21037b3c26Smrg * SOFTWARE.
22037b3c26Smrg *
23037b3c26Smrg * Authors:
24037b3c26Smrg *    Christian Gmeiner <christian.gmeiner@gmail.com>
25037b3c26Smrg */
26037b3c26Smrg
27037b3c26Smrg#undef NDEBUG
28037b3c26Smrg#include <assert.h>
29037b3c26Smrg#include <string.h>
30037b3c26Smrg#include <stdio.h>
31037b3c26Smrg
32037b3c26Smrg#include "etnaviv_drmif.h"
33037b3c26Smrg
34037b3c26Smrgstatic void test_avail()
35037b3c26Smrg{
36037b3c26Smrg	struct etna_cmd_stream *stream;
37037b3c26Smrg
38037b3c26Smrg	printf("testing etna_cmd_stream_avail ... ");
39037b3c26Smrg
40037b3c26Smrg	/* invalid size */
41037b3c26Smrg	stream = etna_cmd_stream_new(NULL, 0, NULL, NULL);
42037b3c26Smrg	assert(stream == NULL);
43037b3c26Smrg
44037b3c26Smrg	stream = etna_cmd_stream_new(NULL, 4, NULL, NULL);
45037b3c26Smrg	assert(stream);
46037b3c26Smrg	assert(etna_cmd_stream_avail(stream) == 2);
47037b3c26Smrg	etna_cmd_stream_del(stream);
48037b3c26Smrg
49037b3c26Smrg	stream = etna_cmd_stream_new(NULL, 20, NULL, NULL);
50037b3c26Smrg	assert(stream);
51037b3c26Smrg	assert(etna_cmd_stream_avail(stream) == 18);
52037b3c26Smrg	etna_cmd_stream_del(stream);
53037b3c26Smrg
54037b3c26Smrg	/* odd number of 32 bit words */
55037b3c26Smrg	stream = etna_cmd_stream_new(NULL, 1, NULL, NULL);
56037b3c26Smrg	assert(stream);
57037b3c26Smrg	assert(etna_cmd_stream_avail(stream) == 0);
58037b3c26Smrg	etna_cmd_stream_del(stream);
59037b3c26Smrg
60037b3c26Smrg	stream = etna_cmd_stream_new(NULL, 23, NULL, NULL);
61037b3c26Smrg	assert(stream);
62037b3c26Smrg	assert(etna_cmd_stream_avail(stream) == 22);
63037b3c26Smrg	etna_cmd_stream_del(stream);
64037b3c26Smrg
65037b3c26Smrg	printf("ok\n");
66037b3c26Smrg}
67037b3c26Smrg
68037b3c26Smrgstatic void test_emit()
69037b3c26Smrg{
70037b3c26Smrg	struct etna_cmd_stream *stream;
71037b3c26Smrg
72037b3c26Smrg	printf("testing etna_cmd_stream_emit ... ");
73037b3c26Smrg
74037b3c26Smrg	stream = etna_cmd_stream_new(NULL, 6, NULL, NULL);
75037b3c26Smrg	assert(stream);
76037b3c26Smrg	assert(etna_cmd_stream_avail(stream) == 4);
77037b3c26Smrg
78037b3c26Smrg	etna_cmd_stream_emit(stream, 0x1);
79037b3c26Smrg	assert(etna_cmd_stream_avail(stream) == 3);
80037b3c26Smrg
81037b3c26Smrg	etna_cmd_stream_emit(stream, 0x2);
82037b3c26Smrg	assert(etna_cmd_stream_avail(stream) == 2);
83037b3c26Smrg
84037b3c26Smrg	etna_cmd_stream_emit(stream, 0x3);
85037b3c26Smrg	assert(etna_cmd_stream_avail(stream) == 1);
86037b3c26Smrg
87037b3c26Smrg	etna_cmd_stream_del(stream);
88037b3c26Smrg
89037b3c26Smrg	printf("ok\n");
90037b3c26Smrg}
91037b3c26Smrg
92037b3c26Smrgstatic void test_offset()
93037b3c26Smrg{
94037b3c26Smrg	struct etna_cmd_stream *stream;
95037b3c26Smrg
96037b3c26Smrg	printf("testing etna_cmd_stream_offset ... ");
97037b3c26Smrg
98037b3c26Smrg	stream = etna_cmd_stream_new(NULL, 6, NULL, NULL);
99037b3c26Smrg	assert(etna_cmd_stream_offset(stream) == 0);
100037b3c26Smrg
101037b3c26Smrg	etna_cmd_stream_emit(stream, 0x1);
102037b3c26Smrg	assert(etna_cmd_stream_offset(stream) == 1);
103037b3c26Smrg
104037b3c26Smrg	etna_cmd_stream_emit(stream, 0x2);
105037b3c26Smrg	assert(etna_cmd_stream_offset(stream) == 2);
106037b3c26Smrg
107037b3c26Smrg	etna_cmd_stream_emit(stream, 0x3);
108037b3c26Smrg	etna_cmd_stream_emit(stream, 0x4);
109037b3c26Smrg	assert(etna_cmd_stream_offset(stream) == 4);
110037b3c26Smrg
111037b3c26Smrg	etna_cmd_stream_del(stream);
112037b3c26Smrg
113037b3c26Smrg	printf("ok\n");
114037b3c26Smrg}
115037b3c26Smrg
116037b3c26Smrgint main(int argc, char *argv[])
117037b3c26Smrg{
118037b3c26Smrg	test_avail();
119037b3c26Smrg	test_emit();
120037b3c26Smrg	test_offset();
121037b3c26Smrg
122037b3c26Smrg	return 0;
123037b3c26Smrg}
124