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>
42 struct drm_i915_gem_create create;
43 struct drm_gem_flink flink;
44 struct drm_gem_open open;
47 printf("Testing flink and open.\n");
49 memset(&create, 0, sizeof(create));
50 create.size = 16 * 1024;
51 ret = ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
54 flink.handle = create.handle;
55 ret = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink);
58 open.name = flink.name;
59 ret = ioctl(fd, DRM_IOCTL_GEM_OPEN, &open);
61 assert(open.handle != 0);
65 test_double_flink(int fd)
67 struct drm_i915_gem_create create;
68 struct drm_gem_flink flink;
69 struct drm_gem_flink flink2;
72 printf("Testing repeated flink.\n");
74 memset(&create, 0, sizeof(create));
75 create.size = 16 * 1024;
76 ret = ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
79 flink.handle = create.handle;
80 ret = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink);
83 flink2.handle = create.handle;
84 ret = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink2);
86 assert(flink2.name == flink.name);
90 test_bad_flink(int fd)
92 struct drm_gem_flink flink;
95 printf("Testing error return on bad flink ioctl.\n");
97 flink.handle = 0x10101010;
98 ret = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink);
99 assert(ret == -1 && errno == ENOENT);
103 test_bad_open(int fd)
105 struct drm_gem_open open;
108 printf("Testing error return on bad open ioctl.\n");
110 open.name = 0x10101010;
111 ret = ioctl(fd, DRM_IOCTL_GEM_OPEN, &open);
113 assert(ret == -1 && errno == ENOENT);
116 int main(int argc, char **argv)
121 fprintf(stderr, "requires root privileges, skipping\n");
125 fd = drm_open_matching("8086:*", 0);
127 fprintf(stderr, "failed to open intel drm device, skipping\n");
132 test_double_flink(fd);