diff options
Diffstat (limited to 'tests/etnaviv/etnaviv_bo_cache_test.c')
-rw-r--r-- | tests/etnaviv/etnaviv_bo_cache_test.c | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/tests/etnaviv/etnaviv_bo_cache_test.c b/tests/etnaviv/etnaviv_bo_cache_test.c new file mode 100644 index 00000000..fb01f8d3 --- /dev/null +++ b/tests/etnaviv/etnaviv_bo_cache_test.c | |||
@@ -0,0 +1,121 @@ | |||
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 | #ifdef HAVE_CONFIG_H | ||
28 | # include "config.h" | ||
29 | #endif | ||
30 | |||
31 | #undef NDEBUG | ||
32 | #include <assert.h> | ||
33 | |||
34 | #include <fcntl.h> | ||
35 | #include <stdio.h> | ||
36 | #include <string.h> | ||
37 | #include <unistd.h> | ||
38 | |||
39 | #include "xf86drm.h" | ||
40 | #include "etnaviv_drmif.h" | ||
41 | #include "etnaviv_drm.h" | ||
42 | |||
43 | static void test_cache(struct etna_device *dev) | ||
44 | { | ||
45 | struct etna_bo *bo, *tmp; | ||
46 | |||
47 | /* allocate and free some bo's with same size - we must | ||
48 | * get the same bo over and over. */ | ||
49 | printf("testing bo cache ... "); | ||
50 | |||
51 | bo = tmp = etna_bo_new(dev, 0x100, ETNA_BO_UNCACHED); | ||
52 | assert(bo); | ||
53 | etna_bo_del(bo); | ||
54 | |||
55 | for (unsigned i = 0; i < 100; i++) { | ||
56 | tmp = etna_bo_new(dev, 0x100, ETNA_BO_UNCACHED); | ||
57 | etna_bo_del(tmp); | ||
58 | assert(tmp == bo); | ||
59 | } | ||
60 | |||
61 | printf("ok\n"); | ||
62 | } | ||
63 | |||
64 | static void test_size_rounding(struct etna_device *dev) | ||
65 | { | ||
66 | struct etna_bo *bo; | ||
67 | |||
68 | printf("testing size rounding ... "); | ||
69 | |||
70 | bo = etna_bo_new(dev, 15, ETNA_BO_UNCACHED); | ||
71 | assert(etna_bo_size(bo) == 4096); | ||
72 | etna_bo_del(bo); | ||
73 | |||
74 | bo = etna_bo_new(dev, 4096, ETNA_BO_UNCACHED); | ||
75 | assert(etna_bo_size(bo) == 4096); | ||
76 | etna_bo_del(bo); | ||
77 | |||
78 | bo = etna_bo_new(dev, 4100, ETNA_BO_UNCACHED); | ||
79 | assert(etna_bo_size(bo) == 8192); | ||
80 | etna_bo_del(bo); | ||
81 | |||
82 | printf("ok\n"); | ||
83 | } | ||
84 | |||
85 | int main(int argc, char *argv[]) | ||
86 | { | ||
87 | struct etna_device *dev; | ||
88 | |||
89 | drmVersionPtr version; | ||
90 | int fd, ret = 0; | ||
91 | |||
92 | fd = open(argv[1], O_RDWR); | ||
93 | if (fd < 0) | ||
94 | return 1; | ||
95 | |||
96 | version = drmGetVersion(fd); | ||
97 | if (version) { | ||
98 | printf("Version: %d.%d.%d\n", version->version_major, | ||
99 | version->version_minor, version->version_patchlevel); | ||
100 | printf(" Name: %s\n", version->name); | ||
101 | printf(" Date: %s\n", version->date); | ||
102 | printf(" Description: %s\n", version->desc); | ||
103 | drmFreeVersion(version); | ||
104 | } | ||
105 | |||
106 | dev = etna_device_new(fd); | ||
107 | if (!dev) { | ||
108 | ret = 2; | ||
109 | goto out; | ||
110 | } | ||
111 | |||
112 | test_cache(dev); | ||
113 | test_size_rounding(dev); | ||
114 | |||
115 | etna_device_del(dev); | ||
116 | |||
117 | out: | ||
118 | close(fd); | ||
119 | |||
120 | return ret; | ||
121 | } | ||