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 BLIT_RELOC_UDW(devid);
190 OUT_BATCH(0 << 16 | 0);
192 OUT_RELOC_FENCED(target_bo, I915_GEM_DOMAIN_RENDER, 0, 0);
193 BLIT_RELOC_UDW(devid);
196 if (IS_GEN6(devid) || IS_GEN7(devid)) {
198 OUT_BATCH(XY_SETUP_CLIP_BLT_CMD);
205 dummy_bo = target_bo;
208 intel_batchbuffer_flush(batch);
210 drm_intel_bo_unreference(dummy_bo);
211 drm_intel_bo_unreference(target_bo);
214 static void emit_fence_stress(struct test_output *o)
216 const int num_fences = gem_available_fences(drm_fd);
217 struct igt_fb *fb_info = &o->fb_info[o->current_fb_id];
218 struct drm_i915_gem_execbuffer2 execbuf;
219 struct drm_i915_gem_exec_object2 *exec;
220 uint32_t buf[2] = { MI_BATCH_BUFFER_END, 0 };
224 bo = calloc(sizeof(*bo), num_fences);
225 exec = calloc(sizeof(*exec), num_fences+1);
226 for (i = 0; i < num_fences - 1; i++) {
227 uint32_t tiling = I915_TILING_X;
228 unsigned long pitch = 0;
229 bo[i] = drm_intel_bo_alloc_tiled(bufmgr,
230 "tiled bo", 1024, 1024, 4,
232 exec[i].handle = bo[i]->handle;
233 exec[i].flags = EXEC_OBJECT_NEEDS_FENCE;
235 exec[i].handle = fb_info->gem_handle;
236 exec[i].flags = EXEC_OBJECT_NEEDS_FENCE;
237 exec[++i].handle = gem_create(drm_fd, 4096);
238 gem_write(drm_fd, exec[i].handle, 0, buf, sizeof(buf));
240 memset(&execbuf, 0, sizeof(execbuf));
241 execbuf.buffers_ptr = (uintptr_t)exec;
242 execbuf.buffer_count = i + 1;
243 execbuf.batch_len = sizeof(buf);
244 if (HAS_BLT_RING(intel_get_drm_devid(drm_fd)))
245 execbuf.flags = I915_EXEC_BLT;
247 gem_execbuf(drm_fd, &execbuf);
249 gem_close(drm_fd, exec[i].handle);
250 for (i = 0; i < num_fences - 1; i++)
251 drm_intel_bo_unreference(bo[i]);
256 static void emit_dummy_load__rcs(struct test_output *o)
258 const struct igt_fb *fb_info = &o->fb_info[o->current_fb_id];
259 igt_render_copyfunc_t copyfunc;
260 struct igt_buf sb[2], *src, *dst;
263 copyfunc = igt_get_render_copyfunc(devid);
264 if (copyfunc == NULL)
265 return emit_dummy_load__bcs(o);
267 limit = intel_gen(devid) < 6 ? 500 : 5000;
269 sb[0].bo = drm_intel_bo_alloc(bufmgr, "dummy_bo", fb_info->size, 4096);
270 igt_assert(sb[0].bo);
271 sb[0].size = sb[0].bo->size;
272 sb[0].tiling = I915_TILING_NONE;
274 sb[0].num_tiles = sb[0].bo->size;
275 sb[0].stride = 4 * o->fb_width;
277 sb[1].bo = gem_handle_to_libdrm_bo(bufmgr, drm_fd, "imported", fb_info->gem_handle);
278 igt_assert(sb[1].bo);
279 sb[1].size = sb[1].bo->size;
280 sb[1].tiling = fb_info->tiling;
282 sb[1].num_tiles = sb[1].bo->size;
283 sb[1].stride = fb_info->stride;
288 for (i = 0; i < limit; i++) {
291 copyfunc(batch, NULL,
293 o->fb_width, o->fb_height,
300 intel_batchbuffer_flush(batch);
302 drm_intel_bo_unreference(sb[0].bo);
303 drm_intel_bo_unreference(sb[1].bo);
306 static void dpms_off_other_outputs(struct test_output *o)
309 drmModeConnector *connector;
310 uint32_t connector_id;
312 for (i = 0; i < resources->count_connectors; i++) {
313 connector_id = resources->connectors[i];
315 for (n = 0; n < o->count; n++) {
316 if (connector_id == o->kconnector[n]->connector_id)
320 connector = drmModeGetConnector(drm_fd, connector_id);
322 kmstest_set_connector_dpms(drm_fd, connector, DRM_MODE_DPMS_ON);
323 kmstest_set_connector_dpms(drm_fd, connector, DRM_MODE_DPMS_OFF);
325 drmModeFreeConnector(connector);
331 static void set_dpms(struct test_output *o, int mode)
333 for (int n = 0; n < o->count; n++)
334 kmstest_set_connector_dpms(drm_fd, o->kconnector[n], mode);
337 static void set_flag(unsigned int *v, unsigned int flag)
339 igt_assert(!(*v & flag));
343 static void clear_flag(unsigned int *v, unsigned int flag)
345 igt_assert(*v & flag);
349 static int do_page_flip(struct test_output *o, uint32_t fb_id, bool event)
355 for (n = 0; ret == 0 && n < o->count; n++)
356 ret = drmModePageFlip(drm_fd, o->_crtc[n], fb_id,
357 event ? DRM_MODE_PAGE_FLIP_EVENT : 0,
358 event ? (void *)((unsigned long)o | (n==0)) : NULL);
360 if (ret == 0 && event)
361 set_flag(&o->pending_events, EVENT_FLIP);
366 struct vblank_reply {
367 unsigned int sequence;
371 static int __wait_for_vblank(unsigned int flags, int crtc_idx,
372 int target_seq, unsigned long ret_data,
373 struct vblank_reply *reply)
377 unsigned crtc_idx_mask;
378 bool event = !(flags & TEST_VBLANK_BLOCK);
380 memset(&wait_vbl, 0, sizeof(wait_vbl));
382 crtc_idx_mask = crtc_idx << DRM_VBLANK_HIGH_CRTC_SHIFT;
383 igt_assert(!(crtc_idx_mask & ~DRM_VBLANK_HIGH_CRTC_MASK));
385 wait_vbl.request.type = crtc_idx_mask;
386 if (flags & TEST_VBLANK_ABSOLUTE)
387 wait_vbl.request.type |= DRM_VBLANK_ABSOLUTE;
389 wait_vbl.request.type |= DRM_VBLANK_RELATIVE;
391 wait_vbl.request.type |= DRM_VBLANK_EVENT;
392 wait_vbl.request.signal = ret_data;
394 wait_vbl.request.sequence = target_seq;
396 ret = drmWaitVBlank(drm_fd, &wait_vbl);
399 reply->ts.tv_sec = wait_vbl.reply.tval_sec;
400 reply->ts.tv_usec = wait_vbl.reply.tval_usec;
401 reply->sequence = wait_vbl.reply.sequence;
408 static int do_wait_for_vblank(struct test_output *o, int pipe_id,
409 int target_seq, struct vblank_reply *reply)
412 unsigned flags = o->flags;
414 /* Absolute waits only works once we have a frame counter. */
415 if (!(o->vblank_state.count > 0))
416 flags &= ~TEST_VBLANK_ABSOLUTE;
418 ret = __wait_for_vblank(flags, pipe_id, target_seq, (unsigned long)o,
420 if (ret == 0 && !(o->flags & TEST_VBLANK_BLOCK))
421 set_flag(&o->pending_events, EVENT_VBLANK);
427 analog_tv_connector(struct test_output *o)
429 uint32_t connector_type = o->kconnector[0]->connector_type;
431 return connector_type == DRM_MODE_CONNECTOR_TV ||
432 connector_type == DRM_MODE_CONNECTOR_9PinDIN ||
433 connector_type == DRM_MODE_CONNECTOR_SVIDEO ||
434 connector_type == DRM_MODE_CONNECTOR_Composite;
437 static void event_handler(struct event_state *es, unsigned int frame,
438 unsigned int sec, unsigned int usec)
442 if (monotonic_timestamp) {
445 clock_gettime(CLOCK_MONOTONIC, &ts);
446 now.tv_sec = ts.tv_sec;
447 now.tv_usec = ts.tv_nsec / 1000;
449 gettimeofday(&now, NULL);
451 es->current_received_ts = now;
453 es->current_ts.tv_sec = sec;
454 es->current_ts.tv_usec = usec;
455 es->current_seq = frame;
458 static void page_flip_handler(int fd, unsigned int frame, unsigned int sec,
459 unsigned int usec, void *data)
461 int primary = (unsigned long)data & 1;
462 struct test_output *o = (void *)((unsigned long)data & ~ 1);
464 if (++o->flip_count == o->count)
465 clear_flag(&o->pending_events, EVENT_FLIP);
467 event_handler(&o->flip_state, frame, sec, usec);
470 static double frame_time(struct test_output *o)
472 return 1000.0 * 1000.0 / o->kmode[0].vrefresh;
475 static void *vblank_wait_thread_func(void *data)
477 struct test_output *o = data;
478 struct vblank_reply reply;
481 for (i = 0; i < 32; i++) {
482 unsigned long start = gettime_us();
483 __wait_for_vblank(TEST_VBLANK_BLOCK, o->pipe, 20, (unsigned long)o, &reply);
484 if (gettime_us() - start > 2 * frame_time(o))
491 static void spawn_vblank_wait_thread(struct test_output *o)
493 igt_assert(pthread_create(&vblank_wait_thread, NULL,
494 vblank_wait_thread_func, o) == 0);
497 static void join_vblank_wait_thread(void)
499 igt_assert(pthread_join(vblank_wait_thread, NULL) == 0);
502 static void fixup_premature_vblank_ts(struct test_output *o,
503 struct event_state *es)
506 * In case a power off event preempts the completion of a
507 * wait-for-vblank event the kernel will return a wf-vblank event with
508 * a zeroed-out timestamp. In order that check_state() doesn't
509 * complain replace this ts with a valid ts. As we can't calculate the
510 * exact timestamp, just use the time we received the event.
514 if (!(o->flags & (TEST_DPMS | TEST_MODESET)))
517 if (o->vblank_state.current_ts.tv_sec != 0 ||
518 o->vblank_state.current_ts.tv_usec != 0)
523 timersub(&es->current_received_ts, &tv, &es->current_ts);
526 static void vblank_handler(int fd, unsigned int frame, unsigned int sec,
527 unsigned int usec, void *data)
529 struct test_output *o = data;
531 clear_flag(&o->pending_events, EVENT_VBLANK);
532 event_handler(&o->vblank_state, frame, sec, usec);
533 fixup_premature_vblank_ts(o, &o->vblank_state);
536 static void check_state(struct test_output *o, struct event_state *es)
539 double usec_interflip;
541 timersub(&es->current_ts, &es->current_received_ts, &diff);
542 if (!analog_tv_connector(o)) {
543 igt_assert_f(diff.tv_sec < 0 || (diff.tv_sec == 0 && diff.tv_usec <= 2000),
544 "%s ts delayed for too long: %is, %iusec\n",
545 es->name, (int)diff.tv_sec, (int)diff.tv_usec);
552 timersub(&es->current_ts, &es->last_received_ts, &diff);
553 igt_assert_f(timercmp(&es->last_received_ts, &es->current_ts, <),
554 "%s ts before the %s was issued!\n"
555 "timerdiff %is, %ius\n",
557 (int) diff.tv_sec, (int) diff.tv_usec);
559 /* check only valid if no modeset happens in between, that increments by
560 * (1 << 23) on each step. This bounding matches the one in
561 * DRM_IOCTL_WAIT_VBLANK. */
562 if (!(o->flags & (TEST_DPMS | TEST_MODESET)))
563 igt_assert_f(es->current_seq - (es->last_seq + o->seq_step) <= 1UL << 23,
564 "unexpected %s seq %u, should be >= %u\n",
565 es->name, es->current_seq, es->last_seq + o->seq_step);
567 /* Check that the vblank frame didn't wrap unexpectedly. */
568 if (o->flags & TEST_TS_CONT) {
569 /* Ignore seq_step here since vblank waits time out immediately
570 * when we kill the crtc. */
571 igt_assert_f(es->current_seq - es->last_seq >= 0,
572 "unexpected %s seq %u, should be >= %u\n",
573 es->name, es->current_seq, es->last_seq);
574 igt_assert_f(es->current_seq - es->last_seq <= 100,
575 "unexpected %s seq %u, should be < %u\n",
576 es->name, es->current_seq, es->last_seq + 100);
578 igt_debug("testing ts continuity: Current frame %u, old frame %u\n",
579 es->current_seq, es->last_seq);
582 if ((o->flags & TEST_CHECK_TS) && (!analog_tv_connector(o))) {
583 timersub(&es->current_ts, &es->last_ts, &diff);
584 usec_interflip = (double)o->seq_step * frame_time(o);
586 igt_assert_f(fabs((((double) diff.tv_usec) - usec_interflip) /
587 usec_interflip) <= 0.005,
588 "inter-%s ts jitter: %is, %ius\n",
589 es->name, (int) diff.tv_sec, (int) diff.tv_usec);
591 igt_assert_f(es->current_seq == es->last_seq + o->seq_step,
592 "unexpected %s seq %u, expected %u\n",
593 es->name, es->current_seq,
594 es->last_seq + o->seq_step);
598 static void check_state_correlation(struct test_output *o,
599 struct event_state *es1,
600 struct event_state *es2)
602 struct timeval tv_diff;
607 if (es1->count == 0 || es2->count == 0)
610 timersub(&es2->current_ts, &es1->current_ts, &tv_diff);
611 usec_diff = tv_diff.tv_sec * 1000 * 1000 + tv_diff.tv_usec;
613 seq_diff = es2->current_seq - es1->current_seq;
614 ftime = frame_time(o);
615 usec_diff -= seq_diff * ftime;
617 igt_assert_f(fabs(usec_diff) / ftime <= 0.005,
618 "timestamp mismatch between %s and %s (diff %.4f sec)\n",
619 es1->name, es2->name, usec_diff / 1000 / 1000);
622 static void check_all_state(struct test_output *o,
623 unsigned int completed_events)
627 flip = completed_events & EVENT_FLIP;
628 vblank = completed_events & EVENT_VBLANK;
631 check_state(o, &o->flip_state);
633 check_state(o, &o->vblank_state);
635 /* FIXME: Correlation check is broken. */
636 if (flip && vblank && 0)
637 check_state_correlation(o, &o->flip_state, &o->vblank_state);
640 static void recreate_fb(struct test_output *o)
643 struct igt_fb *fb_info = &o->fb_info[o->current_fb_id];
646 /* Call rmfb/getfb/addfb to ensure those don't introduce stalls */
647 r = drmModeGetFB(drm_fd, fb_info->fb_id);
650 do_or_die(drmModeAddFB(drm_fd, o->fb_width, o->fb_height, o->depth,
651 o->bpp, fb_info->stride,
652 r->handle, &new_fb_id));
654 gem_close(drm_fd, r->handle);
656 do_or_die(drmModeRmFB(drm_fd, fb_info->fb_id));
658 o->fb_ids[o->current_fb_id] = new_fb_id;
659 o->fb_info[o->current_fb_id].fb_id = new_fb_id;
662 static void set_y_tiling(struct test_output *o, int fb_idx)
665 struct igt_fb *fb_info = &o->fb_info[fb_idx];
667 /* Call rmfb/getfb/addfb to ensure those don't introduce stalls */
668 r = drmModeGetFB(drm_fd, fb_info->fb_id);
670 /* Newer kernels don't allow such shenagians any more, so skip the test. */
671 igt_require(__gem_set_tiling(drm_fd, r->handle, I915_TILING_Y, fb_info->stride) == 0);
672 gem_close(drm_fd, r->handle);
676 static void stop_rings(bool stop)
679 igt_set_stop_rings(STOP_RING_DEFAULTS);
681 igt_set_stop_rings(STOP_RING_NONE);
684 static void eat_error_state(void)
686 static const char dfs_base[] = "/sys/kernel/debug/dri";
687 static const char dfs_entry_error[] = "i915_error_state";
688 static const char data[] = "";
689 char fname[FILENAME_MAX];
690 int card_index = drm_get_card();
693 igt_assert(card_index != -1);
695 /* clear the error state */
696 snprintf(fname, FILENAME_MAX, "%s/%i/%s",
697 dfs_base, card_index, dfs_entry_error);
699 fd = open(fname, O_WRONLY);
702 igt_assert(write(fd, data, sizeof(data)) == sizeof(data));
705 /* and check whether stop_rings is not reset, i.e. the hang has indeed
707 igt_assert_f(igt_get_stop_rings() == STOP_RING_NONE,
708 "no gpu hang detected, stop_rings is still 0x%x\n",
709 igt_get_stop_rings());
714 static void unhang_gpu(int fd, uint32_t handle)
716 gem_sync(drm_fd, handle);
717 gem_close(drm_fd, handle);
722 static uint32_t hang_gpu(int fd)
724 struct drm_i915_gem_execbuffer2 execbuf;
725 struct drm_i915_gem_exec_object2 gem_exec;
726 uint32_t b[2] = {MI_BATCH_BUFFER_END};
730 memset(&gem_exec, 0, sizeof(gem_exec));
731 gem_exec.handle = gem_create(fd, 4096);
732 gem_write(fd, gem_exec.handle, 0, b, sizeof(b));
734 memset(&execbuf, 0, sizeof(execbuf));
735 execbuf.buffers_ptr = (uintptr_t)&gem_exec;
736 execbuf.buffer_count = 1;
737 execbuf.batch_len = sizeof(b);
739 if (drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf)) {
740 igt_assert_f(errno == EIO,
741 "failed to exercise page flip hang recovery\n");
743 unhang_gpu(fd, gem_exec.handle);
747 return gem_exec.handle;
750 static bool is_hung(int fd)
752 if (drmIoctl(fd, DRM_IOCTL_I915_GEM_THROTTLE, 0) == 0)
758 static int set_mode(struct test_output *o, uint32_t fb, int x, int y)
762 for (n = 0; n < o->count; n++) {
764 int ret = drmModeSetCrtc(drm_fd, o->_crtc[n],
770 int ret = drmModeSetCrtc(drm_fd, o->_crtc[n],
772 &o->_connector[n], 1, &o->kmode[n]);
781 /* Return mask of completed events. */
782 static unsigned int run_test_step(struct test_output *o)
784 unsigned int new_fb_id;
785 /* for funny reasons page_flip returns -EBUSY on disabled crtcs ... */
786 int expected_einval = o->flags & TEST_MODESET ? -EBUSY : -EINVAL;
787 unsigned int completed_events = 0;
790 struct vblank_reply vbl_reply;
791 unsigned int target_seq;
792 uint32_t hang = 0; /* Suppress GCC warning */
794 target_seq = o->vblank_state.seq_step;
795 /* Absolute waits only works once we have a frame counter. */
796 if (o->flags & TEST_VBLANK_ABSOLUTE && o->vblank_state.count > 0)
797 target_seq += o->vblank_state.last_seq;
800 * It's possible that we don't have a pending flip here, in case both
801 * wf-vblank and flip were scheduled and the wf-vblank event was
802 * delivered earlier. The same applies to vblank events w.r.t flip.
804 do_flip = (o->flags & TEST_FLIP) && !(o->pending_events & EVENT_FLIP);
805 do_vblank = (o->flags & TEST_VBLANK) &&
806 !(o->pending_events & EVENT_VBLANK);
808 if (o->flags & TEST_DPMS_OFF_OTHERS)
809 dpms_off_other_outputs(o);
811 if (o->flags & TEST_WITH_DUMMY_BCS)
812 emit_dummy_load__bcs(o);
814 if (o->flags & TEST_WITH_DUMMY_RCS)
815 emit_dummy_load__rcs(o);
817 if (!(o->flags & TEST_SINGLE_BUFFER))
818 o->current_fb_id = !o->current_fb_id;
820 if (o->flags & TEST_FB_RECREATE)
822 new_fb_id = o->fb_ids[o->current_fb_id];
824 if (o->flags & TEST_FB_BAD_TILING)
825 new_fb_id = o->fb_ids[2];
827 if ((o->flags & TEST_VBLANK_EXPIRED_SEQ) &&
828 !(o->pending_events & EVENT_VBLANK) && o->flip_state.count > 0) {
829 struct vblank_reply reply;
830 unsigned int exp_seq;
833 exp_seq = o->flip_state.current_seq;
834 start = gettime_us();
835 do_or_die(__wait_for_vblank(TEST_VBLANK_ABSOLUTE |
836 TEST_VBLANK_BLOCK, o->pipe, exp_seq,
838 igt_assert(gettime_us() - start < 500);
839 igt_assert(reply.sequence == exp_seq);
840 igt_assert(timercmp(&reply.ts, &o->flip_state.last_ts, ==));
843 if (o->flags & TEST_ENOENT) {
844 /* hope that fb 0xfffffff0 does not exist */
845 igt_assert(do_page_flip(o, 0xfffffff0, false) == -ENOENT);
846 igt_assert(set_mode(o, 0xfffffff0, 0, 0) == -ENOENT);
849 if (do_flip && (o->flags & TEST_EINVAL) && o->flip_state.count > 0)
850 igt_assert(do_page_flip(o, new_fb_id, true) == expected_einval);
852 if (o->flags & TEST_FB_BAD_TILING)
853 new_fb_id = o->fb_ids[o->current_fb_id];
855 if (do_vblank && (o->flags & TEST_EINVAL) && o->vblank_state.count > 0)
856 igt_assert(do_wait_for_vblank(o, o->pipe, target_seq, &vbl_reply)
859 if (o->flags & TEST_VBLANK_RACE) {
860 spawn_vblank_wait_thread(o);
862 if (o->flags & TEST_MODESET)
863 igt_assert_f(set_mode(o, 0 /* no fb */, 0, 0) == 0,
864 "failed to disable output: %s\n",
868 if (o->flags & TEST_DPMS_OFF)
869 set_dpms(o, DRM_MODE_DPMS_OFF);
871 if (o->flags & TEST_MODESET)
872 igt_assert(set_mode(o, o->fb_ids[o->current_fb_id], 0, 0) == 0);
874 if (o->flags & TEST_DPMS)
875 set_dpms(o, DRM_MODE_DPMS_ON);
877 if (o->flags & TEST_VBLANK_RACE) {
878 struct vblank_reply reply;
879 unsigned long start, end;
881 /* modeset/DPMS is done, vblank wait should work normally now */
882 start = gettime_us();
883 igt_assert(__wait_for_vblank(TEST_VBLANK_BLOCK, o->pipe, 1, 0, &reply) == 0);
885 igt_assert(end - start > 1 * frame_time(o) / 2 &&
886 end - start < 3 * frame_time(o) / 2);
887 join_vblank_wait_thread();
890 igt_info("."); fflush(stdout);
892 if (do_flip && (o->flags & TEST_HANG)) {
893 hang = hang_gpu(drm_fd);
894 igt_assert_f(hang, "failed to exercise page flip hang recovery\n");
897 /* try to make sure we can issue two flips during the same frame */
898 if (do_flip && (o->flags & TEST_EBUSY)) {
899 struct vblank_reply reply;
900 igt_assert(__wait_for_vblank(TEST_VBLANK_BLOCK, o->pipe, 1, 0, &reply) == 0);
904 do_or_die(do_page_flip(o, new_fb_id, !(o->flags & TEST_NOEVENT)));
906 if (o->flags & TEST_FENCE_STRESS)
907 emit_fence_stress(o);
910 do_or_die(do_wait_for_vblank(o, o->pipe, target_seq,
912 if (o->flags & TEST_VBLANK_BLOCK) {
913 event_handler(&o->vblank_state, vbl_reply.sequence,
915 vbl_reply.ts.tv_usec);
916 completed_events = EVENT_VBLANK;
920 if (do_flip && (o->flags & TEST_EBUSY))
921 igt_assert(do_page_flip(o, new_fb_id, true) == -EBUSY);
923 if (do_flip && (o->flags & TEST_RMFB))
926 /* pan before the flip completes */
927 if (o->flags & TEST_PAN) {
928 int count = do_flip ?
929 o->flip_state.count : o->vblank_state.count;
930 int x_ofs = count * 10 > o->fb_width - o->kmode[0].hdisplay ? o->fb_width - o->kmode[0].hdisplay : count * 10;
932 /* Make sure DSPSURF changes value */
933 if (o->flags & TEST_HANG)
934 o->current_fb_id = !o->current_fb_id;
936 igt_assert_f(set_mode(o, o->fb_ids[o->current_fb_id], x_ofs, 0) == 0,
937 "failed to pan (%dx%d@%dHz)+%d: %s\n",
938 o->kmode[0].hdisplay, o->kmode[0].vdisplay, o->kmode[0].vrefresh,
939 x_ofs, strerror(errno));
942 if (o->flags & TEST_DPMS)
943 set_dpms(o, DRM_MODE_DPMS_OFF);
945 if (o->flags & TEST_MODESET && !(o->flags & TEST_RMFB) && !(o->flags & TEST_VBLANK_RACE))
946 igt_assert_f(set_mode(o, 0 /* no fb */, 0, 0) == 0,
947 "failed to disable output: %s\n",
950 if (o->flags & TEST_RPM)
951 igt_assert(igt_wait_for_pm_status(IGT_RUNTIME_PM_STATUS_SUSPENDED));
953 if (o->flags & TEST_SUSPEND)
954 igt_system_suspend_autoresume();
956 if (do_vblank && (o->flags & TEST_EINVAL) && o->vblank_state.count > 0)
957 igt_assert(do_wait_for_vblank(o, o->pipe, target_seq, &vbl_reply)
960 if (do_flip && (o->flags & TEST_EINVAL) && !(o->flags & TEST_FB_BAD_TILING))
961 igt_assert(do_page_flip(o, new_fb_id, true) == expected_einval);
964 unhang_gpu(drm_fd, hang);
966 return completed_events;
969 static void update_state(struct event_state *es)
971 es->last_received_ts = es->current_received_ts;
972 es->last_ts = es->current_ts;
973 es->last_seq = es->current_seq;
977 static void update_all_state(struct test_output *o,
978 unsigned int completed_events)
980 if (completed_events & EVENT_FLIP)
981 update_state(&o->flip_state);
983 if (completed_events & EVENT_VBLANK)
984 update_state(&o->vblank_state);
987 static void connector_find_preferred_mode(uint32_t connector_id, int crtc_idx,
988 struct test_output *o)
990 struct kmstest_connector_config config;
992 if (kmstest_get_connector_config(drm_fd, connector_id, 1 << crtc_idx,
998 o->pipe = config.pipe;
999 o->kconnector[0] = config.connector;
1000 o->kencoder[0] = config.encoder;
1001 o->_crtc[0] = config.crtc->crtc_id;
1002 o->kmode[0] = config.default_mode;
1005 o->fb_width = o->kmode[0].hdisplay;
1006 o->fb_height = o->kmode[0].vdisplay;
1008 drmModeFreeCrtc(config.crtc);
1011 static bool mode_compatible(const drmModeModeInfo *a, const drmModeModeInfo *b)
1015 if (a->hdisplay != b->hdisplay)
1018 if (a->vdisplay != b->vdisplay)
1021 d_refresh = a->vrefresh - b->vrefresh;
1022 if (d_refresh < -1 || d_refresh > 1)
1028 static void connector_find_compatible_mode(int crtc_idx0, int crtc_idx1,
1029 struct test_output *o)
1031 struct kmstest_connector_config config[2];
1032 drmModeModeInfo *mode[2];
1035 if (kmstest_get_connector_config(drm_fd, o->_connector[0],
1036 1 << crtc_idx0, &config[0]) < 0)
1039 if (kmstest_get_connector_config(drm_fd, o->_connector[1],
1040 1 << crtc_idx1, &config[1]) < 0) {
1041 kmstest_free_connector_config(&config[0]);
1045 mode[0] = &config[0].default_mode;
1046 mode[1] = &config[1].default_mode;
1047 if (!mode_compatible(mode[0], mode[1])) {
1048 for (n = 0; n < config[0].connector->count_modes; n++) {
1049 mode[0] = &config[0].connector->modes[n];
1050 for (m = 0; m < config[1].connector->count_modes; m++) {
1051 mode[1] = &config[1].connector->modes[m];
1052 if (mode_compatible(mode[0], mode[1]))
1057 /* hope for the best! */
1058 mode[1] = mode[0] = &config[0].default_mode;
1062 o->pipe = config[0].pipe;
1063 o->fb_width = mode[0]->hdisplay;
1064 o->fb_height = mode[0]->vdisplay;
1067 o->kconnector[0] = config[0].connector;
1068 o->kencoder[0] = config[0].encoder;
1069 o->_crtc[0] = config[0].crtc->crtc_id;
1070 o->kmode[0] = *mode[0];
1072 o->kconnector[1] = config[1].connector;
1073 o->kencoder[1] = config[1].encoder;
1074 o->_crtc[1] = config[1].crtc->crtc_id;
1075 o->kmode[1] = *mode[1];
1077 drmModeFreeCrtc(config[0].crtc);
1078 drmModeFreeCrtc(config[1].crtc);
1081 static void paint_flip_mode(struct igt_fb *fb, bool odd_frame)
1083 cairo_t *cr = igt_get_cairo_ctx(drm_fd, fb);
1084 int width = fb->width;
1085 int height = fb->height;
1087 igt_paint_test_pattern(cr, width, height);
1090 cairo_rectangle(cr, width/4, height/2, width/4, height/8);
1092 cairo_rectangle(cr, width/2, height/2, width/4, height/8);
1094 cairo_set_source_rgb(cr, 1, 1, 1);
1097 igt_assert(!cairo_status(cr));
1102 fb_is_bound(struct test_output *o, int fb)
1106 for (n = 0; n < o->count; n++) {
1107 struct drm_mode_crtc mode;
1109 mode.crtc_id = o->_crtc[n];
1110 if (drmIoctl(drm_fd, DRM_IOCTL_MODE_GETCRTC, &mode))
1113 if (!mode.mode_valid || mode.fb_id != fb)
1120 static void check_final_state(struct test_output *o, struct event_state *es,
1121 unsigned int elapsed)
1123 igt_assert_f(es->count > 0,
1124 "no %s event received\n", es->name);
1126 /* Verify we drop no frames, but only if it's not a TV encoder, since
1127 * those use some funny fake timings behind userspace's back. */
1128 if (o->flags & TEST_CHECK_TS && !analog_tv_connector(o)) {
1130 int count = es->count;
1132 count *= o->seq_step;
1133 expected = elapsed * o->kmode[0].vrefresh / (1000 * 1000);
1134 igt_assert_f(count >= expected * 99/100 && count <= expected * 101/100,
1135 "dropped frames, expected %d, counted %d, encoder type %d\n",
1136 expected, count, o->kencoder[0]->encoder_type);
1141 * Wait until at least one pending event completes. Return mask of completed
1144 static unsigned int wait_for_events(struct test_output *o)
1146 drmEventContext evctx;
1147 struct timeval timeout = { .tv_sec = 3, .tv_usec = 0 };
1149 unsigned int event_mask;
1152 event_mask = o->pending_events;
1153 igt_assert(event_mask);
1155 memset(&evctx, 0, sizeof evctx);
1156 evctx.version = DRM_EVENT_CONTEXT_VERSION;
1157 evctx.vblank_handler = vblank_handler;
1158 evctx.page_flip_handler = page_flip_handler;
1160 /* make timeout lax with the dummy load */
1161 if (o->flags & (TEST_WITH_DUMMY_BCS | TEST_WITH_DUMMY_RCS))
1162 timeout.tv_sec *= 60;
1165 FD_SET(drm_fd, &fds);
1168 ret = select(drm_fd + 1, &fds, NULL, NULL, &timeout);
1169 } while (ret < 0 && errno == EINTR);
1171 igt_assert_f(ret >= 0,
1172 "select error (errno %i)\n", errno);
1173 igt_assert_f(ret > 0,
1174 "select timed out or error (ret %d)\n", ret);
1175 igt_assert_f(!FD_ISSET(0, &fds),
1176 "no fds active, breaking\n");
1178 do_or_die(drmHandleEvent(drm_fd, &evctx));
1179 } while (o->pending_events);
1181 event_mask ^= o->pending_events;
1182 igt_assert(event_mask);
1187 /* Returned the elapsed time in us */
1188 static unsigned event_loop(struct test_output *o, unsigned duration_ms)
1190 unsigned long start, end;
1191 uint32_t hang = 0; /* Suppress GCC warning */
1194 if (o->flags & TEST_HANG_ONCE) {
1195 hang = hang_gpu(drm_fd);
1196 igt_assert_f(hang, "failed to exercise page flip hang recovery\n");
1199 start = gettime_us();
1202 unsigned int completed_events;
1204 completed_events = run_test_step(o);
1205 if (o->pending_events)
1206 completed_events |= wait_for_events(o);
1207 check_all_state(o, completed_events);
1208 update_all_state(o, completed_events);
1210 if (count && (gettime_us() - start) / 1000 >= duration_ms)
1219 unhang_gpu(drm_fd, hang);
1221 /* Flush any remaining events */
1222 if (o->pending_events)
1228 static void free_test_output(struct test_output *o)
1232 for (i = 0; i < o->count; i++) {
1233 drmModeFreeEncoder(o->kencoder[i]);
1234 drmModeFreeConnector(o->kconnector[i]);
1238 static void run_test_on_crtc_set(struct test_output *o, int *crtc_idxs,
1239 int crtc_count, int duration_ms)
1241 char test_name[128];
1243 unsigned bo_size = 0;
1247 switch (crtc_count) {
1249 connector_find_preferred_mode(o->_connector[0], crtc_idxs[0], o);
1250 snprintf(test_name, sizeof(test_name),
1251 "%s on crtc %d, connector %d",
1252 igt_subtest_name(), o->_crtc[0], o->_connector[0]);
1255 connector_find_compatible_mode(crtc_idxs[0], crtc_idxs[1], o);
1256 snprintf(test_name, sizeof(test_name),
1257 "%s on crtc %d:%d, connector %d:%d",
1258 igt_subtest_name(), o->_crtc[0], o->_crtc[1],
1259 o->_connector[0], o->_connector[1]);
1267 igt_assert(o->count == crtc_count);
1269 last_connector = o->kconnector[0];
1271 igt_info("Beginning %s\n", test_name);
1273 if (o->flags & TEST_PAN)
1277 if (o->flags & TEST_FENCE_STRESS)
1280 /* 256 MB is usually the maximum mappable aperture,
1281 * (make it 4x times that to ensure failure) */
1282 if (o->flags & TEST_BO_TOOBIG)
1283 bo_size = 4*256*1024*1024;
1285 o->fb_ids[0] = igt_create_fb(drm_fd, o->fb_width, o->fb_height,
1286 igt_bpp_depth_to_drm_format(o->bpp, o->depth),
1287 tiled, &o->fb_info[0]);
1288 o->fb_ids[1] = igt_create_fb_with_bo_size(drm_fd, o->fb_width, o->fb_height,
1289 igt_bpp_depth_to_drm_format(o->bpp, o->depth),
1290 tiled, &o->fb_info[1], bo_size);
1291 o->fb_ids[2] = igt_create_fb(drm_fd, o->fb_width, o->fb_height,
1292 igt_bpp_depth_to_drm_format(o->bpp, o->depth),
1293 true, &o->fb_info[2]);
1294 igt_assert(o->fb_ids[0]);
1295 igt_assert(o->fb_ids[1]);
1296 if (o->flags & TEST_FB_BAD_TILING)
1297 igt_require(o->fb_ids[2]);
1299 paint_flip_mode(&o->fb_info[0], false);
1300 if (!(o->flags & TEST_BO_TOOBIG))
1301 paint_flip_mode(&o->fb_info[1], true);
1303 paint_flip_mode(&o->fb_info[2], true);
1305 if (o->flags & TEST_FB_BAD_TILING)
1308 for (i = 0; i < o->count; i++)
1309 kmstest_dump_mode(&o->kmode[i]);
1311 if (set_mode(o, o->fb_ids[0], 0, 0)) {
1312 /* We may fail to apply the mode if there are hidden
1313 * constraints, such as bandwidth on the third pipe.
1315 igt_assert_f(crtc_count > 1 || crtc_idxs[0] < 2,
1316 "set_mode may only fail on the 3rd pipe or in multiple crtc tests\n");
1319 igt_assert(fb_is_bound(o, o->fb_ids[0]));
1321 /* quiescent the hw a bit so ensure we don't miss a single frame */
1322 if (o->flags & TEST_CHECK_TS)
1325 if (o->flags & TEST_BO_TOOBIG) {
1326 igt_assert(do_page_flip(o, o->fb_ids[1], true) == -E2BIG);
1329 igt_assert(do_page_flip(o, o->fb_ids[1], true) == 0);
1332 o->current_fb_id = 1;
1334 if (o->flags & TEST_FLIP)
1335 o->flip_state.seq_step = 1;
1337 o->flip_state.seq_step = 0;
1338 if (o->flags & TEST_VBLANK)
1339 o->vblank_state.seq_step = 10;
1341 o->vblank_state.seq_step = 0;
1343 /* We run the vblank and flip actions in parallel by default. */
1344 o->seq_step = max(o->vblank_state.seq_step, o->flip_state.seq_step);
1346 elapsed = event_loop(o, duration_ms);
1348 if (o->flags & TEST_FLIP && !(o->flags & TEST_NOEVENT))
1349 check_final_state(o, &o->flip_state, elapsed);
1350 if (o->flags & TEST_VBLANK)
1351 check_final_state(o, &o->vblank_state, elapsed);
1353 igt_info("\n%s: PASSED\n\n", test_name);
1357 igt_remove_fb(drm_fd, &o->fb_info[2]);
1358 igt_remove_fb(drm_fd, &o->fb_info[1]);
1359 igt_remove_fb(drm_fd, &o->fb_info[0]);
1361 last_connector = NULL;
1363 free_test_output(o);
1366 static int run_test(int duration, int flags)
1368 struct test_output o;
1369 int i, n, modes = 0;
1371 igt_require((flags & TEST_HANG) == 0 || !is_hung(drm_fd));
1374 if (flags & TEST_RPM)
1375 igt_require(igt_setup_runtime_pm());
1377 resources = drmModeGetResources(drm_fd);
1378 igt_assert(resources);
1380 /* Count output configurations to scale test runtime. */
1381 for (i = 0; i < resources->count_connectors; i++) {
1382 for (n = 0; n < resources->count_crtcs; n++) {
1383 memset(&o, 0, sizeof(o));
1385 o._connector[0] = resources->connectors[i];
1387 o.flip_state.name = "flip";
1388 o.vblank_state.name = "vblank";
1392 connector_find_preferred_mode(o._connector[0], n, &o);
1396 free_test_output(&o);
1401 duration = duration * 1000 / modes;
1402 duration = duration < 500 ? 500 : duration;
1404 /* Find any connected displays */
1405 for (i = 0; i < resources->count_connectors; i++) {
1406 for (n = 0; n < resources->count_crtcs; n++) {
1409 memset(&o, 0, sizeof(o));
1411 o._connector[0] = resources->connectors[i];
1413 o.flip_state.name = "flip";
1414 o.vblank_state.name = "vblank";
1419 run_test_on_crtc_set(&o, &crtc_idx, 1, duration);
1423 drmModeFreeResources(resources);
1427 static int run_pair(int duration, int flags)
1429 struct test_output o;
1430 int i, j, m, n, modes = 0;
1432 igt_require((flags & TEST_HANG) == 0 || !is_hung(drm_fd));
1434 resources = drmModeGetResources(drm_fd);
1435 igt_assert(resources);
1437 /* Find a pair of connected displays */
1438 for (i = 0; i < resources->count_connectors; i++) {
1439 for (n = 0; n < resources->count_crtcs; n++) {
1440 for (j = i + 1; j < resources->count_connectors; j++) {
1441 for (m = n + 1; m < resources->count_crtcs; m++) {
1442 memset(&o, 0, sizeof(o));
1444 o._connector[0] = resources->connectors[i];
1445 o._connector[1] = resources->connectors[j];
1447 o.flip_state.name = "flip";
1448 o.vblank_state.name = "vblank";
1452 connector_find_compatible_mode(n, m, &o);
1456 free_test_output(&o);
1462 /* If we have fewer than 2 connected outputs then we won't have any
1463 * configuration at all. So skip in that case. */
1465 duration = duration * 1000 / modes;
1466 duration = duration < 500 ? 500 : duration;
1468 /* Find a pair of connected displays */
1469 for (i = 0; i < resources->count_connectors; i++) {
1470 for (n = 0; n < resources->count_crtcs; n++) {
1471 for (j = i + 1; j < resources->count_connectors; j++) {
1472 for (m = n + 1; m < resources->count_crtcs; m++) {
1475 memset(&o, 0, sizeof(o));
1477 o._connector[0] = resources->connectors[i];
1478 o._connector[1] = resources->connectors[j];
1480 o.flip_state.name = "flip";
1481 o.vblank_state.name = "vblank";
1488 run_test_on_crtc_set(&o, crtc_idxs, 2,
1495 drmModeFreeResources(resources);
1499 static void get_timestamp_format(void)
1504 ret = drmGetCap(drm_fd, DRM_CAP_TIMESTAMP_MONOTONIC, &cap_mono);
1505 igt_assert(ret == 0 || errno == EINVAL);
1506 monotonic_timestamp = ret == 0 && cap_mono == 1;
1507 igt_info("Using %s timestamps\n",
1508 monotonic_timestamp ? "monotonic" : "real");
1511 static void kms_flip_exit_handler(int sig)
1515 kmstest_set_connector_dpms(drm_fd, last_connector, DRM_MODE_DPMS_ON);
1519 int main(int argc, char **argv)
1526 { 30, TEST_VBLANK, "wf_vblank" },
1527 { 30, TEST_VBLANK | TEST_CHECK_TS, "wf_vblank-ts-check" },
1528 { 30, TEST_VBLANK | TEST_VBLANK_BLOCK | TEST_CHECK_TS,
1529 "blocking-wf_vblank" },
1530 { 30, TEST_VBLANK | TEST_VBLANK_ABSOLUTE,
1531 "absolute-wf_vblank" },
1532 { 30, TEST_VBLANK | TEST_VBLANK_BLOCK | TEST_VBLANK_ABSOLUTE,
1533 "blocking-absolute-wf_vblank" },
1534 { 60, TEST_VBLANK | TEST_DPMS | TEST_EINVAL, "wf_vblank-vs-dpms" },
1535 { 60, TEST_VBLANK | TEST_DPMS | TEST_WITH_DUMMY_BCS,
1536 "bcs-wf_vblank-vs-dpms" },
1537 { 60, TEST_VBLANK | TEST_DPMS | TEST_WITH_DUMMY_RCS,
1538 "rcs-wf_vblank-vs-dpms" },
1539 { 60, TEST_VBLANK | TEST_MODESET | TEST_EINVAL, "wf_vblank-vs-modeset" },
1540 { 60, TEST_VBLANK | TEST_MODESET | TEST_WITH_DUMMY_BCS,
1541 "bcs-wf_vblank-vs-modeset" },
1542 { 60, TEST_VBLANK | TEST_MODESET | TEST_WITH_DUMMY_RCS,
1543 "rcs-wf_vblank-vs-modeset" },
1545 { 30, TEST_FLIP , "plain-flip" },
1546 { 30, TEST_FLIP | TEST_EBUSY , "busy-flip" },
1547 { 30, TEST_FLIP | TEST_FENCE_STRESS , "flip-vs-fences" },
1548 { 30, TEST_FLIP | TEST_CHECK_TS, "plain-flip-ts-check" },
1549 { 30, TEST_FLIP | TEST_CHECK_TS | TEST_FB_RECREATE,
1550 "plain-flip-fb-recreate" },
1551 { 30, TEST_FLIP | TEST_RMFB | TEST_MODESET , "flip-vs-rmfb" },
1552 { 60, TEST_FLIP | TEST_DPMS | TEST_EINVAL, "flip-vs-dpms" },
1553 { 60, TEST_FLIP | TEST_DPMS | TEST_WITH_DUMMY_BCS, "bcs-flip-vs-dpms" },
1554 { 60, TEST_FLIP | TEST_DPMS | TEST_WITH_DUMMY_RCS, "rcs-flip-vs-dpms" },
1555 { 30, TEST_FLIP | TEST_PAN, "flip-vs-panning" },
1556 { 60, TEST_FLIP | TEST_PAN | TEST_WITH_DUMMY_BCS, "bcs-flip-vs-panning" },
1557 { 60, TEST_FLIP | TEST_PAN | TEST_WITH_DUMMY_RCS, "rcs-flip-vs-panning" },
1558 { 60, TEST_FLIP | TEST_MODESET | TEST_EINVAL, "flip-vs-modeset" },
1559 { 60, TEST_FLIP | TEST_MODESET | TEST_WITH_DUMMY_BCS, "bcs-flip-vs-modeset" },
1560 { 60, TEST_FLIP | TEST_MODESET | TEST_WITH_DUMMY_RCS, "rcs-flip-vs-modeset" },
1561 { 30, TEST_FLIP | TEST_VBLANK_EXPIRED_SEQ,
1562 "flip-vs-expired-vblank" },
1564 { 30, TEST_FLIP | TEST_VBLANK | TEST_VBLANK_ABSOLUTE |
1565 TEST_CHECK_TS, "flip-vs-absolute-wf_vblank" },
1566 { 30, TEST_FLIP | TEST_VBLANK | TEST_CHECK_TS,
1567 "flip-vs-wf_vblank" },
1568 { 30, TEST_FLIP | TEST_VBLANK | TEST_VBLANK_BLOCK |
1569 TEST_CHECK_TS, "flip-vs-blocking-wf-vblank" },
1570 { 30, TEST_FLIP | TEST_MODESET | TEST_HANG | TEST_NOEVENT, "flip-vs-modeset-vs-hang" },
1571 { 30, TEST_FLIP | TEST_PAN | TEST_HANG, "flip-vs-panning-vs-hang" },
1572 { 30, TEST_VBLANK | TEST_HANG_ONCE, "vblank-vs-hang" },
1573 { 1, TEST_FLIP | TEST_EINVAL | TEST_FB_BAD_TILING, "flip-vs-bad-tiling" },
1575 { 1, TEST_DPMS_OFF | TEST_MODESET | TEST_FLIP,
1576 "flip-vs-dpms-off-vs-modeset" },
1577 { 1, TEST_DPMS_OFF | TEST_MODESET | TEST_FLIP | TEST_SINGLE_BUFFER,
1578 "single-buffer-flip-vs-dpms-off-vs-modeset" },
1579 { 30, TEST_FLIP | TEST_NO_2X_OUTPUT | TEST_DPMS_OFF_OTHERS , "dpms-off-confusion" },
1580 { 0, TEST_ENOENT | TEST_NOEVENT, "nonexisting-fb" },
1581 { 10, TEST_DPMS_OFF | TEST_DPMS | TEST_VBLANK_RACE, "dpms-vs-vblank-race" },
1582 { 10, TEST_MODESET | TEST_VBLANK_RACE, "modeset-vs-vblank-race" },
1583 { 10, TEST_VBLANK | TEST_DPMS | TEST_RPM | TEST_TS_CONT, "vblank-vs-dpms-rpm" },
1584 { 10, TEST_VBLANK | TEST_MODESET | TEST_RPM | TEST_TS_CONT, "vblank-vs-modeset-rpm" },
1585 { 0, TEST_VBLANK | TEST_DPMS | TEST_SUSPEND | TEST_TS_CONT, "vblank-vs-dpms-suspend" },
1586 { 0, TEST_VBLANK | TEST_MODESET | TEST_SUSPEND | TEST_TS_CONT, "vblank-vs-modeset-suspend" },
1587 { 0, TEST_VBLANK | TEST_SUSPEND | TEST_TS_CONT, "vblank-vs-suspend" },
1588 { 0, TEST_BO_TOOBIG | TEST_NO_2X_OUTPUT, "bo-too-big" },
1592 igt_subtest_init(argc, argv);
1593 igt_skip_on_simulation();
1596 drm_fd = drm_open_any();
1598 igt_enable_connectors();
1600 igt_set_vt_graphics_mode();
1601 igt_install_exit_handler(kms_flip_exit_handler);
1602 get_timestamp_format();
1604 bufmgr = drm_intel_bufmgr_gem_init(drm_fd, 4096);
1605 devid = intel_get_drm_devid(drm_fd);
1606 batch = intel_batchbuffer_alloc(bufmgr, devid);
1609 for (i = 0; i < sizeof(tests) / sizeof (tests[0]); i++) {
1610 igt_subtest(tests[i].name)
1611 run_test(tests[i].duration, tests[i].flags);
1613 if (tests[i].flags & TEST_NO_2X_OUTPUT)
1616 /* code doesn't disable all crtcs, so skip rpm tests */
1617 if (tests[i].flags & TEST_RPM)
1620 igt_subtest_f( "2x-%s", tests[i].name)
1621 run_pair(tests[i].duration, tests[i].flags);
1624 igt_fork_signal_helper();
1625 for (i = 0; i < sizeof(tests) / sizeof (tests[0]); i++) {
1626 /* relative blocking vblank waits that get constantly interrupt
1627 * take forver. So don't do them. */
1628 if ((tests[i].flags & TEST_VBLANK_BLOCK) &&
1629 !(tests[i].flags & TEST_VBLANK_ABSOLUTE))
1632 igt_subtest_f( "%s-interruptible", tests[i].name)
1633 run_test(tests[i].duration, tests[i].flags);
1635 if (tests[i].flags & TEST_NO_2X_OUTPUT)
1638 /* code doesn't disable all crtcs, so skip rpm tests */
1639 if (tests[i].flags & TEST_RPM)
1642 igt_subtest_f( "2x-%s-interruptible", tests[i].name)
1643 run_pair(tests[i].duration, tests[i].flags);
1645 igt_stop_signal_helper();
1648 * Let drm_fd leak, since it's needed by the dpms restore
1649 * exit_handler and igt_exit() won't return.