All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maxime Ripard <maxime.ripard@bootlin.com>
To: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Cc: Petri Latvala <petri.latvala@intel.com>,
	Eben Upton <eben@raspberrypi.org>,
	igt-dev@lists.freedesktop.org,
	Boris Brezillon <boris.brezillon@bootlin.com>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Subject: Re: [igt-dev] [PATCH i-g-t v2 12/12] chamelium: Add a CRC-based display test for randomized planes
Date: Fri, 14 Dec 2018 10:22:52 +0100	[thread overview]
Message-ID: <20181214092252.ohezjsfvsyfdbtvt@flea> (raw)
In-Reply-To: <20181213155533.18048-13-paul.kocialkowski@bootlin.com>


[-- Attachment #1.1: Type: text/plain, Size: 11338 bytes --]

Hi,

On Thu, Dec 13, 2018 at 04:55:33PM +0100, Paul Kocialkowski wrote:
> This introduces a new test for the Chamelium, that sets up planes
> with randomized properties such as the format, dimensions, position,
> in-framebuffer offsets and stride. The Chamelium capture is checked
> against the reference generated by cairo with a CRC.
> 
> This test also includes testing of the VC4-specific T-tiled mode
> (in XR24 format).
> 
> Since this test does not share much with previous CRC-based display
> tests (especially regarding KMS configuration), most of the code is
> not shared with other tests.
> 
> This test can be derived with reproducible properties for regression
> testing in the future. For now, it serves as a fuzzing test
> 
> Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>

I'm really wondering if we shouldn't just move the common functions
(like enable_output) to lib, and create a new file for this test.

This test is quite unusual since it's an exploratory test, where you
want to test values that will break, while the rest of the tests in
that file are regression tests.

> ---
>  tests/kms_chamelium.c | 296 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 296 insertions(+)
> 
> diff --git a/tests/kms_chamelium.c b/tests/kms_chamelium.c
> index 7d95a8bc52f3..efd70f0f1b59 100644
> --- a/tests/kms_chamelium.c
> +++ b/tests/kms_chamelium.c
> @@ -26,6 +26,8 @@
>  
>  #include "config.h"
>  #include "igt.h"
> +#include "igt_sysfs.h"
> +#include "igt_vc4.h"
>  
>  #include <fcntl.h>
>  #include <string.h>
> @@ -703,6 +705,295 @@ test_display_frame_dump(data_t *data, struct chamelium_port *port)
>  	drmModeFreeConnector(connector);
>  }
>  
> +static uint32_t random_plane_formats[] = {
> +	DRM_FORMAT_ABGR8888,
> +	DRM_FORMAT_ARGB1555,
> +	DRM_FORMAT_ARGB8888,
> +	DRM_FORMAT_RGB565,
> +	DRM_FORMAT_BGR565,
> +	DRM_FORMAT_RGB888,
> +	DRM_FORMAT_BGR888,
> +	DRM_FORMAT_XBGR8888,
> +	DRM_FORMAT_XRGB1555,
> +	DRM_FORMAT_XRGB8888,
> +};

I guess we should make this generic to whatever is supported by
igt_convert and the hardware?

> +static void randomize_plane_dimensions(drmModeModeInfo *mode,
> +				       uint32_t *width, uint32_t *height,
> +				       uint32_t *src_x, uint32_t *src_y,
> +				       uint32_t *crtc_w, uint32_t *crtc_h,
> +				       int32_t *crtc_x, int32_t *crtc_y)
> +{
> +	/* Randomize width and height in the mode dimensions range. */
> +	*width = (rand() % mode->hdisplay) + 1;
> +	*height = (rand() % mode->vdisplay) + 1;
> +
> +	/*
> +	 * Randomize source offset, but keep at least half of the
> +	 * original size.
> +	 */
> +	*src_x = rand() % (*width / 2);
> +	*src_y = rand() % (*height / 2);
> +
> +	/*
> +	 * The on-crtc size does not include the source offset, so it
> +	 * needs to be subtracted to avoid scaling.
> +	 */
> +	*crtc_w = *width - *src_x;
> +	*crtc_h = *height - *src_y;
> +
> +	/*
> +	 * Randomize the on-crtc position and allow the plane to go
> +	 * off-display by up to half of its width and height.
> +	 */
> +	*crtc_x = (rand() % mode->hdisplay) - *width / 2;
> +	*crtc_y = (rand() % mode->vdisplay) - *height / 2;
> +}
> +
> +static void blit_plane_cairo(data_t *data, cairo_surface_t *result,
> +			     uint32_t src_x, uint32_t src_y,
> +			     uint32_t crtc_w, uint32_t crtc_h,
> +			     int32_t crtc_x, int32_t crtc_y,
> +			     struct igt_fb *fb)
> +{
> +	cairo_surface_t *surface;
> +	int32_t x, y;
> +	cairo_t *cr;
> +
> +	surface = igt_get_cairo_surface(data->drm_fd, fb);
> +
> +	x = crtc_x - (int32_t) src_x;
> +	y = crtc_y - (int32_t) src_y;
> +
> +	cr = cairo_create(result);
> +
> +	cairo_set_source_surface(cr, surface, x, y);
> +	cairo_surface_destroy(surface);
> +
> +	/* Clip the surface to a rectangle if needed. */
> +	if (src_x || src_y) {
> +		cairo_rectangle(cr, crtc_x, crtc_y, crtc_w, crtc_h);
> +		cairo_clip(cr);
> +	}
> +
> +	cairo_paint(cr);
> +
> +	cairo_destroy(cr);
> +}
> +
> +static void configure_plane(igt_plane_t *plane, uint32_t src_x, uint32_t src_y,
> +			    uint32_t crtc_w, uint32_t crtc_h, int32_t crtc_x,
> +			    int32_t crtc_y, struct igt_fb *fb)
> +{
> +	igt_plane_set_fb(plane, fb);
> +
> +	igt_plane_set_position(plane, crtc_x, crtc_y);
> +	igt_plane_set_size(plane, crtc_w, crtc_h);
> +
> +	igt_fb_set_position(fb, plane, src_x, src_y);
> +	/* Framebuffer source size set to on-CRTC size to avoid scaling. */
> +	igt_fb_set_size(fb, plane, crtc_w, crtc_h);
> +}
> +
> +static void test_display_planes_random(data_t *data,
> +				       struct chamelium_port *port,
> +				       enum chamelium_check check)
> +{
> +	igt_output_t *output;
> +	drmModeModeInfo *mode;
> +	igt_plane_t *primary_plane;
> +	struct igt_fb primary_fb;
> +	struct igt_fb result_fb;
> +	struct igt_fb *overlay_fbs;
> +	igt_crc_t *crc;
> +	igt_crc_t *expected_crc;
> +	struct chamelium_fb_crc_async_data *fb_crc;
> +	unsigned int overlay_planes_max = 0;
> +	unsigned int overlay_planes_count;
> +	cairo_surface_t *result_surface;
> +	int captured_frame_count;
> +	unsigned int i;
> +	int fb_id;
> +
> +	igt_assert(check == CHAMELIUM_CHECK_CRC);
> +
> +	srand(time(NULL));
> +
> +	reset_state(data, port);
> +
> +	/* Find the connector and pipe. */
> +	output = prepare_output(data, port);
> +
> +	mode = igt_output_get_mode(output);
> +
> +	/* Get a framebuffer for the primary plane. */
> +	primary_plane = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
> +	igt_assert(primary_plane);
> +
> +	fb_id = chamelium_get_pattern_fb(data, mode->hdisplay, mode->vdisplay,
> +					 DRM_FORMAT_XRGB8888, 64, &primary_fb);
> +	igt_assert(fb_id > 0);
> +
> +	/* Get a framebuffer for the cairo composition result. */
> +	fb_id = igt_create_fb(data->drm_fd, mode->hdisplay,
> +			      mode->vdisplay, DRM_FORMAT_XRGB8888,
> +			      LOCAL_DRM_FORMAT_MOD_NONE, &result_fb);
> +	igt_assert(fb_id > 0);
> +
> +	result_surface = igt_get_cairo_surface(data->drm_fd, &result_fb);
> +
> +	/* Paint the primary framebuffer on the result surface. */
> +	blit_plane_cairo(data, result_surface, 0, 0, 0, 0, 0, 0, &primary_fb);
> +
> +	/* Configure the primary plane. */
> +	igt_plane_set_fb(primary_plane, &primary_fb);
> +
> +	overlay_planes_max =
> +		igt_output_count_plane_type(output, DRM_PLANE_TYPE_OVERLAY);
> +
> +	/* Limit the number of planes to a reasonable scene. */
> +	if (overlay_planes_max > 4)
> +		overlay_planes_max = 4;
> +
> +	overlay_planes_count = (rand() % overlay_planes_max) + 1;
> +	igt_debug("Using %d overlay planes\n", overlay_planes_count);
> +
> +	overlay_fbs = calloc(sizeof(struct igt_fb), overlay_planes_count);
> +
> +	for (i = 0; i < overlay_planes_count; i++) {
> +		struct igt_fb *overlay_fb = &overlay_fbs[i];
> +		igt_plane_t *plane;
> +		struct igt_fb pattern_fb;
> +		uint32_t overlay_fb_w, overlay_fb_h;
> +		int32_t overlay_crtc_x, overlay_crtc_y;
> +		uint32_t overlay_crtc_w, overlay_crtc_h;
> +		uint32_t overlay_src_x, overlay_src_y;
> +		unsigned int index;
> +		unsigned int stride_min;
> +		unsigned int stride;
> +		bool vc4_t_tiled;
> +		uint32_t format;
> +
> +		plane = igt_output_get_plane_type_index(output,
> +							DRM_PLANE_TYPE_OVERLAY,
> +							i);
> +		igt_assert(plane);
> +
> +		randomize_plane_dimensions(mode, &overlay_fb_w, &overlay_fb_h,
> +					   &overlay_src_x, &overlay_src_y,
> +					   &overlay_crtc_w, &overlay_crtc_h,
> +					   &overlay_crtc_x, &overlay_crtc_y);
> +
> +		igt_debug("Plane %d: on-crtc size %dx%d\n", i, overlay_crtc_w,
> +			  overlay_crtc_h);
> +		igt_debug("Plane %d: on-crtc position %dx%d\n", i,
> +			  overlay_crtc_x, overlay_crtc_y);
> +		igt_debug("Plane %d: in-framebuffer position %dx%d\n", i,
> +			  overlay_src_x, overlay_src_y);
> +
> +		/* Get a pattern framebuffer for the overlay plane. */
> +		fb_id = chamelium_get_pattern_fb(data, overlay_fb_w,
> +						 overlay_fb_h,
> +						 DRM_FORMAT_XRGB8888,
> +						 32, &pattern_fb);
> +		igt_assert(fb_id > 0);
> +
> +		/* Randomize the use of tiled mode with a 1/4 probability. */
> +		index = rand() % 4;
> +
> +		if (is_vc4_device(data->drm_fd) && index == 0) {
> +			format = DRM_FORMAT_XRGB8888;
> +			vc4_t_tiled = true;
> +
> +			igt_debug("Plane %d: VC4 T-tiled %s format\n", i,
> +				  igt_format_str(format));
> +		} else {
> +			/* Randomize the format to test. */
> +			index = rand() % ARRAY_SIZE(random_plane_formats);
> +			format = random_plane_formats[index];
> +			vc4_t_tiled = false;
> +
> +			igt_debug("Plane %d: %s format\n", i,
> +				  igt_format_str(format));
> +		}
> +
> +		/* Convert the pattern to the test format if needed. */
> +		if (vc4_t_tiled) {
> +			fb_id = igt_vc4_fb_t_tiled_convert(overlay_fb,
> +							   &pattern_fb);
> +			igt_assert(fb_id > 0);
> +		} else {
> +			stride_min = overlay_fb_w *
> +				     igt_format_plane_bpp(format, 0) / 8;
> +
> +			/* Randomize the stride with at most twice the minimum. */
> +			stride = (rand() % stride_min) + stride_min;
> +
> +			/* Pixman requires the stride to be aligned to 32-byte words. */
> +			stride = ALIGN(stride, sizeof(uint32_t));
> +
> +			igt_debug("Plane %d: using stride %d\n", i, stride);
> +
> +			fb_id = igt_fb_convert_with_stride(overlay_fb,
> +							   &pattern_fb,
> +							   format, stride);
> +			igt_assert(fb_id);
> +		}
> +
> +		blit_plane_cairo(data, result_surface, overlay_src_x,
> +				 overlay_src_y, overlay_crtc_w, overlay_crtc_h,
> +				 overlay_crtc_x, overlay_crtc_y, &pattern_fb);
> +
> +		configure_plane(plane, overlay_src_x, overlay_src_y,
> +				overlay_crtc_w, overlay_crtc_h, overlay_crtc_x,
> +				overlay_crtc_y, overlay_fb);
> +
> +		/* Remove the original pattern framebuffer. */
> +		igt_remove_fb(data->drm_fd, &pattern_fb);
> +	}
> +
> +	cairo_surface_destroy(result_surface);
> +
> +	fb_crc = chamelium_calculate_fb_crc_async_start(data->drm_fd,
> +							&result_fb);
> +
> +	igt_display_commit2(&data->display, COMMIT_ATOMIC);
> +
> +	chamelium_capture(data->chamelium, port, 0, 0, 0, 0, 1);
> +	crc = chamelium_read_captured_crcs(data->chamelium,
> +					   &captured_frame_count);
> +
> +	igt_assert(captured_frame_count == 1);
> +
> +	expected_crc = chamelium_calculate_fb_crc_async_finish(fb_crc);
> +
> +	chamelium_assert_crc_eq_or_dump(data->chamelium,
> +					expected_crc, crc,
> +					&result_fb, i);
> +
> +	free(expected_crc);
> +	free(crc);
> +
> +	for (i = 0; i < overlay_planes_count; i++) {
> +		struct igt_fb *overlay_fb = &overlay_fbs[i];
> +		igt_plane_t *plane;
> +
> +		plane = igt_output_get_plane_type_index(output,
> +							DRM_PLANE_TYPE_OVERLAY,
> +							i);
> +		igt_assert(plane);
> +
> +		igt_plane_set_fb(plane, NULL);
> +		igt_remove_fb(data->drm_fd, overlay_fb);
> +	}
> +
> +	free(overlay_fbs);
> +
> +	igt_plane_set_fb(primary_plane, NULL);
> +	igt_remove_fb(data->drm_fd, &primary_fb);
> +	igt_remove_fb(data->drm_fd, &result_fb);
> +}
> +

This function is still pretty long and could be split into smaller chunks.

Maxime

-- 
Maxime Ripard, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 154 bytes --]

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

  reply	other threads:[~2018-12-14  9:23 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-13 15:55 [igt-dev] [PATCH i-g-t v2 00/12] Chamelium VC4 plane testing, with T-tiled mode Paul Kocialkowski
2018-12-13 15:55 ` [igt-dev] [PATCH i-g-t v2 01/12] chamelium: Pass dimensions instead of mode to pattern generation helper Paul Kocialkowski
2018-12-14  8:58   ` Maxime Ripard
2018-12-13 15:55 ` [igt-dev] [PATCH i-g-t v2 02/12] chamelium: Pass the pattern block size as argument to helpers Paul Kocialkowski
2018-12-14  9:00   ` Maxime Ripard
2018-12-13 15:55 ` [igt-dev] [PATCH i-g-t v2 03/12] chamelium: Debug-print CRCs when comparing them and dumping frames Paul Kocialkowski
2018-12-14  9:00   ` Maxime Ripard
2018-12-14 19:42   ` Lyude Paul
2018-12-13 15:55 ` [igt-dev] [PATCH i-g-t v2 04/12] lib: drmtest: Add helpers to check and require the VC4 driver Paul Kocialkowski
2018-12-14  9:00   ` Maxime Ripard
2018-12-13 15:55 ` [igt-dev] [PATCH i-g-t v2 05/12] lib/igt_fb: Add checks on i915 for i915-specific tiled buffer allocation Paul Kocialkowski
2018-12-14  9:02   ` Maxime Ripard
2018-12-13 15:55 ` [igt-dev] [PATCH i-g-t v2 06/12] lib/igt_fb: Add support for allocating T-tiled VC4 buffers Paul Kocialkowski
2018-12-14  9:03   ` Maxime Ripard
2018-12-13 15:55 ` [igt-dev] [PATCH i-g-t v2 07/12] lib/igt_vc4: Add helpers for converting linear to T-tiled XRGB buffers Paul Kocialkowski
2018-12-14  9:03   ` Maxime Ripard
2018-12-13 15:55 ` [igt-dev] [PATCH i-g-t v2 08/12] lib/igt_fb: Add a stride-provisioned fashion of igt_fb_convert Paul Kocialkowski
2018-12-14  9:05   ` Maxime Ripard
2018-12-13 15:55 ` [igt-dev] [PATCH i-g-t v2 09/12] lib/igt_fb: Add a helper to retreive the plane bpp for a given format Paul Kocialkowski
2018-12-14  9:05   ` Maxime Ripard
2018-12-13 15:55 ` [igt-dev] [PATCH i-g-t v2 10/12] lib/igt_kms: Add helpers to count and iterate planes from pipe Paul Kocialkowski
2018-12-13 15:55 ` [igt-dev] [PATCH i-g-t v2 11/12] lib/igt_kms: Add helpers to count and iterate planes from output Paul Kocialkowski
2018-12-13 15:55 ` [igt-dev] [PATCH i-g-t v2 12/12] chamelium: Add a CRC-based display test for randomized planes Paul Kocialkowski
2018-12-14  9:22   ` Maxime Ripard [this message]
2018-12-13 16:18 ` [igt-dev] ✗ Fi.CI.BAT: failure for Chamelium VC4 plane testing, with T-tiled mode (rev2) 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=20181214092252.ohezjsfvsyfdbtvt@flea \
    --to=maxime.ripard@bootlin.com \
    --cc=boris.brezillon@bootlin.com \
    --cc=eben@raspberrypi.org \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=paul.kocialkowski@bootlin.com \
    --cc=petri.latvala@intel.com \
    --cc=thomas.petazzoni@bootlin.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.