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>
35 #include <sys/ioctl.h>
37 #include "ioctl_wrappers.h"
43 struct drm_i915_gem_create create;
44 struct drm_gem_flink flink;
45 struct drm_gem_open open_struct;
48 igt_info("Testing flink and open.\n");
50 memset(&create, 0, sizeof(create));
51 create.size = 16 * 1024;
52 ret = ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
55 flink.handle = create.handle;
56 ret = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink);
59 open_struct.name = flink.name;
60 ret = ioctl(fd, DRM_IOCTL_GEM_OPEN, &open_struct);
62 igt_assert(open_struct.handle != 0);
66 test_double_flink(int fd)
68 struct drm_i915_gem_create create;
69 struct drm_gem_flink flink;
70 struct drm_gem_flink flink2;
73 igt_info("Testing repeated flink.\n");
75 memset(&create, 0, sizeof(create));
76 create.size = 16 * 1024;
77 ret = ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
80 flink.handle = create.handle;
81 ret = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink);
84 flink2.handle = create.handle;
85 ret = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink2);
87 igt_assert(flink2.name == flink.name);
91 test_bad_flink(int fd)
93 struct drm_gem_flink flink;
96 igt_info("Testing error return on bad flink ioctl.\n");
98 flink.handle = 0x10101010;
99 ret = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink);
100 igt_assert(ret == -1 && errno == ENOENT);
104 test_bad_open(int fd)
106 struct drm_gem_open open_struct;
109 igt_info("Testing error return on bad open ioctl.\n");
111 open_struct.name = 0x10101010;
112 ret = ioctl(fd, DRM_IOCTL_GEM_OPEN, &open_struct);
114 igt_assert(ret == -1 && errno == ENOENT);
118 test_flink_lifetime(int fd)
120 struct drm_i915_gem_create create;
121 struct drm_gem_flink flink;
122 struct drm_gem_open open_struct;
125 igt_info("Testing flink lifetime.\n");
127 fd2 = drm_open_any();
129 memset(&create, 0, sizeof(create));
130 create.size = 16 * 1024;
131 ret = ioctl(fd2, DRM_IOCTL_I915_GEM_CREATE, &create);
132 igt_assert(ret == 0);
134 flink.handle = create.handle;
135 ret = ioctl(fd2, DRM_IOCTL_GEM_FLINK, &flink);
136 igt_assert(ret == 0);
138 open_struct.name = flink.name;
139 ret = ioctl(fd, DRM_IOCTL_GEM_OPEN, &open_struct);
140 igt_assert(ret == 0);
141 igt_assert(open_struct.handle != 0);
144 fd2 = drm_open_any();
146 open_struct.name = flink.name;
147 ret = ioctl(fd2, DRM_IOCTL_GEM_OPEN, &open_struct);
148 igt_assert(ret == 0);
149 igt_assert(open_struct.handle != 0);
161 igt_subtest("double-flink")
162 test_double_flink(fd);
163 igt_subtest("bad-flink")
165 igt_subtest("bad-open")
167 igt_subtest("flink-lifetime")
168 test_flink_lifetime(fd);