blob: b33a7408c4769cbe2af248fc6ea284b65be17d91 [file] [log] [blame]
Daniel Vettercd3850e2014-04-23 20:23:28 +02001/*
2 * Copyright (c) 2014 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 * Daniel Vetter
25 *
26 */
27
28#include <unistd.h>
29#include <stdlib.h>
30#include <stdint.h>
31#include <stdio.h>
32#include <string.h>
33#include <fcntl.h>
34#include <inttypes.h>
35#include <errno.h>
36#include <sys/stat.h>
37#include <sys/ioctl.h>
38#include <sys/time.h>
39#include "drm.h"
40
41#include "ioctl_wrappers.h"
42#include "drmtest.h"
43#include "intel_io.h"
44#include "intel_chipset.h"
45#include "igt_aux.h"
46
47#define LOCAL_I915_EXEC_VEBOX (4<<0)
Zhipeng Gongf8d47cb2015-01-13 08:50:20 +080048#define LOCAL_I915_EXEC_BSD_MASK (3<<13)
49#define LOCAL_I915_EXEC_BSD_RING1 (1<<13)
50#define LOCAL_I915_EXEC_BSD_RING2 (2<<13)
Abdiel Janulgue8ad1e402015-06-16 13:37:44 +030051#define LOCAL_I915_EXEC_RESOURCE_STREAMER (1<<15)
Daniel Vettercd3850e2014-04-23 20:23:28 +020052
53struct drm_i915_gem_execbuffer2 execbuf;
54struct drm_i915_gem_exec_object2 gem_exec[1];
55uint32_t batch[2] = {MI_BATCH_BUFFER_END};
56uint32_t handle, devid;
57int fd;
58
59igt_main
60{
61 igt_fixture {
62 fd = drm_open_any();
63
64 devid = intel_get_drm_devid(fd);
65
66 handle = gem_create(fd, 4096);
67 gem_write(fd, handle, 0, batch, sizeof(batch));
68
69 gem_exec[0].handle = handle;
70 gem_exec[0].relocation_count = 0;
71 gem_exec[0].relocs_ptr = 0;
72 gem_exec[0].alignment = 0;
73 gem_exec[0].offset = 0;
74 gem_exec[0].flags = 0;
75 gem_exec[0].rsvd1 = 0;
76 gem_exec[0].rsvd2 = 0;
77
78 execbuf.buffers_ptr = (uintptr_t)gem_exec;
79 execbuf.buffer_count = 1;
80 execbuf.batch_start_offset = 0;
81 execbuf.batch_len = 8;
82 execbuf.cliprects_ptr = 0;
83 execbuf.num_cliprects = 0;
84 execbuf.DR1 = 0;
85 execbuf.DR4 = 0;
86 execbuf.flags = 0;
87 i915_execbuffer2_set_context_id(execbuf, 0);
88 execbuf.rsvd2 = 0;
89 }
90
91 igt_subtest("control") {
92 igt_assert(drmIoctl(fd,
93 DRM_IOCTL_I915_GEM_EXECBUFFER2,
94 &execbuf) == 0);
95 execbuf.flags = I915_EXEC_RENDER;
96 igt_assert(drmIoctl(fd,
97 DRM_IOCTL_I915_GEM_EXECBUFFER2,
98 &execbuf) == 0);
99 }
100
101#define RUN_FAIL(expected_errno) do { \
102 igt_assert(drmIoctl(fd, \
103 DRM_IOCTL_I915_GEM_EXECBUFFER2, \
104 &execbuf) == -1); \
Chris Wilson3b94d3f2014-08-29 13:11:40 +0100105 igt_assert_eq(errno, expected_errno); \
Daniel Vettercd3850e2014-04-23 20:23:28 +0200106 } while(0)
107
108 igt_subtest("no-bsd") {
109 igt_require(!gem_has_bsd(fd));
110 execbuf.flags = I915_EXEC_BSD;
111 RUN_FAIL(EINVAL);
112 }
113 igt_subtest("no-blt") {
114 igt_require(!gem_has_blt(fd));
115 execbuf.flags = I915_EXEC_BLT;
116 RUN_FAIL(EINVAL);
117 }
118 igt_subtest("no-vebox") {
119 igt_require(!gem_has_vebox(fd));
120 execbuf.flags = LOCAL_I915_EXEC_VEBOX;
121 RUN_FAIL(EINVAL);
122 }
123 igt_subtest("invalid-ring") {
Daniel Vetter6abfe2f2014-04-28 15:26:15 +0200124 execbuf.flags = I915_EXEC_RING_MASK;
125 RUN_FAIL(EINVAL);
126 }
127
128 igt_subtest("invalid-ring2") {
Daniel Vettercd3850e2014-04-23 20:23:28 +0200129 execbuf.flags = LOCAL_I915_EXEC_VEBOX+1;
130 RUN_FAIL(EINVAL);
131 }
132
Zhipeng Gongf8d47cb2015-01-13 08:50:20 +0800133 igt_subtest("invalid-bsd-ring") {
134 igt_require(gem_has_bsd2(fd));
135 execbuf.flags = I915_EXEC_BSD | LOCAL_I915_EXEC_BSD_MASK;
136 RUN_FAIL(EINVAL);
137 }
138
139 igt_subtest("invalid-bsd1-flag-on-render") {
140 execbuf.flags = I915_EXEC_RENDER | LOCAL_I915_EXEC_BSD_RING1;
141 RUN_FAIL(EINVAL);
142 }
143
144 igt_subtest("invalid-bsd2-flag-on-render") {
145 execbuf.flags = I915_EXEC_RENDER | LOCAL_I915_EXEC_BSD_RING2;
146 RUN_FAIL(EINVAL);
147 }
148
149 igt_subtest("invalid-bsd1-flag-on-blt") {
150 execbuf.flags = I915_EXEC_BLT | LOCAL_I915_EXEC_BSD_RING1;
151 RUN_FAIL(EINVAL);
152 }
153
154 igt_subtest("invalid-bsd2-flag-on-blt") {
155 execbuf.flags = I915_EXEC_BLT | LOCAL_I915_EXEC_BSD_RING2;
156 RUN_FAIL(EINVAL);
157 }
158
159 igt_subtest("invalid-bsd1-flag-on-vebox") {
160 igt_require(gem_has_vebox(fd));
161 execbuf.flags = LOCAL_I915_EXEC_VEBOX | LOCAL_I915_EXEC_BSD_RING1;
162 RUN_FAIL(EINVAL);
163 }
164
165 igt_subtest("invalid-bsd2-flag-on-vebox") {
166 igt_require(gem_has_vebox(fd));
167 execbuf.flags = LOCAL_I915_EXEC_VEBOX | LOCAL_I915_EXEC_BSD_RING2;
168 RUN_FAIL(EINVAL);
169 }
170
Daniel Vettercd3850e2014-04-23 20:23:28 +0200171 igt_subtest("rel-constants-invalid-ring") {
172 igt_require(gem_has_bsd(fd));
173 execbuf.flags = I915_EXEC_BSD | I915_EXEC_CONSTANTS_ABSOLUTE;
174 RUN_FAIL(EINVAL);
175 }
176
177 igt_subtest("rel-constants-invalid-rel-gen5") {
178 igt_require(intel_gen(devid) > 5);
179 execbuf.flags = I915_EXEC_RENDER | I915_EXEC_CONSTANTS_REL_SURFACE;
180 RUN_FAIL(EINVAL);
181 }
182
183 igt_subtest("rel-constants-invalid") {
Daniel Vetter16390222014-04-24 10:43:38 +0200184 execbuf.flags = I915_EXEC_RENDER | (I915_EXEC_CONSTANTS_REL_SURFACE+(1<<6));
Daniel Vettercd3850e2014-04-23 20:23:28 +0200185 RUN_FAIL(EINVAL);
186 }
187
188 igt_subtest("sol-reset-invalid") {
189 igt_require(gem_has_bsd(fd));
190 execbuf.flags = I915_EXEC_BSD | I915_EXEC_GEN7_SOL_RESET;
191 RUN_FAIL(EINVAL);
192 }
193
194 igt_subtest("sol-reset-not-gen7") {
195 igt_require(intel_gen(devid) != 7);
196 execbuf.flags = I915_EXEC_RENDER | I915_EXEC_GEN7_SOL_RESET;
197 RUN_FAIL(EINVAL);
198 }
199
200 igt_subtest("secure-non-root") {
201 igt_fork(child, 1) {
202 igt_drop_root();
203
204 execbuf.flags = I915_EXEC_RENDER | I915_EXEC_SECURE;
205 RUN_FAIL(EPERM);
206 }
207
208 igt_waitchildren();
209 }
210
211 igt_subtest("secure-non-master") {
212 do_or_die(drmDropMaster(fd));
213 execbuf.flags = I915_EXEC_RENDER | I915_EXEC_SECURE;
214 RUN_FAIL(EPERM);
215 do_or_die(drmSetMaster(fd));
216 igt_assert(drmIoctl(fd,
217 DRM_IOCTL_I915_GEM_EXECBUFFER2,
218 &execbuf) == 0);
219 }
220
221 /* HANDLE_LUT and NO_RELOC are already exercised by gem_exec_lut_handle */
222
223 igt_subtest("invalid-flag") {
Daniel Vetteradfc2942015-08-07 19:27:30 +0200224 /* NOTE: This test intentionally exercise the next available
225 * flag. Don't "fix" this testcase without adding the required
226 * tests for the new flag first. */
Abdiel Janulgue8ad1e402015-06-16 13:37:44 +0300227 execbuf.flags = I915_EXEC_RENDER | (LOCAL_I915_EXEC_RESOURCE_STREAMER << 1);
Daniel Vettercd3850e2014-04-23 20:23:28 +0200228 RUN_FAIL(EINVAL);
229 }
230
231 /* rsvd1 aka context id is already exercised by gem_ctx_bad_exec */
232
233 igt_subtest("cliprects-invalid") {
234 igt_require(intel_gen(devid) >= 5);
235 execbuf.flags = 0;
236 execbuf.num_cliprects = 1;
237 RUN_FAIL(EINVAL);
238 execbuf.num_cliprects = 0;
239 }
240
Abdiel Janulgue8ad1e402015-06-16 13:37:44 +0300241 igt_subtest("rs-invalid-on-bsd-ring") {
242 igt_require(IS_HASWELL(devid) || intel_gen(devid) >= 8);
243 execbuf.flags = I915_EXEC_BSD | LOCAL_I915_EXEC_RESOURCE_STREAMER;
244 RUN_FAIL(EINVAL);
245 }
246
247 igt_subtest("rs-invalid-on-blt-ring") {
248 igt_require(IS_HASWELL(devid) || intel_gen(devid) >= 8);
249 execbuf.flags = I915_EXEC_BLT | LOCAL_I915_EXEC_RESOURCE_STREAMER;
250 RUN_FAIL(EINVAL);
251 }
252
253 igt_subtest("rs-invalid-on-vebox-ring") {
254 igt_require(IS_HASWELL(devid) || intel_gen(devid) >= 8);
255 execbuf.flags = I915_EXEC_VEBOX | LOCAL_I915_EXEC_RESOURCE_STREAMER;
256 RUN_FAIL(EINVAL);
257 }
258
259 igt_subtest("rs-invalid-gen") {
260 igt_require(!IS_HASWELL(devid) && intel_gen(devid) < 8);
261 execbuf.flags = I915_EXEC_RENDER | LOCAL_I915_EXEC_RESOURCE_STREAMER;
262 RUN_FAIL(EINVAL);
263 }
264
Daniel Vettercd3850e2014-04-23 20:23:28 +0200265#define DIRT(name) \
266 igt_subtest(#name "-dirt") { \
267 execbuf.flags = 0; \
268 execbuf.name = 1; \
269 RUN_FAIL(EINVAL); \
270 execbuf.name = 0; \
271 }
272
273 DIRT(rsvd2);
274 DIRT(cliprects_ptr);
275 DIRT(DR1);
276 DIRT(DR4);
277#undef DIRT
278
279#undef RUN_FAIL
280
281 igt_fixture {
282 gem_close(fd, handle);
283
284 close(fd);
285 }
286}