Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t] tests/kms_render: Rewrite test to take advantage of igt_display.
Date: Wed, 24 Jan 2018 11:25:00 +0100	[thread overview]
Message-ID: <20180124102500.71999-1-maarten.lankhorst@linux.intel.com> (raw)

This test was taking ~100s for each subtest, and both tests were the same,
but required the user to pay attention. I've changed it to automated
checking with CRC, and removed the subtests.

This reduces the runtime for the test from about 200s to 10s
(with NV12 enabled), and checks whether pixel formats are supported
without special casing them.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
 tests/kms_render.c | 191 ++++++++++++++++++-----------------------------------
 1 file changed, 64 insertions(+), 127 deletions(-)

diff --git a/tests/kms_render.c b/tests/kms_render.c
index 255cf3de39cf..0b31d351dd90 100644
--- a/tests/kms_render.c
+++ b/tests/kms_render.c
@@ -31,16 +31,7 @@
 
 #include "intel_bufmgr.h"
 
-drmModeRes *resources;
-int drm_fd;
-
-enum test_flags {
-	TEST_DIRECT_RENDER	= 0x01,
-	TEST_GPU_BLIT		= 0x02,
-};
-
-static int paint_fb(struct igt_fb *fb, const char *test_name,
-		    const char *mode_format_str, const char *cconf_str)
+static int paint_fb(int drm_fd, struct igt_fb *fb, const char *mode_format_str, const char *cconf_str)
 {
 	cairo_t *cr;
 
@@ -51,7 +42,7 @@ static int paint_fb(struct igt_fb *fb, const char *test_name,
 
 	cairo_move_to(cr, fb->width / 2, fb->height / 2);
 	cairo_set_font_size(cr, 36);
-	igt_cairo_printf_line(cr, align_hcenter, 10, "%s", test_name);
+	igt_cairo_printf_line(cr, align_hcenter, 10, "kms_render");
 	igt_cairo_printf_line(cr, align_hcenter, 10, "%s", mode_format_str);
 	igt_cairo_printf_line(cr, align_hcenter, 10, "%s", cconf_str);
 
@@ -60,7 +51,7 @@ static int paint_fb(struct igt_fb *fb, const char *test_name,
 	return 0;
 }
 
-static void gpu_blit(struct igt_fb *dst_fb, struct igt_fb *src_fb)
+static void gpu_blit(int drm_fd, struct igt_fb *dst_fb, struct igt_fb *src_fb)
 {
 	drm_intel_bo *dst_bo;
 	drm_intel_bo *src_bo;
@@ -101,156 +92,102 @@ static void gpu_blit(struct igt_fb *dst_fb, struct igt_fb *src_fb)
 	drm_intel_bo_unreference(dst_bo);
 }
 
-static int test_format(const char *test_name,
-		       struct kmstest_connector_config *cconf,
-		       drmModeModeInfo *mode, uint32_t format,
-		       enum test_flags flags)
+static void test_format(igt_display_t *display,
+			enum pipe pipe,
+			igt_output_t *output,
+			igt_plane_t *primary,
+			uint32_t format)
 {
-	int width;
-	int height;
+	drmModeModeInfo *mode = igt_output_get_mode(output);
+	int width = mode->hdisplay, height = mode->vdisplay, ret, drm_fd = display->drm_fd;
 	struct igt_fb fb[2];
 	char *mode_format_str;
 	char *cconf_str;
-	int ret;
+	igt_pipe_crc_t *pipe_crc;
+	igt_crc_t direct, blit;
 
 	ret = asprintf(&mode_format_str, "%s @ %dHz / %s",
-		 mode->name, mode->vrefresh, igt_format_str(format));
+		       mode->name, mode->vrefresh, igt_format_str(format));
 	igt_assert_lt(0, ret);
+
 	ret = asprintf(&cconf_str, "pipe %s, encoder %s, connector %s",
-		       kmstest_pipe_name(cconf->pipe),
-		       kmstest_encoder_type_str(cconf->encoder->encoder_type),
-		       kmstest_connector_type_str(cconf->connector->connector_type));
+		       kmstest_pipe_name(pipe),
+		       kmstest_encoder_type_str(output->config.encoder->encoder_type),
+		       output->name);
 	igt_assert_lt(0, ret);
 
-	igt_info("Beginning test %s with %s on %s\n",
-		 test_name, mode_format_str, cconf_str);
-
-	width = mode->hdisplay;
-	height = mode->vdisplay;
-
-	if (!igt_create_fb(drm_fd, width, height, format,
-			   LOCAL_DRM_FORMAT_MOD_NONE, &fb[0]))
-		goto err1;
-
-	if (!igt_create_fb(drm_fd, width, height, format,
-			   LOCAL_DRM_FORMAT_MOD_NONE,	&fb[1]))
-		goto err2;
-
-	if (drmModeSetCrtc(drm_fd, cconf->crtc->crtc_id, fb[0].fb_id,
-				 0, 0, &cconf->connector->connector_id, 1,
-				 mode))
-		goto err2;
-	do_or_die(drmModePageFlip(drm_fd, cconf->crtc->crtc_id, fb[0].fb_id,
-				  0, NULL));
-	sleep(2);
-
-	if (flags & TEST_DIRECT_RENDER) {
-		paint_fb(&fb[0], test_name, mode_format_str, cconf_str);
-	} else if (flags & TEST_GPU_BLIT) {
-		paint_fb(&fb[1], test_name, mode_format_str, cconf_str);
-		gpu_blit(&fb[0], &fb[1]);
-	}
-	sleep(5);
+	igt_create_fb(drm_fd, width, height, format,
+		      LOCAL_DRM_FORMAT_MOD_NONE, &fb[0]);
 
-	igt_info("Test %s with %s on %s: PASSED\n",
-		 test_name, mode_format_str, cconf_str);
-	free(mode_format_str);
-	free(cconf_str);
+	igt_create_fb(drm_fd, width, height, format,
+		      LOCAL_DRM_FORMAT_MOD_NONE, &fb[1]);
 
-	igt_remove_fb(drm_fd, &fb[1]);
-	igt_remove_fb(drm_fd, &fb[0]);
+	paint_fb(drm_fd, &fb[0], mode_format_str, cconf_str);
+	gpu_blit(drm_fd, &fb[1], &fb[0]);
 
-	return 0;
+	igt_plane_set_fb(primary, &fb[0]);
+	igt_display_commit2(display, display->is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY);
+
+	pipe_crc = igt_pipe_crc_new(drm_fd, pipe, INTEL_PIPE_CRC_SOURCE_AUTO);
+	igt_pipe_crc_collect_crc(pipe_crc, &direct);
+
+	igt_plane_set_fb(primary, &fb[1]);
+	igt_display_commit2(display, display->is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY);
+	igt_pipe_crc_collect_crc(pipe_crc, &blit);
+
+	igt_assert_crc_equal(&direct, &blit);
+
+	igt_pipe_crc_free(pipe_crc);
 
-err2:
-	igt_remove_fb(drm_fd, &fb[0]);
-err1:
-	igt_info("Test %s with %s on %s: SKIPPED\n",
-		 test_name, mode_format_str, cconf_str);
 	free(mode_format_str);
 	free(cconf_str);
 
-	return -1;
+	igt_remove_fb(drm_fd, &fb[1]);
+	igt_remove_fb(drm_fd, &fb[0]);
 }
 
-static void test_connector(const char *test_name,
-			   struct kmstest_connector_config *cconf,
-			   enum test_flags flags)
+static void test_connector(igt_display_t *display, enum pipe pipe,
+			   igt_output_t *output)
 {
 	const uint32_t *formats;
-	int format_count;
-	int i;
+	igt_plane_t *primary = &display->pipes[pipe].planes[0];
+	int format_count, i, j, tested = 0;
+
+	igt_display_reset(display);
+	igt_output_set_pipe(output, pipe);
 
 	igt_get_all_cairo_formats(&formats, &format_count);
 	for (i = 0; i < format_count; i++) {
-		if (is_i915_device(drm_fd)
-		    && intel_gen(intel_get_drm_devid(drm_fd)) < 4
-		    && formats[i] == DRM_FORMAT_XRGB2101010) {
-			igt_info("gen2/3 don't support 10bpc, skipping\n");
-			continue;
-		}
-
-		test_format(test_name,
-			    cconf, &cconf->connector->modes[0],
-			    formats[i], flags);
-	}
-}
-
-static int run_test(const char *test_name, enum test_flags flags)
-{
-	int i;
-
-	resources = drmModeGetResources(drm_fd);
-	igt_assert(resources);
-
-	/* Find any connected displays */
-	for (i = 0; i < resources->count_connectors; i++) {
-		uint32_t connector_id;
-		int j;
-
-		connector_id = resources->connectors[i];
-		for (j = 0; j < resources->count_crtcs; j++) {
-			struct kmstest_connector_config cconf;
-
-			if (!kmstest_get_connector_config(drm_fd, connector_id,
-							   1 << j, &cconf))
+		for (j = 0; j < primary->drm_plane->count_formats; j++) {
+			if (primary->drm_plane->formats[j] != formats[i])
 				continue;
 
-			test_connector(test_name, &cconf, flags);
-
-			kmstest_free_connector_config(&cconf);
+			test_format(display, pipe, output,
+				    primary, formats[i]);
+			tested = 1;
+			break;
 		}
 	}
-
-	drmModeFreeResources(resources);
-
-	return 1;
+	igt_require_f(tested > 0, "No valid formats could be tested\n");
 }
 
-igt_main
+igt_simple_main
 {
-	struct {
-		enum test_flags flags;
-		const char *name;
-	} tests[] = {
-		{ TEST_DIRECT_RENDER,	"direct-render" },
-		{ TEST_GPU_BLIT,	"gpu-blit" },
-	};
-	int i;
+	igt_display_t display;
+	igt_output_t *output;
+	enum pipe pipe;
 
 	igt_skip_on_simulation();
 
-	igt_fixture {
-		drm_fd = drm_open_driver_master(DRIVER_ANY);
+	display.drm_fd = drm_open_driver_master(DRIVER_ANY);
 
-		kmstest_set_vt_graphics_mode();
-	}
+	kmstest_set_vt_graphics_mode();
+	igt_display_init(&display, display.drm_fd);
+	igt_display_require_output(&display);
 
-	for (i = 0; i < ARRAY_SIZE(tests); i++) {
-		igt_subtest(tests[i].name)
-			run_test(tests[i].name, tests[i].flags);
-	}
+	for_each_pipe_with_valid_output(&display, pipe, output)
+		test_connector(&display, pipe, output);
 
-	igt_fixture
-		close(drm_fd);
+	igt_display_fini(&display);
+	close(display.drm_fd);
 }
-- 
2.15.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

             reply	other threads:[~2018-01-24 10:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-24 10:25 Maarten Lankhorst [this message]
2018-01-24 11:01 ` [igt-dev] ✓ Fi.CI.BAT: success for tests/kms_render: Rewrite test to take advantage of igt_display Patchwork
2018-01-24 11:08 ` [igt-dev] [PATCH i-g-t] " Chris Wilson
2018-01-24 11:22   ` Maarten Lankhorst
2018-01-30  8:01     ` Daniel Vetter
2018-01-30  9:54       ` Maarten Lankhorst
2018-01-31 14:25       ` Imre Deak
2018-01-24 11:55 ` Mika Kahola
2018-01-24 13:24 ` [igt-dev] ✗ Fi.CI.IGT: failure for " 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=20180124102500.71999-1-maarten.lankhorst@linux.intel.com \
    --to=maarten.lankhorst@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox