aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am4
-rw-r--r--tests/dristat.c2
-rw-r--r--tests/modedemo/Makefile14
-rw-r--r--tests/modedemo/demo.c634
-rwxr-xr-xtests/modedemo/test1
-rw-r--r--tests/modefb/Makefile14
-rw-r--r--tests/modefb/demo.c230
-rwxr-xr-xtests/modefb/test1
-rw-r--r--tests/modehotplug/Makefile14
-rw-r--r--tests/modehotplug/demo.c157
-rwxr-xr-xtests/modehotplug/test1
-rw-r--r--tests/modeprint/Makefile14
-rw-r--r--tests/modeprint/modetest.c371
-rwxr-xr-xtests/modeprint/test1
-rw-r--r--tests/modetest/Makefile14
-rw-r--r--tests/modetest/modetest.c410
-rwxr-xr-xtests/modetest/test2
-rw-r--r--tests/radeon_gem_basic.c114
-rw-r--r--tests/radeon_gem_mmap.c132
19 files changed, 2 insertions, 2128 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 805bf770..95f0f22e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -26,9 +26,7 @@ TESTS = auth \
26 gem_basic \ 26 gem_basic \
27 gem_flink \ 27 gem_flink \
28 gem_readwrite \ 28 gem_readwrite \
29 gem_mmap \ 29 gem_mmap
30 radeon_gem_mmap \
31 radeon_gem_basic
32 30
33EXTRA_PROGRAMS = $(TESTS) 31EXTRA_PROGRAMS = $(TESTS)
34CLEANFILES = $(EXTRA_PROGRAMS) $(EXTRA_LTLIBRARIES) 32CLEANFILES = $(EXTRA_PROGRAMS) $(EXTRA_LTLIBRARIES)
diff --git a/tests/dristat.c b/tests/dristat.c
index 48c3b51b..89853164 100644
--- a/tests/dristat.c
+++ b/tests/dristat.c
@@ -263,7 +263,7 @@ int main(int argc, char **argv)
263 263
264 for (i = 0; i < 16; i++) if (!minor || i == minor) { 264 for (i = 0; i < 16; i++) if (!minor || i == minor) {
265 sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, i); 265 sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, i);
266 fd = drmOpenMinor(i, 1, DRM_NODE_RENDER); 266 fd = drmOpenMinor(i, 1);
267 if (fd >= 0) { 267 if (fd >= 0) {
268 printf("%s\n", buf); 268 printf("%s\n", buf);
269 if (mask & DRM_BUSID) getbusid(fd); 269 if (mask & DRM_BUSID) getbusid(fd);
diff --git a/tests/modedemo/Makefile b/tests/modedemo/Makefile
deleted file mode 100644
index 467fb11a..00000000
--- a/tests/modedemo/Makefile
+++ /dev/null
@@ -1,14 +0,0 @@
1
2all: app
3
4#CFLAGS = -g -ansi -pedantic -DPOSIX_C_SOURCE=199309L \
5# -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE \
6
7app: demo.c
8 @gcc $(CFLAGS) -o app -Wall -I../../libdrm -I../../shared-core -L../../libdrm/.libs -ldrm demo.c
9
10clean:
11 @rm -f app
12
13run: app
14 sudo ./test
diff --git a/tests/modedemo/demo.c b/tests/modedemo/demo.c
deleted file mode 100644
index 72d69405..00000000
--- a/tests/modedemo/demo.c
+++ /dev/null
@@ -1,634 +0,0 @@
1/*
2 * Some defines to define the behavior of the program
3 */
4
5#define CLEAN_FBDEV
6#undef DEMO_CLONE
7
8#define SIZE_X 2048
9#define SIZE_Y 2048
10/* Pitch needs to be power of two */
11#define PITCH 2048
12
13#include <assert.h>
14#include <stdio.h>
15#include <stdlib.h>
16#include <stdint.h>
17#include <unistd.h>
18#include <string.h>
19#ifdef CLEAN_FBDEV
20#include <errno.h>
21#include <fcntl.h>
22#include <sys/ioctl.h>
23#include <linux/fb.h>
24#endif
25#include <signal.h>
26
27#include "xf86drm.h"
28#include "xf86drmMode.h"
29
30/* old functions to be replaced */
31drmModeFBPtr createFB(int fd, drmModeResPtr res);
32void testCursor(int fd, uint32_t crtc);
33void prettyColors(int fd, unsigned int handle);
34void prettyCursor(int fd, unsigned int handle, unsigned int color);
35
36#ifdef CLEAN_FBDEV
37struct fb_var_screeninfo var;
38struct fb_fix_screeninfo fix;
39#endif
40
41/* structs for the demo_driver */
42
43struct demo_driver;
44
45struct demo_screen
46{
47 /* drm stuff */
48 drmBO buffer;
49 drmModeFBPtr fb;
50 drmModeCrtcPtr crtc;
51
52 size_t num_outputs;
53 uint32_t outputs_id[8];
54 drmModeOutputPtr outputs[8];
55
56 struct drm_mode_modeinfo *mode;
57
58 /* virtual buffer */
59 uint32_t virt_x;
60 uint32_t virt_y;
61 uint32_t pitch;
62
63 /* parent */
64 struct demo_driver *driver;
65};
66
67#define DEMO_MAX_SCREENS 4
68#define MAX_FIND_OUTPUTS 8
69
70struct demo_driver
71{
72 /* drm stuff */
73 int fd;
74 drmModeResPtr res;
75
76 /* screens */
77 size_t numScreens;
78 struct demo_screen screens[DEMO_MAX_SCREENS];
79};
80
81struct demo_driver* demoCreateDriver(void);
82void demoUpdateRes(struct demo_driver *driver);
83int demoCreateScreens(struct demo_driver *driver);
84int demoCreateScreenCloned(struct demo_driver *driver);
85void demoTakeDownScreen(struct demo_screen *screen);
86int demoFindConnectedOutputs(struct demo_driver *driver, drmModeOutputPtr *out, size_t max_out);
87drmModeCrtcPtr demoFindFreeCrtc(struct demo_driver *driver, drmModeOutputPtr output);
88void demoPanScreen(struct demo_screen *screen, uint16_t x, uint16_t y);
89/* yet to be implemented */
90void demoMouseActivate(struct demo_screen *screen);
91void demoMouseMove(struct demo_screen *screen, uint16_t x, uint16_t y);
92
93static struct drm_mode_modeinfo mode = {
94 .name = "Test mode",
95 .clock = 25200,
96 .hdisplay = 640,
97 .hsync_start = 656,
98 .hsync_end = 752,
99 .htotal = 800,
100 .hskew = 0,
101 .vdisplay = 480,
102 .vsync_start = 490,
103 .vsync_end = 492,
104 .vtotal = 525,
105 .vscan = 0,
106 .vrefresh = 60000, /* vertical refresh * 1000 */
107 .flags = 10,
108};
109
110int main(int argc, char **argv)
111{
112 struct demo_driver *driver;
113 int num;
114 int i;
115
116#ifdef CLEAN_FBDEV
117 int fbdev_fd;
118
119 fbdev_fd = open("/dev/fb0", O_RDWR);
120
121 memset(&var, 0, sizeof(struct fb_var_screeninfo));
122 memset(&fix, 0, sizeof(struct fb_fix_screeninfo));
123
124 if (ioctl(fbdev_fd, FBIOGET_VSCREENINFO, &var))
125 printf("var %s\n", strerror(errno));
126 if (ioctl(fbdev_fd, FBIOGET_FSCREENINFO, &fix))
127 printf("fix %s\n", strerror(errno));
128#endif
129
130 printf("starting demo\n");
131
132 driver = demoCreateDriver();
133
134 if (!driver) {
135 printf("failed to create driver\n");
136 return 1;
137 }
138
139#ifndef DEMO_CLONE
140 num = demoCreateScreens(driver);
141#else
142 num = demoCreateScreenCloned(driver);
143#endif
144
145 if (num < 1) {
146 printf("no screens attached or an error occured\n");
147 return 1;
148 }
149 printf("created %i screens\n", num);
150
151 for (i = 0; i < num; i++) {
152 prettyColors(driver->fd, driver->screens[i].fb->handle);
153 }
154 sleep(1);
155
156 for (i = 0; i < num; i++) {
157 printf("%i: 100 0\n", i);
158 demoPanScreen(&driver->screens[i], 100, 0);
159 sleep(1);
160
161 printf("%i: 0 100\n", i);
162 demoPanScreen(&driver->screens[i], 0, 100);
163 sleep(1);
164
165 printf("%i: 100 100\n", i);
166 demoPanScreen(&driver->screens[i], 100, 100);
167 sleep(1);
168
169 printf("%i: 0 0\n", i);
170 demoPanScreen(&driver->screens[i], 0, 1);
171 sleep(1);
172 testCursor(driver->fd, driver->screens[i].crtc->crtc_id);
173 }
174
175 sleep(2);
176 printf("taking down screens\n");
177 for (i = 0; i < num; i++) {
178 demoTakeDownScreen(&driver->screens[i]);
179 }
180
181#ifdef CLEAN_FBDEV
182 if (ioctl(fbdev_fd, FBIOPUT_VSCREENINFO, &var))
183 printf("var %s\n", strerror(errno));
184
185 close(fbdev_fd);
186#endif
187
188 printf("ok\n");
189 return 0;
190}
191
192int demoCreateScreens(struct demo_driver *driver)
193{
194 drmModeOutputPtr out[MAX_FIND_OUTPUTS];
195 int num;
196 int num_screens = 0;
197 struct demo_screen *screen;
198 int ret = 0;
199 int i;
200
201 num = demoFindConnectedOutputs(driver, out, MAX_FIND_OUTPUTS);
202 if (num < 0)
203 return 0;
204
205 printf("found %i connected outputs\n", num);
206
207 for (i = 0; i < num; i++) {
208 screen = &driver->screens[i];
209
210 screen->crtc = demoFindFreeCrtc(driver, out[i]);
211 if (!screen->crtc) {
212 printf("found no free crtc for output\n");
213 drmModeFreeOutput(out[i]);
214 continue;
215 }
216
217 screen->fb = createFB(driver->fd, driver->res);
218 if (!screen->fb) {
219 drmModeFreeOutput(out[i]);
220 drmModeFreeCrtc(screen->crtc);
221 screen->crtc = 0;
222 printf("could not create framebuffer\n");
223 continue;
224 }
225
226 screen->virt_x = SIZE_X;
227 screen->virt_y = SIZE_Y;
228 screen->pitch = PITCH;
229
230 screen->outputs[0] = out[i];
231 screen->outputs_id[0] = out[i]->output_id;
232 screen->num_outputs = 1;
233
234 screen->mode = &mode;
235 screen->driver = driver;
236
237 ret = drmModeSetCrtc(
238 driver->fd,
239 screen->crtc->crtc_id,
240 screen->fb->buffer_id,
241 0, 0,
242 screen->outputs_id, screen->num_outputs,
243 screen->mode);
244
245 if (ret) {
246 printf("failed to set mode\n");
247 demoTakeDownScreen(screen);
248 } else {
249 num_screens++;
250 }
251
252 demoUpdateRes(driver);
253 }
254
255 return num_screens;
256}
257
258int demoCreateScreenCloned(struct demo_driver *driver)
259{
260 drmModeOutputPtr out[MAX_FIND_OUTPUTS];
261 int num;
262 struct demo_screen *screen;
263 int ret = 0;
264 int i;
265
266 num = demoFindConnectedOutputs(driver, out, MAX_FIND_OUTPUTS);
267 if (num < 0)
268 return 0;
269
270 printf("found %i connected outputs\n", num);
271
272 screen = &driver->screens[0];
273
274 screen->fb = createFB(driver->fd, driver->res);
275 if (!screen->fb) {
276 printf("could not create framebuffer\n");
277 return 0;
278 }
279
280 screen->mode = &mode;
281 screen->driver = driver;
282
283 screen->virt_x = SIZE_X;
284 screen->virt_y = SIZE_Y;
285 screen->pitch = PITCH;
286
287 screen->num_outputs = 0;
288 for (i = 0; i < num; i++) {
289 screen->crtc = demoFindFreeCrtc(driver, out[i]);
290 if (!screen->crtc) {
291 printf("found no free crtc for output\n");
292 drmModeFreeOutput(out[i]);
293 continue;
294 }
295
296 screen->outputs[screen->num_outputs] = out[i];
297 screen->outputs_id[screen->num_outputs] = out[i]->output_id;
298 screen->num_outputs++;
299 printf("%u, %u\n", out[i]->output_id, screen->num_outputs);
300 }
301
302 ret = drmModeSetCrtc(
303 driver->fd,
304 screen->crtc->crtc_id,
305 screen->fb->buffer_id,
306 0, 0,
307 screen->outputs_id, screen->num_outputs,
308 screen->mode);
309
310 if (ret) {
311 printf("failed to set mode\n");
312 demoTakeDownScreen(screen);
313 return 0;
314 }
315
316 demoUpdateRes(driver);
317
318 return 1;
319}
320
321void demoTakeDownScreen(struct demo_screen *screen)
322{
323 int fd = screen->driver->fd;
324 int i;
325 drmBO bo;
326
327#if 0
328 /* This can bust the fbdev arrangement as it basically unhooks
329 * the outputs and the fbdev backend doesn't know how to put things
330 * back on track. Realistically, it's up to the crtc owner to restore
331 * things.....
332 *
333 * So if you are mixing API's make sure the modesetting owner puts
334 * back the original CRTC arrangement so fbdev can continue...
335 *
336 * Ho-hum..
337 */
338 if (screen->crtc)
339 drmModeSetCrtc(fd, screen->crtc->crtc_id, 0, 0, 0, 0, 0, 0);
340#endif
341
342 if (screen->fb)
343 drmModeRmFB(fd, screen->fb->buffer_id);
344
345 /* maybe we should keep a pointer to the bo on the screen */
346 if (screen->fb && !drmBOReference(fd, screen->fb->handle, &bo)) {
347 drmBOUnreference(fd, &bo);
348 drmBOUnreference(fd, &bo);
349 } else {
350 printf("bo error\n");
351 }
352
353 for (i = 0; i < screen->num_outputs; i++) {
354 drmModeFreeOutput(screen->outputs[i]);
355 screen->outputs[i] = NULL;
356 }
357
358 drmModeFreeCrtc(screen->crtc);
359 drmModeFreeFB(screen->fb);
360
361 screen->crtc = NULL;
362 screen->fb = NULL;
363}
364
365drmModeCrtcPtr demoFindFreeCrtc(struct demo_driver *driver, drmModeOutputPtr output)
366{
367 drmModeCrtcPtr crtc;
368 int i, j, used = 0;
369 drmModeResPtr res = driver->res;
370
371 for (i = 0; i < res->count_crtcs; i++) {
372 used = 0;
373 for (j = 0; j < DEMO_MAX_SCREENS; j++) {
374 crtc = driver->screens[j].crtc;
375
376 if (crtc && crtc->crtc_id == res->crtcs[i])
377 used = 1;
378 }
379
380 if (!used) {
381 crtc = drmModeGetCrtc(driver->fd, res->crtcs[i]);
382 break;
383 } else {
384 crtc = 0;
385 }
386 }
387
388 return crtc;
389}
390
391static int driverfd;
392
393static void
394hotplugSIGNAL(int sig, siginfo_t *si, void *d)
395{
396 union drm_wait_hotplug hw;
397 int ret;
398
399 printf("GOT HOTPLUG EVENT!\n");
400
401 /* ask for another hotplug event ! */
402 memset(&hw, 0, sizeof(hw));
403 hw.request.type = _DRM_HOTPLUG_SIGNAL;
404 hw.request.signal = SIGUSR1;
405 ret = ioctl(driverfd, DRM_IOCTL_WAIT_HOTPLUG, &hw);
406}
407
408struct demo_driver* demoCreateDriver(void)
409{
410 struct demo_driver* driver = malloc(sizeof(struct demo_driver));
411 union drm_wait_hotplug hw;
412 int ret = 0;
413
414 memset(driver, 0, sizeof(struct demo_driver));
415
416 driver->fd = drmOpen("i915",NULL);
417
418 if (driver->fd < 0) {
419 printf("Failed to open the card fb\n");
420 goto err_driver;
421 }
422
423#if 0
424 /* ioctl wait for hotplug */
425 do {
426 memset(&hw, 0, sizeof(hw));
427 ret = ioctl(driver->fd, DRM_IOCTL_WAIT_HOTPLUG, &hw);
428 printf("HOTPLUG %d %d %d\n",ret,errno,hw.reply.counter);
429 } while (ret && errno == EBUSY);
430#else
431 /* signal for hotplug */
432 {
433 struct sigaction sa;
434 struct sigaction osa;
435
436 sigemptyset(&sa.sa_mask);
437 sa.sa_flags = SA_SIGINFO;
438 sa.sa_sigaction = hotplugSIGNAL;
439 sigaction(SIGUSR1, &sa, &osa);
440
441 driverfd = driver->fd;
442
443 memset(&hw, 0, sizeof(hw));
444 hw.request.type = _DRM_HOTPLUG_SIGNAL;
445 hw.request.signal = SIGUSR1;
446 ret = ioctl(driver->fd, DRM_IOCTL_WAIT_HOTPLUG, &hw);
447 }
448#endif
449
450 demoUpdateRes(driver);
451 if (!driver->res) {
452 printf("could not retrive resources\n");
453 goto err_res;
454 }
455
456 return driver;
457
458err_res:
459 drmClose(driver->fd);
460err_driver:
461 free(driver);
462 return NULL;
463}
464
465void demoUpdateRes(struct demo_driver *driver)
466{
467 if (driver->res)
468 drmModeFreeResources(driver->res);
469
470 driver->res = drmModeGetResources(driver->fd);
471
472 if (!driver->res)
473 printf("failed to get resources from kernel\n");
474}
475
476int demoFindConnectedOutputs(struct demo_driver *driver, drmModeOutputPtr *out, size_t max_out)
477{
478 int count = 0;
479 int i,j;
480 int fd = driver->fd;
481 drmModeResPtr res = driver->res;
482
483 drmModeOutputPtr output;
484
485 for (i = 0; i < res->count_outputs && count < max_out; i++) {
486 output = drmModeGetOutput(fd, res->outputs[i]);
487
488 if (!output)
489 continue;
490
491 if (output->connection == DRM_MODE_DISCONNECTED) {
492 drmModeFreeOutput(output);
493 continue;
494 }
495
496 for (j = 0; j < output->count_props; j++) {
497 drmModePropertyPtr prop;
498
499 prop = drmModeGetProperty(fd, output->props[j]);
500
501 printf("Property: %s\n",prop->name);
502 if (prop->count_enums)
503 printf("%s\n",prop->enums[output->prop_values[j]].name);
504 }
505
506 out[count++] = output;
507 }
508
509 return count;
510}
511
512void demoPanScreen(struct demo_screen *screen, uint16_t x, uint16_t y)
513{
514 drmModeSetCrtc(
515 screen->driver->fd,
516 screen->crtc->crtc_id,
517 screen->fb->buffer_id,
518 x, y,
519 screen->outputs_id, screen->num_outputs,
520 screen->mode);
521}
522
523drmModeFBPtr createFB(int fd, drmModeResPtr res)
524{
525 drmModeFBPtr frame;
526 unsigned int fb = 0;
527 int ret = 0;
528 drmBO bo;
529
530 ret = drmBOCreate(fd, SIZE_X * SIZE_Y * 4, 0, 0,
531 DRM_BO_FLAG_READ |
532 DRM_BO_FLAG_WRITE |
533 DRM_BO_FLAG_MEM_TT |
534 DRM_BO_FLAG_MEM_VRAM |
535 DRM_BO_FLAG_NO_EVICT,
536 DRM_BO_HINT_DONT_FENCE, &bo);
537
538 if (ret) {
539 printf("failed to create framebuffer (ret %d)\n",ret);
540 goto err;
541 }
542
543 ret = drmModeAddFB(fd, SIZE_X, SIZE_Y, 32, 32, PITCH * 4, bo.handle, &fb);
544
545 if (ret)
546 goto err_bo;
547
548 frame = drmModeGetFB(fd, fb);
549
550 if (!frame)
551 goto err_bo;
552
553 return frame;
554
555err_bo:
556 drmBOUnreference(fd, &bo);
557err:
558 return 0;
559}
560
561void draw(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int v, unsigned int *ptr)
562{
563 int i, j;
564
565 for (i = x; i < x + w; i++)
566 for(j = y; j < y + h; j++)
567 ptr[(i * PITCH) + j] = v;
568
569}
570
571void prettyColors(int fd, unsigned int handle)
572{
573 drmBO bo;
574 unsigned int *ptr;
575 int i;
576
577 drmBOReference(fd, handle, &bo);
578 drmBOMap(fd, &bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, (void**)&ptr);
579
580 for (i = 0; i < (SIZE_X*SIZE_Y); i++)
581 ptr[i] = 0xFFFFFFFF;
582
583 for (i = 0; i < 8; i++)
584 draw(i * 40, i * 40, 40, 40, 0, ptr);
585
586
587 draw(200, 100, 40, 40, 0xff00ff, ptr);
588 draw(100, 200, 40, 40, 0xff00ff, ptr);
589
590 drmBOUnmap(fd, &bo);
591}
592
593void testCursor(int fd, uint32_t crtc)
594{
595 drmBO bo;
596 int ret;
597 ret = drmBOCreate(fd, 64 * 64 * 4, 0, 0,
598 DRM_BO_FLAG_READ |
599 DRM_BO_FLAG_WRITE |
600 DRM_BO_FLAG_MEM_VRAM |
601 DRM_BO_FLAG_NO_EVICT,
602 DRM_BO_HINT_DONT_FENCE, &bo);
603
604 prettyCursor(fd, bo.handle, 0xFFFF00FF);
605 printf("set cursor\n");
606 drmModeSetCursor(fd, crtc, bo.handle, 64, 64);
607 printf("move cursor 0, 0\n");
608 drmModeMoveCursor(fd, crtc, 0, 0);
609 sleep(1);
610 prettyCursor(fd, bo.handle, 0xFFFF0000);
611 printf("move cursor 40, 40\n");
612 drmModeMoveCursor(fd, crtc, 40, 40);
613 sleep(1);
614 printf("move cursor 100, 100\n");
615 drmModeMoveCursor(fd, crtc, 100, 100);
616 sleep(1);
617 drmModeSetCursor(fd, crtc, 0, 0, 0);
618}
619
620void prettyCursor(int fd, unsigned int handle, unsigned int color)
621{
622 drmBO bo;
623 unsigned int *ptr;
624 int i;
625
626 drmBOReference(fd, handle, &bo);
627 drmBOMap(fd, &bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, (void**)&ptr);
628
629 for (i = 0; i < (64 * 64); i++)
630 ptr[i] = color;
631
632 drmBOUnmap(fd, &bo);
633 drmBOUnreference(fd, &bo);
634}
diff --git a/tests/modedemo/test b/tests/modedemo/test
deleted file mode 100755
index f98e3708..00000000
--- a/tests/modedemo/test
+++ /dev/null
@@ -1 +0,0 @@
1LD_PRELOAD=../../libdrm/.libs/libdrm.so ./app
diff --git a/tests/modefb/Makefile b/tests/modefb/Makefile
deleted file mode 100644
index 467fb11a..00000000
--- a/tests/modefb/Makefile
+++ /dev/null
@@ -1,14 +0,0 @@
1
2all: app
3
4#CFLAGS = -g -ansi -pedantic -DPOSIX_C_SOURCE=199309L \
5# -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE \
6
7app: demo.c
8 @gcc $(CFLAGS) -o app -Wall -I../../libdrm -I../../shared-core -L../../libdrm/.libs -ldrm demo.c
9
10clean:
11 @rm -f app
12
13run: app
14 sudo ./test
diff --git a/tests/modefb/demo.c b/tests/modefb/demo.c
deleted file mode 100644
index ead53334..00000000
--- a/tests/modefb/demo.c
+++ /dev/null
@@ -1,230 +0,0 @@
1#include <stdio.h>
2#include <unistd.h>
3#include <stdlib.h>
4#include <errno.h>
5#include <fcntl.h>
6#include <string.h>
7#include "linux/fb.h"
8#include <sys/mman.h>
9#include "sys/ioctl.h"
10#include "xf86drm.h"
11#include "xf86drmMode.h"
12
13void pretty(int fd);
14void setMode(struct fb_var_screeninfo *var);
15void pan(int fd, struct fb_var_screeninfo *var, int x, int y);
16void cursor(int fd, int drmfd);
17void prettyColors(int fd);
18void prettyCursor(int fd, unsigned int handle, unsigned int color);
19
20struct fb_var_screeninfo var;
21struct fb_fix_screeninfo fix;
22
23int main(int argc, char **argv)
24{
25 char name[100];
26 int i,d;
27 int fd;
28 int drmfd = drmOpen("i915", NULL);
29
30 if (drmfd < 0) {
31 printf("drmOpenControl failed\n");
32 return 1;
33 }
34
35 /* try four devices */
36 for (d = 0; d < 4; d++) {
37 snprintf(name, 100, "/dev/fb%d", d);
38 fd = open(name, O_RDWR);
39
40 if (fd == -1) {
41 printf("open %s : %s\n", name, strerror(errno));
42 return 1;
43 }
44
45 memset(&var, 0, sizeof(struct fb_var_screeninfo));
46 memset(&fix, 0, sizeof(struct fb_fix_screeninfo));
47
48 if (ioctl(fd, FBIOGET_VSCREENINFO, &var))
49 printf("var %s\n", strerror(errno));
50 if (ioctl(fd, FBIOGET_FSCREENINFO, &fix))
51 printf("fix %s\n", strerror(errno));
52
53 setMode(&var);
54
55 if (ioctl(fd, FBIOPUT_VSCREENINFO, &var))
56 printf("var %s\n", strerror(errno));
57
58 for (i = 0; i < 1; i++) {
59 prettyColors(fd);
60 }
61 sleep(1);
62
63 printf("pan: 0, 0\n");
64 pan(fd, &var, 0, 0);
65 sleep(2);
66 printf("pan: 100, 0\n");
67 pan(fd, &var, 100, 0);
68 sleep(2);
69 printf("pan: 0, 100\n");
70 pan(fd, &var, 0, 100);
71 sleep(2);
72 printf("pan: 100, 100\n");
73 pan(fd, &var, 100, 100);
74 sleep(2);
75 printf("pan: 0, 0\n");
76 pan(fd, &var, 0, 0);
77 sleep(2);
78
79 printf("cursor (may show up on wrong CRTC - fixme)\n");
80 cursor(fd, drmfd);
81
82 close(fd);
83 }
84 return 0;
85}
86
87void pan(int fd, struct fb_var_screeninfo *var, int x, int y)
88{
89 var->xoffset = x;
90 var->yoffset = y;
91
92 if (ioctl(fd, FBIOPAN_DISPLAY, var))
93 printf("pan error: %s\n", strerror(errno));
94}
95
96void draw(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int v, unsigned int *ptr)
97{
98 int i, j;
99
100 for (i = x; i < x + w; i++)
101 for(j = y; j < y + h; j++)
102 ptr[(i * var.xres_virtual) + j] = v;
103}
104
105void prettyColors(int fd)
106{
107 unsigned int *ptr;
108 int i;
109 int size = var.xres * var.yres * var.bits_per_pixel;
110
111 ptr = (unsigned int *)mmap(NULL, size,
112 PROT_READ|PROT_WRITE, MAP_SHARED, fd,
113 0);
114 if (ptr < 0) {
115 printf("FAILED MMAP %d\n",errno);
116 exit(1);
117 }
118
119 memset(ptr, 0xFF, size);
120
121 for (i = 0; i < 8; i++)
122 draw(i * 40, i * 40, 40, 40, 0, ptr);
123
124
125 draw(200, 100, 40, 40, 0xff00ff, ptr);
126 draw(100, 200, 40, 40, 0xff00ff, ptr);
127
128 munmap(ptr, size);
129}
130
131/*
132 * Cursor support removed from the fb kernel interface
133 * using drm instead.
134 */
135void cursor(int fd, int drmfd)
136{
137 drmModeResPtr res = drmModeGetResources(drmfd);
138 uint32_t crtc = res->crtcs[1]; /* select crtc here */
139 drmBO bo;
140 int ret;
141 ret = drmBOCreate(drmfd, 64 * 64 * 4, 0, 0,
142 DRM_BO_FLAG_READ |
143 DRM_BO_FLAG_WRITE |
144 DRM_BO_FLAG_MEM_VRAM |
145 DRM_BO_FLAG_NO_EVICT,
146 DRM_BO_HINT_DONT_FENCE, &bo);
147
148 if (ret) {
149 printf("failed to create buffer: %s\n", strerror(ret));
150 return;
151 }
152
153 prettyCursor(drmfd, bo.handle, 0xFFFF00FF);
154 drmModeSetCursor(drmfd, crtc, bo.handle, 64, 64);
155 drmModeMoveCursor(drmfd, crtc, 0, 0);
156 sleep(1);
157 prettyCursor(drmfd, bo.handle, 0xFFFF0000);
158 drmModeMoveCursor(drmfd, crtc, 40, 40);
159 sleep(1);
160 drmModeMoveCursor(drmfd, crtc, 100, 100);
161 sleep(1);
162 drmModeSetCursor(drmfd, crtc, 0, 0, 0);
163 drmBOUnreference(drmfd, &bo);
164}
165
166void prettyCursor(int drmfd, unsigned int handle, unsigned int color)
167{
168 drmBO bo;
169 unsigned int *ptr;
170 int i;
171
172 drmBOReference(drmfd, handle, &bo);
173 drmBOMap(drmfd, &bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, (void**)&ptr);
174
175 for (i = 0; i < (64 * 64); i++)
176 ptr[i] = color;
177
178 drmBOUnmap(drmfd, &bo);
179 drmBOUnreference(drmfd, &bo);
180}
181
182struct drm_mode
183{
184 int clock;
185 int hdisplay;
186 int hsync_start;
187 int hsync_end;
188 int htotal;
189 int hskew;
190 int vdisplay;
191 int vsync_start;
192 int vsync_end;
193 int vtotal;
194 int vscan;
195 int vrefresh;
196 int flags;
197};
198
199struct drm_mode mode =
200{
201 .clock = 25200,
202 .hdisplay = 640,
203 .hsync_start = 656,
204 .hsync_end = 752,
205 .htotal = 800,
206 .hskew = 0,
207 .vdisplay = 480,
208 .vsync_start = 490,
209 .vsync_end = 492,
210 .vtotal = 525,
211 .vscan = 0,
212 .vrefresh = 60000, /* vertical refresh * 1000 */
213 .flags = 10,
214};
215
216void setMode(struct fb_var_screeninfo *var) {
217 var->activate = FB_ACTIVATE_NOW;
218 var->xres = mode.hdisplay;
219 var->right_margin = mode.hsync_start - mode.hdisplay;
220 var->hsync_len = mode.hsync_end - mode.hsync_start;
221 var->left_margin = mode.htotal - mode.hsync_end;
222 var->yres = mode.vdisplay;
223 var->lower_margin = mode.vsync_start - mode.vdisplay;
224 var->vsync_len = mode.vsync_end - mode.vsync_start;
225 var->upper_margin = mode.vtotal - mode.vsync_end;
226 var->pixclock = 10000000 / mode.htotal * 1000 / mode.vtotal * 100;
227 /* avoid overflow */
228 var->pixclock = var->pixclock * 1000 / mode.vrefresh;
229 var->bits_per_pixel = 32;
230}
diff --git a/tests/modefb/test b/tests/modefb/test
deleted file mode 100755
index f98e3708..00000000
--- a/tests/modefb/test
+++ /dev/null
@@ -1 +0,0 @@
1LD_PRELOAD=../../libdrm/.libs/libdrm.so ./app
diff --git a/tests/modehotplug/Makefile b/tests/modehotplug/Makefile
deleted file mode 100644
index 467fb11a..00000000
--- a/tests/modehotplug/Makefile
+++ /dev/null
@@ -1,14 +0,0 @@
1
2all: app
3
4#CFLAGS = -g -ansi -pedantic -DPOSIX_C_SOURCE=199309L \
5# -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE \
6
7app: demo.c
8 @gcc $(CFLAGS) -o app -Wall -I../../libdrm -I../../shared-core -L../../libdrm/.libs -ldrm demo.c
9
10clean:
11 @rm -f app
12
13run: app
14 sudo ./test
diff --git a/tests/modehotplug/demo.c b/tests/modehotplug/demo.c
deleted file mode 100644
index 4ef2e386..00000000
--- a/tests/modehotplug/demo.c
+++ /dev/null
@@ -1,157 +0,0 @@
1
2#include <assert.h>
3#include <stdio.h>
4#include <stdlib.h>
5#include <stdint.h>
6#include <unistd.h>
7#include <string.h>
8
9#include "xf86drm.h"
10#include "xf86drmMode.h"
11
12/* structs for the demo_driver */
13
14#define DEMO_MAX_OUTPUTS 8
15
16struct demo_driver
17{
18 /* drm stuff */
19 int fd;
20 drmModeResPtr res;
21 uint32_t counter;
22
23 drmModeOutputPtr outputs[DEMO_MAX_OUTPUTS];
24};
25
26struct demo_driver* demoCreateDriver(void);
27void demoUpdateRes(struct demo_driver *driver);
28
29void demoPopulateOutputs(struct demo_driver *driver);
30void demoHotplug(struct demo_driver *driver);
31
32const char* demoGetStatus(drmModeOutputPtr out);
33
34int main(int argc, char **argv)
35{
36 struct demo_driver *driver;
37 uint32_t temp;
38 int i;
39
40 printf("starting demo\n");
41
42 driver = demoCreateDriver();
43
44 if (!driver) {
45 printf("failed to create driver\n");
46 return 1;
47 }
48
49 driver->counter = drmModeGetHotplug(driver->fd);
50 demoPopulateOutputs(driver);
51 while (driver->counter != (temp = drmModeGetHotplug(driver->fd))) {
52 demoPopulateOutputs(driver);
53 driver->counter = temp;
54 }
55
56 for (i = 0; i < driver->res->count_outputs && i < DEMO_MAX_OUTPUTS; i++) {
57 printf("Output %u is %s\n",
58 driver->outputs[i]->output_id,
59 demoGetStatus(driver->outputs[i]));
60 }
61
62 while(1) {
63 usleep(100000);
64 temp = drmModeGetHotplug(driver->fd);
65 if (temp == driver->counter)
66 continue;
67
68 demoHotplug(driver);
69 driver->counter = temp;
70 }
71
72 return 0;
73}
74
75const char* demoGetStatus(drmModeOutputPtr output)
76{
77 switch (output->connection) {
78 case DRM_MODE_CONNECTED:
79 return "connected";
80 case DRM_MODE_DISCONNECTED:
81 return "disconnected";
82 default:
83 return "unknown";
84 }
85}
86
87void demoHotplug(struct demo_driver *driver)
88{
89 drmModeResPtr res = driver->res;
90 int i;
91 drmModeOutputPtr temp, current;
92
93 for (i = 0; i < res->count_outputs && i < DEMO_MAX_OUTPUTS; i++) {
94 temp = drmModeGetOutput(driver->fd, res->outputs[i]);
95 current = driver->outputs[i];
96
97 if (temp->connection != current->connection) {
98 printf("Output %u became %s was %s\n",
99 temp->output_id,
100 demoGetStatus(temp),
101 demoGetStatus(current));
102 }
103
104 drmModeFreeOutput(current);
105 driver->outputs[i] = temp;
106 }
107}
108
109void demoPopulateOutputs(struct demo_driver *driver)
110{
111 drmModeResPtr res = driver->res;
112 int i;
113
114 for (i = 0; i < res->count_outputs && i < DEMO_MAX_OUTPUTS; i++) {
115 drmModeFreeOutput(driver->outputs[i]);
116 driver->outputs[i] = drmModeGetOutput(driver->fd, res->outputs[i]);
117 }
118}
119
120struct demo_driver* demoCreateDriver(void)
121{
122 struct demo_driver* driver = malloc(sizeof(struct demo_driver));
123
124 memset(driver, 0, sizeof(struct demo_driver));
125
126 driver->fd = drmOpen("i915", NULL);
127
128 if (driver->fd < 0) {
129 printf("Failed to open the card fb\n");
130 goto err_driver;
131 }
132
133 demoUpdateRes(driver);
134 if (!driver->res) {
135 printf("could not retrive resources\n");
136 goto err_res;
137 }
138
139 return driver;
140
141err_res:
142 drmClose(driver->fd);
143err_driver:
144 free(driver);
145 return NULL;
146}
147
148void demoUpdateRes(struct demo_driver *driver)
149{
150 if (driver->res)
151 drmModeFreeResources(driver->res);
152
153 driver->res = drmModeGetResources(driver->fd);
154
155 if (!driver->res)
156 printf("failed to get resources from kernel\n");
157}
diff --git a/tests/modehotplug/test b/tests/modehotplug/test
deleted file mode 100755
index f98e3708..00000000
--- a/tests/modehotplug/test
+++ /dev/null
@@ -1 +0,0 @@
1LD_PRELOAD=../../libdrm/.libs/libdrm.so ./app
diff --git a/tests/modeprint/Makefile b/tests/modeprint/Makefile
deleted file mode 100644
index 7a9c3c24..00000000
--- a/tests/modeprint/Makefile
+++ /dev/null
@@ -1,14 +0,0 @@
1
2all: app
3
4#CFLAGS = -g -ansi -pedantic -DPOSIX_C_SOURCE=199309L \
5# -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE \
6
7app: modetest.c
8 @gcc $(CFLAGS) -o app -Wall -I../../libdrm -I../../shared-core -L../../libdrm/.libs -ldrm modetest.c
9
10clean:
11 @rm -f app
12
13run: app
14 @sudo ./test
diff --git a/tests/modeprint/modetest.c b/tests/modeprint/modetest.c
deleted file mode 100644
index cefa5262..00000000
--- a/tests/modeprint/modetest.c
+++ /dev/null
@@ -1,371 +0,0 @@
1
2#include <assert.h>
3#include <stdio.h>
4#include <stdlib.h>
5#include <stdint.h>
6#include <unistd.h>
7#include <string.h>
8
9#include "xf86drm.h"
10#include "xf86drmMode.h"
11
12int connectors;
13int full_props;
14int edid;
15int modes;
16int full_modes;
17int encoders;
18int crtcs;
19int fbs;
20char *module_name;
21
22const char* getConnectionText(drmModeConnection conn)
23{
24 switch (conn) {
25 case DRM_MODE_CONNECTED:
26 return "connected";
27 case DRM_MODE_DISCONNECTED:
28 return "disconnected";
29 default:
30 return "unknown";
31 }
32
33}
34
35int printMode(struct drm_mode_modeinfo *mode)
36{
37 if (full_modes) {
38 printf("Mode: %s\n", mode->name);
39 printf("\tclock : %i\n", mode->clock);
40 printf("\thdisplay : %i\n", mode->hdisplay);
41 printf("\thsync_start : %i\n", mode->hsync_start);
42 printf("\thsync_end : %i\n", mode->hsync_end);
43 printf("\thtotal : %i\n", mode->htotal);
44 printf("\thskew : %i\n", mode->hskew);
45 printf("\tvdisplay : %i\n", mode->vdisplay);
46 printf("\tvsync_start : %i\n", mode->vsync_start);
47 printf("\tvsync_end : %i\n", mode->vsync_end);
48 printf("\tvtotal : %i\n", mode->vtotal);
49 printf("\tvscan : %i\n", mode->vscan);
50 printf("\tvrefresh : %i\n", mode->vrefresh);
51 printf("\tflags : %i\n", mode->flags);
52 } else {
53 printf("Mode: \"%s\" %ix%i %.0f\n", mode->name,
54 mode->hdisplay, mode->vdisplay, mode->vrefresh / 1000.0);
55 }
56 return 0;
57}
58
59int printProperty(int fd, drmModeResPtr res, drmModePropertyPtr props, uint64_t value)
60{
61 const unsigned char *name = NULL;
62 int j;
63
64 printf("Property: %s\n", props->name);
65 printf("\tid : %i\n", props->prop_id);
66 printf("\tflags : %i\n", props->flags);
67 printf("\tcount_values : %d\n", props->count_values);
68
69
70 if (props->count_values) {
71 printf("\tvalues :");
72 for (j = 0; j < props->count_values; j++)
73 printf(" %lld", props->values[j]);
74 printf("\n");
75 }
76
77
78 printf("\tcount_enums : %d\n", props->count_enums);
79
80 if (props->flags & DRM_MODE_PROP_BLOB) {
81 drmModePropertyBlobPtr blob;
82
83 blob = drmModeGetPropertyBlob(fd, value);
84 if (blob) {
85 printf("blob is %d length, %08X\n", blob->length, *(uint32_t *)blob->data);
86 drmModeFreePropertyBlob(blob);
87 } else {
88 printf("error getting blob %lld\n", value);
89 }
90
91 } else {
92 if (!strncmp(props->name, "DPMS", 4))
93 ;
94
95 for (j = 0; j < props->count_enums; j++) {
96 printf("\t\t%lld = %s\n", props->enums[j].value, props->enums[j].name);
97 if (props->enums[j].value == value)
98 name = props->enums[j].name;
99 }
100
101 if (props->count_enums && name) {
102 printf("\tcon_value : %s\n", name);
103 } else {
104 printf("\tcon_value : %lld\n", value);
105 }
106 }
107
108 return 0;
109}
110
111int printConnector(int fd, drmModeResPtr res, drmModeConnectorPtr connector, uint32_t id)
112{
113 int i = 0;
114 struct drm_mode_modeinfo *mode = NULL;
115 drmModePropertyPtr props;
116
117 printf("Connector: %d-%d\n", connector->connector_type, connector->connector_type_id);
118 printf("\tid : %i\n", id);
119 printf("\tencoder id : %i\n", connector->encoder_id);
120 printf("\tconn : %s\n", getConnectionText(connector->connection));
121 printf("\tsize : %ix%i (mm)\n", connector->mmWidth, connector->mmHeight);
122 printf("\tcount_modes : %i\n", connector->count_modes);
123 printf("\tcount_props : %i\n", connector->count_props);
124 if (connector->count_props) {
125 printf("\tprops :");
126 for (i = 0; i < connector->count_props; i++)
127 printf(" %i", connector->props[i]);
128 printf("\n");
129 }
130
131 printf("\tcount_encoders : %i\n", connector->count_encoders);
132 if (connector->count_encoders) {
133 printf("\tencoders :");
134 for (i = 0; i < connector->count_encoders; i++)
135 printf(" %i", connector->encoders[i]);
136 printf("\n");
137 }
138
139 if (modes) {
140 for (i = 0; i < connector->count_modes; i++) {
141 mode = &connector->modes[i];
142 printMode(mode);
143 }
144 }
145
146 if (full_props) {
147 for (i = 0; i < connector->count_props; i++) {
148 props = drmModeGetProperty(fd, connector->props[i]);
149 if (props) {
150 printProperty(fd, res, props, connector->prop_values[i]);
151 drmModeFreeProperty(props);
152 }
153 }
154 }
155
156 return 0;
157}
158
159int printEncoder(int fd, drmModeResPtr res, drmModeEncoderPtr encoder, uint32_t id)
160{
161 printf("Encoder\n");
162 printf("\tid :%i\n", id);
163 printf("\tcrtc_id :%d\n", encoder->crtc_id);
164 printf("\ttype :%d\n", encoder->encoder_type);
165 printf("\tpossible_crtcs :%d\n", encoder->possible_crtcs);
166 printf("\tpossible_clones :%d\n", encoder->possible_clones);
167 return 0;
168}
169
170int printCrtc(int fd, drmModeResPtr res, drmModeCrtcPtr crtc, uint32_t id)
171{
172 printf("Crtc\n");
173 printf("\tid : %i\n", id);
174 printf("\tx : %i\n", crtc->x);
175 printf("\ty : %i\n", crtc->y);
176 printf("\twidth : %i\n", crtc->width);
177 printf("\theight : %i\n", crtc->height);
178 printf("\tmode : %p\n", &crtc->mode);
179 printf("\tgamma size : %d\n", crtc->gamma_size);
180
181 return 0;
182}
183
184int printFrameBuffer(int fd, drmModeResPtr res, drmModeFBPtr fb)
185{
186 printf("Framebuffer\n");
187 printf("\thandle : %i\n", fb->handle);
188 printf("\twidth : %i\n", fb->width);
189 printf("\theight : %i\n", fb->height);
190 printf("\tpitch : %i\n", fb->pitch);;
191 printf("\tbpp : %i\n", fb->bpp);
192 printf("\tdepth : %i\n", fb->depth);
193 printf("\tbuffer_id : %i\n", fb->buffer_id);
194
195 return 0;
196}
197
198int printRes(int fd, drmModeResPtr res)
199{
200 int i;
201 drmModeFBPtr fb;
202 drmModeCrtcPtr crtc;
203 drmModeEncoderPtr encoder;
204 drmModeConnectorPtr connector;
205
206 printf("Resources\n\n");
207
208 printf("count_connectors : %i\n", res->count_connectors);
209 printf("count_encoders : %i\n", res->count_encoders);
210 printf("count_crtcs : %i\n", res->count_crtcs);
211 printf("count_fbs : %i\n", res->count_fbs);
212
213 printf("\n");
214
215 if (connectors) {
216 for (i = 0; i < res->count_connectors; i++) {
217 connector = drmModeGetConnector(fd, res->connectors[i]);
218
219 if (!connector)
220 printf("Could not get connector %i\n", res->connectors[i]);
221 else {
222 printConnector(fd, res, connector, res->connectors[i]);
223 drmModeFreeConnector(connector);
224 }
225 }
226 printf("\n");
227 }
228
229
230 if (encoders) {
231 for (i = 0; i < res->count_encoders; i++) {
232 encoder = drmModeGetEncoder(fd, res->encoders[i]);
233
234 if (!encoder)
235 printf("Could not get encoder %i\n", res->encoders[i]);
236 else {
237 printEncoder(fd, res, encoder, res->encoders[i]);
238 drmModeFreeEncoder(encoder);
239 }
240 }
241 printf("\n");
242 }
243
244 if (crtcs) {
245 for (i = 0; i < res->count_crtcs; i++) {
246 crtc = drmModeGetCrtc(fd, res->crtcs[i]);
247
248 if (!crtc)
249 printf("Could not get crtc %i\n", res->crtcs[i]);
250 else {
251 printCrtc(fd, res, crtc, res->crtcs[i]);
252 drmModeFreeCrtc(crtc);
253 }
254 }
255 printf("\n");
256 }
257
258 if (fbs) {
259 for (i = 0; i < res->count_fbs; i++) {
260 fb = drmModeGetFB(fd, res->fbs[i]);
261
262 if (!fb)
263 printf("Could not get fb %i\n", res->fbs[i]);
264 else {
265 printFrameBuffer(fd, res, fb);
266 drmModeFreeFB(fb);
267 }
268 }
269 }
270
271 return 0;
272}
273
274void args(int argc, char **argv)
275{
276 int i;
277
278 fbs = 0;
279 edid = 0;
280 crtcs = 0;
281 modes = 0;
282 encoders = 0;
283 full_modes = 0;
284 full_props = 0;
285 connectors = 0;
286
287 module_name = argv[1];
288
289 for (i = 2; i < argc; i++) {
290 if (strcmp(argv[i], "-fb") == 0) {
291 fbs = 1;
292 } else if (strcmp(argv[i], "-crtcs") == 0) {
293 crtcs = 1;
294 } else if (strcmp(argv[i], "-cons") == 0) {
295 connectors = 1;
296 modes = 1;
297 } else if (strcmp(argv[i], "-modes") == 0) {
298 connectors = 1;
299 modes = 1;
300 } else if (strcmp(argv[i], "-full") == 0) {
301 connectors = 1;
302 modes = 1;
303 full_modes = 1;
304 } else if (strcmp(argv[i], "-props") == 0) {
305 connectors = 1;
306 full_props = 1;
307 } else if (strcmp(argv[i], "-edids") == 0) {
308 connectors = 1;
309 edid = 1;
310 } else if (strcmp(argv[i], "-encoders") == 0) {
311 encoders = 1;
312 } else if (strcmp(argv[i], "-v") == 0) {
313 fbs = 1;
314 edid = 1;
315 crtcs = 1;
316 modes = 1;
317 encoders = 1;
318 full_modes = 1;
319 full_props = 1;
320 connectors = 1;
321 }
322 }
323
324 if (argc == 2) {
325 fbs = 1;
326 edid = 1;
327 crtcs = 1;
328 modes = 1;
329 encoders = 1;
330 full_modes = 0;
331 full_props = 0;
332 connectors = 1;
333 }
334}
335
336int main(int argc, char **argv)
337{
338 int fd;
339 drmModeResPtr res;
340
341 if (argc == 1) {
342 printf("Please add modulename as first argument\n");
343 return 1;
344 }
345
346 args(argc, argv);
347
348 printf("Starting test\n");
349
350 fd = drmOpen(module_name, NULL);
351
352 if (fd < 0) {
353 printf("Failed to open the card fd (%d)\n",fd);
354 return 1;
355 }
356
357 res = drmModeGetResources(fd);
358 if (res == 0) {
359 printf("Failed to get resources from card\n");
360 drmClose(fd);
361 return 1;
362 }
363
364 printRes(fd, res);
365
366 drmModeFreeResources(res);
367
368 printf("Ok\n");
369
370 return 0;
371}
diff --git a/tests/modeprint/test b/tests/modeprint/test
deleted file mode 100755
index bd1952cc..00000000
--- a/tests/modeprint/test
+++ /dev/null
@@ -1 +0,0 @@
1LD_PRELOAD=../../libdrm/.libs/libdrm.so ./app $@
diff --git a/tests/modetest/Makefile b/tests/modetest/Makefile
deleted file mode 100644
index 8583ae82..00000000
--- a/tests/modetest/Makefile
+++ /dev/null
@@ -1,14 +0,0 @@
1
2all: app
3
4#CFLAGS = -g -ansi -pedantic -DPOSIX_C_SOURCE=199309L \
5# -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE \
6
7app: modetest.c
8 gcc $(CFLAGS) -o app -Wall -I../../libdrm -I../../libdrm/intel -I../../shared-core -L../../libdrm/.libs -L../../libdrm/intel/.libs -ldrm -ldrm_intel modetest.c
9
10clean:
11 @rm -f app
12
13run: app
14 sudo ./test
diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c
deleted file mode 100644
index 66c7f9cd..00000000
--- a/tests/modetest/modetest.c
+++ /dev/null
@@ -1,410 +0,0 @@
1/*
2 * DRM based mode setting test program
3 * Copyright 2008 Tungsten Graphics
4 * Jakob Bornecrantz <jakob@tungstengraphics.com>
5 * Copyright 2008 Intel Corporation
6 * Jesse Barnes <jesse.barnes@intel.com>
7 */
8#include <assert.h>
9#include <stdio.h>
10#include <stdlib.h>
11#include <stdint.h>
12#include <unistd.h>
13#include <string.h>
14#include <errno.h>
15
16#include "xf86drm.h"
17#include "xf86drmMode.h"
18#include "intel_bufmgr.h"
19
20drmModeRes *resources;
21int fd, modes;
22
23#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
24
25struct type_name {
26 int type;
27 char *name;
28};
29
30#define type_name_fn(res) \
31char * res##_str(int type) { \
32 int i; \
33 for (i = 0; i < ARRAY_SIZE(res##_names); i++) { \
34 if (res##_names[i].type == type) \
35 return res##_names[i].name; \
36 } \
37 return "(invalid)"; \
38}
39
40struct type_name encoder_type_names[] = {
41 { DRM_MODE_ENCODER_NONE, "none" },
42 { DRM_MODE_ENCODER_DAC, "DAC" },
43 { DRM_MODE_ENCODER_TMDS, "TMDS" },
44 { DRM_MODE_ENCODER_LVDS, "LVDS" },
45 { DRM_MODE_ENCODER_TVDAC, "TVDAC" },
46};
47
48type_name_fn(encoder_type)
49
50struct type_name connector_status_names[] = {
51 { DRM_MODE_CONNECTED, "connected" },
52 { DRM_MODE_DISCONNECTED, "disconnected" },
53 { DRM_MODE_UNKNOWNCONNECTION, "unknown" },
54};
55
56type_name_fn(connector_status)
57
58struct type_name connector_type_names[] = {
59 { DRM_MODE_CONNECTOR_Unknown, "unknown" },
60 { DRM_MODE_CONNECTOR_VGA, "VGA" },
61 { DRM_MODE_CONNECTOR_DVII, "DVI-I" },
62 { DRM_MODE_CONNECTOR_DVID, "DVI-D" },
63 { DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
64 { DRM_MODE_CONNECTOR_Composite, "composite" },
65 { DRM_MODE_CONNECTOR_SVIDEO, "s-video" },
66 { DRM_MODE_CONNECTOR_LVDS, "LVDS" },
67 { DRM_MODE_CONNECTOR_Component, "component" },
68 { DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" },
69 { DRM_MODE_CONNECTOR_DisplayPort, "displayport" },
70 { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
71 { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
72};
73
74type_name_fn(connector_type)
75
76void dump_encoders(void)
77{
78 drmModeEncoder *encoder;
79 int i;
80
81 printf("Encoders:\n");
82 printf("id\tcrtc\ttype\tpossible crtcs\tpossible clones\t\n");
83 for (i = 0; i < resources->count_encoders; i++) {
84 encoder = drmModeGetEncoder(fd, resources->encoders[i]);
85
86 if (!encoder) {
87 fprintf(stderr, "could not get encoder %i: %s\n",
88 resources->encoders[i], strerror(errno));
89 continue;
90 }
91 printf("%d\t%d\t%s\t0x%08x\t0x%08x\n",
92 encoder->encoder_id,
93 encoder->crtc_id,
94 encoder_type_str(encoder->encoder_type),
95 encoder->possible_crtcs,
96 encoder->possible_clones);
97 drmModeFreeEncoder(encoder);
98 }
99}
100
101void dump_connectors(void)
102{
103 drmModeConnector *connector;
104 int i, j;
105
106 printf("Connectors:\n");
107 printf("id\tencoder\tstatus\t\ttype\tsize (mm)\tmodes\n");
108 for (i = 0; i < resources->count_connectors; i++) {
109 connector = drmModeGetConnector(fd, resources->connectors[i]);
110
111 if (!connector) {
112 fprintf(stderr, "could not get connector %i: %s\n",
113 resources->connectors[i], strerror(errno));
114 continue;
115 }
116
117 printf("%d\t%d\t%s\t%s\t%dx%d\t\t%d\n",
118 connector->connector_id,
119 connector->encoder_id,
120 connector_status_str(connector->connection),
121 connector_type_str(connector->connector_type),
122 connector->mmWidth, connector->mmHeight,
123 connector->count_modes);
124
125 if (!connector->count_modes)
126 continue;
127
128 printf(" modes:\n");
129 printf(" name refresh (Hz) hdisp hss hse htot vdisp "
130 "vss vse vtot)\n");
131 for (j = 0; j < connector->count_modes; j++) {
132 struct drm_mode_modeinfo *mode;
133
134 mode = &connector->modes[j];
135 printf(" %s %.02f %d %d %d %d %d %d %d %d\n",
136 mode->name,
137 (float)mode->vrefresh / 1000,
138 mode->hdisplay,
139 mode->hsync_start,
140 mode->hsync_end,
141 mode->htotal,
142 mode->vdisplay,
143 mode->vsync_start,
144 mode->vsync_end,
145 mode->vtotal);
146 }
147 drmModeFreeConnector(connector);
148 }
149}
150
151void dump_crtcs(void)
152{
153 drmModeCrtc *crtc;
154 int i;
155
156 for (i = 0; i < resources->count_crtcs; i++) {
157 crtc = drmModeGetCrtc(fd, resources->crtcs[i]);
158
159 if (!crtc) {
160 fprintf(stderr, "could not get crtc %i: %s\n",
161 resources->crtcs[i], strerror(errno));
162 continue;
163 }
164 drmModeFreeCrtc(crtc);
165 }
166}
167
168void dump_framebuffers(void)
169{
170 drmModeFB *fb;
171 int i;
172
173 for (i = 0; i < resources->count_fbs; i++) {
174 fb = drmModeGetFB(fd, resources->fbs[i]);
175
176 if (!fb) {
177 fprintf(stderr, "could not get fb %i: %s\n",
178 resources->fbs[i], strerror(errno));
179 continue;
180 }
181 drmModeFreeFB(fb);
182 }
183}
184
185void set_mode(int connector_id, char *mode_str)
186{
187 drmModeConnector *connector;
188 drmModeEncoder *encoder = NULL;
189 struct drm_mode_modeinfo *mode = NULL;
190 drm_intel_bufmgr *bufmgr;
191 drm_intel_bo *bo;
192 unsigned int fb_id, *fb_ptr;
193 int i, j, size, ret, width, height;
194
195 /* First, find the connector & mode */
196 for (i = 0; i < resources->count_connectors; i++) {
197 connector = drmModeGetConnector(fd, resources->connectors[i]);
198
199 if (!connector) {
200 fprintf(stderr, "could not get connector %i: %s\n",
201 resources->connectors[i], strerror(errno));
202 drmModeFreeConnector(connector);
203 continue;
204 }
205
206 if (!connector->count_modes) {
207 drmModeFreeConnector(connector);
208 continue;
209 }
210
211 if (connector->connector_id != connector_id) {
212 drmModeFreeConnector(connector);
213 continue;
214 }
215
216 for (j = 0; j < connector->count_modes; j++) {
217 mode = &connector->modes[j];
218 if (!strcmp(mode->name, mode_str))
219 break;
220 }
221
222 /* Found it, break out */
223 if (mode)
224 break;
225
226 drmModeFreeConnector(connector);
227 }
228
229 if (!mode) {
230 fprintf(stderr, "failed to find mode \"%s\"\n", mode_str);
231 return;
232 }
233
234 width = mode->hdisplay;
235 height = mode->vdisplay;
236
237 /* Now get the encoder */
238 for (i = 0; i < resources->count_encoders; i++) {
239 encoder = drmModeGetEncoder(fd, resources->encoders[i]);
240
241 if (!encoder) {
242 fprintf(stderr, "could not get encoder %i: %s\n",
243 resources->encoders[i], strerror(errno));
244 drmModeFreeEncoder(encoder);
245 continue;
246 }
247
248 if (encoder->encoder_id == connector->encoder_id)
249 break;
250
251 drmModeFreeEncoder(encoder);
252 }
253
254 bufmgr = drm_intel_bufmgr_gem_init(fd, 2<<20);
255 if (!bufmgr) {
256 fprintf(stderr, "failed to init bufmgr: %s\n", strerror(errno));
257 return;
258 }
259
260 /* Mode size at 32 bpp */
261 size = width * height * 4;
262
263 bo = drm_intel_bo_alloc(bufmgr, "frontbuffer", size, 4096);
264 if (!bo) {
265 fprintf(stderr, "failed to alloc buffer: %s\n",
266 strerror(errno));
267 return;
268 }
269
270 ret = drm_intel_bo_pin(bo, 4096);
271 if (ret) {
272 fprintf(stderr, "failed to pin buffer: %s\n", strerror(errno));
273 return;
274 }
275
276 ret = drm_intel_gem_bo_map_gtt(bo);
277 if (ret) {
278 fprintf(stderr, "failed to GTT map buffer: %s\n",
279 strerror(errno));
280 return;
281 }
282
283 fb_ptr = bo->virtual;
284
285 /* paint the buffer blue */
286 for (i = 0; i < width * height; i++)
287 fb_ptr[i] = 0xff;
288
289 ret = drmModeAddFB(fd, width, height, 32, 32, width * 4, bo->handle,
290 &fb_id);
291 if (ret) {
292 fprintf(stderr, "failed to add fb: %s\n", strerror(errno));
293 return;
294 }
295
296 ret = drmModeSetCrtc(fd, encoder->crtc_id, fb_id, 0, 0,
297 &connector->connector_id, 1, mode);
298 if (ret) {
299 fprintf(stderr, "failed to set mode: %s\n", strerror(errno));
300 return;
301 }
302}
303
304extern char *optarg;
305extern int optind, opterr, optopt;
306static char optstr[] = "ecpmfs:";
307
308void usage(char *name)
309{
310 fprintf(stderr, "usage: %s [-ecpmf]\n", name);
311 fprintf(stderr, "\t-e\tlist encoders\n");
312 fprintf(stderr, "\t-c\tlist connectors\n");
313 fprintf(stderr, "\t-p\tlist CRTCs (pipes)\n");
314 fprintf(stderr, "\t-m\tlist modes\n");
315 fprintf(stderr, "\t-f\tlist framebuffers\n");
316 fprintf(stderr, "\t-s <connector_id>:<mode>\tset a mode\n");
317 fprintf(stderr, "\n\tDefault is to dump all info.\n");
318 exit(0);
319}
320
321#define dump_resource(res) if (res) dump_##res()
322
323int main(int argc, char **argv)
324{
325 int c;
326 int encoders = 0, connectors = 0, crtcs = 0, framebuffers = 0;
327 char *modules[] = { "i915", "radeon" };
328 char *modeset = NULL, *mode, *connector;
329 int i, connector_id;
330
331 opterr = 0;
332 while ((c = getopt(argc, argv, optstr)) != -1) {
333 switch (c) {
334 case 'e':
335 encoders = 1;
336 break;
337 case 'c':
338 connectors = 1;
339 break;
340 case 'p':
341 crtcs = 1;
342 break;
343 case 'm':
344 modes = 1;
345 break;
346 case 'f':
347 framebuffers = 1;
348 break;
349 case 's':
350 modeset = strdup(optarg);
351 break;
352 default:
353 usage(argv[0]);
354 break;
355 }
356 }
357
358 if (argc == 1)
359 encoders = connectors = crtcs = modes = framebuffers = 1;
360
361 for (i = 0; i < ARRAY_SIZE(modules); i++) {
362 printf("trying to load module %s...", modules[i]);
363 fd = drmOpen(modules[i], NULL);
364 if (fd < 0) {
365 printf("failed.\n");
366 } else {
367 printf("success.\n");
368 break;
369 }
370 }
371
372 if (i == ARRAY_SIZE(modules)) {
373 fprintf(stderr, "failed to load any modules, aborting.\n");
374 return -1;
375 }
376
377 resources = drmModeGetResources(fd);
378 if (!resources) {
379 fprintf(stderr, "drmModeGetResources failed: %s\n",
380 strerror(errno));
381 drmClose(fd);
382 return 1;
383 }
384
385 dump_resource(encoders);
386 dump_resource(connectors);
387 dump_resource(crtcs);
388 dump_resource(framebuffers);
389
390 if (modeset) {
391 connector = strtok(modeset, ":");
392 if (!connector)
393 usage(argv[0]);
394 connector_id = atoi(connector);
395
396 mode = strtok(NULL, ":");
397 if (!mode)
398 usage(argv[0]);
399 printf("setting connector %d to mode %s\n", connector_id,
400 mode);
401 set_mode(connector_id, mode);
402 sleep(3);
403 }
404
405 sleep(3);
406
407 drmModeFreeResources(resources);
408
409 return 0;
410}
diff --git a/tests/modetest/test b/tests/modetest/test
deleted file mode 100755
index 5bb552ef..00000000
--- a/tests/modetest/test
+++ /dev/null
@@ -1,2 +0,0 @@
1export LD_LIBRARY_PATH=../../libdrm/.libs:../../libdrm/intel/.libs
2LD_PRELOAD=../../libdrm/.libs/libdrm.so ./app $@
diff --git a/tests/radeon_gem_basic.c b/tests/radeon_gem_basic.c
deleted file mode 100644
index d8231879..00000000
--- a/tests/radeon_gem_basic.c
+++ /dev/null
@@ -1,114 +0,0 @@
1/*
2 * Copyright © 2008 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 <stdlib.h>
29#include <stdio.h>
30#include <string.h>
31#include <assert.h>
32#include <fcntl.h>
33#include <inttypes.h>
34#include <errno.h>
35#include <sys/stat.h>
36#include "drm.h"
37#include "radeon_drm.h"
38
39static void
40test_bad_close(int fd)
41{
42 struct drm_gem_close close;
43 int ret;
44
45 printf("Testing error return on bad close ioctl.\n");
46
47 close.handle = 0x10101010;
48 ret = ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close);
49
50 assert(ret == -1 && errno == EINVAL);
51}
52
53static void
54test_create_close(int fd)
55{
56 struct drm_radeon_gem_create create;
57 struct drm_gem_close close;
58 int ret;
59
60 printf("Testing creating and closing an object.\n");
61
62 memset(&create, 0, sizeof(create));
63 create.size = 16 * 1024;
64 ret = ioctl(fd, DRM_IOCTL_RADEON_GEM_CREATE, &create);
65 assert(ret == 0);
66
67 close.handle = create.handle;
68 ret = ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close);
69}
70
71static void
72test_create_fd_close(int fd)
73{
74 struct drm_radeon_gem_create create;
75 int ret;
76
77 printf("Testing closing with an object allocated.\n");
78
79 memset(&create, 0, sizeof(create));
80 create.size = 16 * 1024;
81 ret = ioctl(fd, DRM_IOCTL_RADEON_GEM_CREATE, &create);
82 assert(ret == 0);
83
84 close(fd);
85}
86
87int test_gem_info(int fd)
88{
89 struct drm_radeon_gem_info info;
90 int ret;
91
92 ret = ioctl(fd, DRM_IOCTL_RADEON_GEM_INFO, &info);
93 assert(ret == 0);
94
95 fprintf(stderr,"%lld %lld %lld %lld %lld\n",
96 info.gtt_start, info.gtt_size,
97 info.vram_start, info.vram_size,
98 info.vram_visible);
99
100}
101
102int main(int argc, char **argv)
103{
104 int fd;
105
106 fd = drm_open_any();
107
108 test_gem_info(fd);
109 test_bad_close(fd);
110 test_create_close(fd);
111 test_create_fd_close(fd);
112
113 return 0;
114}
diff --git a/tests/radeon_gem_mmap.c b/tests/radeon_gem_mmap.c
deleted file mode 100644
index aa7b0196..00000000
--- a/tests/radeon_gem_mmap.c
+++ /dev/null
@@ -1,132 +0,0 @@
1/*
2 * Copyright © 2008 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 <stdlib.h>
29#include <stdio.h>
30#include <string.h>
31#include <assert.h>
32#include <fcntl.h>
33#include <inttypes.h>
34#include <errno.h>
35#include <sys/stat.h>
36#include "drm.h"
37#include "radeon_drm.h"
38
39#define OBJECT_SIZE 16384
40
41int do_read(int fd, int handle, void *buf, int offset, int size)
42{
43 struct drm_radeon_gem_pread read;
44
45 /* Ensure that we don't have any convenient data in buf in case
46 * we fail.
47 */
48 memset(buf, 0xd0, size);
49
50 memset(&read, 0, sizeof(read));
51 read.handle = handle;
52 read.data_ptr = (uintptr_t)buf;
53 read.size = size;
54 read.offset = offset;
55
56 return ioctl(fd, DRM_IOCTL_RADEON_GEM_PREAD, &read);
57}
58
59int do_write(int fd, int handle, void *buf, int offset, int size)
60{
61 struct drm_radeon_gem_pwrite write;
62
63 memset(&write, 0, sizeof(write));
64 write.handle = handle;
65 write.data_ptr = (uintptr_t)buf;
66 write.size = size;
67 write.offset = offset;
68
69 return ioctl(fd, DRM_IOCTL_RADEON_GEM_PWRITE, &write);
70}
71
72int main(int argc, char **argv)
73{
74 int fd;
75 struct drm_radeon_gem_create create;
76 struct drm_radeon_gem_mmap mmap;
77 struct drm_gem_close unref;
78 uint8_t expected[OBJECT_SIZE];
79 uint8_t buf[OBJECT_SIZE];
80 uint8_t *addr;
81 int ret;
82 int handle;
83
84 fd = drm_open_any();
85
86 memset(&mmap, 0, sizeof(mmap));
87 mmap.handle = 0x10101010;
88 mmap.offset = 0;
89 mmap.size = 4096;
90 printf("Testing mmaping of bad object.\n");
91 ret = ioctl(fd, DRM_IOCTL_RADEON_GEM_MMAP, &mmap);
92 assert(ret == -1 && errno == EINVAL);
93
94 memset(&create, 0, sizeof(create));
95 create.size = OBJECT_SIZE;
96 ret = ioctl(fd, DRM_IOCTL_RADEON_GEM_CREATE, &create);
97 assert(ret == 0);
98 handle = create.handle;
99
100 printf("Testing mmaping of newly created object.\n");
101 mmap.handle = handle;
102 mmap.offset = 0;
103 mmap.size = OBJECT_SIZE;
104 ret = ioctl(fd, DRM_IOCTL_RADEON_GEM_MMAP, &mmap);
105 assert(ret == 0);
106 addr = (uint8_t *)(uintptr_t)mmap.addr_ptr;
107
108 printf("Testing contents of newly created object.\n");
109 memset(expected, 0, sizeof(expected));
110 assert(memcmp(addr, expected, sizeof(expected)) == 0);
111
112 printf("Testing coherency of writes and mmap reads.\n");
113 memset(buf, 0, sizeof(buf));
114 memset(buf + 1024, 0x01, 1024);
115 memset(expected + 1024, 0x01, 1024);
116 ret = do_write(fd, handle, buf, 0, OBJECT_SIZE);
117 assert(ret == 0);
118 assert(memcmp(buf, addr, sizeof(buf)) == 0);
119
120 printf("Testing that mapping stays after close\n");
121 unref.handle = handle;
122 ret = ioctl(fd, DRM_IOCTL_GEM_CLOSE, &unref);
123 assert(ret == 0);
124 assert(memcmp(buf, addr, sizeof(buf)) == 0);
125
126 printf("Testing unmapping\n");
127 munmap(addr, OBJECT_SIZE);
128
129 close(fd);
130
131 return 0;
132}