2 * Copyright © 2008 Intel Corporation
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:
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
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
24 * Eric Anholt <eric@anholt.net>
38 #define OBJECT_SIZE 16384
40 int do_read(int fd, int handle, void *buf, int offset, int size)
42 struct drm_mm_pread_args read;
44 /* Ensure that we don't have any convenient data in buf in case
47 memset(buf, 0xd0, size);
49 memset(&read, 0, sizeof(read));
55 return ioctl(fd, DRM_IOCTL_MM_PREAD, &read);
58 int do_write(int fd, int handle, void *buf, int offset, int size)
60 struct drm_mm_pwrite_args write;
62 memset(&write, 0, sizeof(write));
63 write.handle = handle;
66 write.offset = offset;
68 return ioctl(fd, DRM_IOCTL_MM_PWRITE, &write);
71 int main(int argc, char **argv)
74 struct drm_mm_alloc_args alloc;
75 uint8_t expected[OBJECT_SIZE];
76 uint8_t buf[OBJECT_SIZE];
82 memset(&alloc, 0, sizeof(alloc));
83 alloc.size = OBJECT_SIZE;
84 ret = ioctl(fd, DRM_IOCTL_MM_ALLOC, &alloc);
86 handle = alloc.handle;
88 printf("Testing contents of newly allocated object.\n");
89 ret = do_read(fd, handle, buf, 0, OBJECT_SIZE);
91 memset(&expected, 0, sizeof(expected));
92 assert(memcmp(expected, buf, sizeof(expected)) == 0);
94 printf("Testing read beyond end of buffer.\n");
95 ret = do_read(fd, handle, buf, OBJECT_SIZE / 2, OBJECT_SIZE);
96 assert(ret == -1 && errno == EINVAL);
98 printf("Testing full write of buffer\n");
99 memset(buf, 0, sizeof(buf));
100 memset(buf + 1024, 0x01, 1024);
101 memset(expected + 1024, 0x01, 1024);
102 ret = do_write(fd, handle, buf, 0, OBJECT_SIZE);
104 ret = do_read(fd, handle, buf, 0, OBJECT_SIZE);
106 assert(memcmp(buf, expected, sizeof(buf)) == 0);
108 printf("Testing partial write of buffer\n");
109 memset(buf + 4096, 0x02, 1024);
110 memset(expected + 4096, 0x02, 1024);
111 ret = do_write(fd, handle, buf + 4096, 4096, 1024);
113 ret = do_read(fd, handle, buf, 0, OBJECT_SIZE);
115 assert(memcmp(buf, expected, sizeof(buf)) == 0);
117 printf("Testing partial read of buffer\n");
118 ret = do_read(fd, handle, buf, 512, 1024);
120 assert(memcmp(buf, expected + 512, 1024) == 0);