blob: d2e4ed76957cbb5be4b98758021bb915689cb5eb [file] [log] [blame]
Chris Wilsoneb7d60e2015-06-17 18:29:49 +01001/*
2 * Copyright © 2015 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 */
24
25/*
26 * Testcase: Test that only specific ioctl report a wedged GPU.
27 *
28 */
29
Thomas Wood804e11f2015-08-17 17:57:43 +010030#include "igt.h"
Chris Wilsoneb7d60e2015-06-17 18:29:49 +010031#include <stdlib.h>
32#include <stdio.h>
33#include <string.h>
34#include <unistd.h>
35#include <fcntl.h>
36#include <inttypes.h>
37#include <errno.h>
38#include <sys/ioctl.h>
39
40#include <drm.h>
41
Chris Wilsoneb7d60e2015-06-17 18:29:49 +010042
43IGT_TEST_DESCRIPTION("Test that specific ioctls report a wedged GPU (EIO).");
44
45static bool i915_reset_control(bool enable)
46{
47 const char *path = "/sys/module/i915/parameters/reset";
48 int fd, ret;
49
50 igt_debug("%s GPU reset\n", enable ? "Enabling" : "Disabling");
51
52 fd = open(path, O_RDWR);
53 igt_require(fd >= 0);
54
55 ret = write(fd, &"NY"[enable], 1) == 1;
56 close(fd);
57
58 return ret;
59}
60
61static bool i915_wedged_set(void)
62{
63 int fd, ret;
64
65 igt_debug("Triggering GPU reset\n");
66
67 fd = igt_debugfs_open("i915_wedged", O_RDWR);
68 igt_require(fd >= 0);
69
70 ret = write(fd, "1\n", 2) == 2;
71 close(fd);
72
73 return ret;
74}
75
76static void trigger_reset(int fd)
77{
78 igt_assert(i915_wedged_set());
79
80 /* And just check the gpu is indeed running again */
81 igt_debug("Checking that the GPU recovered\n");
82 gem_quiescent_gpu(fd);
83}
84
85static void wedge_gpu(int fd)
86{
87 /* First idle the GPU then disable GPU resets before injecting a hang */
88 gem_quiescent_gpu(fd);
89
90 igt_require(i915_reset_control(false));
91
92 igt_debug("Wedging GPU by injecting hang\n");
93 igt_post_hang_ring(fd, igt_hang_ring(fd, I915_EXEC_DEFAULT));
94
95 igt_assert(i915_reset_control(true));
96}
97
98static int __gem_throttle(int fd)
99{
100 int err = 0;
101 if (drmIoctl(fd, DRM_IOCTL_I915_GEM_THROTTLE, NULL))
102 err = -errno;
103 return err;
104}
105
106static void test_throttle(int fd)
107{
108 wedge_gpu(fd);
109
110 igt_assert_eq(__gem_throttle(fd), -EIO);
111
112 trigger_reset(fd);
113}
114
115static int __gem_execbuf(int fd, struct drm_i915_gem_execbuffer2 *eb)
116{
117 int err = 0;
118 if (drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, eb))
119 err = -errno;
120 return err;
121}
122
123static void test_execbuf(int fd)
124{
125 struct drm_i915_gem_execbuffer2 execbuf;
126 struct drm_i915_gem_exec_object2 exec;
127 uint32_t tmp[] = { MI_BATCH_BUFFER_END };
128
129 memset(&exec, 0, sizeof(exec));
130 memset(&execbuf, 0, sizeof(execbuf));
131
132 exec.handle = gem_create(fd, 4096);
133 gem_write(fd, exec.handle, 0, tmp, sizeof(tmp));
134
135 execbuf.buffers_ptr = (uintptr_t)&exec;
136 execbuf.buffer_count = 1;
137
138 wedge_gpu(fd);
139
140 igt_assert_eq(__gem_execbuf(fd, &execbuf), -EIO);
141 gem_close(fd, exec.handle);
142
143 trigger_reset(fd);
144}
145
Chris Wilson32c89882015-07-15 16:18:10 +0100146static int __gem_wait(int fd, uint32_t handle, int64_t timeout)
147{
148 struct drm_i915_gem_wait wait;
149 int err = 0;
150
151 memset(&wait, 0, sizeof(wait));
152 wait.bo_handle = handle;
153 wait.timeout_ns = timeout;
154 if (drmIoctl(fd, DRM_IOCTL_I915_GEM_WAIT, &wait))
155 err = -errno;
156
157 return err;
158}
159
160static void test_wait(int fd)
161{
162 igt_hang_ring_t hang;
163
Daniel Vetter40798ef2015-12-16 13:13:58 +0000164 /* If the request we wait on completes due to a hang (even for
165 * that request), the user expects the return value to 0 (success).
166 */
Chris Wilson32c89882015-07-15 16:18:10 +0100167 hang = igt_hang_ring(fd, I915_EXEC_DEFAULT);
Daniel Vetter40798ef2015-12-16 13:13:58 +0000168 igt_assert_eq(__gem_wait(fd, hang.handle, -1), 0);
Chris Wilson32c89882015-07-15 16:18:10 +0100169 igt_post_hang_ring(fd, hang);
170
Daniel Vetter40798ef2015-12-16 13:13:58 +0000171 /* If the GPU is wedged during the wait, again we expect the return
172 * value to be 0 (success).
173 */
174 igt_require(i915_reset_control(false));
175 hang = igt_hang_ring(fd, I915_EXEC_DEFAULT);
176 igt_assert_eq(__gem_wait(fd, hang.handle, -1), 0);
177 igt_post_hang_ring(fd, hang);
178 igt_require(i915_reset_control(true));
179
Chris Wilson32c89882015-07-15 16:18:10 +0100180 trigger_reset(fd);
181}
182
Chris Wilsoneb7d60e2015-06-17 18:29:49 +0100183igt_main
184{
Chris Wilson32c89882015-07-15 16:18:10 +0100185 int fd = -1;
Chris Wilsoneb7d60e2015-06-17 18:29:49 +0100186
187 igt_skip_on_simulation();
188
189 igt_fixture {
Micah Fedkec81d2932015-07-22 21:54:02 +0000190 fd = drm_open_driver(DRIVER_INTEL);
Chris Wilson92caf132015-12-16 09:23:56 +0000191 igt_require_hang_ring(fd, I915_EXEC_DEFAULT);
Chris Wilsoneb7d60e2015-06-17 18:29:49 +0100192 }
193
194 igt_subtest("throttle")
195 test_throttle(fd);
196
197 igt_subtest("execbuf")
198 test_execbuf(fd);
199
Chris Wilson32c89882015-07-15 16:18:10 +0100200 igt_subtest("wait")
201 test_wait(fd);
202
Chris Wilsoneb7d60e2015-06-17 18:29:49 +0100203 igt_fixture
204 close(fd);
205}