tests/gem_reset_stats: add support for BDW+
[platform/upstream/intel-gpu-tools.git] / tests / gem_reset_stats.c
1 /*
2  * Copyright (c) 2013 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  *  Mika Kuoppala <mika.kuoppala@intel.com>
25  *
26  */
27
28 #include <unistd.h>
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <string.h>
32 #include <fcntl.h>
33 #include <inttypes.h>
34 #include <errno.h>
35 #include <sys/stat.h>
36 #include <sys/ioctl.h>
37 #include <sys/mman.h>
38 #include <time.h>
39
40 #include "i915_drm.h"
41 #include "intel_bufmgr.h"
42 #include "intel_batchbuffer.h"
43 #include "intel_gpu_tools.h"
44 #include "rendercopy.h"
45
46 #define RS_NO_ERROR      0
47 #define RS_BATCH_ACTIVE  (1 << 0)
48 #define RS_BATCH_PENDING (1 << 1)
49 #define RS_UNKNOWN       (1 << 2)
50
51 struct local_drm_i915_reset_stats {
52         __u32 ctx_id;
53         __u32 flags;
54         __u32 reset_count;
55         __u32 batch_active;
56         __u32 batch_pending;
57         __u32 pad;
58 };
59
60 struct local_drm_i915_gem_context_create {
61         __u32 ctx_id;
62         __u32 pad;
63 };
64
65 struct local_drm_i915_gem_context_destroy {
66         __u32 ctx_id;
67         __u32 pad;
68 };
69
70 #define MAX_FD 32
71
72 #define CONTEXT_CREATE_IOCTL DRM_IOWR(DRM_COMMAND_BASE + 0x2d, struct local_drm_i915_gem_context_create)
73 #define CONTEXT_DESTROY_IOCTL DRM_IOWR(DRM_COMMAND_BASE + 0x2e, struct local_drm_i915_gem_context_destroy)
74 #define GET_RESET_STATS_IOCTL DRM_IOWR(DRM_COMMAND_BASE + 0x32, struct local_drm_i915_reset_stats)
75
76 static uint32_t context_create(int fd)
77 {
78         struct local_drm_i915_gem_context_create create;
79         int ret;
80
81         create.ctx_id = rand();
82         create.pad = rand();
83
84         ret = drmIoctl(fd, CONTEXT_CREATE_IOCTL, &create);
85         igt_assert(ret == 0);
86
87         return create.ctx_id;
88 }
89
90 static int context_destroy(int fd, uint32_t ctx_id)
91 {
92         int ret;
93         struct local_drm_i915_gem_context_destroy destroy;
94
95         destroy.ctx_id = ctx_id;
96         destroy.pad = rand();
97
98         ret = drmIoctl(fd, CONTEXT_DESTROY_IOCTL, &destroy);
99         if (ret != 0)
100                 return -errno;
101
102         return 0;
103 }
104
105 static int gem_reset_stats(int fd, int ctx_id,
106                            struct local_drm_i915_reset_stats *rs)
107 {
108         int ret;
109
110         rs->ctx_id = ctx_id;
111         rs->flags = 0;
112         rs->reset_count = rand();
113         rs->batch_active = rand();
114         rs->batch_pending = rand();
115         rs->pad = 0;
116
117         do {
118                 ret = ioctl(fd, GET_RESET_STATS_IOCTL, rs);
119         } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
120
121         if (ret < 0)
122                 return -errno;
123
124         return 0;
125 }
126
127 static int gem_reset_status(int fd, int ctx_id)
128 {
129         int ret;
130         struct local_drm_i915_reset_stats rs;
131
132         ret = gem_reset_stats(fd, ctx_id, &rs);
133         if (ret)
134                 return ret;
135
136         if (rs.batch_active)
137                 return RS_BATCH_ACTIVE;
138         if (rs.batch_pending)
139                 return RS_BATCH_PENDING;
140
141         return RS_NO_ERROR;
142 }
143
144 static int gem_exec(int fd, struct drm_i915_gem_execbuffer2 *execbuf)
145 {
146         int ret;
147
148         ret = ioctl(fd,
149                     DRM_IOCTL_I915_GEM_EXECBUFFER2,
150                     execbuf);
151
152         if (ret < 0)
153                 return -errno;
154
155         return 0;
156 }
157
158 static int exec_valid(int fd, int ctx)
159 {
160         struct drm_i915_gem_execbuffer2 execbuf;
161         struct drm_i915_gem_exec_object2 exec;
162         int ret;
163
164         uint32_t buf[2] = { MI_BATCH_BUFFER_END, 0 };
165
166         exec.handle = gem_create(fd, 4096);
167         gem_write(fd, exec.handle, 0, buf, sizeof(buf));
168         exec.relocation_count = 0;
169         exec.relocs_ptr = 0;
170         exec.alignment = 0;
171         exec.offset = 0;
172         exec.flags = 0;
173         exec.rsvd1 = 0;
174         exec.rsvd2 = 0;
175
176         execbuf.buffers_ptr = (uintptr_t)&exec;
177         execbuf.buffer_count = 1;
178         execbuf.batch_start_offset = 0;
179         execbuf.batch_len = sizeof(buf);
180         execbuf.cliprects_ptr = 0;
181         execbuf.num_cliprects = 0;
182         execbuf.DR1 = 0;
183         execbuf.DR4 = 0;
184         execbuf.flags = 0;
185         i915_execbuffer2_set_context_id(execbuf, ctx);
186         execbuf.rsvd2 = 0;
187
188         ret = gem_exec(fd, &execbuf);
189         if (ret < 0)
190                 return ret;
191
192         return exec.handle;
193 }
194
195 #define BUFSIZE (4 * 1024)
196 #define ITEMS   (BUFSIZE >> 2)
197
198 static int inject_hang(int fd, int ctx)
199 {
200         struct drm_i915_gem_execbuffer2 execbuf;
201         struct drm_i915_gem_exec_object2 exec;
202         uint64_t gtt_off;
203         uint32_t *buf;
204         int roff, i;
205         unsigned cmd_len = 2;
206
207         srandom(time(NULL));
208
209         if (intel_gen(intel_get_drm_devid(fd)) >= 8)
210                 cmd_len = 3;
211
212         buf = malloc(BUFSIZE);
213         igt_assert(buf != NULL);
214
215         buf[0] = MI_BATCH_BUFFER_END;
216         buf[1] = MI_NOOP;
217
218         exec.handle = gem_create(fd, BUFSIZE);
219         gem_write(fd, exec.handle, 0, buf, BUFSIZE);
220         exec.relocation_count = 0;
221         exec.relocs_ptr = 0;
222         exec.alignment = 0;
223         exec.offset = 0;
224         exec.flags = 0;
225         exec.rsvd1 = 0;
226         exec.rsvd2 = 0;
227
228         execbuf.buffers_ptr = (uintptr_t)&exec;
229         execbuf.buffer_count = 1;
230         execbuf.batch_start_offset = 0;
231         execbuf.batch_len = BUFSIZE;
232         execbuf.cliprects_ptr = 0;
233         execbuf.num_cliprects = 0;
234         execbuf.DR1 = 0;
235         execbuf.DR4 = 0;
236         execbuf.flags = 0;
237         i915_execbuffer2_set_context_id(execbuf, ctx);
238         execbuf.rsvd2 = 0;
239
240         igt_assert(gem_exec(fd, &execbuf) == 0);
241
242         gtt_off = exec.offset;
243
244         for (i = 0; i < ITEMS; i++)
245                 buf[i] = MI_NOOP;
246
247         roff = random() % (ITEMS - cmd_len);
248         buf[roff] = MI_BATCH_BUFFER_START | (cmd_len - 2);
249         buf[roff + 1] = (gtt_off & 0xfffffffc) + (roff << 2);
250         if (cmd_len == 3)
251                 buf[roff + 2] = gtt_off & 0xffffffff00000000ull;
252
253 #ifdef VERBOSE
254         printf("loop injected at 0x%lx (off 0x%x, bo_start 0x%lx, bo_end 0x%lx)\n",
255                (long unsigned int)((roff << 2) + gtt_off),
256                roff << 2, (long unsigned int)gtt_off,
257                (long unsigned int)(gtt_off + BUFSIZE - 1));
258 #endif
259         gem_write(fd, exec.handle, 0, buf, BUFSIZE);
260
261         exec.relocation_count = 0;
262         exec.relocs_ptr = 0;
263         exec.alignment = 0;
264         exec.offset = 0;
265         exec.flags = 0;
266         exec.rsvd1 = 0;
267         exec.rsvd2 = 0;
268
269         execbuf.buffers_ptr = (uintptr_t)&exec;
270         execbuf.buffer_count = 1;
271         execbuf.batch_start_offset = 0;
272         execbuf.batch_len = BUFSIZE;
273         execbuf.cliprects_ptr = 0;
274         execbuf.num_cliprects = 0;
275         execbuf.DR1 = 0;
276         execbuf.DR4 = 0;
277         execbuf.flags = 0;
278         i915_execbuffer2_set_context_id(execbuf, ctx);
279         execbuf.rsvd2 = 0;
280
281         igt_assert(gem_exec(fd, &execbuf) == 0);
282
283         igt_assert(gtt_off == exec.offset);
284
285         free(buf);
286
287         return exec.handle;
288 }
289
290 static int _assert_reset_status(int fd, int ctx, int status)
291 {
292         int rs;
293
294         rs = gem_reset_status(fd, ctx);
295         if (rs < 0) {
296                 printf("reset status for %d ctx %d returned %d\n",
297                        fd, ctx, rs);
298                 return rs;
299         }
300
301         if (rs != status) {
302                 printf("%d:%d reset status %d differs from assumed %d\n",
303                        fd, ctx, rs, status);
304
305                 return 1;
306         }
307
308         return 0;
309 }
310
311 #define assert_reset_status(fd, ctx, status) \
312         igt_assert(_assert_reset_status(fd, ctx, status) == 0)
313
314 static void test_rs(int num_fds, int hang_index, int rs_assumed_no_hang)
315 {
316         int i;
317         int fd[MAX_FD];
318         int h[MAX_FD];
319
320         igt_assert (num_fds <= MAX_FD);
321         igt_assert (hang_index < MAX_FD);
322
323         for (i = 0; i < num_fds; i++) {
324                 fd[i] = drm_open_any();
325                 igt_assert(fd[i]);
326         }
327
328         for (i = 0; i < num_fds; i++)
329                 assert_reset_status(fd[i], 0, RS_NO_ERROR);
330
331         for (i = 0; i < num_fds; i++) {
332                 if (i == hang_index)
333                         h[i] = inject_hang(fd[i], 0);
334                 else
335                         h[i] = exec_valid(fd[i], 0);
336         }
337
338         gem_sync(fd[num_fds - 1], h[num_fds - 1]);
339
340         for (i = 0; i < num_fds; i++) {
341                 if (hang_index < 0) {
342                         assert_reset_status(fd[i], 0, rs_assumed_no_hang);
343                         continue;
344                 }
345
346                 if (i < hang_index)
347                         assert_reset_status(fd[i], 0, RS_NO_ERROR);
348                 if (i == hang_index)
349                         assert_reset_status(fd[i], 0, RS_BATCH_ACTIVE);
350                 if (i > hang_index)
351                         assert_reset_status(fd[i], 0, RS_BATCH_PENDING);
352         }
353
354         for (i = 0; i < num_fds; i++) {
355                 gem_close(fd[i], h[i]);
356                 close(fd[i]);
357         }
358 }
359
360 #define MAX_CTX 100
361 static void test_rs_ctx(int num_fds, int num_ctx, int hang_index,
362                         int hang_context)
363 {
364         int i, j;
365         int fd[MAX_FD];
366         int h[MAX_FD][MAX_CTX];
367         int ctx[MAX_FD][MAX_CTX];
368
369         igt_assert (num_fds <= MAX_FD);
370         igt_assert (hang_index < MAX_FD);
371
372         igt_assert (num_ctx <= MAX_CTX);
373         igt_assert (hang_context < MAX_CTX);
374
375         test_rs(num_fds, -1, RS_NO_ERROR);
376
377         for (i = 0; i < num_fds; i++) {
378                 fd[i] = drm_open_any();
379                 igt_assert(fd[i]);
380                 assert_reset_status(fd[i], 0, RS_NO_ERROR);
381
382                 for (j = 0; j < num_ctx; j++) {
383                         ctx[i][j] = context_create(fd[i]);
384
385                 }
386
387                 assert_reset_status(fd[i], 0, RS_NO_ERROR);
388         }
389
390         for (i = 0; i < num_fds; i++) {
391
392                 assert_reset_status(fd[i], 0, RS_NO_ERROR);
393
394                 for (j = 0; j < num_ctx; j++)
395                         assert_reset_status(fd[i], ctx[i][j], RS_NO_ERROR);
396
397                 assert_reset_status(fd[i], 0, RS_NO_ERROR);
398         }
399
400         for (i = 0; i < num_fds; i++) {
401                 for (j = 0; j < num_ctx; j++) {
402                         if (i == hang_index && j == hang_context)
403                                 h[i][j] = inject_hang(fd[i], ctx[i][j]);
404                         else
405                                 h[i][j] = exec_valid(fd[i], ctx[i][j]);
406                 }
407         }
408
409         gem_sync(fd[num_fds - 1], ctx[num_fds - 1][num_ctx - 1]);
410
411         for (i = 0; i < num_fds; i++)
412                 assert_reset_status(fd[i], 0, RS_NO_ERROR);
413
414         for (i = 0; i < num_fds; i++) {
415                 for (j = 0; j < num_ctx; j++) {
416                         if (i < hang_index)
417                                 assert_reset_status(fd[i], ctx[i][j], RS_NO_ERROR);
418                         if (i == hang_index && j < hang_context)
419                                 assert_reset_status(fd[i], ctx[i][j], RS_NO_ERROR);
420                         if (i == hang_index && j == hang_context)
421                                 assert_reset_status(fd[i], ctx[i][j],
422                                                     RS_BATCH_ACTIVE);
423                         if (i == hang_index && j > hang_context)
424                                 assert_reset_status(fd[i], ctx[i][j],
425                                                     RS_BATCH_PENDING);
426                         if (i > hang_index)
427                                 assert_reset_status(fd[i], ctx[i][j],
428                                                     RS_BATCH_PENDING);
429                 }
430         }
431
432         for (i = 0; i < num_fds; i++) {
433                 for (j = 0; j < num_ctx; j++) {
434                         gem_close(fd[i], h[i][j]);
435                         igt_assert(context_destroy(fd[i], ctx[i][j]) == 0);
436                 }
437
438                 assert_reset_status(fd[i], 0, RS_NO_ERROR);
439
440                 close(fd[i]);
441         }
442 }
443
444 static void test_ban(void)
445 {
446         int h1,h2,h3,h4,h5,h6,h7;
447         int ctx_good, ctx_bad;
448         int fd;
449         int retry = 10;
450         int active_count = 0, pending_count = 0;
451         struct local_drm_i915_reset_stats rs_bad, rs_good;
452
453         fd = drm_open_any();
454         igt_assert(fd >= 0);
455
456         assert_reset_status(fd, 0, RS_NO_ERROR);
457
458         ctx_good = context_create(fd);
459         ctx_bad = context_create(fd);
460
461         assert_reset_status(fd, 0, RS_NO_ERROR);
462         assert_reset_status(fd, ctx_good, RS_NO_ERROR);
463         assert_reset_status(fd, ctx_bad, RS_NO_ERROR);
464
465         h1 = exec_valid(fd, ctx_bad);
466         igt_assert(h1 >= 0);
467         h5 = exec_valid(fd, ctx_good);
468         igt_assert(h5 >= 0);
469
470         assert_reset_status(fd, ctx_good, RS_NO_ERROR);
471         assert_reset_status(fd, ctx_bad, RS_NO_ERROR);
472
473         h2 = inject_hang(fd, ctx_bad);
474         igt_assert(h2 >= 0);
475         active_count++;
476         /* Second hang will be pending for this */
477         pending_count++;
478
479         h6 = exec_valid(fd, ctx_good);
480         h7 = exec_valid(fd, ctx_good);
481
482         while (retry--) {
483                 h3 = inject_hang(fd, ctx_bad);
484                 igt_assert(h3 >= 0);
485                 gem_sync(fd, h3);
486                 active_count++;
487                 /* This second hand will count as pending */
488                 assert_reset_status(fd, ctx_bad, RS_BATCH_ACTIVE);
489
490                 h4 = exec_valid(fd, ctx_bad);
491                 if (h4 == -EIO) {
492                         gem_close(fd, h3);
493                         break;
494                 }
495
496                 /* Should not happen often but sometimes hang is declared too slow
497                  * due to our way of faking hang using loop */
498
499                 igt_assert(h4 >= 0);
500                 gem_close(fd, h3);
501                 gem_close(fd, h4);
502
503                 printf("retrying for ban (%d)\n", retry);
504         }
505
506         igt_assert(h4 == -EIO);
507         assert_reset_status(fd, ctx_bad, RS_BATCH_ACTIVE);
508
509         gem_sync(fd, h7);
510         assert_reset_status(fd, ctx_good, RS_BATCH_PENDING);
511
512         igt_assert(gem_reset_stats(fd, ctx_good, &rs_good) == 0);
513         igt_assert(gem_reset_stats(fd, ctx_bad, &rs_bad) == 0);
514
515         igt_assert(rs_bad.batch_active == active_count);
516         igt_assert(rs_bad.batch_pending == pending_count);
517         igt_assert(rs_good.batch_active == 0);
518         igt_assert(rs_good.batch_pending == 2);
519
520         gem_close(fd, h1);
521         gem_close(fd, h2);
522         gem_close(fd, h6);
523         gem_close(fd, h7);
524
525         h1 = exec_valid(fd, ctx_good);
526         igt_assert(h1 >= 0);
527         gem_close(fd, h1);
528
529         igt_assert(context_destroy(fd, ctx_good) == 0);
530         igt_assert(context_destroy(fd, ctx_bad) == 0);
531         igt_assert(gem_reset_status(fd, ctx_good) < 0);
532         igt_assert(gem_reset_status(fd, ctx_bad) < 0);
533         igt_assert(exec_valid(fd, ctx_good) < 0);
534         igt_assert(exec_valid(fd, ctx_bad) < 0);
535
536         close(fd);
537 }
538
539 static void test_nonrelated_hang(void)
540 {
541         int h1,h2;
542         int fd1,fd2;
543         int ctx_guilty, ctx_unrelated;
544
545         fd1 = drm_open_any();
546         fd2 = drm_open_any();
547         assert_reset_status(fd1, 0, RS_NO_ERROR);
548         assert_reset_status(fd2, 0, RS_NO_ERROR);
549         ctx_guilty = context_create(fd1);
550         ctx_unrelated = context_create(fd2);
551
552         assert_reset_status(fd1, ctx_guilty, RS_NO_ERROR);
553         assert_reset_status(fd2, ctx_unrelated, RS_NO_ERROR);
554
555         h1 = inject_hang(fd1, ctx_guilty);
556         igt_assert(h1 >= 0);
557         gem_sync(fd1, h1);
558         assert_reset_status(fd1, ctx_guilty, RS_BATCH_ACTIVE);
559         assert_reset_status(fd2, ctx_unrelated, RS_NO_ERROR);
560
561         h2 = exec_valid(fd2, ctx_unrelated);
562         igt_assert(h2 >= 0);
563         gem_sync(fd2, h2);
564         assert_reset_status(fd1, ctx_guilty, RS_BATCH_ACTIVE);
565         assert_reset_status(fd2, ctx_unrelated, RS_NO_ERROR);
566         gem_close(fd1, h1);
567         gem_close(fd2, h2);
568
569         igt_assert(context_destroy(fd1, ctx_guilty) == 0);
570         igt_assert(context_destroy(fd2, ctx_unrelated) == 0);
571
572         close(fd1);
573         close(fd2);
574 }
575
576 static int get_reset_count(int fd, int ctx)
577 {
578         int ret;
579         struct local_drm_i915_reset_stats rs;
580
581         ret = gem_reset_stats(fd, ctx, &rs);
582         if (ret)
583                 return ret;
584
585         return rs.reset_count;
586 }
587
588 static void test_double_destroy_pending(void)
589 {
590         int fd, h;
591         uint32_t ctx;
592
593         fd = drm_open_any();
594         igt_assert(fd >= 0);
595         ctx = context_create(fd);
596
597         assert_reset_status(fd, ctx, RS_NO_ERROR);
598
599         h = inject_hang(fd, ctx);
600         igt_assert(h >= 0);
601         igt_assert(context_destroy(fd, ctx) == 0);
602         igt_assert(context_destroy(fd, ctx) == -ENOENT);
603
604         gem_close(fd, h);
605         close(fd);
606 }
607
608 static void test_close_pending(void)
609 {
610         int fd, h;
611
612         fd = drm_open_any();
613         igt_assert(fd >= 0);
614
615         assert_reset_status(fd, 0, RS_NO_ERROR);
616
617         h = inject_hang(fd, 0);
618         igt_assert(h >= 0);
619
620         gem_close(fd, h);
621         close(fd);
622 }
623
624 static void __test_count(const bool create_ctx)
625 {
626         int fd, h, ctx;
627         long c1, c2;
628
629         fd = drm_open_any();
630         igt_assert(fd >= 0);
631         if (create_ctx)
632                 ctx = context_create(fd);
633         else
634                 ctx = 0;
635
636         assert_reset_status(fd, ctx, RS_NO_ERROR);
637
638         c1 = get_reset_count(fd, ctx);
639         igt_assert(c1 >= 0);
640
641         h = inject_hang(fd, ctx);
642         igt_assert (h >= 0);
643         gem_sync(fd, h);
644
645         assert_reset_status(fd, ctx, RS_BATCH_ACTIVE);
646         c2 = get_reset_count(fd, ctx);
647         igt_assert(c2 >= 0);
648
649         igt_assert(c2 == (c1 + 1));
650
651         gem_close(fd, h);
652
653         if (create_ctx)
654                 context_destroy(fd, ctx);
655
656         close(fd);
657 }
658
659 static void test_count(void)
660 {
661         return __test_count(false);
662 }
663
664 static void test_count_context(void)
665 {
666         return __test_count(true);
667 }
668
669 static void test_global_reset_count(void)
670 {
671         test_count();
672         test_count_context();
673 }
674
675 static int _test_params(int fd, int ctx, uint32_t flags, uint32_t pad)
676 {
677         struct local_drm_i915_reset_stats rs;
678         int ret;
679
680         rs.ctx_id = ctx;
681         rs.flags = flags;
682         rs.reset_count = rand();
683         rs.batch_active = rand();
684         rs.batch_pending = rand();
685         rs.pad = pad;
686
687         do {
688                 ret = ioctl(fd, GET_RESET_STATS_IOCTL, &rs);
689         } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
690
691         if (ret < 0)
692                 return -errno;
693
694         return 0;
695 }
696
697 static void test_param_ctx(int fd, int ctx)
698 {
699         const uint32_t bad = rand() + 1;
700
701         igt_assert(_test_params(fd, ctx, 0, 0) == 0);
702         igt_assert(_test_params(fd, ctx, 0, bad) == -EINVAL);
703         igt_assert(_test_params(fd, ctx, bad, 0) == -EINVAL);
704         igt_assert(_test_params(fd, ctx, bad, bad) == -EINVAL);
705 }
706
707 static void test_params(void)
708 {
709         int fd, ctx;
710
711         fd = drm_open_any();
712         igt_assert(fd >= 0);
713         ctx = context_create(fd);
714
715         igt_assert(ioctl(fd, GET_RESET_STATS_IOCTL, 0) == -1);
716
717         igt_assert(_test_params(fd, 0xbadbad, 0, 0) == -ENOENT);
718
719         test_param_ctx(fd, 0);
720         test_param_ctx(fd, ctx);
721
722         close(fd);
723 }
724
725
726 igt_main
727 {
728         struct local_drm_i915_gem_context_create create;
729         uint32_t devid;
730         int fd;
731         int ret;
732
733         igt_skip_on_simulation();
734
735         igt_fixture {
736                 fd = drm_open_any();
737                 devid = intel_get_drm_devid(fd);
738                 igt_require_f(intel_gen(devid) >= 4,
739                               "Architecture %d too old\n", intel_gen(devid));
740
741                 ret = drmIoctl(fd, CONTEXT_CREATE_IOCTL, &create);
742                 igt_skip_on_f(ret != 0 && (errno == ENODEV || errno == EINVAL),
743                               "Kernel is too old, or contexts not supported: %s\n",
744                               strerror(errno));
745
746                 close(fd);
747         }
748
749         igt_subtest("basic-reset-status")
750                 test_rs(4, 1, 0);
751
752         igt_subtest("context-reset-status")
753                 test_rs_ctx(4, 4, 1, 2);
754
755         igt_subtest("ban")
756                 test_ban();
757
758         igt_subtest("ctx-unrelated")
759                 test_nonrelated_hang();
760
761         igt_subtest("global-count")
762                 test_global_reset_count();
763
764         igt_subtest("double-destroy-pending")
765                 test_double_destroy_pending();
766
767         igt_subtest("close-pending")
768                 test_close_pending();
769
770         igt_subtest("params")
771                 test_params();
772 }