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