kms_rotation_crc: Remove useless comments
[platform/upstream/intel-gpu-tools.git] / tests / gem_flink.c
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 <fcntl.h>
32 #include <inttypes.h>
33 #include <errno.h>
34 #include <sys/stat.h>
35 #include <sys/ioctl.h>
36 #include "drm.h"
37 #include "ioctl_wrappers.h"
38 #include "drmtest.h"
39
40 static void
41 test_flink(int fd)
42 {
43         struct drm_i915_gem_create create;
44         struct drm_gem_flink flink;
45         struct drm_gem_open open_struct;
46         int ret;
47
48         igt_info("Testing flink and open.\n");
49
50         memset(&create, 0, sizeof(create));
51         create.size = 16 * 1024;
52         ret = ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
53         igt_assert(ret == 0);
54
55         flink.handle = create.handle;
56         ret = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink);
57         igt_assert(ret == 0);
58
59         open_struct.name = flink.name;
60         ret = ioctl(fd, DRM_IOCTL_GEM_OPEN, &open_struct);
61         igt_assert(ret == 0);
62         igt_assert(open_struct.handle != 0);
63 }
64
65 static void
66 test_double_flink(int fd)
67 {
68         struct drm_i915_gem_create create;
69         struct drm_gem_flink flink;
70         struct drm_gem_flink flink2;
71         int ret;
72
73         igt_info("Testing repeated flink.\n");
74
75         memset(&create, 0, sizeof(create));
76         create.size = 16 * 1024;
77         ret = ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
78         igt_assert(ret == 0);
79
80         flink.handle = create.handle;
81         ret = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink);
82         igt_assert(ret == 0);
83
84         flink2.handle = create.handle;
85         ret = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink2);
86         igt_assert(ret == 0);
87         igt_assert(flink2.name == flink.name);
88 }
89
90 static void
91 test_bad_flink(int fd)
92 {
93         struct drm_gem_flink flink;
94         int ret;
95
96         igt_info("Testing error return on bad flink ioctl.\n");
97
98         flink.handle = 0x10101010;
99         ret = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink);
100         igt_assert(ret == -1 && errno == ENOENT);
101 }
102
103 static void
104 test_bad_open(int fd)
105 {
106         struct drm_gem_open open_struct;
107         int ret;
108
109         igt_info("Testing error return on bad open ioctl.\n");
110
111         open_struct.name = 0x10101010;
112         ret = ioctl(fd, DRM_IOCTL_GEM_OPEN, &open_struct);
113
114         igt_assert(ret == -1 && errno == ENOENT);
115 }
116
117 static void
118 test_flink_lifetime(int fd)
119 {
120         struct drm_i915_gem_create create;
121         struct drm_gem_flink flink;
122         struct drm_gem_open open_struct;
123         int ret, fd2;
124
125         igt_info("Testing flink lifetime.\n");
126
127         fd2 = drm_open_any();
128
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);
133
134         flink.handle = create.handle;
135         ret = ioctl(fd2, DRM_IOCTL_GEM_FLINK, &flink);
136         igt_assert(ret == 0);
137
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);
142
143         close(fd2);
144         fd2 = drm_open_any();
145
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);
150 }
151
152 int fd;
153
154 igt_main
155 {
156         igt_fixture
157                 fd = drm_open_any();
158
159         igt_subtest("basic")
160                 test_flink(fd);
161         igt_subtest("double-flink")
162                 test_double_flink(fd);
163         igt_subtest("bad-flink")
164                 test_bad_flink(fd);
165         igt_subtest("bad-open")
166                 test_bad_open(fd);
167         igt_subtest("flink-lifetime")
168                 test_flink_lifetime(fd);
169 }