blob: b1d996c530f53dcd4908d8f714d4099823d62410 [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)
48
49struct drm_i915_gem_execbuffer2 execbuf;
50struct drm_i915_gem_exec_object2 gem_exec[1];
51uint32_t batch[2] = {MI_BATCH_BUFFER_END};
52uint32_t handle, devid;
53int fd;
54
55igt_main
56{
57 igt_fixture {
58 fd = drm_open_any();
59
60 devid = intel_get_drm_devid(fd);
61
62 handle = gem_create(fd, 4096);
63 gem_write(fd, handle, 0, batch, sizeof(batch));
64
65 gem_exec[0].handle = handle;
66 gem_exec[0].relocation_count = 0;
67 gem_exec[0].relocs_ptr = 0;
68 gem_exec[0].alignment = 0;
69 gem_exec[0].offset = 0;
70 gem_exec[0].flags = 0;
71 gem_exec[0].rsvd1 = 0;
72 gem_exec[0].rsvd2 = 0;
73
74 execbuf.buffers_ptr = (uintptr_t)gem_exec;
75 execbuf.buffer_count = 1;
76 execbuf.batch_start_offset = 0;
77 execbuf.batch_len = 8;
78 execbuf.cliprects_ptr = 0;
79 execbuf.num_cliprects = 0;
80 execbuf.DR1 = 0;
81 execbuf.DR4 = 0;
82 execbuf.flags = 0;
83 i915_execbuffer2_set_context_id(execbuf, 0);
84 execbuf.rsvd2 = 0;
85 }
86
87 igt_subtest("control") {
88 igt_assert(drmIoctl(fd,
89 DRM_IOCTL_I915_GEM_EXECBUFFER2,
90 &execbuf) == 0);
91 execbuf.flags = I915_EXEC_RENDER;
92 igt_assert(drmIoctl(fd,
93 DRM_IOCTL_I915_GEM_EXECBUFFER2,
94 &execbuf) == 0);
95 }
96
97#define RUN_FAIL(expected_errno) do { \
98 igt_assert(drmIoctl(fd, \
99 DRM_IOCTL_I915_GEM_EXECBUFFER2, \
100 &execbuf) == -1); \
101 igt_assert_cmpint(errno, ==, expected_errno); \
102 } while(0)
103
104 igt_subtest("no-bsd") {
105 igt_require(!gem_has_bsd(fd));
106 execbuf.flags = I915_EXEC_BSD;
107 RUN_FAIL(EINVAL);
108 }
109 igt_subtest("no-blt") {
110 igt_require(!gem_has_blt(fd));
111 execbuf.flags = I915_EXEC_BLT;
112 RUN_FAIL(EINVAL);
113 }
114 igt_subtest("no-vebox") {
115 igt_require(!gem_has_vebox(fd));
116 execbuf.flags = LOCAL_I915_EXEC_VEBOX;
117 RUN_FAIL(EINVAL);
118 }
119 igt_subtest("invalid-ring") {
120 execbuf.flags = LOCAL_I915_EXEC_VEBOX+1;
121 RUN_FAIL(EINVAL);
122 }
123
124 igt_subtest("rel-constants-invalid-ring") {
125 igt_require(gem_has_bsd(fd));
126 execbuf.flags = I915_EXEC_BSD | I915_EXEC_CONSTANTS_ABSOLUTE;
127 RUN_FAIL(EINVAL);
128 }
129
130 igt_subtest("rel-constants-invalid-rel-gen5") {
131 igt_require(intel_gen(devid) > 5);
132 execbuf.flags = I915_EXEC_RENDER | I915_EXEC_CONSTANTS_REL_SURFACE;
133 RUN_FAIL(EINVAL);
134 }
135
136 igt_subtest("rel-constants-invalid") {
137 execbuf.flags = I915_EXEC_RENDER | (I915_EXEC_CONSTANTS_REL_SURFACE+1);
138 RUN_FAIL(EINVAL);
139 }
140
141 igt_subtest("sol-reset-invalid") {
142 igt_require(gem_has_bsd(fd));
143 execbuf.flags = I915_EXEC_BSD | I915_EXEC_GEN7_SOL_RESET;
144 RUN_FAIL(EINVAL);
145 }
146
147 igt_subtest("sol-reset-not-gen7") {
148 igt_require(intel_gen(devid) != 7);
149 execbuf.flags = I915_EXEC_RENDER | I915_EXEC_GEN7_SOL_RESET;
150 RUN_FAIL(EINVAL);
151 }
152
153 igt_subtest("secure-non-root") {
154 igt_fork(child, 1) {
155 igt_drop_root();
156
157 execbuf.flags = I915_EXEC_RENDER | I915_EXEC_SECURE;
158 RUN_FAIL(EPERM);
159 }
160
161 igt_waitchildren();
162 }
163
164 igt_subtest("secure-non-master") {
165 do_or_die(drmDropMaster(fd));
166 execbuf.flags = I915_EXEC_RENDER | I915_EXEC_SECURE;
167 RUN_FAIL(EPERM);
168 do_or_die(drmSetMaster(fd));
169 igt_assert(drmIoctl(fd,
170 DRM_IOCTL_I915_GEM_EXECBUFFER2,
171 &execbuf) == 0);
172 }
173
174 /* HANDLE_LUT and NO_RELOC are already exercised by gem_exec_lut_handle */
175
176 igt_subtest("invalid-flag") {
177 execbuf.flags = I915_EXEC_RENDER | (I915_EXEC_HANDLE_LUT << 1);
178 RUN_FAIL(EINVAL);
179 }
180
181 /* rsvd1 aka context id is already exercised by gem_ctx_bad_exec */
182
183 igt_subtest("cliprects-invalid") {
184 igt_require(intel_gen(devid) >= 5);
185 execbuf.flags = 0;
186 execbuf.num_cliprects = 1;
187 RUN_FAIL(EINVAL);
188 execbuf.num_cliprects = 0;
189 }
190
191#define DIRT(name) \
192 igt_subtest(#name "-dirt") { \
193 execbuf.flags = 0; \
194 execbuf.name = 1; \
195 RUN_FAIL(EINVAL); \
196 execbuf.name = 0; \
197 }
198
199 DIRT(rsvd2);
200 DIRT(cliprects_ptr);
201 DIRT(DR1);
202 DIRT(DR4);
203#undef DIRT
204
205#undef RUN_FAIL
206
207 igt_fixture {
208 gem_close(fd, handle);
209
210 close(fd);
211 }
212}