tests: add gem_reset_stats
[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
206         srandom(time(NULL));
207
208         buf = malloc(BUFSIZE);
209         igt_assert(buf != NULL);
210
211         buf[0] = MI_BATCH_BUFFER_END;
212         buf[1] = MI_NOOP;
213
214         exec.handle = gem_create(fd, BUFSIZE);
215         gem_write(fd, exec.handle, 0, buf, BUFSIZE);
216         exec.relocation_count = 0;
217         exec.relocs_ptr = 0;
218         exec.alignment = 0;
219         exec.offset = 0;
220         exec.flags = 0;
221         exec.rsvd1 = 0;
222         exec.rsvd2 = 0;
223
224         execbuf.buffers_ptr = (uintptr_t)&exec;
225         execbuf.buffer_count = 1;
226         execbuf.batch_start_offset = 0;
227         execbuf.batch_len = BUFSIZE;
228         execbuf.cliprects_ptr = 0;
229         execbuf.num_cliprects = 0;
230         execbuf.DR1 = 0;
231         execbuf.DR4 = 0;
232         execbuf.flags = 0;
233         i915_execbuffer2_set_context_id(execbuf, ctx);
234         execbuf.rsvd2 = 0;
235
236         igt_assert(gem_exec(fd, &execbuf) == 0);
237
238         gtt_off = exec.offset;
239
240         for (i = 0; i < ITEMS; i++)
241                 buf[i] = MI_NOOP;
242
243         roff = random() % (ITEMS - 2);
244         buf[roff] = MI_BATCH_BUFFER_START;
245         buf[roff + 1] = gtt_off + (roff << 2);
246
247 #ifdef VERBOSE
248         printf("loop injected at 0x%lx (off 0x%x, bo_start 0x%lx, bo_end 0x%lx)\n",
249                (long unsigned int)((roff << 2) + gtt_off),
250                roff << 2, (long unsigned int)gtt_off,
251                (long unsigned int)(gtt_off + BUFSIZE - 1));
252 #endif
253         gem_write(fd, exec.handle, 0, buf, BUFSIZE);
254
255         exec.relocation_count = 0;
256         exec.relocs_ptr = 0;
257         exec.alignment = 0;
258         exec.offset = 0;
259         exec.flags = 0;
260         exec.rsvd1 = 0;
261         exec.rsvd2 = 0;
262
263         execbuf.buffers_ptr = (uintptr_t)&exec;
264         execbuf.buffer_count = 1;
265         execbuf.batch_start_offset = 0;
266         execbuf.batch_len = BUFSIZE;
267         execbuf.cliprects_ptr = 0;
268         execbuf.num_cliprects = 0;
269         execbuf.DR1 = 0;
270         execbuf.DR4 = 0;
271         execbuf.flags = 0;
272         i915_execbuffer2_set_context_id(execbuf, ctx);
273         execbuf.rsvd2 = 0;
274
275         igt_assert(gem_exec(fd, &execbuf) == 0);
276
277         igt_assert(gtt_off == exec.offset);
278
279         free(buf);
280
281         return exec.handle;
282 }
283
284 static int _assert_reset_status(int fd, int ctx, int status)
285 {
286         int rs;
287
288         rs = gem_reset_status(fd, ctx);
289         if (rs < 0) {
290                 printf("reset status for %d ctx %d returned %d\n",
291                        fd, ctx, rs);
292                 return rs;
293         }
294
295         if (rs != status) {
296                 printf("%d:%d reset status %d differs from assumed %d\n",
297                        fd, ctx, rs, status);
298
299                 return 1;
300         }
301
302         return 0;
303 }
304
305 #define assert_reset_status(fd, ctx, status) \
306         igt_assert(_assert_reset_status(fd, ctx, status) == 0)
307
308 static void test_rs(int num_fds, int hang_index, int rs_assumed_no_hang)
309 {
310         int i;
311         int fd[MAX_FD];
312         int h[MAX_FD];
313
314         igt_assert (num_fds <= MAX_FD);
315         igt_assert (hang_index < MAX_FD);
316
317         for (i = 0; i < num_fds; i++) {
318                 fd[i] = drm_open_any();
319                 igt_assert(fd[i]);
320         }
321
322         for (i = 0; i < num_fds; i++)
323                 assert_reset_status(fd[i], 0, RS_NO_ERROR);
324
325         for (i = 0; i < num_fds; i++) {
326                 if (i == hang_index)
327                         h[i] = inject_hang(fd[i], 0);
328                 else
329                         h[i] = exec_valid(fd[i], 0);
330         }
331
332         gem_sync(fd[num_fds - 1], h[num_fds - 1]);
333
334         for (i = 0; i < num_fds; i++) {
335                 if (hang_index < 0) {
336                         assert_reset_status(fd[i], 0, rs_assumed_no_hang);
337                         continue;
338                 }
339
340                 if (i < hang_index)
341                         assert_reset_status(fd[i], 0, RS_NO_ERROR);
342                 if (i == hang_index)
343                         assert_reset_status(fd[i], 0, RS_BATCH_ACTIVE);
344                 if (i > hang_index)
345                         assert_reset_status(fd[i], 0, RS_BATCH_PENDING);
346         }
347
348         for (i = 0; i < num_fds; i++) {
349                 gem_close(fd[i], h[i]);
350                 close(fd[i]);
351         }
352 }
353
354 #define MAX_CTX 100
355 static void test_rs_ctx(int num_fds, int num_ctx, int hang_index,
356                         int hang_context)
357 {
358         int i, j;
359         int fd[MAX_FD];
360         int h[MAX_FD][MAX_CTX];
361         int ctx[MAX_FD][MAX_CTX];
362
363         igt_assert (num_fds <= MAX_FD);
364         igt_assert (hang_index < MAX_FD);
365
366         igt_assert (num_ctx <= MAX_CTX);
367         igt_assert (hang_context < MAX_CTX);
368
369         test_rs(num_fds, -1, RS_NO_ERROR);
370
371         for (i = 0; i < num_fds; i++) {
372                 fd[i] = drm_open_any();
373                 igt_assert(fd[i]);
374                 assert_reset_status(fd[i], 0, RS_NO_ERROR);
375
376                 for (j = 0; j < num_ctx; j++) {
377                         ctx[i][j] = context_create(fd[i]);
378
379                 }
380
381                 assert_reset_status(fd[i], 0, RS_NO_ERROR);
382         }
383
384         for (i = 0; i < num_fds; i++) {
385
386                 assert_reset_status(fd[i], 0, RS_NO_ERROR);
387
388                 for (j = 0; j < num_ctx; j++)
389                         assert_reset_status(fd[i], ctx[i][j], RS_NO_ERROR);
390
391                 assert_reset_status(fd[i], 0, RS_NO_ERROR);
392         }
393
394         for (i = 0; i < num_fds; i++) {
395                 for (j = 0; j < num_ctx; j++) {
396                         if (i == hang_index && j == hang_context)
397                                 h[i][j] = inject_hang(fd[i], ctx[i][j]);
398                         else
399                                 h[i][j] = exec_valid(fd[i], ctx[i][j]);
400                 }
401         }
402
403         gem_sync(fd[num_fds - 1], ctx[num_fds - 1][num_ctx - 1]);
404
405         for (i = 0; i < num_fds; i++)
406                 assert_reset_status(fd[i], 0, RS_NO_ERROR);
407
408         for (i = 0; i < num_fds; i++) {
409                 for (j = 0; j < num_ctx; j++) {
410                         if (i < hang_index)
411                                 assert_reset_status(fd[i], ctx[i][j], RS_NO_ERROR);
412                         if (i == hang_index && j < hang_context)
413                                 assert_reset_status(fd[i], ctx[i][j], RS_NO_ERROR);
414                         if (i == hang_index && j == hang_context)
415                                 assert_reset_status(fd[i], ctx[i][j],
416                                                     RS_BATCH_ACTIVE);
417                         if (i == hang_index && j > hang_context)
418                                 assert_reset_status(fd[i], ctx[i][j],
419                                                     RS_BATCH_PENDING);
420                         if (i > hang_index)
421                                 assert_reset_status(fd[i], ctx[i][j],
422                                                     RS_BATCH_PENDING);
423                 }
424         }
425
426         for (i = 0; i < num_fds; i++) {
427                 for (j = 0; j < num_ctx; j++) {
428                         gem_close(fd[i], h[i][j]);
429                         igt_assert(context_destroy(fd[i], ctx[i][j]) == 0);
430                 }
431
432                 assert_reset_status(fd[i], 0, RS_NO_ERROR);
433
434                 close(fd[i]);
435         }
436 }
437
438 static void test_ban(void)
439 {
440         int h1,h2,h3,h4,h5,h6,h7;
441         int ctx_good, ctx_bad;
442         int fd;
443         int retry = 10;
444         int active_count = 0, pending_count = 0;
445         struct local_drm_i915_reset_stats rs_bad, rs_good;
446
447         fd = drm_open_any();
448         igt_assert(fd >= 0);
449
450         assert_reset_status(fd, 0, RS_NO_ERROR);
451
452         ctx_good = context_create(fd);
453         ctx_bad = context_create(fd);
454
455         assert_reset_status(fd, 0, RS_NO_ERROR);
456         assert_reset_status(fd, ctx_good, RS_NO_ERROR);
457         assert_reset_status(fd, ctx_bad, RS_NO_ERROR);
458
459         h1 = exec_valid(fd, ctx_bad);
460         igt_assert(h1 >= 0);
461         h5 = exec_valid(fd, ctx_good);
462         igt_assert(h5 >= 0);
463
464         assert_reset_status(fd, ctx_good, RS_NO_ERROR);
465         assert_reset_status(fd, ctx_bad, RS_NO_ERROR);
466
467         h2 = inject_hang(fd, ctx_bad);
468         igt_assert(h2 >= 0);
469         active_count++;
470         /* Second hang will be pending for this */
471         pending_count++;
472
473         h6 = exec_valid(fd, ctx_good);
474         h7 = exec_valid(fd, ctx_good);
475
476         while (retry--) {
477                 h3 = inject_hang(fd, ctx_bad);
478                 igt_assert(h3 >= 0);
479                 gem_sync(fd, h3);
480                 active_count++;
481                 /* This second hand will count as pending */
482                 assert_reset_status(fd, ctx_bad, RS_BATCH_ACTIVE);
483
484                 h4 = exec_valid(fd, ctx_bad);
485                 if (h4 == -EIO) {
486                         gem_close(fd, h3);
487                         break;
488                 }
489
490                 /* Should not happen often but sometimes hang is declared too slow
491                  * due to our way of faking hang using loop */
492
493                 igt_assert(h4 >= 0);
494                 gem_close(fd, h3);
495                 gem_close(fd, h4);
496
497                 printf("retrying for ban (%d)\n", retry);
498         }
499
500         igt_assert(h4 == -EIO);
501         assert_reset_status(fd, ctx_bad, RS_BATCH_ACTIVE);
502
503         gem_sync(fd, h7);
504         assert_reset_status(fd, ctx_good, RS_BATCH_PENDING);
505
506         igt_assert(gem_reset_stats(fd, ctx_good, &rs_good) == 0);
507         igt_assert(gem_reset_stats(fd, ctx_bad, &rs_bad) == 0);
508
509         igt_assert(rs_bad.batch_active == active_count);
510         igt_assert(rs_bad.batch_pending == pending_count);
511         igt_assert(rs_good.batch_active == 0);
512         igt_assert(rs_good.batch_pending == 2);
513
514         gem_close(fd, h1);
515         gem_close(fd, h2);
516         gem_close(fd, h6);
517         gem_close(fd, h7);
518
519         h1 = exec_valid(fd, ctx_good);
520         igt_assert(h1 >= 0);
521         gem_close(fd, h1);
522
523         igt_assert(context_destroy(fd, ctx_good) == 0);
524         igt_assert(context_destroy(fd, ctx_bad) == 0);
525         igt_assert(gem_reset_status(fd, ctx_good) < 0);
526         igt_assert(gem_reset_status(fd, ctx_bad) < 0);
527         igt_assert(exec_valid(fd, ctx_good) < 0);
528         igt_assert(exec_valid(fd, ctx_bad) < 0);
529
530         close(fd);
531 }
532
533 static void test_nonrelated_hang(void)
534 {
535         int h1,h2;
536         int fd1,fd2;
537         int ctx_guilty, ctx_unrelated;
538
539         fd1 = drm_open_any();
540         fd2 = drm_open_any();
541         assert_reset_status(fd1, 0, RS_NO_ERROR);
542         assert_reset_status(fd2, 0, RS_NO_ERROR);
543         ctx_guilty = context_create(fd1);
544         ctx_unrelated = context_create(fd2);
545
546         assert_reset_status(fd1, ctx_guilty, RS_NO_ERROR);
547         assert_reset_status(fd2, ctx_unrelated, RS_NO_ERROR);
548
549         h1 = inject_hang(fd1, ctx_guilty);
550         igt_assert(h1 >= 0);
551         gem_sync(fd1, h1);
552         assert_reset_status(fd1, ctx_guilty, RS_BATCH_ACTIVE);
553         assert_reset_status(fd2, ctx_unrelated, RS_NO_ERROR);
554
555         h2 = exec_valid(fd2, ctx_unrelated);
556         igt_assert(h2 >= 0);
557         gem_sync(fd2, h2);
558         assert_reset_status(fd1, ctx_guilty, RS_BATCH_ACTIVE);
559         assert_reset_status(fd2, ctx_unrelated, RS_NO_ERROR);
560         gem_close(fd1, h1);
561         gem_close(fd2, h2);
562
563         igt_assert(context_destroy(fd1, ctx_guilty) == 0);
564         igt_assert(context_destroy(fd2, ctx_unrelated) == 0);
565
566         close(fd1);
567         close(fd2);
568 }
569
570 static int get_reset_count(int fd, int ctx)
571 {
572         int ret;
573         struct local_drm_i915_reset_stats rs;
574
575         ret = gem_reset_stats(fd, ctx, &rs);
576         if (ret)
577                 return ret;
578
579         return rs.reset_count;
580 }
581
582 static void test_double_destroy_pending(void)
583 {
584         int fd, h;
585         uint32_t ctx;
586
587         fd = drm_open_any();
588         igt_assert(fd >= 0);
589         ctx = context_create(fd);
590
591         assert_reset_status(fd, ctx, RS_NO_ERROR);
592
593         h = inject_hang(fd, ctx);
594         igt_assert(h >= 0);
595         igt_assert(context_destroy(fd, ctx) == 0);
596         igt_assert(context_destroy(fd, ctx) == -ENOENT);
597
598         gem_close(fd, h);
599         close(fd);
600 }
601
602 static void test_close_pending(void)
603 {
604         int fd, h;
605
606         fd = drm_open_any();
607         igt_assert(fd >= 0);
608
609         assert_reset_status(fd, 0, RS_NO_ERROR);
610
611         h = inject_hang(fd, 0);
612         igt_assert(h >= 0);
613
614         gem_close(fd, h);
615         close(fd);
616 }
617
618 static void __test_count(const bool create_ctx)
619 {
620         int fd, h, ctx;
621         long c1, c2;
622
623         fd = drm_open_any();
624         igt_assert(fd >= 0);
625         if (create_ctx)
626                 ctx = context_create(fd);
627         else
628                 ctx = 0;
629
630         assert_reset_status(fd, ctx, RS_NO_ERROR);
631
632         c1 = get_reset_count(fd, ctx);
633         igt_assert(c1 >= 0);
634
635         h = inject_hang(fd, ctx);
636         igt_assert (h >= 0);
637         gem_sync(fd, h);
638
639         assert_reset_status(fd, ctx, RS_BATCH_ACTIVE);
640         c2 = get_reset_count(fd, ctx);
641         igt_assert(c2 >= 0);
642
643         igt_assert(c2 == (c1 + 1));
644
645         gem_close(fd, h);
646
647         if (create_ctx)
648                 context_destroy(fd, ctx);
649
650         close(fd);
651 }
652
653 static void test_count(void)
654 {
655         return __test_count(false);
656 }
657
658 static void test_count_context(void)
659 {
660         return __test_count(true);
661 }
662
663 static void test_global_reset_count(void)
664 {
665         test_count();
666         test_count_context();
667 }
668
669 static int _test_params(int fd, int ctx, uint32_t flags, uint32_t pad)
670 {
671         struct local_drm_i915_reset_stats rs;
672         int ret;
673
674         rs.ctx_id = ctx;
675         rs.flags = flags;
676         rs.reset_count = rand();
677         rs.batch_active = rand();
678         rs.batch_pending = rand();
679         rs.pad = pad;
680
681         do {
682                 ret = ioctl(fd, GET_RESET_STATS_IOCTL, &rs);
683         } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
684
685         if (ret < 0)
686                 return -errno;
687
688         return 0;
689 }
690
691 static void test_param_ctx(int fd, int ctx)
692 {
693         const uint32_t bad = rand() + 1;
694
695         igt_assert(_test_params(fd, ctx, 0, 0) == 0);
696         igt_assert(_test_params(fd, ctx, 0, bad) == -EINVAL);
697         igt_assert(_test_params(fd, ctx, bad, 0) == -EINVAL);
698         igt_assert(_test_params(fd, ctx, bad, bad) == -EINVAL);
699 }
700
701 static void test_params(void)
702 {
703         int fd, ctx;
704
705         fd = drm_open_any();
706         igt_assert(fd >= 0);
707         ctx = context_create(fd);
708
709         igt_assert(ioctl(fd, GET_RESET_STATS_IOCTL, 0) == -1);
710
711         igt_assert(_test_params(fd, 0xbadbad, 0, 0) == -ENOENT);
712
713         test_param_ctx(fd, 0);
714         test_param_ctx(fd, ctx);
715
716         close(fd);
717 }
718
719
720 int main(int argc, char **argv)
721 {
722         struct local_drm_i915_gem_context_create create;
723         uint32_t devid;
724         int fd;
725         int ret;
726
727         igt_skip_on_simulation();
728
729         igt_subtest_init(argc, argv);
730
731         igt_fixture {
732                 fd = drm_open_any();
733                 devid = intel_get_drm_devid(fd);
734                 if (intel_gen(devid) < 4)
735                         igt_skip("Architecture %d too old\n", intel_gen(devid));
736
737                 ret = drmIoctl(fd, CONTEXT_CREATE_IOCTL, &create);
738                 if (ret != 0 && (errno == ENODEV || errno == EINVAL))
739                         igt_skip("Kernel is too old, or contexts not supported: %s\n",
740                                  strerror(errno));
741
742                 close(fd);
743         }
744
745         igt_subtest("basic-reset-status")
746                 test_rs(4, 1, 0);
747
748         igt_subtest("context-reset-status")
749                 test_rs_ctx(4, 4, 1, 2);
750
751         igt_subtest("ban")
752                 test_ban();
753
754         igt_subtest("ctx-unrelated")
755                 test_nonrelated_hang();
756
757         igt_subtest("global-count")
758                 test_global_reset_count();
759
760         igt_subtest("double-destroy-pending")
761                 test_double_destroy_pending();
762
763         igt_subtest("close-pending")
764                 test_close_pending();
765
766         igt_subtest("params")
767                 test_params();
768
769         igt_exit();
770 }