2 * Copyright 2012 Intel Corporation
3 * Jesse Barnes <jesse.barnes@intel.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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 THE
18 * 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
36 #include <sys/ioctl.h>
41 #include "ioctl_wrappers.h"
43 #include "intel_chipset.h"
44 #include "intel_batchbuffer.h"
47 #include "igt_debugfs.h"
49 #define TEST_DPMS (1 << 0)
50 #define TEST_WITH_DUMMY_BCS (1 << 1)
51 #define TEST_WITH_DUMMY_RCS (1 << 2)
52 #define TEST_PAN (1 << 3)
53 #define TEST_MODESET (1 << 4)
54 #define TEST_CHECK_TS (1 << 5)
55 #define TEST_EBUSY (1 << 6)
56 #define TEST_EINVAL (1 << 7)
57 #define TEST_FLIP (1 << 8)
58 #define TEST_VBLANK (1 << 9)
59 #define TEST_VBLANK_BLOCK (1 << 10)
60 #define TEST_VBLANK_ABSOLUTE (1 << 11)
61 #define TEST_VBLANK_EXPIRED_SEQ (1 << 12)
62 #define TEST_FB_RECREATE (1 << 13)
63 #define TEST_RMFB (1 << 14)
64 #define TEST_HANG (1 << 15)
65 #define TEST_NOEVENT (1 << 16)
66 #define TEST_FB_BAD_TILING (1 << 17)
67 #define TEST_SINGLE_BUFFER (1 << 18)
68 #define TEST_DPMS_OFF (1 << 19)
69 #define TEST_NO_2X_OUTPUT (1 << 20)
70 #define TEST_DPMS_OFF_OTHERS (1 << 21)
71 #define TEST_ENOENT (1 << 22)
72 #define TEST_FENCE_STRESS (1 << 23)
73 #define TEST_VBLANK_RACE (1 << 24)
74 #define TEST_RPM (1 << 25)
75 #define TEST_SUSPEND (1 << 26)
76 #define TEST_TS_CONT (1 << 27)
77 #define TEST_BO_TOOBIG (1 << 28)
78 #define TEST_HANG_ONCE (1 << 29)
80 #define EVENT_FLIP (1 << 0)
81 #define EVENT_VBLANK (1 << 1)
83 #ifndef DRM_CAP_TIMESTAMP_MONOTONIC
84 #define DRM_CAP_TIMESTAMP_MONOTONIC 6
87 #define max(a, b) ((a) > (b) ? (a) : (b))
89 drmModeRes *resources;
91 static drm_intel_bufmgr *bufmgr;
92 struct intel_batchbuffer *batch;
95 static bool monotonic_timestamp;
96 static pthread_t vblank_wait_thread;
98 static drmModeConnector *last_connector;
111 * Event data for the last event that has already passed our check.
112 * Updated using the below current_* vars in update_state().
114 struct timeval last_ts; /* kernel reported timestamp */
115 struct timeval last_received_ts; /* the moment we received it */
116 unsigned int last_seq; /* kernel reported seq. num */
119 * Event data for for the current event that we just received and
120 * going to check for validity. Set in event_handler().
122 struct timeval current_ts; /* kernel reported timestamp */
123 struct timeval current_received_ts; /* the moment we received it */
124 unsigned int current_seq; /* kernel reported seq. num */
126 int count; /* # of events of this type */
128 /* Step between the current and next 'target' sequence number. */
134 drmModeModeInfo kmode[4];
135 drmModeEncoder *kencoder[4];
136 drmModeConnector *kconnector[4];
137 uint32_t _connector[4];
139 int count; /* 1:1 mapping between crtc:connector */
141 int pipe; /* primary pipe for vblank */
142 unsigned int current_fb_id;
143 unsigned int fb_width;
144 unsigned int fb_height;
145 unsigned int fb_ids[3];
147 struct igt_fb fb_info[3];
149 struct event_state flip_state;
150 struct event_state vblank_state;
151 /* Overall step between each round */
153 unsigned int pending_events;
158 static unsigned long gettime_us(void)
162 clock_gettime(CLOCK_MONOTONIC, &ts);
164 return ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
167 static void emit_dummy_load__bcs(struct test_output *o)
170 drm_intel_bo *dummy_bo, *target_bo, *tmp_bo;
171 struct igt_fb *fb_info = &o->fb_info[o->current_fb_id];
172 unsigned pitch = fb_info->stride;
174 limit = intel_gen(devid) < 6 ? 500 : 5000;
176 dummy_bo = drm_intel_bo_alloc(bufmgr, "dummy_bo", fb_info->size, 4096);
177 igt_assert(dummy_bo);
178 target_bo = gem_handle_to_libdrm_bo(bufmgr, drm_fd, "imported", fb_info->gem_handle);
179 igt_assert(target_bo);
181 for (i = 0; i < limit; i++) {
182 BLIT_COPY_BATCH_START(devid, 0);
183 OUT_BATCH((3 << 24) | /* 32 bits */
184 (0xcc << 16) | /* copy ROP */
186 OUT_BATCH(0 << 16 | 0);
187 OUT_BATCH(o->fb_height << 16 | o->fb_width);
188 OUT_RELOC_FENCED(dummy_bo, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
189 OUT_BATCH(0 << 16 | 0);
191 OUT_RELOC_FENCED(target_bo, I915_GEM_DOMAIN_RENDER, 0, 0);
194 if (IS_GEN6(devid) || IS_GEN7(devid)) {
196 OUT_BATCH(XY_SETUP_CLIP_BLT_CMD);
203 dummy_bo = target_bo;
206 intel_batchbuffer_flush(batch);
208 drm_intel_bo_unreference(dummy_bo);
209 drm_intel_bo_unreference(target_bo);
212 static void emit_fence_stress(struct test_output *o)
214 const int num_fences = gem_available_fences(drm_fd);
215 struct igt_fb *fb_info = &o->fb_info[o->current_fb_id];
216 struct drm_i915_gem_execbuffer2 execbuf;
217 struct drm_i915_gem_exec_object2 *exec;
218 uint32_t buf[2] = { MI_BATCH_BUFFER_END, 0 };
222 bo = calloc(sizeof(*bo), num_fences);
223 exec = calloc(sizeof(*exec), num_fences+1);
224 for (i = 0; i < num_fences - 1; i++) {
225 uint32_t tiling = I915_TILING_X;
226 unsigned long pitch = 0;
227 bo[i] = drm_intel_bo_alloc_tiled(bufmgr,
228 "X tiled bo", 1024, 1024, 4,
230 exec[i].handle = bo[i]->handle;
231 exec[i].flags = EXEC_OBJECT_NEEDS_FENCE;
233 exec[i].handle = fb_info->gem_handle;
234 exec[i].flags = EXEC_OBJECT_NEEDS_FENCE;
235 exec[++i].handle = gem_create(drm_fd, 4096);
236 gem_write(drm_fd, exec[i].handle, 0, buf, sizeof(buf));
238 memset(&execbuf, 0, sizeof(execbuf));
239 execbuf.buffers_ptr = (uintptr_t)exec;
240 execbuf.buffer_count = i + 1;
241 execbuf.batch_len = sizeof(buf);
242 if (HAS_BLT_RING(intel_get_drm_devid(drm_fd)))
243 execbuf.flags = I915_EXEC_BLT;
245 gem_execbuf(drm_fd, &execbuf);
247 gem_close(drm_fd, exec[i].handle);
248 for (i = 0; i < num_fences - 1; i++)
249 drm_intel_bo_unreference(bo[i]);
254 static void emit_dummy_load__rcs(struct test_output *o)
256 const struct igt_fb *fb_info = &o->fb_info[o->current_fb_id];
257 igt_render_copyfunc_t copyfunc;
258 struct igt_buf sb[2], *src, *dst;
261 copyfunc = igt_get_render_copyfunc(devid);
262 if (copyfunc == NULL)
263 return emit_dummy_load__bcs(o);
265 limit = intel_gen(devid) < 6 ? 500 : 5000;
267 sb[0].bo = drm_intel_bo_alloc(bufmgr, "dummy_bo", fb_info->size, 4096);
268 igt_assert(sb[0].bo);
269 sb[0].size = sb[0].bo->size;
270 sb[0].tiling = I915_TILING_NONE;
272 sb[0].num_tiles = sb[0].bo->size;
273 sb[0].stride = 4 * o->fb_width;
275 sb[1].bo = gem_handle_to_libdrm_bo(bufmgr, drm_fd, "imported", fb_info->gem_handle);
276 igt_assert(sb[1].bo);
277 sb[1].size = sb[1].bo->size;
278 sb[1].tiling = fb_info->tiling;
280 sb[1].num_tiles = sb[1].bo->size;
281 sb[1].stride = fb_info->stride;
286 for (i = 0; i < limit; i++) {
289 copyfunc(batch, NULL,
291 o->fb_width, o->fb_height,
298 intel_batchbuffer_flush(batch);
300 drm_intel_bo_unreference(sb[0].bo);
301 drm_intel_bo_unreference(sb[1].bo);
304 static void dpms_off_other_outputs(struct test_output *o)
307 drmModeConnector *connector;
308 uint32_t connector_id;
310 for (i = 0; i < resources->count_connectors; i++) {
311 connector_id = resources->connectors[i];
313 for (n = 0; n < o->count; n++) {
314 if (connector_id == o->kconnector[n]->connector_id)
318 connector = drmModeGetConnector(drm_fd, connector_id);
320 kmstest_set_connector_dpms(drm_fd, connector, DRM_MODE_DPMS_ON);
321 kmstest_set_connector_dpms(drm_fd, connector, DRM_MODE_DPMS_OFF);
323 drmModeFreeConnector(connector);
329 static void set_dpms(struct test_output *o, int mode)
331 for (int n = 0; n < o->count; n++)
332 kmstest_set_connector_dpms(drm_fd, o->kconnector[n], mode);
335 static void set_flag(unsigned int *v, unsigned int flag)
337 igt_assert(!(*v & flag));
341 static void clear_flag(unsigned int *v, unsigned int flag)
343 igt_assert(*v & flag);
347 static int do_page_flip(struct test_output *o, uint32_t fb_id, bool event)
353 for (n = 0; ret == 0 && n < o->count; n++)
354 ret = drmModePageFlip(drm_fd, o->_crtc[n], fb_id,
355 event ? DRM_MODE_PAGE_FLIP_EVENT : 0,
356 event ? (void *)((unsigned long)o | (n==0)) : NULL);
358 if (ret == 0 && event)
359 set_flag(&o->pending_events, EVENT_FLIP);
364 struct vblank_reply {
365 unsigned int sequence;
369 static int __wait_for_vblank(unsigned int flags, int crtc_idx,
370 int target_seq, unsigned long ret_data,
371 struct vblank_reply *reply)
375 unsigned crtc_idx_mask;
376 bool event = !(flags & TEST_VBLANK_BLOCK);
378 memset(&wait_vbl, 0, sizeof(wait_vbl));
380 crtc_idx_mask = crtc_idx << DRM_VBLANK_HIGH_CRTC_SHIFT;
381 igt_assert(!(crtc_idx_mask & ~DRM_VBLANK_HIGH_CRTC_MASK));
383 wait_vbl.request.type = crtc_idx_mask;
384 if (flags & TEST_VBLANK_ABSOLUTE)
385 wait_vbl.request.type |= DRM_VBLANK_ABSOLUTE;
387 wait_vbl.request.type |= DRM_VBLANK_RELATIVE;
389 wait_vbl.request.type |= DRM_VBLANK_EVENT;
390 wait_vbl.request.signal = ret_data;
392 wait_vbl.request.sequence = target_seq;
394 ret = drmWaitVBlank(drm_fd, &wait_vbl);
397 reply->ts.tv_sec = wait_vbl.reply.tval_sec;
398 reply->ts.tv_usec = wait_vbl.reply.tval_usec;
399 reply->sequence = wait_vbl.reply.sequence;
406 static int do_wait_for_vblank(struct test_output *o, int pipe_id,
407 int target_seq, struct vblank_reply *reply)
410 unsigned flags = o->flags;
412 /* Absolute waits only works once we have a frame counter. */
413 if (!(o->vblank_state.count > 0))
414 flags &= ~TEST_VBLANK_ABSOLUTE;
416 ret = __wait_for_vblank(flags, pipe_id, target_seq, (unsigned long)o,
418 if (ret == 0 && !(o->flags & TEST_VBLANK_BLOCK))
419 set_flag(&o->pending_events, EVENT_VBLANK);
425 analog_tv_connector(struct test_output *o)
427 uint32_t connector_type = o->kconnector[0]->connector_type;
429 return connector_type == DRM_MODE_CONNECTOR_TV ||
430 connector_type == DRM_MODE_CONNECTOR_9PinDIN ||
431 connector_type == DRM_MODE_CONNECTOR_SVIDEO ||
432 connector_type == DRM_MODE_CONNECTOR_Composite;
435 static void event_handler(struct event_state *es, unsigned int frame,
436 unsigned int sec, unsigned int usec)
440 if (monotonic_timestamp) {
443 clock_gettime(CLOCK_MONOTONIC, &ts);
444 now.tv_sec = ts.tv_sec;
445 now.tv_usec = ts.tv_nsec / 1000;
447 gettimeofday(&now, NULL);
449 es->current_received_ts = now;
451 es->current_ts.tv_sec = sec;
452 es->current_ts.tv_usec = usec;
453 es->current_seq = frame;
456 static void page_flip_handler(int fd, unsigned int frame, unsigned int sec,
457 unsigned int usec, void *data)
459 int primary = (unsigned long)data & 1;
460 struct test_output *o = (void *)((unsigned long)data & ~ 1);
462 if (++o->flip_count == o->count)
463 clear_flag(&o->pending_events, EVENT_FLIP);
465 event_handler(&o->flip_state, frame, sec, usec);
468 static double frame_time(struct test_output *o)
470 return 1000.0 * 1000.0 / o->kmode[0].vrefresh;
473 static void *vblank_wait_thread_func(void *data)
475 struct test_output *o = data;
476 struct vblank_reply reply;
479 for (i = 0; i < 32; i++) {
480 unsigned long start = gettime_us();
481 __wait_for_vblank(TEST_VBLANK_BLOCK, o->pipe, 20, (unsigned long)o, &reply);
482 if (gettime_us() - start > 2 * frame_time(o))
489 static void spawn_vblank_wait_thread(struct test_output *o)
491 igt_assert(pthread_create(&vblank_wait_thread, NULL,
492 vblank_wait_thread_func, o) == 0);
495 static void join_vblank_wait_thread(void)
497 igt_assert(pthread_join(vblank_wait_thread, NULL) == 0);
500 static void fixup_premature_vblank_ts(struct test_output *o,
501 struct event_state *es)
504 * In case a power off event preempts the completion of a
505 * wait-for-vblank event the kernel will return a wf-vblank event with
506 * a zeroed-out timestamp. In order that check_state() doesn't
507 * complain replace this ts with a valid ts. As we can't calculate the
508 * exact timestamp, just use the time we received the event.
512 if (!(o->flags & (TEST_DPMS | TEST_MODESET)))
515 if (o->vblank_state.current_ts.tv_sec != 0 ||
516 o->vblank_state.current_ts.tv_usec != 0)
521 timersub(&es->current_received_ts, &tv, &es->current_ts);
524 static void vblank_handler(int fd, unsigned int frame, unsigned int sec,
525 unsigned int usec, void *data)
527 struct test_output *o = data;
529 clear_flag(&o->pending_events, EVENT_VBLANK);
530 event_handler(&o->vblank_state, frame, sec, usec);
531 fixup_premature_vblank_ts(o, &o->vblank_state);
534 static void check_state(struct test_output *o, struct event_state *es)
537 double usec_interflip;
539 timersub(&es->current_ts, &es->current_received_ts, &diff);
540 if (!analog_tv_connector(o)) {
541 igt_assert_f(diff.tv_sec < 0 || (diff.tv_sec == 0 && diff.tv_usec <= 2000),
542 "%s ts delayed for too long: %is, %iusec\n",
543 es->name, (int)diff.tv_sec, (int)diff.tv_usec);
550 timersub(&es->current_ts, &es->last_received_ts, &diff);
551 igt_assert_f(timercmp(&es->last_received_ts, &es->current_ts, <),
552 "%s ts before the %s was issued!\n"
553 "timerdiff %is, %ius\n",
555 (int) diff.tv_sec, (int) diff.tv_usec);
557 /* check only valid if no modeset happens in between, that increments by
558 * (1 << 23) on each step. This bounding matches the one in
559 * DRM_IOCTL_WAIT_VBLANK. */
560 if (!(o->flags & (TEST_DPMS | TEST_MODESET)))
561 igt_assert_f(es->current_seq - (es->last_seq + o->seq_step) <= 1UL << 23,
562 "unexpected %s seq %u, should be >= %u\n",
563 es->name, es->current_seq, es->last_seq + o->seq_step);
565 /* Check that the vblank frame didn't wrap unexpectedly. */
566 if (o->flags & TEST_TS_CONT) {
567 /* Ignore seq_step here since vblank waits time out immediately
568 * when we kill the crtc. */
569 igt_assert_f(es->current_seq - es->last_seq >= 0,
570 "unexpected %s seq %u, should be >= %u\n",
571 es->name, es->current_seq, es->last_seq);
572 igt_assert_f(es->current_seq - es->last_seq <= 100,
573 "unexpected %s seq %u, should be < %u\n",
574 es->name, es->current_seq, es->last_seq + 100);
576 igt_debug("testing ts continuity: Current frame %u, old frame %u\n",
577 es->current_seq, es->last_seq);
580 if ((o->flags & TEST_CHECK_TS) && (!analog_tv_connector(o))) {
581 timersub(&es->current_ts, &es->last_ts, &diff);
582 usec_interflip = (double)o->seq_step * frame_time(o);
584 igt_assert_f(fabs((((double) diff.tv_usec) - usec_interflip) /
585 usec_interflip) <= 0.005,
586 "inter-%s ts jitter: %is, %ius\n",
587 es->name, (int) diff.tv_sec, (int) diff.tv_usec);
589 igt_assert_f(es->current_seq == es->last_seq + o->seq_step,
590 "unexpected %s seq %u, expected %u\n",
591 es->name, es->current_seq,
592 es->last_seq + o->seq_step);
596 static void check_state_correlation(struct test_output *o,
597 struct event_state *es1,
598 struct event_state *es2)
600 struct timeval tv_diff;
605 if (es1->count == 0 || es2->count == 0)
608 timersub(&es2->current_ts, &es1->current_ts, &tv_diff);
609 usec_diff = tv_diff.tv_sec * 1000 * 1000 + tv_diff.tv_usec;
611 seq_diff = es2->current_seq - es1->current_seq;
612 ftime = frame_time(o);
613 usec_diff -= seq_diff * ftime;
615 igt_assert_f(fabs(usec_diff) / ftime <= 0.005,
616 "timestamp mismatch between %s and %s (diff %.4f sec)\n",
617 es1->name, es2->name, usec_diff / 1000 / 1000);
620 static void check_all_state(struct test_output *o,
621 unsigned int completed_events)
625 flip = completed_events & EVENT_FLIP;
626 vblank = completed_events & EVENT_VBLANK;
629 check_state(o, &o->flip_state);
631 check_state(o, &o->vblank_state);
633 /* FIXME: Correlation check is broken. */
634 if (flip && vblank && 0)
635 check_state_correlation(o, &o->flip_state, &o->vblank_state);
638 static void recreate_fb(struct test_output *o)
641 struct igt_fb *fb_info = &o->fb_info[o->current_fb_id];
644 /* Call rmfb/getfb/addfb to ensure those don't introduce stalls */
645 r = drmModeGetFB(drm_fd, fb_info->fb_id);
648 do_or_die(drmModeAddFB(drm_fd, o->fb_width, o->fb_height, o->depth,
649 o->bpp, fb_info->stride,
650 r->handle, &new_fb_id));
652 gem_close(drm_fd, r->handle);
654 do_or_die(drmModeRmFB(drm_fd, fb_info->fb_id));
656 o->fb_ids[o->current_fb_id] = new_fb_id;
657 o->fb_info[o->current_fb_id].fb_id = new_fb_id;
660 static void set_y_tiling(struct test_output *o, int fb_idx)
663 struct igt_fb *fb_info = &o->fb_info[fb_idx];
665 /* Call rmfb/getfb/addfb to ensure those don't introduce stalls */
666 r = drmModeGetFB(drm_fd, fb_info->fb_id);
668 /* Newer kernels don't allow such shenagians any more, so skip the test. */
669 igt_require(__gem_set_tiling(drm_fd, r->handle, I915_TILING_Y, fb_info->stride) == 0);
670 gem_close(drm_fd, r->handle);
674 static void stop_rings(bool stop)
677 igt_set_stop_rings(STOP_RING_DEFAULTS);
679 igt_set_stop_rings(STOP_RING_NONE);
682 static void eat_error_state(void)
684 static const char dfs_base[] = "/sys/kernel/debug/dri";
685 static const char dfs_entry_error[] = "i915_error_state";
686 static const char data[] = "";
687 char fname[FILENAME_MAX];
688 int card_index = drm_get_card();
691 igt_assert(card_index != -1);
693 /* clear the error state */
694 snprintf(fname, FILENAME_MAX, "%s/%i/%s",
695 dfs_base, card_index, dfs_entry_error);
697 fd = open(fname, O_WRONLY);
700 igt_assert(write(fd, data, sizeof(data)) == sizeof(data));
703 /* and check whether stop_rings is not reset, i.e. the hang has indeed
705 igt_assert_f(igt_get_stop_rings() == STOP_RING_NONE,
706 "no gpu hang detected, stop_rings is still 0x%x\n",
707 igt_get_stop_rings());
712 static void unhang_gpu(int fd, uint32_t handle)
714 gem_sync(drm_fd, handle);
715 gem_close(drm_fd, handle);
720 static uint32_t hang_gpu(int fd)
722 struct drm_i915_gem_execbuffer2 execbuf;
723 struct drm_i915_gem_exec_object2 gem_exec;
724 uint32_t b[2] = {MI_BATCH_BUFFER_END};
728 memset(&gem_exec, 0, sizeof(gem_exec));
729 gem_exec.handle = gem_create(fd, 4096);
730 gem_write(fd, gem_exec.handle, 0, b, sizeof(b));
732 memset(&execbuf, 0, sizeof(execbuf));
733 execbuf.buffers_ptr = (uintptr_t)&gem_exec;
734 execbuf.buffer_count = 1;
735 execbuf.batch_len = sizeof(b);
737 if (drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf)) {
738 igt_assert_f(errno == EIO,
739 "failed to exercise page flip hang recovery\n");
741 unhang_gpu(fd, gem_exec.handle);
745 return gem_exec.handle;
748 static bool is_hung(int fd)
750 if (drmIoctl(fd, DRM_IOCTL_I915_GEM_THROTTLE, 0) == 0)
756 static int set_mode(struct test_output *o, uint32_t fb, int x, int y)
760 for (n = 0; n < o->count; n++) {
762 int ret = drmModeSetCrtc(drm_fd, o->_crtc[n],
768 int ret = drmModeSetCrtc(drm_fd, o->_crtc[n],
770 &o->_connector[n], 1, &o->kmode[n]);
779 /* Return mask of completed events. */
780 static unsigned int run_test_step(struct test_output *o)
782 unsigned int new_fb_id;
783 /* for funny reasons page_flip returns -EBUSY on disabled crtcs ... */
784 int expected_einval = o->flags & TEST_MODESET ? -EBUSY : -EINVAL;
785 unsigned int completed_events = 0;
788 struct vblank_reply vbl_reply;
789 unsigned int target_seq;
790 uint32_t hang = 0; /* Suppress GCC warning */
792 target_seq = o->vblank_state.seq_step;
793 /* Absolute waits only works once we have a frame counter. */
794 if (o->flags & TEST_VBLANK_ABSOLUTE && o->vblank_state.count > 0)
795 target_seq += o->vblank_state.last_seq;
798 * It's possible that we don't have a pending flip here, in case both
799 * wf-vblank and flip were scheduled and the wf-vblank event was
800 * delivered earlier. The same applies to vblank events w.r.t flip.
802 do_flip = (o->flags & TEST_FLIP) && !(o->pending_events & EVENT_FLIP);
803 do_vblank = (o->flags & TEST_VBLANK) &&
804 !(o->pending_events & EVENT_VBLANK);
806 if (o->flags & TEST_DPMS_OFF_OTHERS)
807 dpms_off_other_outputs(o);
809 if (o->flags & TEST_WITH_DUMMY_BCS)
810 emit_dummy_load__bcs(o);
812 if (o->flags & TEST_WITH_DUMMY_RCS)
813 emit_dummy_load__rcs(o);
815 if (!(o->flags & TEST_SINGLE_BUFFER))
816 o->current_fb_id = !o->current_fb_id;
818 if (o->flags & TEST_FB_RECREATE)
820 new_fb_id = o->fb_ids[o->current_fb_id];
822 if (o->flags & TEST_FB_BAD_TILING)
823 new_fb_id = o->fb_ids[2];
825 if ((o->flags & TEST_VBLANK_EXPIRED_SEQ) &&
826 !(o->pending_events & EVENT_VBLANK) && o->flip_state.count > 0) {
827 struct vblank_reply reply;
828 unsigned int exp_seq;
831 exp_seq = o->flip_state.current_seq;
832 start = gettime_us();
833 do_or_die(__wait_for_vblank(TEST_VBLANK_ABSOLUTE |
834 TEST_VBLANK_BLOCK, o->pipe, exp_seq,
836 igt_assert(gettime_us() - start < 500);
837 igt_assert(reply.sequence == exp_seq);
838 igt_assert(timercmp(&reply.ts, &o->flip_state.last_ts, ==));
841 if (o->flags & TEST_ENOENT) {
842 /* hope that fb 0xfffffff0 does not exist */
843 igt_assert(do_page_flip(o, 0xfffffff0, false) == -ENOENT);
844 igt_assert(set_mode(o, 0xfffffff0, 0, 0) == -ENOENT);
847 if (do_flip && (o->flags & TEST_EINVAL) && o->flip_state.count > 0)
848 igt_assert(do_page_flip(o, new_fb_id, true) == expected_einval);
850 if (o->flags & TEST_FB_BAD_TILING)
851 new_fb_id = o->fb_ids[o->current_fb_id];
853 if (do_vblank && (o->flags & TEST_EINVAL) && o->vblank_state.count > 0)
854 igt_assert(do_wait_for_vblank(o, o->pipe, target_seq, &vbl_reply)
857 if (o->flags & TEST_VBLANK_RACE) {
858 spawn_vblank_wait_thread(o);
860 if (o->flags & TEST_MODESET)
861 igt_assert_f(set_mode(o, 0 /* no fb */, 0, 0) == 0,
862 "failed to disable output: %s\n",
866 if (o->flags & TEST_DPMS_OFF)
867 set_dpms(o, DRM_MODE_DPMS_OFF);
869 if (o->flags & TEST_MODESET)
870 igt_assert(set_mode(o, o->fb_ids[o->current_fb_id], 0, 0) == 0);
872 if (o->flags & TEST_DPMS)
873 set_dpms(o, DRM_MODE_DPMS_ON);
875 if (o->flags & TEST_VBLANK_RACE) {
876 struct vblank_reply reply;
877 unsigned long start, end;
879 /* modeset/DPMS is done, vblank wait should work normally now */
880 start = gettime_us();
881 igt_assert(__wait_for_vblank(TEST_VBLANK_BLOCK, o->pipe, 1, 0, &reply) == 0);
883 igt_assert(end - start > 1 * frame_time(o) / 2 &&
884 end - start < 3 * frame_time(o) / 2);
885 join_vblank_wait_thread();
888 igt_info("."); fflush(stdout);
890 if (do_flip && (o->flags & TEST_HANG)) {
891 hang = hang_gpu(drm_fd);
892 igt_assert_f(hang, "failed to exercise page flip hang recovery\n");
895 /* try to make sure we can issue two flips during the same frame */
896 if (do_flip && (o->flags & TEST_EBUSY)) {
897 struct vblank_reply reply;
898 igt_assert(__wait_for_vblank(TEST_VBLANK_BLOCK, o->pipe, 1, 0, &reply) == 0);
902 do_or_die(do_page_flip(o, new_fb_id, !(o->flags & TEST_NOEVENT)));
904 if (o->flags & TEST_FENCE_STRESS)
905 emit_fence_stress(o);
908 do_or_die(do_wait_for_vblank(o, o->pipe, target_seq,
910 if (o->flags & TEST_VBLANK_BLOCK) {
911 event_handler(&o->vblank_state, vbl_reply.sequence,
913 vbl_reply.ts.tv_usec);
914 completed_events = EVENT_VBLANK;
918 if (do_flip && (o->flags & TEST_EBUSY))
919 igt_assert(do_page_flip(o, new_fb_id, true) == -EBUSY);
921 if (do_flip && (o->flags & TEST_RMFB))
924 /* pan before the flip completes */
925 if (o->flags & TEST_PAN) {
926 int count = do_flip ?
927 o->flip_state.count : o->vblank_state.count;
928 int x_ofs = count * 10 > o->fb_width - o->kmode[0].hdisplay ? o->fb_width - o->kmode[0].hdisplay : count * 10;
930 /* Make sure DSPSURF changes value */
931 if (o->flags & TEST_HANG)
932 o->current_fb_id = !o->current_fb_id;
934 igt_assert_f(set_mode(o, o->fb_ids[o->current_fb_id], x_ofs, 0) == 0,
935 "failed to pan (%dx%d@%dHz)+%d: %s\n",
936 o->kmode[0].hdisplay, o->kmode[0].vdisplay, o->kmode[0].vrefresh,
937 x_ofs, strerror(errno));
940 if (o->flags & TEST_DPMS)
941 set_dpms(o, DRM_MODE_DPMS_OFF);
943 if (o->flags & TEST_MODESET && !(o->flags & TEST_RMFB) && !(o->flags & TEST_VBLANK_RACE))
944 igt_assert_f(set_mode(o, 0 /* no fb */, 0, 0) == 0,
945 "failed to disable output: %s\n",
948 if (o->flags & TEST_RPM)
949 igt_assert(igt_wait_for_pm_status(IGT_RUNTIME_PM_STATUS_SUSPENDED));
951 if (o->flags & TEST_SUSPEND)
952 igt_system_suspend_autoresume();
954 if (do_vblank && (o->flags & TEST_EINVAL) && o->vblank_state.count > 0)
955 igt_assert(do_wait_for_vblank(o, o->pipe, target_seq, &vbl_reply)
958 if (do_flip && (o->flags & TEST_EINVAL) && !(o->flags & TEST_FB_BAD_TILING))
959 igt_assert(do_page_flip(o, new_fb_id, true) == expected_einval);
962 unhang_gpu(drm_fd, hang);
964 return completed_events;
967 static void update_state(struct event_state *es)
969 es->last_received_ts = es->current_received_ts;
970 es->last_ts = es->current_ts;
971 es->last_seq = es->current_seq;
975 static void update_all_state(struct test_output *o,
976 unsigned int completed_events)
978 if (completed_events & EVENT_FLIP)
979 update_state(&o->flip_state);
981 if (completed_events & EVENT_VBLANK)
982 update_state(&o->vblank_state);
985 static void connector_find_preferred_mode(uint32_t connector_id, int crtc_idx,
986 struct test_output *o)
988 struct kmstest_connector_config config;
990 if (!kmstest_get_connector_config(drm_fd, connector_id, 1 << crtc_idx,
996 o->pipe = config.pipe;
997 o->kconnector[0] = config.connector;
998 o->kencoder[0] = config.encoder;
999 o->_crtc[0] = config.crtc->crtc_id;
1000 o->kmode[0] = config.default_mode;
1003 o->fb_width = o->kmode[0].hdisplay;
1004 o->fb_height = o->kmode[0].vdisplay;
1006 drmModeFreeCrtc(config.crtc);
1009 static bool mode_compatible(const drmModeModeInfo *a, const drmModeModeInfo *b)
1013 if (a->hdisplay != b->hdisplay)
1016 if (a->vdisplay != b->vdisplay)
1019 d_refresh = a->vrefresh - b->vrefresh;
1020 if (d_refresh < -1 || d_refresh > 1)
1026 static void connector_find_compatible_mode(int crtc_idx0, int crtc_idx1,
1027 struct test_output *o)
1029 struct kmstest_connector_config config[2];
1030 drmModeModeInfo *mode[2];
1033 if (!kmstest_get_connector_config(drm_fd, o->_connector[0],
1034 1 << crtc_idx0, &config[0]))
1037 if (!kmstest_get_connector_config(drm_fd, o->_connector[1],
1038 1 << crtc_idx1, &config[1])) {
1039 kmstest_free_connector_config(&config[0]);
1043 mode[0] = &config[0].default_mode;
1044 mode[1] = &config[1].default_mode;
1045 if (!mode_compatible(mode[0], mode[1])) {
1046 for (n = 0; n < config[0].connector->count_modes; n++) {
1047 mode[0] = &config[0].connector->modes[n];
1048 for (m = 0; m < config[1].connector->count_modes; m++) {
1049 mode[1] = &config[1].connector->modes[m];
1050 if (mode_compatible(mode[0], mode[1]))
1055 /* hope for the best! */
1056 mode[1] = mode[0] = &config[0].default_mode;
1060 o->pipe = config[0].pipe;
1061 o->fb_width = mode[0]->hdisplay;
1062 o->fb_height = mode[0]->vdisplay;
1065 o->kconnector[0] = config[0].connector;
1066 o->kencoder[0] = config[0].encoder;
1067 o->_crtc[0] = config[0].crtc->crtc_id;
1068 o->kmode[0] = *mode[0];
1070 o->kconnector[1] = config[1].connector;
1071 o->kencoder[1] = config[1].encoder;
1072 o->_crtc[1] = config[1].crtc->crtc_id;
1073 o->kmode[1] = *mode[1];
1075 drmModeFreeCrtc(config[0].crtc);
1076 drmModeFreeCrtc(config[1].crtc);
1079 static void paint_flip_mode(struct igt_fb *fb, bool odd_frame)
1081 cairo_t *cr = igt_get_cairo_ctx(drm_fd, fb);
1082 int width = fb->width;
1083 int height = fb->height;
1085 igt_paint_test_pattern(cr, width, height);
1088 cairo_rectangle(cr, width/4, height/2, width/4, height/8);
1090 cairo_rectangle(cr, width/2, height/2, width/4, height/8);
1092 cairo_set_source_rgb(cr, 1, 1, 1);
1095 igt_assert(!cairo_status(cr));
1100 fb_is_bound(struct test_output *o, int fb)
1104 for (n = 0; n < o->count; n++) {
1105 struct drm_mode_crtc mode;
1107 mode.crtc_id = o->_crtc[n];
1108 if (drmIoctl(drm_fd, DRM_IOCTL_MODE_GETCRTC, &mode))
1111 if (!mode.mode_valid || mode.fb_id != fb)
1118 static void check_final_state(struct test_output *o, struct event_state *es,
1119 unsigned int elapsed)
1121 igt_assert_f(es->count > 0,
1122 "no %s event received\n", es->name);
1124 /* Verify we drop no frames, but only if it's not a TV encoder, since
1125 * those use some funny fake timings behind userspace's back. */
1126 if (o->flags & TEST_CHECK_TS && !analog_tv_connector(o)) {
1128 int count = es->count;
1130 count *= o->seq_step;
1131 expected = elapsed * o->kmode[0].vrefresh / (1000 * 1000);
1132 igt_assert_f(count >= expected * 99/100 && count <= expected * 101/100,
1133 "dropped frames, expected %d, counted %d, encoder type %d\n",
1134 expected, count, o->kencoder[0]->encoder_type);
1139 * Wait until at least one pending event completes. Return mask of completed
1142 static unsigned int wait_for_events(struct test_output *o)
1144 drmEventContext evctx;
1145 struct timeval timeout = { .tv_sec = 3, .tv_usec = 0 };
1147 unsigned int event_mask;
1150 event_mask = o->pending_events;
1151 igt_assert(event_mask);
1153 memset(&evctx, 0, sizeof evctx);
1154 evctx.version = DRM_EVENT_CONTEXT_VERSION;
1155 evctx.vblank_handler = vblank_handler;
1156 evctx.page_flip_handler = page_flip_handler;
1158 /* make timeout lax with the dummy load */
1159 if (o->flags & (TEST_WITH_DUMMY_BCS | TEST_WITH_DUMMY_RCS))
1160 timeout.tv_sec *= 60;
1163 FD_SET(drm_fd, &fds);
1166 ret = select(drm_fd + 1, &fds, NULL, NULL, &timeout);
1167 } while (ret < 0 && errno == EINTR);
1169 igt_assert_f(ret >= 0,
1170 "select error (errno %i)\n", errno);
1171 igt_assert_f(ret > 0,
1172 "select timed out or error (ret %d)\n", ret);
1173 igt_assert_f(!FD_ISSET(0, &fds),
1174 "no fds active, breaking\n");
1176 do_or_die(drmHandleEvent(drm_fd, &evctx));
1177 } while (o->pending_events);
1179 event_mask ^= o->pending_events;
1180 igt_assert(event_mask);
1185 /* Returned the elapsed time in us */
1186 static unsigned event_loop(struct test_output *o, unsigned duration_ms)
1188 unsigned long start, end;
1189 uint32_t hang = 0; /* Suppress GCC warning */
1192 if (o->flags & TEST_HANG_ONCE) {
1193 hang = hang_gpu(drm_fd);
1194 igt_assert_f(hang, "failed to exercise page flip hang recovery\n");
1197 start = gettime_us();
1200 unsigned int completed_events;
1202 completed_events = run_test_step(o);
1203 if (o->pending_events)
1204 completed_events |= wait_for_events(o);
1205 check_all_state(o, completed_events);
1206 update_all_state(o, completed_events);
1208 if (count && (gettime_us() - start) / 1000 >= duration_ms)
1217 unhang_gpu(drm_fd, hang);
1219 /* Flush any remaining events */
1220 if (o->pending_events)
1226 static void free_test_output(struct test_output *o)
1230 for (i = 0; i < o->count; i++) {
1231 drmModeFreeEncoder(o->kencoder[i]);
1232 drmModeFreeConnector(o->kconnector[i]);
1236 static void run_test_on_crtc_set(struct test_output *o, int *crtc_idxs,
1237 int crtc_count, int duration_ms)
1239 char test_name[128];
1241 unsigned bo_size = 0;
1242 unsigned int tiling;
1245 switch (crtc_count) {
1247 connector_find_preferred_mode(o->_connector[0], crtc_idxs[0], o);
1248 snprintf(test_name, sizeof(test_name),
1249 "%s on crtc %d, connector %d",
1250 igt_subtest_name(), o->_crtc[0], o->_connector[0]);
1253 connector_find_compatible_mode(crtc_idxs[0], crtc_idxs[1], o);
1254 snprintf(test_name, sizeof(test_name),
1255 "%s on crtc %d:%d, connector %d:%d",
1256 igt_subtest_name(), o->_crtc[0], o->_crtc[1],
1257 o->_connector[0], o->_connector[1]);
1265 igt_assert(o->count == crtc_count);
1267 last_connector = o->kconnector[0];
1269 igt_info("Beginning %s\n", test_name);
1271 if (o->flags & TEST_PAN)
1274 tiling = I915_TILING_NONE;
1275 if (o->flags & TEST_FENCE_STRESS)
1276 tiling = I915_TILING_X;
1278 /* 256 MB is usually the maximum mappable aperture,
1279 * (make it 4x times that to ensure failure) */
1280 if (o->flags & TEST_BO_TOOBIG)
1281 bo_size = 4*256*1024*1024;
1283 o->fb_ids[0] = igt_create_fb(drm_fd, o->fb_width, o->fb_height,
1284 igt_bpp_depth_to_drm_format(o->bpp, o->depth),
1285 tiling, &o->fb_info[0]);
1286 o->fb_ids[1] = igt_create_fb_with_bo_size(drm_fd, o->fb_width, o->fb_height,
1287 igt_bpp_depth_to_drm_format(o->bpp, o->depth),
1288 tiling, &o->fb_info[1], bo_size);
1289 o->fb_ids[2] = igt_create_fb(drm_fd, o->fb_width, o->fb_height,
1290 igt_bpp_depth_to_drm_format(o->bpp, o->depth),
1291 I915_TILING_X, &o->fb_info[2]);
1292 igt_assert(o->fb_ids[0]);
1293 igt_assert(o->fb_ids[1]);
1294 if (o->flags & TEST_FB_BAD_TILING)
1295 igt_require(o->fb_ids[2]);
1297 paint_flip_mode(&o->fb_info[0], false);
1298 if (!(o->flags & TEST_BO_TOOBIG))
1299 paint_flip_mode(&o->fb_info[1], true);
1301 paint_flip_mode(&o->fb_info[2], true);
1303 if (o->flags & TEST_FB_BAD_TILING)
1306 for (i = 0; i < o->count; i++)
1307 kmstest_dump_mode(&o->kmode[i]);
1309 if (set_mode(o, o->fb_ids[0], 0, 0)) {
1310 /* We may fail to apply the mode if there are hidden
1311 * constraints, such as bandwidth on the third pipe.
1313 igt_assert_f(crtc_count > 1 || crtc_idxs[0] < 2,
1314 "set_mode may only fail on the 3rd pipe or in multiple crtc tests\n");
1317 igt_assert(fb_is_bound(o, o->fb_ids[0]));
1319 /* quiescent the hw a bit so ensure we don't miss a single frame */
1320 if (o->flags & TEST_CHECK_TS)
1323 if (o->flags & TEST_BO_TOOBIG) {
1324 igt_assert(do_page_flip(o, o->fb_ids[1], true) == -E2BIG);
1327 igt_assert(do_page_flip(o, o->fb_ids[1], true) == 0);
1330 o->current_fb_id = 1;
1332 if (o->flags & TEST_FLIP)
1333 o->flip_state.seq_step = 1;
1335 o->flip_state.seq_step = 0;
1336 if (o->flags & TEST_VBLANK)
1337 o->vblank_state.seq_step = 10;
1339 o->vblank_state.seq_step = 0;
1341 /* We run the vblank and flip actions in parallel by default. */
1342 o->seq_step = max(o->vblank_state.seq_step, o->flip_state.seq_step);
1344 elapsed = event_loop(o, duration_ms);
1346 if (o->flags & TEST_FLIP && !(o->flags & TEST_NOEVENT))
1347 check_final_state(o, &o->flip_state, elapsed);
1348 if (o->flags & TEST_VBLANK)
1349 check_final_state(o, &o->vblank_state, elapsed);
1351 igt_info("\n%s: PASSED\n\n", test_name);
1355 igt_remove_fb(drm_fd, &o->fb_info[2]);
1356 igt_remove_fb(drm_fd, &o->fb_info[1]);
1357 igt_remove_fb(drm_fd, &o->fb_info[0]);
1359 last_connector = NULL;
1361 free_test_output(o);
1364 static int run_test(int duration, int flags)
1366 struct test_output o;
1367 int i, n, modes = 0;
1369 igt_require((flags & TEST_HANG) == 0 || !is_hung(drm_fd));
1371 if (flags & TEST_RPM)
1372 igt_require(igt_setup_runtime_pm());
1374 resources = drmModeGetResources(drm_fd);
1375 igt_assert(resources);
1377 /* Count output configurations to scale test runtime. */
1378 for (i = 0; i < resources->count_connectors; i++) {
1379 for (n = 0; n < resources->count_crtcs; n++) {
1380 memset(&o, 0, sizeof(o));
1382 o._connector[0] = resources->connectors[i];
1384 o.flip_state.name = "flip";
1385 o.vblank_state.name = "vblank";
1389 connector_find_preferred_mode(o._connector[0], n, &o);
1393 free_test_output(&o);
1398 duration = duration * 1000 / modes;
1399 duration = duration < 500 ? 500 : duration;
1401 /* Find any connected displays */
1402 for (i = 0; i < resources->count_connectors; i++) {
1403 for (n = 0; n < resources->count_crtcs; n++) {
1406 memset(&o, 0, sizeof(o));
1408 o._connector[0] = resources->connectors[i];
1410 o.flip_state.name = "flip";
1411 o.vblank_state.name = "vblank";
1416 run_test_on_crtc_set(&o, &crtc_idx, 1, duration);
1420 drmModeFreeResources(resources);
1424 static int run_pair(int duration, int flags)
1426 struct test_output o;
1427 int i, j, m, n, modes = 0;
1429 igt_require((flags & TEST_HANG) == 0 || !is_hung(drm_fd));
1431 resources = drmModeGetResources(drm_fd);
1432 igt_assert(resources);
1434 /* Find a pair of connected displays */
1435 for (i = 0; i < resources->count_connectors; i++) {
1436 for (n = 0; n < resources->count_crtcs; n++) {
1437 for (j = i + 1; j < resources->count_connectors; j++) {
1438 for (m = n + 1; m < resources->count_crtcs; m++) {
1439 memset(&o, 0, sizeof(o));
1441 o._connector[0] = resources->connectors[i];
1442 o._connector[1] = resources->connectors[j];
1444 o.flip_state.name = "flip";
1445 o.vblank_state.name = "vblank";
1449 connector_find_compatible_mode(n, m, &o);
1453 free_test_output(&o);
1459 /* If we have fewer than 2 connected outputs then we won't have any
1460 * configuration at all. So skip in that case. */
1462 duration = duration * 1000 / modes;
1463 duration = duration < 500 ? 500 : duration;
1465 /* Find a pair of connected displays */
1466 for (i = 0; i < resources->count_connectors; i++) {
1467 for (n = 0; n < resources->count_crtcs; n++) {
1468 for (j = i + 1; j < resources->count_connectors; j++) {
1469 for (m = n + 1; m < resources->count_crtcs; m++) {
1472 memset(&o, 0, sizeof(o));
1474 o._connector[0] = resources->connectors[i];
1475 o._connector[1] = resources->connectors[j];
1477 o.flip_state.name = "flip";
1478 o.vblank_state.name = "vblank";
1485 run_test_on_crtc_set(&o, crtc_idxs, 2,
1492 drmModeFreeResources(resources);
1496 static void get_timestamp_format(void)
1501 ret = drmGetCap(drm_fd, DRM_CAP_TIMESTAMP_MONOTONIC, &cap_mono);
1502 igt_assert(ret == 0 || errno == EINVAL);
1503 monotonic_timestamp = ret == 0 && cap_mono == 1;
1504 igt_info("Using %s timestamps\n",
1505 monotonic_timestamp ? "monotonic" : "real");
1508 static void kms_flip_exit_handler(int sig)
1512 kmstest_set_connector_dpms(drm_fd, last_connector, DRM_MODE_DPMS_ON);
1516 int main(int argc, char **argv)
1523 { 30, TEST_VBLANK, "wf_vblank" },
1524 { 30, TEST_VBLANK | TEST_CHECK_TS, "wf_vblank-ts-check" },
1525 { 30, TEST_VBLANK | TEST_VBLANK_BLOCK | TEST_CHECK_TS,
1526 "blocking-wf_vblank" },
1527 { 30, TEST_VBLANK | TEST_VBLANK_ABSOLUTE,
1528 "absolute-wf_vblank" },
1529 { 30, TEST_VBLANK | TEST_VBLANK_BLOCK | TEST_VBLANK_ABSOLUTE,
1530 "blocking-absolute-wf_vblank" },
1531 { 60, TEST_VBLANK | TEST_DPMS | TEST_EINVAL, "wf_vblank-vs-dpms" },
1532 { 60, TEST_VBLANK | TEST_DPMS | TEST_WITH_DUMMY_BCS,
1533 "bcs-wf_vblank-vs-dpms" },
1534 { 60, TEST_VBLANK | TEST_DPMS | TEST_WITH_DUMMY_RCS,
1535 "rcs-wf_vblank-vs-dpms" },
1536 { 60, TEST_VBLANK | TEST_MODESET | TEST_EINVAL, "wf_vblank-vs-modeset" },
1537 { 60, TEST_VBLANK | TEST_MODESET | TEST_WITH_DUMMY_BCS,
1538 "bcs-wf_vblank-vs-modeset" },
1539 { 60, TEST_VBLANK | TEST_MODESET | TEST_WITH_DUMMY_RCS,
1540 "rcs-wf_vblank-vs-modeset" },
1542 { 30, TEST_FLIP , "plain-flip" },
1543 { 30, TEST_FLIP | TEST_EBUSY , "busy-flip" },
1544 { 30, TEST_FLIP | TEST_FENCE_STRESS , "flip-vs-fences" },
1545 { 30, TEST_FLIP | TEST_CHECK_TS, "plain-flip-ts-check" },
1546 { 30, TEST_FLIP | TEST_CHECK_TS | TEST_FB_RECREATE,
1547 "plain-flip-fb-recreate" },
1548 { 30, TEST_FLIP | TEST_RMFB | TEST_MODESET , "flip-vs-rmfb" },
1549 { 60, TEST_FLIP | TEST_DPMS | TEST_EINVAL, "flip-vs-dpms" },
1550 { 60, TEST_FLIP | TEST_DPMS | TEST_WITH_DUMMY_BCS, "bcs-flip-vs-dpms" },
1551 { 60, TEST_FLIP | TEST_DPMS | TEST_WITH_DUMMY_RCS, "rcs-flip-vs-dpms" },
1552 { 30, TEST_FLIP | TEST_PAN, "flip-vs-panning" },
1553 { 60, TEST_FLIP | TEST_PAN | TEST_WITH_DUMMY_BCS, "bcs-flip-vs-panning" },
1554 { 60, TEST_FLIP | TEST_PAN | TEST_WITH_DUMMY_RCS, "rcs-flip-vs-panning" },
1555 { 60, TEST_FLIP | TEST_MODESET | TEST_EINVAL, "flip-vs-modeset" },
1556 { 60, TEST_FLIP | TEST_MODESET | TEST_WITH_DUMMY_BCS, "bcs-flip-vs-modeset" },
1557 { 60, TEST_FLIP | TEST_MODESET | TEST_WITH_DUMMY_RCS, "rcs-flip-vs-modeset" },
1558 { 30, TEST_FLIP | TEST_VBLANK_EXPIRED_SEQ,
1559 "flip-vs-expired-vblank" },
1561 { 30, TEST_FLIP | TEST_VBLANK | TEST_VBLANK_ABSOLUTE |
1562 TEST_CHECK_TS, "flip-vs-absolute-wf_vblank" },
1563 { 30, TEST_FLIP | TEST_VBLANK | TEST_CHECK_TS,
1564 "flip-vs-wf_vblank" },
1565 { 30, TEST_FLIP | TEST_VBLANK | TEST_VBLANK_BLOCK |
1566 TEST_CHECK_TS, "flip-vs-blocking-wf-vblank" },
1567 { 30, TEST_FLIP | TEST_MODESET | TEST_HANG | TEST_NOEVENT, "flip-vs-modeset-vs-hang" },
1568 { 30, TEST_FLIP | TEST_PAN | TEST_HANG, "flip-vs-panning-vs-hang" },
1569 { 30, TEST_VBLANK | TEST_HANG_ONCE, "vblank-vs-hang" },
1570 { 1, TEST_FLIP | TEST_EINVAL | TEST_FB_BAD_TILING, "flip-vs-bad-tiling" },
1572 { 1, TEST_DPMS_OFF | TEST_MODESET | TEST_FLIP,
1573 "flip-vs-dpms-off-vs-modeset" },
1574 { 1, TEST_DPMS_OFF | TEST_MODESET | TEST_FLIP | TEST_SINGLE_BUFFER,
1575 "single-buffer-flip-vs-dpms-off-vs-modeset" },
1576 { 30, TEST_FLIP | TEST_NO_2X_OUTPUT | TEST_DPMS_OFF_OTHERS , "dpms-off-confusion" },
1577 { 0, TEST_ENOENT | TEST_NOEVENT, "nonexisting-fb" },
1578 { 10, TEST_DPMS_OFF | TEST_DPMS | TEST_VBLANK_RACE, "dpms-vs-vblank-race" },
1579 { 10, TEST_MODESET | TEST_VBLANK_RACE, "modeset-vs-vblank-race" },
1580 { 10, TEST_VBLANK | TEST_DPMS | TEST_RPM | TEST_TS_CONT, "vblank-vs-dpms-rpm" },
1581 { 10, TEST_VBLANK | TEST_MODESET | TEST_RPM | TEST_TS_CONT, "vblank-vs-modeset-rpm" },
1582 { 0, TEST_VBLANK | TEST_DPMS | TEST_SUSPEND | TEST_TS_CONT, "vblank-vs-dpms-suspend" },
1583 { 0, TEST_VBLANK | TEST_MODESET | TEST_SUSPEND | TEST_TS_CONT, "vblank-vs-modeset-suspend" },
1584 { 0, TEST_VBLANK | TEST_SUSPEND | TEST_TS_CONT, "vblank-vs-suspend" },
1585 { 0, TEST_BO_TOOBIG | TEST_NO_2X_OUTPUT, "bo-too-big" },
1589 igt_subtest_init(argc, argv);
1590 igt_skip_on_simulation();
1593 drm_fd = drm_open_any();
1595 igt_enable_connectors();
1597 kmstest_set_vt_graphics_mode();
1598 igt_install_exit_handler(kms_flip_exit_handler);
1599 get_timestamp_format();
1601 bufmgr = drm_intel_bufmgr_gem_init(drm_fd, 4096);
1602 devid = intel_get_drm_devid(drm_fd);
1603 batch = intel_batchbuffer_alloc(bufmgr, devid);
1606 for (i = 0; i < sizeof(tests) / sizeof (tests[0]); i++) {
1607 igt_subtest(tests[i].name)
1608 run_test(tests[i].duration, tests[i].flags);
1610 if (tests[i].flags & TEST_NO_2X_OUTPUT)
1613 /* code doesn't disable all crtcs, so skip rpm tests */
1614 if (tests[i].flags & TEST_RPM)
1617 igt_subtest_f( "2x-%s", tests[i].name)
1618 run_pair(tests[i].duration, tests[i].flags);
1621 igt_fork_signal_helper();
1622 for (i = 0; i < sizeof(tests) / sizeof (tests[0]); i++) {
1623 /* relative blocking vblank waits that get constantly interrupt
1624 * take forver. So don't do them. */
1625 if ((tests[i].flags & TEST_VBLANK_BLOCK) &&
1626 !(tests[i].flags & TEST_VBLANK_ABSOLUTE))
1629 igt_subtest_f( "%s-interruptible", tests[i].name)
1630 run_test(tests[i].duration, tests[i].flags);
1632 if (tests[i].flags & TEST_NO_2X_OUTPUT)
1635 /* code doesn't disable all crtcs, so skip rpm tests */
1636 if (tests[i].flags & TEST_RPM)
1639 igt_subtest_f( "2x-%s-interruptible", tests[i].name)
1640 run_pair(tests[i].duration, tests[i].flags);
1642 igt_stop_signal_helper();
1645 * Let drm_fd leak, since it's needed by the dpms restore
1646 * exit_handler and igt_exit() won't return.