lib/igt_kms: Unify pipe name helpers
[platform/upstream/intel-gpu-tools.git] / tests / gem_exec_params.c
1 /*
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
49 struct drm_i915_gem_execbuffer2 execbuf;
50 struct drm_i915_gem_exec_object2 gem_exec[1];
51 uint32_t batch[2] = {MI_BATCH_BUFFER_END};
52 uint32_t handle, devid;
53 int fd;
54
55 igt_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 = I915_EXEC_RING_MASK;
121                 RUN_FAIL(EINVAL);
122         }
123
124         igt_subtest("invalid-ring2") {
125                 execbuf.flags = LOCAL_I915_EXEC_VEBOX+1;
126                 RUN_FAIL(EINVAL);
127         }
128
129         igt_subtest("rel-constants-invalid-ring") {
130                 igt_require(gem_has_bsd(fd));
131                 execbuf.flags = I915_EXEC_BSD | I915_EXEC_CONSTANTS_ABSOLUTE;
132                 RUN_FAIL(EINVAL);
133         }
134
135         igt_subtest("rel-constants-invalid-rel-gen5") {
136                 igt_require(intel_gen(devid) > 5);
137                 execbuf.flags = I915_EXEC_RENDER | I915_EXEC_CONSTANTS_REL_SURFACE;
138                 RUN_FAIL(EINVAL);
139         }
140
141         igt_subtest("rel-constants-invalid") {
142                 execbuf.flags = I915_EXEC_RENDER | (I915_EXEC_CONSTANTS_REL_SURFACE+(1<<6));
143                 RUN_FAIL(EINVAL);
144         }
145
146         igt_subtest("sol-reset-invalid") {
147                 igt_require(gem_has_bsd(fd));
148                 execbuf.flags = I915_EXEC_BSD | I915_EXEC_GEN7_SOL_RESET;
149                 RUN_FAIL(EINVAL);
150         }
151
152         igt_subtest("sol-reset-not-gen7") {
153                 igt_require(intel_gen(devid) != 7);
154                 execbuf.flags = I915_EXEC_RENDER | I915_EXEC_GEN7_SOL_RESET;
155                 RUN_FAIL(EINVAL);
156         }
157
158         igt_subtest("secure-non-root") {
159                 igt_fork(child, 1) {
160                         igt_drop_root();
161
162                         execbuf.flags = I915_EXEC_RENDER | I915_EXEC_SECURE;
163                         RUN_FAIL(EPERM);
164                 }
165
166                 igt_waitchildren();
167         }
168
169         igt_subtest("secure-non-master") {
170                 do_or_die(drmDropMaster(fd));
171                 execbuf.flags = I915_EXEC_RENDER | I915_EXEC_SECURE;
172                 RUN_FAIL(EPERM);
173                 do_or_die(drmSetMaster(fd));
174                 igt_assert(drmIoctl(fd,
175                                     DRM_IOCTL_I915_GEM_EXECBUFFER2,
176                                     &execbuf) == 0);
177         }
178
179         /* HANDLE_LUT and NO_RELOC are already exercised by gem_exec_lut_handle */
180
181         igt_subtest("invalid-flag") {
182                 execbuf.flags = I915_EXEC_RENDER | (I915_EXEC_HANDLE_LUT << 1);
183                 RUN_FAIL(EINVAL);
184         }
185
186         /* rsvd1 aka context id is already exercised  by gem_ctx_bad_exec */
187
188         igt_subtest("cliprects-invalid") {
189                 igt_require(intel_gen(devid) >= 5);
190                 execbuf.flags = 0;
191                 execbuf.num_cliprects = 1;
192                 RUN_FAIL(EINVAL);
193                 execbuf.num_cliprects = 0;
194         }
195
196 #define DIRT(name) \
197         igt_subtest(#name "-dirt") { \
198                 execbuf.flags = 0; \
199                 execbuf.name = 1; \
200                 RUN_FAIL(EINVAL); \
201                 execbuf.name = 0; \
202         }
203
204         DIRT(rsvd2);
205         DIRT(cliprects_ptr);
206         DIRT(DR1);
207         DIRT(DR4);
208 #undef DIRT
209
210 #undef RUN_FAIL
211
212         igt_fixture {
213                 gem_close(fd, handle);
214
215                 close(fd);
216         }
217 }