lib/igt_kms: Unify pipe name helpers
[platform/upstream/intel-gpu-tools.git] / tests / gem_ctx_bad_exec.c
1 /*
2  * Copyright © 2012 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  *    Ben Widawsky <ben@bwidawsk.net>
25  *
26  */
27
28 /*
29  * Negative test cases:
30  *  test we can't submit contexts to unsupported rings
31  */
32
33 #include <unistd.h>
34 #include <stdlib.h>
35 #include <stdint.h>
36 #include <stdio.h>
37 #include <string.h>
38 #include <fcntl.h>
39 #include <inttypes.h>
40 #include <errno.h>
41 #include <sys/stat.h>
42 #include <sys/ioctl.h>
43 #include <sys/time.h>
44 #include "drm.h"
45 #include "ioctl_wrappers.h"
46 #include "drmtest.h"
47
48 /* Copied from gem_exec_nop.c */
49 static int exec(int fd, uint32_t handle, int ring, int ctx_id)
50 {
51         struct drm_i915_gem_execbuffer2 execbuf;
52         struct drm_i915_gem_exec_object2 gem_exec;
53         int ret = 0;
54
55         gem_exec.handle = handle;
56         gem_exec.relocation_count = 0;
57         gem_exec.relocs_ptr = 0;
58         gem_exec.alignment = 0;
59         gem_exec.offset = 0;
60         gem_exec.flags = 0;
61         gem_exec.rsvd1 = 0;
62         gem_exec.rsvd2 = 0;
63
64         execbuf.buffers_ptr = (uintptr_t)&gem_exec;
65         execbuf.buffer_count = 1;
66         execbuf.batch_start_offset = 0;
67         execbuf.batch_len = 8;
68         execbuf.cliprects_ptr = 0;
69         execbuf.num_cliprects = 0;
70         execbuf.DR1 = 0;
71         execbuf.DR4 = 0;
72         execbuf.flags = ring;
73         i915_execbuffer2_set_context_id(execbuf, ctx_id);
74         execbuf.rsvd2 = 0;
75
76         ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2,
77                         &execbuf);
78         gem_sync(fd, handle);
79
80         return ret;
81 }
82
83 uint32_t handle;
84 uint32_t batch[2] = {MI_BATCH_BUFFER_END};
85 uint32_t ctx_id;
86 int fd;
87
88 igt_main
89 {
90         igt_skip_on_simulation();
91
92         igt_fixture {
93                 fd = drm_open_any_render();
94
95                 ctx_id = gem_context_create(fd);
96
97                 handle = gem_create(fd, 4096);
98                 gem_write(fd, handle, 0, batch, sizeof(batch));
99         }
100
101         igt_subtest("render")
102                 igt_assert(exec(fd, handle, I915_EXEC_RENDER, ctx_id) == 0);
103         igt_subtest("bsd")
104                 igt_assert(exec(fd, handle, I915_EXEC_BSD, ctx_id) != 0);
105         igt_subtest("blt")
106                 igt_assert(exec(fd, handle, I915_EXEC_BLT, ctx_id) != 0);
107 #ifdef I915_EXEC_VEBOX
108         igt_fixture
109                 igt_require(gem_has_vebox(fd));
110         igt_subtest("vebox")
111                 igt_assert(exec(fd, handle, I915_EXEC_VEBOX, ctx_id) != 0);
112 #endif
113 }