1d722e3fbSopenharmony_ci/*
2d722e3fbSopenharmony_ci * Copyright (C) 2016 Etnaviv Project
3d722e3fbSopenharmony_ci *
4d722e3fbSopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5d722e3fbSopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6d722e3fbSopenharmony_ci * to deal in the Software without restriction, including without limitation
7d722e3fbSopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8d722e3fbSopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9d722e3fbSopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10d722e3fbSopenharmony_ci *
11d722e3fbSopenharmony_ci * The above copyright notice and this permission notice (including the next
12d722e3fbSopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13d722e3fbSopenharmony_ci * Software.
14d722e3fbSopenharmony_ci *
15d722e3fbSopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16d722e3fbSopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17d722e3fbSopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18d722e3fbSopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19d722e3fbSopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20d722e3fbSopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21d722e3fbSopenharmony_ci * SOFTWARE.
22d722e3fbSopenharmony_ci *
23d722e3fbSopenharmony_ci * Authors:
24d722e3fbSopenharmony_ci *    Christian Gmeiner <christian.gmeiner@gmail.com>
25d722e3fbSopenharmony_ci */
26d722e3fbSopenharmony_ci
27d722e3fbSopenharmony_ci#undef NDEBUG
28d722e3fbSopenharmony_ci#include <assert.h>
29d722e3fbSopenharmony_ci
30d722e3fbSopenharmony_ci#include <fcntl.h>
31d722e3fbSopenharmony_ci#include <stdio.h>
32d722e3fbSopenharmony_ci#include <string.h>
33d722e3fbSopenharmony_ci#include <unistd.h>
34d722e3fbSopenharmony_ci
35d722e3fbSopenharmony_ci#include "xf86drm.h"
36d722e3fbSopenharmony_ci#include "etnaviv_drmif.h"
37d722e3fbSopenharmony_ci#include "etnaviv_drm.h"
38d722e3fbSopenharmony_ci
39d722e3fbSopenharmony_cistatic void test_cache(struct etna_device *dev)
40d722e3fbSopenharmony_ci{
41d722e3fbSopenharmony_ci	struct etna_bo *bo, *tmp;
42d722e3fbSopenharmony_ci
43d722e3fbSopenharmony_ci	/* allocate and free some bo's with same size - we must
44d722e3fbSopenharmony_ci	 * get the same bo over and over. */
45d722e3fbSopenharmony_ci	printf("testing bo cache ... ");
46d722e3fbSopenharmony_ci
47d722e3fbSopenharmony_ci	bo = tmp = etna_bo_new(dev, 0x100, ETNA_BO_UNCACHED);
48d722e3fbSopenharmony_ci	assert(bo);
49d722e3fbSopenharmony_ci	etna_bo_del(bo);
50d722e3fbSopenharmony_ci
51d722e3fbSopenharmony_ci	for (unsigned i = 0; i < 100; i++) {
52d722e3fbSopenharmony_ci		tmp = etna_bo_new(dev, 0x100, ETNA_BO_UNCACHED);
53d722e3fbSopenharmony_ci		etna_bo_del(tmp);
54d722e3fbSopenharmony_ci		assert(tmp == bo);
55d722e3fbSopenharmony_ci	}
56d722e3fbSopenharmony_ci
57d722e3fbSopenharmony_ci	printf("ok\n");
58d722e3fbSopenharmony_ci}
59d722e3fbSopenharmony_ci
60d722e3fbSopenharmony_cistatic void test_size_rounding(struct etna_device *dev)
61d722e3fbSopenharmony_ci{
62d722e3fbSopenharmony_ci	struct etna_bo *bo;
63d722e3fbSopenharmony_ci
64d722e3fbSopenharmony_ci	printf("testing size rounding ... ");
65d722e3fbSopenharmony_ci
66d722e3fbSopenharmony_ci	bo = etna_bo_new(dev, 15, ETNA_BO_UNCACHED);
67d722e3fbSopenharmony_ci	assert(etna_bo_size(bo) == 4096);
68d722e3fbSopenharmony_ci	etna_bo_del(bo);
69d722e3fbSopenharmony_ci
70d722e3fbSopenharmony_ci	bo = etna_bo_new(dev, 4096, ETNA_BO_UNCACHED);
71d722e3fbSopenharmony_ci	assert(etna_bo_size(bo) == 4096);
72d722e3fbSopenharmony_ci	etna_bo_del(bo);
73d722e3fbSopenharmony_ci
74d722e3fbSopenharmony_ci	bo = etna_bo_new(dev, 4100, ETNA_BO_UNCACHED);
75d722e3fbSopenharmony_ci	assert(etna_bo_size(bo) == 8192);
76d722e3fbSopenharmony_ci	etna_bo_del(bo);
77d722e3fbSopenharmony_ci
78d722e3fbSopenharmony_ci	printf("ok\n");
79d722e3fbSopenharmony_ci}
80d722e3fbSopenharmony_ci
81d722e3fbSopenharmony_ciint main(int argc, char *argv[])
82d722e3fbSopenharmony_ci{
83d722e3fbSopenharmony_ci	struct etna_device *dev;
84d722e3fbSopenharmony_ci
85d722e3fbSopenharmony_ci	drmVersionPtr version;
86d722e3fbSopenharmony_ci	int fd, ret = 0;
87d722e3fbSopenharmony_ci
88d722e3fbSopenharmony_ci	fd = open(argv[1], O_RDWR);
89d722e3fbSopenharmony_ci	if (fd < 0)
90d722e3fbSopenharmony_ci		return 1;
91d722e3fbSopenharmony_ci
92d722e3fbSopenharmony_ci	version = drmGetVersion(fd);
93d722e3fbSopenharmony_ci	if (version) {
94d722e3fbSopenharmony_ci		printf("Version: %d.%d.%d\n", version->version_major,
95d722e3fbSopenharmony_ci		       version->version_minor, version->version_patchlevel);
96d722e3fbSopenharmony_ci		printf("  Name: %s\n", version->name);
97d722e3fbSopenharmony_ci		printf("  Date: %s\n", version->date);
98d722e3fbSopenharmony_ci		printf("  Description: %s\n", version->desc);
99d722e3fbSopenharmony_ci		drmFreeVersion(version);
100d722e3fbSopenharmony_ci	}
101d722e3fbSopenharmony_ci
102d722e3fbSopenharmony_ci	dev = etna_device_new(fd);
103d722e3fbSopenharmony_ci	if (!dev) {
104d722e3fbSopenharmony_ci		ret = 2;
105d722e3fbSopenharmony_ci		goto out;
106d722e3fbSopenharmony_ci	}
107d722e3fbSopenharmony_ci
108d722e3fbSopenharmony_ci	test_cache(dev);
109d722e3fbSopenharmony_ci	test_size_rounding(dev);
110d722e3fbSopenharmony_ci
111d722e3fbSopenharmony_ci	etna_device_del(dev);
112d722e3fbSopenharmony_ci
113d722e3fbSopenharmony_ciout:
114d722e3fbSopenharmony_ci	close(fd);
115d722e3fbSopenharmony_ci
116d722e3fbSopenharmony_ci	return ret;
117d722e3fbSopenharmony_ci}
118