Re: [PATCH i-g-t v5] tests/kms_plane_multiple: CRC based atomic correctness test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Op 02-11-16 om 10:32 schreef Mika Kahola:
> This is a testcase with multiple planes. The idea here is the following
>
>  - draw a uniform frame with blue color
>  - grab crc for reference
>  - put planes randomly on top with the same blue color
>  - punch holes with black color into the primary framebuffer
>  - ideally the planes should cover these holes so that the output is the
>    identical to reference crc
>  - composite all with one ioctl call
>  - grab crc and verify that the reference crc is equal
>  - repeat this for dozen iterations to maximize coverage
>
> v5: Remove limit for max number of iterations and add possibility to
>     loop forever (Daniel)
>     Remove IN_RANGE() macro (Maarten)
>     Remove log file and show random number seed on screen instead (Maarten)
>     Split legacy and atomic plane tests on own functions (Maarten)
>     remove test_atomic() function and pass test mode info as
>     parameter (Maarten)
>     Use bigger rectangle size (256x256) for non-cursor planes and
>     smaller (128x128) size for cursor plane (Maarten)
>
> v4: For atomic test enable crc capturing before entering into a
>     iteration loop. After each iteration, check that page flip
>     didn't take no more than 1 vblank, fetch all crc's and check
>     the values.
>
>     Introduce new command line parameter for the number of iterations.
>     The test run from 1 to 256 iterations.
>
> v3: Cleanup by removing separate plane array
>     For atomic, pass DRM_MODE_PAGE_FLIP_EVENT
>     Grab crc by using igt_pipe_crc_get_crc instead of igt_pipe_crc_collect_crc
>     Rename nplanes variable to max_planes
>     To optimize test execution, run iterations after the modeset
>
> v2: Keep a logfile on random number seeds per subtest that are not skipped
>     due to unmet test requirements
>
> Signed-off-by: Mika Kahola <mika.kahola@xxxxxxxxx>
> ---
>  tests/Makefile.sources     |   1 +
>  tests/kms_plane_multiple.c | 506 +++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 507 insertions(+)
>  create mode 100644 tests/kms_plane_multiple.c
>
> diff --git a/tests/Makefile.sources b/tests/Makefile.sources
> index 6d081c3..ffd59c1 100644
> --- a/tests/Makefile.sources
> +++ b/tests/Makefile.sources
> @@ -105,6 +105,7 @@ TESTS_progs_M = \
>  	kms_pipe_color \
>  	kms_pipe_crc_basic \
>  	kms_plane \
> +	kms_plane_multiple \
>  	kms_properties \
>  	kms_psr_sink_crc \
>  	kms_render \
> diff --git a/tests/kms_plane_multiple.c b/tests/kms_plane_multiple.c
> new file mode 100644
> index 0000000..d13ce1c
> --- /dev/null
> +++ b/tests/kms_plane_multiple.c
> @@ -0,0 +1,506 @@
> +/*
> + * Copyright © 2016 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> + * IN THE SOFTWARE.
> + *
> + */
> +
> +#include "igt.h"
> +#include "drmtest.h"
> +#include <errno.h>
> +#include <stdbool.h>
> +#include <stdio.h>
> +#include <string.h>
> +#include <time.h>
> +
> +IGT_TEST_DESCRIPTION("Test atomic mode setting with multiple planes ");
> +
> +#define MAX_CRCS          1
> +#define SIZE_PLANE      256
> +#define SIZE_CURSOR     128
> +#define LOOP_FOREVER     -1
> +
> +typedef struct {
> +	float red;
> +	float green;
> +	float blue;
> +} color_t;
> +
> +typedef struct {
> +	int drm_fd;
> +	igt_display_t display;
> +	igt_pipe_crc_t *pipe_crc;
> +	igt_plane_t *plane[IGT_MAX_PLANES];
> +	struct igt_fb fb[IGT_MAX_PLANES];
> +} data_t;
> +
> +typedef struct {
> +	data_t *data;
> +	igt_crc_t reference_crc;
> +} test_position_t;
> +
> +/* Command line parameters. */
> +struct {
> +	int iterations;
> +	bool user_seed;
> +	int seed;
> +} opt = {
> +	.iterations = 64,
> +	.user_seed = false,
> +	.seed = 1,
> +};
> +
> +static inline uint32_t pipe_select(int pipe)
> +{
> +	if (pipe > 1)
> +		return pipe << DRM_VBLANK_HIGH_CRTC_SHIFT;
> +	else if (pipe > 0)
> +		return DRM_VBLANK_SECONDARY;
> +	else
> +		return 0;
> +}
> +
> +static unsigned int get_vblank(int fd, int pipe, unsigned int flags)
> +{
> +	union drm_wait_vblank vbl;
> +
> +	memset(&vbl, 0, sizeof(vbl));
> +	vbl.request.type = DRM_VBLANK_RELATIVE | pipe_select(pipe) | flags;
> +	if (drmIoctl(fd, DRM_IOCTL_WAIT_VBLANK, &vbl))
> +		return 0;
> +
> +	return vbl.reply.sequence;
> +}
> +
> +/*
> + * Common code across all tests, acting on data_t
> + */
> +static void test_init(data_t *data, enum pipe pipe)
> +{
> +	data->pipe_crc = igt_pipe_crc_new(pipe, INTEL_PIPE_CRC_SOURCE_AUTO);
> +}
> +
> +static void test_fini(data_t *data, igt_output_t *output, int max_planes)
> +{
> +	for (int i = IGT_PLANE_PRIMARY; i <= max_planes; i++)
> +		igt_plane_set_fb(data->plane[i], NULL);
> +
> +	/* reset the constraint on the pipe */
> +	igt_output_set_pipe(output, PIPE_ANY);
> +
> +	igt_pipe_crc_free(data->pipe_crc);
> +}
> +
> +static void
> +test_grab_crc(data_t *data, igt_output_t *output, enum pipe pipe, bool atomic,
> +	      color_t *color, uint64_t tiling, igt_crc_t *crc /* out */)
> +{
> +	struct igt_fb fb;
> +	drmModeModeInfo *mode;
> +	igt_plane_t *primary;
> +	int ret, n;
> +
> +	igt_output_set_pipe(output, pipe);
> +
> +	primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
> +
> +	mode = igt_output_get_mode(output);
> +
> +	igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
> +			    DRM_FORMAT_XRGB8888,
> +			    LOCAL_DRM_FORMAT_MOD_NONE,
> +			    color->red, color->green, color->blue,
> +			    &fb);
> +
> +	igt_plane_set_fb(primary, &fb);
> +
> +	ret = igt_display_try_commit2(&data->display,
> +				      atomic ? COMMIT_ATOMIC : COMMIT_LEGACY);
> +	igt_skip_on(ret != 0);
> +
> +	igt_pipe_crc_start(data->pipe_crc);
> +	n = igt_pipe_crc_get_crcs(data->pipe_crc, 1, &crc);
> +	igt_assert_eq(n, 1);
> +	igt_pipe_crc_stop(data->pipe_crc);
> +
> +	igt_plane_set_fb(primary, NULL);
> +
> +	ret = igt_display_try_commit2(&data->display,
> +				      atomic ? COMMIT_ATOMIC : COMMIT_LEGACY);
> +	igt_skip_on(ret != 0);
> +
> +	igt_remove_fb(data->drm_fd, &fb);
> +}
> +
> +/*
> + * Multiple plane position test.
> + *   - We start by grabbing a reference CRC of a full blue fb being scanned
> + *     out on the primary plane
> + *   - Then we scannout number of planes:
> + *      * the primary plane uses a blue fb with a black rectangle hole
> + *      * planes, on top of the primary plane, with a blue fb that is set-up
> + *        to cover the black rectangles of the primary plane fb
> + *     The resulting CRC should be identical to the reference CRC
> + */
> +
> +static void
> +create_fb_for_mode_position(data_t *data, drmModeModeInfo *mode,
> +			    color_t *color, int *rect_x, int *rect_y,
> +			    int *rect_w, int *rect_h, uint64_t tiling,
> +			    int max_planes)
> +{
> +	unsigned int fb_id;
> +	cairo_t *cr;
> +
> +	fb_id = igt_create_fb(data->drm_fd,
> +			      mode->hdisplay, mode->vdisplay,
> +			      DRM_FORMAT_XRGB8888,
> +			      tiling,
> +			      &data->fb[IGT_PLANE_PRIMARY]);
> +	igt_assert(fb_id);
> +
> +	cr = igt_get_cairo_ctx(data->drm_fd, &data->fb[IGT_PLANE_PRIMARY]);
> +	igt_paint_color(cr, rect_x[0], rect_y[0],
> +			mode->hdisplay, mode->vdisplay,
> +			color->red, color->green, color->blue);
> +
> +	for (int i = IGT_PLANE_2; i <= max_planes; i++)
> +		igt_paint_color(cr, rect_x[i], rect_y[i],
> +				rect_w[i], rect_h[i], 0.0, 0.0, 0.0);
> +
> +	igt_assert(cairo_status(cr) == 0);
> +	cairo_destroy(cr);
> +}
> +
> +
> +static void
> +test_planes(data_t *data, enum pipe pipe, color_t *color,
> +	    uint64_t tiling, int max_planes, igt_output_t *output)
^prepare_planes?
> +{
> +	drmModeModeInfo *mode;
> +	int x[IGT_MAX_PLANES];
> +	int y[IGT_MAX_PLANES];
> +	int size[IGT_MAX_PLANES];
> +	int i;
> +
> +	igt_output_set_pipe(output, pipe);
> +
> +	mode = igt_output_get_mode(output);
> +
> +	/* planes with random positions */
> +	x[IGT_PLANE_PRIMARY] = 0;
> +	y[IGT_PLANE_PRIMARY] = 0;
> +	for (i = IGT_PLANE_2; i <= max_planes; i++) {
> +		if (i == IGT_PLANE_CURSOR)
> +			size[i] = SIZE_CURSOR;
> +		else
> +			size[i] = SIZE_PLANE;
> +
> +		x[i] = rand() % (mode->hdisplay - size[i]);
> +		y[i] = rand() % (mode->vdisplay - size[i]);
> +
> +		data->plane[i] = igt_output_get_plane(output, i);
> +
> +		igt_create_color_fb(data->drm_fd,
> +				    size[i], size[i],
> +				    data->plane[i]->is_cursor ? DRM_FORMAT_ARGB8888 : DRM_FORMAT_XRGB8888,
> +				    tiling,
> +				    color->red, color->green, color->blue,
> +				    &data->fb[i]);
> +
> +		igt_plane_set_position(data->plane[i], x[i], y[i]);
> +		igt_plane_set_fb(data->plane[i], &data->fb[i]);
> +	}
> +
> +	/* primary plane */
> +	data->plane[IGT_PLANE_PRIMARY] = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
> +	create_fb_for_mode_position(data, mode, color, x, y,
> +				    size, size, tiling, max_planes);
> +	igt_plane_set_fb(data->plane[IGT_PLANE_PRIMARY], &data->fb[IGT_PLANE_PRIMARY]);
> +}
> +
> +static void
> +test_atomic_plane_position_with_output(data_t *data, enum pipe pipe,
> +				       igt_output_t *output, int max_planes,
> +				       uint64_t tiling)
> +{
> +	char buf[256];
> +	struct drm_event *e = (void *)buf;
> +	test_position_t test = { .data = data };
> +	color_t blue  = { 0.0f, 0.0f, 1.0f };
> +	igt_crc_t *crc = NULL;
> +	unsigned int vblank_start;
> +	int i, n, ret;
> +	int iterations = opt.iterations < 1 ? 1 : opt.iterations;
> +	bool loop_forever;
> +	char info[256];
> +
> +	if (opt.iterations == LOOP_FOREVER) {
> +		loop_forever = true;
> +		sprintf(info, "forever");
> +	} else {
> +		loop_forever = false;
> +		sprintf(info, "for %d %s",
> +			iterations, iterations > 1 ? "iterations" : "iteration");
> +	}
> +
> +	igt_info("Testing connector %s using pipe %s with %d planes %s with seed %d\n",
> +		 igt_output_name(output), kmstest_pipe_name(pipe), max_planes,
> +		 info, opt.seed);
> +
> +	test_init(data, pipe);
> +
> +	test_grab_crc(data, output, pipe, true, &blue, tiling,
> +		      &test.reference_crc);
^This function removes the old fb and unsets the fb. You could prevent a legacy modeset here by preserving the fb until after the test loop.

Can also keep crc enabled here.
> +	igt_pipe_crc_start(data->pipe_crc);
> + \
> +	i = 0;
> +	while (i < iterations || loop_forever) {
> +		test_planes(data, pipe, &blue, tiling, max_planes, output);
> +
> +		vblank_start = get_vblank(data->display.drm_fd, pipe, DRM_VBLANK_NEXTONMISS);
> +
> +		igt_display_commit_atomic(&data->display,
> +					  DRM_MODE_PAGE_FLIP_EVENT,
> +					  &data->display);
> +
> +		igt_set_timeout(1, "Stuck on page flip");
> +
> +		ret = read(data->display.drm_fd, buf, sizeof(buf));
> +		igt_assert(ret >= 0);
> +
> +		igt_assert_eq(get_vblank(data->display.drm_fd, pipe, 0), vblank_start + 1);
> +		igt_assert_eq(e->type, DRM_EVENT_FLIP_COMPLETE);
> +		igt_reset_timeout();
> +
> +		n = igt_pipe_crc_get_crcs(data->pipe_crc, MAX_CRCS, &crc);
> +
> +		igt_assert_eq(n, MAX_CRCS);
> +
> +		igt_assert_crc_equal(&test.reference_crc, crc);
> +
> +		i++;
> +	}
> +
> +	igt_pipe_crc_stop(data->pipe_crc);
> +
> +	test_fini(data, output, max_planes);
> +}
> +
> +static void
> +test_legacy_plane_position_with_output(data_t *data, enum pipe pipe,
> +				       igt_output_t *output, int max_planes,
> +				       uint64_t tiling)
> +{
> +	test_position_t test = { .data = data };
> +	color_t blue  = { 0.0f, 0.0f, 1.0f };
> +	igt_crc_t *crc;
> +	int i, n;
> +	int iterations = opt.iterations < 1 ? 1 : opt.iterations;
> +	bool loop_forever;
> +	char info[256];
> +
> +	if (opt.iterations == LOOP_FOREVER) {
> +		loop_forever = true;
> +		sprintf(info, "forever");
> +	} else {
> +		loop_forever = false;
> +		sprintf(info, "for %d %s",
> +			iterations, iterations > 1 ? "iterations" : "iteration");
> +	}
> +
> +	igt_info("Testing connector %s using pipe %s with %d planes %s with seed %d\n",
> +		 igt_output_name(output), kmstest_pipe_name(pipe), max_planes,
> +		 info, opt.seed);
> +
> +	test_init(data, pipe);
> +
> +	test_grab_crc(data, output, pipe, false, &blue, tiling,
> +		      &test.reference_crc);
> +
> +	i = 0;
> +	while (i < iterations || loop_forever) {
> +		test_planes(data, pipe, &blue, tiling, max_planes, output);
> +
> +		igt_display_commit2(&data->display, COMMIT_LEGACY);
> +
> +		igt_pipe_crc_start(data->pipe_crc);
> +		n = igt_pipe_crc_get_crcs(data->pipe_crc, 1, &crc);
> +		igt_assert_eq(n, 1);
> +		igt_pipe_crc_stop(data->pipe_crc);
^Why do you still start/stop crc per update here?
> +		igt_assert_crc_equal(&test.reference_crc, crc);
> +
> +		i++;
> +	}
> +
> +	test_fini(data, output, max_planes);
> +}
> +
> +static void
> +test_plane_position(data_t *data, enum pipe pipe, bool atomic, int max_planes,
> +		    uint64_t tiling)
> +{
> +	igt_output_t *output;
> +	int connected_outs;
> +
> +	if (atomic)
> +		igt_require(data->display.is_atomic);
> +
> +	igt_skip_on(pipe >= data->display.n_pipes);
> +	igt_skip_on(max_planes >= data->display.pipes[pipe].n_planes);
> +
> +	if (!opt.user_seed)
> +		opt.seed = time(NULL);
> +
> +	srand(opt.seed);
> +
> +	connected_outs = 0;
> +	for_each_connected_output(&data->display, output) {
> +		if (atomic)
> +			test_atomic_plane_position_with_output(data, pipe,
> +							       output,
> +							       max_planes,
> +							       tiling);
> +		else
> +			test_legacy_plane_position_with_output(data, pipe,
> +							       output,
> +							       max_planes,
> +							       tiling);
> +
> +		connected_outs++;
> +	}
> +
> +	igt_skip_on(connected_outs == 0);
> +
> +}
> +
> +static void
> +run_tests_for_pipe_plane(data_t *data, enum pipe pipe, int max_planes)
> +{
> +	igt_subtest_f("legacy-pipe-%s-tiling-none-planes-%d",
> +		      kmstest_pipe_name(pipe), max_planes)
> +		test_plane_position(data, pipe, false, max_planes,
> +				    LOCAL_DRM_FORMAT_MOD_NONE);
> +
> +	igt_subtest_f("atomic-pipe-%s-tiling-none-planes-%d",
> +		      kmstest_pipe_name(pipe), max_planes)
> +		test_plane_position(data, pipe, true, max_planes,
> +				    LOCAL_I915_FORMAT_MOD_X_TILED);
> +
> +	igt_subtest_f("legacy-pipe-%s-tiling-x-planes-%d",
> +		      kmstest_pipe_name(pipe), max_planes)
> +		test_plane_position(data, pipe, false, max_planes,
> +				    LOCAL_I915_FORMAT_MOD_X_TILED);
> +
> +	igt_subtest_f("atomic-pipe-%s-tiling-x-planes-%d",
> +		      kmstest_pipe_name(pipe), max_planes)
> +		test_plane_position(data, pipe, true, max_planes,
> +				    LOCAL_I915_FORMAT_MOD_X_TILED);
> +
> +	igt_subtest_f("legacy-pipe-%s-tiling-y-planes-%d",
> +		      kmstest_pipe_name(pipe), max_planes)
> +		test_plane_position(data, pipe, false, max_planes,
> +				    LOCAL_I915_FORMAT_MOD_Y_TILED);
> +
> +	igt_subtest_f("atomic-pipe-%s-tiling-y-planes-%d",
> +		      kmstest_pipe_name(pipe), max_planes)
> +		test_plane_position(data, pipe, true, max_planes,
> +				    LOCAL_I915_FORMAT_MOD_Y_TILED);
> +
> +	igt_subtest_f("legacy-pipe-%s-tiling-yf-planes-%d",
> +		      kmstest_pipe_name(pipe), max_planes)
> +		test_plane_position(data, pipe, false, max_planes,
> +				    LOCAL_I915_FORMAT_MOD_Yf_TILED);
> +
> +	igt_subtest_f("atomic-pipe-%s-tiling-yf-planes-%d",
> +		      kmstest_pipe_name(pipe), max_planes)
> +		test_plane_position(data, pipe, true, max_planes,
> +				    LOCAL_I915_FORMAT_MOD_Yf_TILED);
> +}
> +
> +static void
> +run_tests_for_pipe(data_t *data, enum pipe pipe)
> +{
> +	for (int planes = IGT_PLANE_PRIMARY; planes < IGT_MAX_PLANES; planes++)
> +		run_tests_for_pipe_plane(data, pipe, planes);
> +}
> +
> +static data_t data;
> +
> +static int opt_handler(int option, int option_index, void *input)
> +{
> +	switch (option) {
> +	case 'i':
> +		opt.iterations = strtol(optarg, NULL, 0);
> +
> +		if (opt.iterations < LOOP_FOREVER || opt.iterations == 0) {
> +			igt_info("incorrect number of iterations\n");
> +			igt_assert(false);
> +		}
> +
> +		break;
> +	case 's':
> +		opt.user_seed = true;
> +		opt.seed = strtol(optarg, NULL, 0);
> +		break;
> +	default:
> +		igt_assert(false);
> +	}
> +
> +	return 0;
> +}
> +
> +const char *help_str =
> +	"  --iterations Number of iterations for test coverage. -1 loop forever, default 64 iterations\n"
> +	"  --seed       Seed for random number generator\n";
> +
> +int main(int argc, char *argv[])
> +{
> +	struct option long_options[] = {
> +		{ "iterations", required_argument, NULL, 'i'},
> +		{ "seed",    required_argument, NULL, 's'},
> +		{ 0, 0, 0, 0 }
> +	};
> +
> +	igt_subtest_init_parse_opts(&argc, argv, "", long_options, help_str,
> +				    opt_handler, NULL);
> +
> +	igt_skip_on_simulation();
> +
> +	igt_fixture {
> +		data.drm_fd = drm_open_driver_master(DRIVER_INTEL);
> +
> +		kmstest_set_vt_graphics_mode();
> +
> +		igt_require_pipe_crc();
> +		igt_display_init(&data.display, data.drm_fd);
> +	}
> +
> +	for (int pipe = 0; pipe < I915_MAX_PIPES; pipe++)
> +		run_tests_for_pipe(&data, pipe);
> +
> +	igt_fixture {
> +		igt_display_fini(&data.display);
> +	}
> +
> +	igt_exit();
> +}

Rest looks ok.

~Maarten

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux