blob: 9376e79e77b745b460683afa84cee23f8fe23bae [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
Chris Wilsoneb7d60e2015-06-17 18:29:49 +010061static void trigger_reset(int fd)
62{
Daniele Ceraolo Spurio03c7f842016-03-01 11:01:32 +000063 igt_force_gpu_reset();
Chris Wilsoneb7d60e2015-06-17 18:29:49 +010064
65 /* And just check the gpu is indeed running again */
66 igt_debug("Checking that the GPU recovered\n");
67 gem_quiescent_gpu(fd);
68}
69
70static void wedge_gpu(int fd)
71{
72 /* First idle the GPU then disable GPU resets before injecting a hang */
73 gem_quiescent_gpu(fd);
74
75 igt_require(i915_reset_control(false));
76
77 igt_debug("Wedging GPU by injecting hang\n");
78 igt_post_hang_ring(fd, igt_hang_ring(fd, I915_EXEC_DEFAULT));
79
80 igt_assert(i915_reset_control(true));
81}
82
83static int __gem_throttle(int fd)
84{
85 int err = 0;
86 if (drmIoctl(fd, DRM_IOCTL_I915_GEM_THROTTLE, NULL))
87 err = -errno;
88 return err;
89}
90
91static void test_throttle(int fd)
92{
93 wedge_gpu(fd);
94
95 igt_assert_eq(__gem_throttle(fd), -EIO);
96
97 trigger_reset(fd);
98}
99
Chris Wilsoneb7d60e2015-06-17 18:29:49 +0100100static void test_execbuf(int fd)
101{
102 struct drm_i915_gem_execbuffer2 execbuf;
103 struct drm_i915_gem_exec_object2 exec;
104 uint32_t tmp[] = { MI_BATCH_BUFFER_END };
105
106 memset(&exec, 0, sizeof(exec));
107 memset(&execbuf, 0, sizeof(execbuf));
108
109 exec.handle = gem_create(fd, 4096);
110 gem_write(fd, exec.handle, 0, tmp, sizeof(tmp));
111
112 execbuf.buffers_ptr = (uintptr_t)&exec;
113 execbuf.buffer_count = 1;
114
115 wedge_gpu(fd);
116
117 igt_assert_eq(__gem_execbuf(fd, &execbuf), -EIO);
118 gem_close(fd, exec.handle);
119
120 trigger_reset(fd);
121}
122
Chris Wilson32c89882015-07-15 16:18:10 +0100123static int __gem_wait(int fd, uint32_t handle, int64_t timeout)
124{
125 struct drm_i915_gem_wait wait;
126 int err = 0;
127
128 memset(&wait, 0, sizeof(wait));
129 wait.bo_handle = handle;
130 wait.timeout_ns = timeout;
131 if (drmIoctl(fd, DRM_IOCTL_I915_GEM_WAIT, &wait))
132 err = -errno;
133
134 return err;
135}
136
137static void test_wait(int fd)
138{
Chris Wilson0a1fc452016-09-13 11:13:14 +0100139 igt_hang_t hang;
Chris Wilson32c89882015-07-15 16:18:10 +0100140
Daniel Vetter40798ef2015-12-16 13:13:58 +0000141 /* If the request we wait on completes due to a hang (even for
142 * that request), the user expects the return value to 0 (success).
143 */
Chris Wilson32c89882015-07-15 16:18:10 +0100144 hang = igt_hang_ring(fd, I915_EXEC_DEFAULT);
Daniel Vetter40798ef2015-12-16 13:13:58 +0000145 igt_assert_eq(__gem_wait(fd, hang.handle, -1), 0);
Chris Wilson32c89882015-07-15 16:18:10 +0100146 igt_post_hang_ring(fd, hang);
147
Daniel Vetter40798ef2015-12-16 13:13:58 +0000148 /* If the GPU is wedged during the wait, again we expect the return
149 * value to be 0 (success).
150 */
151 igt_require(i915_reset_control(false));
152 hang = igt_hang_ring(fd, I915_EXEC_DEFAULT);
153 igt_assert_eq(__gem_wait(fd, hang.handle, -1), 0);
154 igt_post_hang_ring(fd, hang);
155 igt_require(i915_reset_control(true));
156
Chris Wilson32c89882015-07-15 16:18:10 +0100157 trigger_reset(fd);
158}
159
Chris Wilsoneb7d60e2015-06-17 18:29:49 +0100160igt_main
161{
Chris Wilson32c89882015-07-15 16:18:10 +0100162 int fd = -1;
Chris Wilsoneb7d60e2015-06-17 18:29:49 +0100163
164 igt_skip_on_simulation();
165
166 igt_fixture {
Micah Fedkec81d2932015-07-22 21:54:02 +0000167 fd = drm_open_driver(DRIVER_INTEL);
Chris Wilson92caf132015-12-16 09:23:56 +0000168 igt_require_hang_ring(fd, I915_EXEC_DEFAULT);
Chris Wilsoneb7d60e2015-06-17 18:29:49 +0100169 }
170
171 igt_subtest("throttle")
172 test_throttle(fd);
173
174 igt_subtest("execbuf")
175 test_execbuf(fd);
176
Chris Wilson32c89882015-07-15 16:18:10 +0100177 igt_subtest("wait")
178 test_wait(fd);
179
Chris Wilsoneb7d60e2015-06-17 18:29:49 +0100180 igt_fixture
181 close(fd);
182}