aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Anholt2007-07-19 08:17:04 -0500
committerEric Anholt2007-07-19 08:17:41 -0500
commitecf3fbe599cd72c495acf339ae24f3a9e01fdb36 (patch)
treed3ffa3160b9c40e7cc318df4a6fecebfa8d3af75
parent50cb405f93da70054ede29e0c365f06352dc8fe5 (diff)
downloadexternal-libdrm-ecf3fbe599cd72c495acf339ae24f3a9e01fdb36.tar.gz
external-libdrm-ecf3fbe599cd72c495acf339ae24f3a9e01fdb36.tar.xz
external-libdrm-ecf3fbe599cd72c495acf339ae24f3a9e01fdb36.zip
Add a test for drawable add, remove, and update.
-rw-r--r--.gitignore1
-rw-r--r--tests/Makefile.am3
-rw-r--r--tests/drmtest.c38
-rw-r--r--tests/drmtest.h1
-rw-r--r--tests/updatedraw.c127
5 files changed, 169 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 9b4eaa89..7ab6ced0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -114,3 +114,4 @@ tests/drmstat
114tests/getclient 114tests/getclient
115tests/getversion 115tests/getversion
116tests/openclose 116tests/openclose
117tests/updatedraw
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 949e2b00..3b97fb79 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -16,7 +16,8 @@ LDADD = libdrmtest.la
16 16
17TESTS = openclose \ 17TESTS = openclose \
18 getversion \ 18 getversion \
19 getclient 19 getclient \
20 updatedraw
20 21
21EXTRA_PROGRAMS = $(TESTS) 22EXTRA_PROGRAMS = $(TESTS)
22CLEANFILES = $(EXTRA_PROGRAMS) $(EXTRA_LTLIBRARIES) \ No newline at end of file 23CLEANFILES = $(EXTRA_PROGRAMS) $(EXTRA_LTLIBRARIES) \ No newline at end of file
diff --git a/tests/drmtest.c b/tests/drmtest.c
index 3697078a..cae99a0c 100644
--- a/tests/drmtest.c
+++ b/tests/drmtest.c
@@ -43,3 +43,41 @@ int drm_open_any(void)
43 abort(); 43 abort();
44} 44}
45 45
46
47/**
48 * Open the first DRM device we can find where we end up being the master.
49 */
50int drm_open_any_master(void)
51{
52 char name[20];
53 int i, fd;
54
55 for (i = 0; i < 16; i++) {
56 drm_client_t client;
57 int ret;
58
59 sprintf(name, "/dev/dri/card%d", i);
60 fd = open(name, O_RDWR);
61 if (fd == -1)
62 continue;
63
64 /* Check that we're the only opener and authed. */
65 client.idx = 0;
66 ret = ioctl(fd, DRM_IOCTL_GET_CLIENT, &client);
67 assert (ret == 0);
68 if (!client.auth) {
69 close(fd);
70 continue;
71 }
72 client.idx = 1;
73 ret = ioctl(fd, DRM_IOCTL_GET_CLIENT, &client);
74 if (ret != -1 || errno != EINVAL) {
75 close(fd);
76 continue;
77 }
78 return fd;
79 }
80 fprintf(stderr, "Couldn't find an un-controlled DRM device\n");
81 abort();
82}
83
diff --git a/tests/drmtest.h b/tests/drmtest.h
index f623ff33..afa0df4a 100644
--- a/tests/drmtest.h
+++ b/tests/drmtest.h
@@ -34,3 +34,4 @@
34#include "xf86drm.h" 34#include "xf86drm.h"
35 35
36int drm_open_any(void); 36int drm_open_any(void);
37int drm_open_any_master(void);
diff --git a/tests/updatedraw.c b/tests/updatedraw.c
new file mode 100644
index 00000000..1186783a
--- /dev/null
+++ b/tests/updatedraw.c
@@ -0,0 +1,127 @@
1/*
2 * Copyright © 2007 Intel Corporation
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
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 *
26 */
27
28#include "drmtest.h"
29
30static void
31set_draw_cliprects_empty(int fd, int drawable)
32{
33 int ret;
34 struct drm_update_draw update;
35
36 update.handle = drawable;
37 update.type = DRM_DRAWABLE_CLIPRECTS;
38 update.num = 0;
39 update.data = 0;
40
41 ret = ioctl(fd, DRM_IOCTL_UPDATE_DRAW, &update);
42 assert(ret == 0);
43}
44
45static void
46set_draw_cliprects_empty_fail(int fd, int drawable)
47{
48 int ret;
49 struct drm_update_draw update;
50
51 update.handle = drawable;
52 update.type = DRM_DRAWABLE_CLIPRECTS;
53 update.num = 0;
54 update.data = 0;
55
56 ret = ioctl(fd, DRM_IOCTL_UPDATE_DRAW, &update);
57 assert(ret == -1 && errno == EINVAL);
58}
59
60static void
61set_draw_cliprects_2(int fd, int drawable)
62{
63 int ret;
64 struct drm_update_draw update;
65 drm_clip_rect_t rects[2];
66
67 rects[0].x1 = 0;
68 rects[0].y1 = 0;
69 rects[0].x2 = 10;
70 rects[0].y2 = 10;
71
72 rects[1].x1 = 10;
73 rects[1].y1 = 10;
74 rects[1].x2 = 20;
75 rects[1].y2 = 20;
76
77 update.handle = drawable;
78 update.type = DRM_DRAWABLE_CLIPRECTS;
79 update.num = 2;
80 update.data = (unsigned long long)(uintptr_t)&rects;
81
82 ret = ioctl(fd, DRM_IOCTL_UPDATE_DRAW, &update);
83 assert(ret == 0);
84}
85
86/**
87 * Tests drawable management: adding, removing, and updating the cliprects of
88 * drawables.
89 */
90int main(int argc, char **argv)
91{
92 drm_draw_t drawarg;
93 int fd, ret, drawable;
94
95 fd = drm_open_any_master();
96
97 /* Create a drawable.
98 * IOCTL_ADD_DRAW is RDWR, though it should really just be RD
99 */
100 drawarg.handle = 0;
101 ret = ioctl(fd, DRM_IOCTL_ADD_DRAW, &drawarg);
102 assert(ret == 0);
103 drawable = drawarg.handle;
104
105 /* Do a series of cliprect updates */
106 set_draw_cliprects_empty(fd, drawable);
107 set_draw_cliprects_2(fd, drawable);
108 set_draw_cliprects_empty(fd, drawable);
109
110 /* Remove our drawable */
111 drawarg.handle = drawable;
112 ret = ioctl(fd, DRM_IOCTL_RM_DRAW, &drawarg);
113 assert(ret == 0);
114 drawable = drawarg.handle;
115
116 /* Check that removing an unknown drawable returns error */
117 drawarg.handle = 0x7fffffff;
118 ret = ioctl(fd, DRM_IOCTL_RM_DRAW, &drawarg);
119 assert(ret == -1 && errno == EINVAL);
120 drawable = drawarg.handle;
121
122 /* Attempt to set cliprects on a nonexistent drawable */
123 set_draw_cliprects_empty_fail(fd, drawable);
124
125 close(fd);
126 return 0;
127}