All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ville Syrjala <ville.syrjala@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Karthik B S <karthik.b.s@intel.com>
Subject: [igt-dev] [PATCH i-g-t v2] tests/kms_async_flips: Add CRC test to make sure the correct fb is being scanned out
Date: Fri, 24 Sep 2021 15:26:31 +0300	[thread overview]
Message-ID: <20210924122631.17746-1-ville.syrjala@linux.intel.com> (raw)
In-Reply-To: <20210304155018.12745-1-ville.syrjala@linux.intel.com>

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Use CRC to confirm that the old fb is no longer being scanned
out after the async flip completes. We do this by immediately
rendering garbage into the old fb after receiving the flip
event. Should fail if someone is improperly using mailbox style
flips while claiming to do async flips.

v2: Only fill a single column of pixels instead of the whole
    fb to allow the test to do more async flips per frame for
    a more stressful experience

Reviewed-by: Karthik B S <karthik.b.s@intel.com> #v1
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 tests/kms_async_flips.c | 145 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 145 insertions(+)

diff --git a/tests/kms_async_flips.c b/tests/kms_async_flips.c
index ecc62680f2c0..064e5022601b 100644
--- a/tests/kms_async_flips.c
+++ b/tests/kms_async_flips.c
@@ -52,6 +52,11 @@ typedef struct {
 	drmModeConnectorPtr connector;
 	unsigned long flip_timestamp_us;
 	double flip_interval;
+	igt_pipe_crc_t *pipe_crc;
+	igt_crc_t ref_crc;
+	int flip_count;
+	int frame_count;
+	bool flip_pending;
 } data_t;
 
 static drmModeConnectorPtr find_connector_for_modeset(data_t *data)
@@ -379,6 +384,142 @@ static void test_init(data_t *data)
 	drmModeFreeResources(res);
 }
 
+static void queue_vblank(data_t *data)
+{
+	drmVBlank wait_vbl = {
+		.request.type = DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT |
+			kmstest_get_pipe_from_crtc_id(data->drm_fd, data->crtc_id),
+		.request.sequence = 1,
+		.request.signal = (long)data,
+	};
+
+	igt_assert(drmIoctl(data->drm_fd, DRM_IOCTL_WAIT_VBLANK, &wait_vbl) == 0);
+}
+
+static void vblank_handler_crc(int fd_, unsigned int sequence, unsigned int tv_sec,
+			       unsigned int tv_usec, void *_data)
+{
+	data_t *data = _data;
+	igt_crc_t crc;
+
+	data->frame_count++;
+
+	igt_pipe_crc_get_single(data->pipe_crc, &crc);
+	igt_assert_crc_equal(&data->ref_crc, &crc);
+
+	/* check again next vblank */
+	queue_vblank(data);
+}
+
+static void flip_handler_crc(int fd_, unsigned int sequence, unsigned int tv_sec,
+			     unsigned int tv_usec, void *_data)
+{
+	data_t *data = _data;
+
+	data->flip_pending = false;
+	data->flip_count++;
+}
+
+static void wait_events_crc(data_t *data)
+{
+	drmEventContext evctx = {
+		.version = 2,
+		.vblank_handler = vblank_handler_crc,
+		.page_flip_handler = flip_handler_crc,
+	};
+
+	while (data->flip_pending) {
+		struct pollfd pfd = {
+			.fd = data->drm_fd,
+			.events = POLLIN,
+		};
+		int ret;
+
+		ret = poll(&pfd, 1, 2000);
+
+		switch (ret) {
+		case 0:
+			igt_assert_f(0, "Flip Timeout\n");
+			break;
+		case 1:
+			ret = drmHandleEvent(data->drm_fd, &evctx);
+			igt_assert(ret == 0);
+			break;
+		default:
+			/* unexpected */
+			igt_assert(0);
+		}
+	}
+}
+
+static unsigned int clock_ms(void)
+{
+	struct timespec ts;
+
+	clock_gettime(CLOCK_MONOTONIC, &ts);
+
+	return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
+}
+
+static void paint_fb(int fd, struct igt_fb *fb, uint32_t color)
+{
+	igt_draw_rect_fb(fd, NULL, 0, fb,
+			 gem_has_mappable_ggtt(fd) ?
+			 IGT_DRAW_MMAP_GTT : IGT_DRAW_MMAP_WC,
+			 0, 0, 1, fb->height, color);
+}
+
+static void test_crc(data_t *data)
+{
+	unsigned int frame = 0;
+	unsigned int start;
+	int ret;
+
+	data->flip_count = 0;
+	data->frame_count = 0;
+	data->flip_pending = false;
+
+	igt_draw_fill_fb(data->drm_fd, &data->bufs[frame], 0xff0000ff);
+	igt_draw_fill_fb(data->drm_fd, &data->bufs[!frame], 0xff0000ff);
+
+	ret = drmModeSetCrtc(data->drm_fd, data->crtc_id, data->bufs[frame].fb_id, 0, 0,
+			     &data->connector->connector_id, 1, &data->connector->modes[0]);
+	igt_assert_eq(ret, 0);
+
+	data->pipe_crc = igt_pipe_crc_new(data->drm_fd,
+					  kmstest_get_pipe_from_crtc_id(data->drm_fd, data->crtc_id),
+					  INTEL_PIPE_CRC_SOURCE_AUTO);
+
+	igt_pipe_crc_start(data->pipe_crc);
+	igt_pipe_crc_get_single(data->pipe_crc, &data->ref_crc);
+
+	queue_vblank(data);
+
+	start = clock_ms();
+
+	while (clock_ms() - start < 2000) {
+		/* fill the next fb with the expected color */
+		paint_fb(data->drm_fd, &data->bufs[frame], 0xff0000ff);
+
+		data->flip_pending = true;
+		ret = drmModePageFlip(data->drm_fd, data->crtc_id, data->bufs[frame].fb_id,
+				      DRM_MODE_PAGE_FLIP_ASYNC | DRM_MODE_PAGE_FLIP_EVENT, data);
+		igt_assert_eq(ret, 0);
+
+		wait_events_crc(data);
+
+		/* clobber the previous fb which should no longer be scanned out */
+		frame = !frame;
+		paint_fb(data->drm_fd, &data->bufs[frame], rand());
+	}
+
+	igt_pipe_crc_stop(data->pipe_crc);
+	igt_pipe_crc_free(data->pipe_crc);
+
+	/* make sure we got at a reasonable number of async flips done */
+	igt_assert_lt(data->frame_count * 2, data->flip_count);
+}
+
 igt_main
 {
 	static data_t data;
@@ -419,6 +560,10 @@ igt_main
 		igt_subtest("invalid-async-flip")
 			test_invalid(&data);
 
+		igt_describe("Use CRC to verify async flip scans out the correct framebuffer");
+		igt_subtest("crc")
+			test_crc(&data);
+
 		igt_fixture {
 			for (i = 0; i < ARRAY_SIZE(data.bufs); i++)
 				igt_remove_fb(data.drm_fd, &data.bufs[i]);
-- 
2.32.0

  parent reply	other threads:[~2021-09-24 12:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-04 15:50 [igt-dev] [PATCH i-g-t] tests/kms_async_flips: Add CRC test to make sure the correct fb is being scanned out Ville Syrjala
2021-03-04 17:15 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
2021-03-04 23:39 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2021-04-09 12:58 ` [igt-dev] ✓ Fi.CI.BAT: success for tests/kms_async_flips: Add CRC test to make sure the correct fb is being scanned out (rev2) Patchwork
2021-04-09 15:16 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2021-05-05  3:32 ` [igt-dev] [PATCH i-g-t] tests/kms_async_flips: Add CRC test to make sure the correct fb is being scanned out Karthik B S
2021-05-05 11:58   ` Ville Syrjälä
2021-05-06  4:56     ` Karthik B S
2021-09-24 12:26 ` Ville Syrjala [this message]
2021-09-24 14:40 ` [igt-dev] ✓ Fi.CI.BAT: success for tests/kms_async_flips: Add CRC test to make sure the correct fb is being scanned out (rev3) Patchwork
2021-09-24 17:23 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210924122631.17746-1-ville.syrjala@linux.intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=karthik.b.s@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.