All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH i-g-t v2] tests/kms_concurrent: Concurrent and interruptible subtests for atomic
@ 2017-03-15  8:43 Mika Kahola
  2017-03-29  9:53 ` Maarten Lankhorst
  0 siblings, 1 reply; 6+ messages in thread
From: Mika Kahola @ 2017-03-15  8:43 UTC (permalink / raw)
  To: intel-gfx

This test case introduces concurrently running test cases for atomic
modesetting.

The first test or thread draws blue backround with black holes on it.
These holes are covered by rectangular, blue planes that are placed
randomly like in test case 'kms_plane_multiple'.

The second thread changes resolution from higher to lower one and back.
The delay between resolution changes is randomly selected between 20 and
50 milliseconds.

The test runs by default 32 iterations to increase the coverage.

v2: use igt_fork instead of pthreads to create concurrent test runs (Maarten)

Signed-off-by: Mika Kahola <mika.kahola@intel.com>
---
 tests/Makefile.sources |   1 +
 tests/kms_concurrent.c | 630 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 631 insertions(+)
 create mode 100644 tests/kms_concurrent.c

diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index 1763b67..0f45f03 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -114,6 +114,7 @@ TESTS_progs_M = \
 	kms_plane \
 	kms_plane_multiple \
 	kms_plane_lowres \
+	kms_concurrent \
 	kms_properties \
 	kms_psr_sink_crc \
 	kms_render \
diff --git a/tests/kms_concurrent.c b/tests/kms_concurrent.c
new file mode 100644
index 0000000..6d20a7e
--- /dev/null
+++ b/tests/kms_concurrent.c
@@ -0,0 +1,630 @@
+/*
+ * Copyright © 2017 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>
+#include <pthread.h>
+
+IGT_TEST_DESCRIPTION("Test atomic mode setting concurrently with multiple planes and screen resolution");
+
+#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;
+	uint32_t crtc_id;
+	uint32_t connector_id;
+	igt_display_t display;
+	igt_output_t *output;
+	int pipe;
+	igt_plane_t **plane;
+	struct igt_fb *fb;
+} 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;
+	bool run;
+} opt = {
+	.iterations = 32,
+	.user_seed = false,
+	.seed = 1,
+	.run = true,
+};
+
+/*
+ * Common code across all tests, acting on data_t
+ */
+static void test_init(data_t *data, int n_planes)
+{
+	data->plane = calloc(n_planes, sizeof(data->plane));
+	igt_assert_f(data->plane != NULL, "Failed to allocate memory for planes\n");
+
+	data->fb = calloc(n_planes, sizeof(struct igt_fb));
+	igt_assert_f(data->fb != NULL, "Failed to allocate memory for FBs\n");
+}
+
+static void test_fini(data_t *data, igt_output_t *output, int n_planes)
+{
+	int i;
+
+	data->display.pipes[data->pipe].mode_blob = 0;
+
+	for (i = 0; i < n_planes; i++) {
+		igt_plane_t *plane = data->plane[i];
+
+		if (!plane)
+			continue;
+		if (plane->type == DRM_PLANE_TYPE_PRIMARY)
+			continue;
+		igt_plane_set_fb(plane, NULL);
+		data->plane[i] = NULL;
+	}
+
+	/* reset the constraint on the pipe */
+	igt_output_set_pipe(output, PIPE_ANY);
+
+	free(data->plane);
+	data->plane = NULL;
+	free(data->fb);
+	data->fb = NULL;
+}
+
+static int
+display_commit_mode(data_t *data, igt_crc_t *crc)
+{
+	char buf[256];
+	struct drm_event *e = (void *)buf;
+	int n, ret;
+	int flags = DRM_MODE_PAGE_FLIP_EVENT | DRM_MODE_ATOMIC_ALLOW_MODESET | DRM_MODE_ATOMIC_NONBLOCK;
+
+	ret = igt_display_try_commit_atomic(&data->display,
+					    flags,
+					    NULL);
+	igt_skip_on(ret != 0);
+
+	igt_set_timeout(1, "Stuck on page flip");
+	ret = read(data->display.drm_fd, buf, sizeof(buf));
+	igt_assert(ret >= 0);
+
+	igt_assert_eq(e->type, DRM_EVENT_FLIP_COMPLETE);
+	igt_reset_timeout();
+
+	return n;
+}
+
+static void
+test_grab_crc(data_t *data, color_t *color, igt_crc_t *crc /* out */)
+{
+	drmModeModeInfo *mode;
+	igt_plane_t *primary;
+	int ret;
+
+	igt_output_set_pipe(data->output, data->pipe);
+
+	primary = igt_output_get_plane_type(data->output, DRM_PLANE_TYPE_PRIMARY);
+	data->plane[primary->index] = primary;
+
+	mode = igt_output_get_mode(data->output);
+
+	igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
+			    DRM_FORMAT_XRGB8888,
+			    LOCAL_I915_FORMAT_MOD_X_TILED,
+			    color->red, color->green, color->blue,
+			    &data->fb[primary->index]);
+
+	igt_plane_set_fb(data->plane[primary->index], &data->fb[primary->index]);
+
+	ret = igt_display_try_commit2(&data->display, COMMIT_ATOMIC);
+	igt_skip_on(ret != 0);
+}
+
+/*
+ * 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;
+	igt_plane_t *primary;
+
+	primary = igt_output_get_plane_type(data->output, DRM_PLANE_TYPE_PRIMARY);
+
+	fb_id = igt_create_fb(data->drm_fd,
+			      mode->hdisplay, mode->vdisplay,
+			      DRM_FORMAT_XRGB8888,
+			      tiling,
+			      &data->fb[primary->index]);
+	igt_assert(fb_id);
+
+	cr = igt_get_cairo_ctx(data->drm_fd, &data->fb[primary->index]);
+	igt_paint_color(cr, rect_x[0], rect_y[0],
+			mode->hdisplay, mode->vdisplay,
+			color->red, color->green, color->blue);
+
+	for (int i = 0; i < max_planes; i++) {
+		if (data->plane[i]->type == DRM_PLANE_TYPE_PRIMARY)
+			continue;
+		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
+prepare_planes(data_t *data, color_t *color, int max_planes)
+{
+	drmModeModeInfo *mode;
+	igt_pipe_t *pipe;
+	igt_plane_t *primary;
+	int *x;
+	int *y;
+	int *size;
+	int i;
+
+	igt_output_set_pipe(data->output, data->pipe);
+	primary = igt_output_get_plane_type(data->output, DRM_PLANE_TYPE_PRIMARY);
+	pipe = primary->pipe;
+
+	x = malloc(pipe->n_planes * sizeof(*x));
+	igt_assert_f(x, "Failed to allocate %ld bytes for variable x\n", (long int) (pipe->n_planes * sizeof(*x)));
+	y = malloc(pipe->n_planes * sizeof(*y));
+	igt_assert_f(y, "Failed to allocate %ld bytes for variable y\n", (long int) (pipe->n_planes * sizeof(*y)));
+	size = malloc(pipe->n_planes * sizeof(*size));
+	igt_assert_f(size, "Failed to allocate %ld bytes for variable size\n", (long int) (pipe->n_planes * sizeof(*size)));
+
+	mode = igt_output_get_mode(data->output);
+
+	/* planes with random positions */
+	x[primary->index] = 0;
+	y[primary->index] = 0;
+	for (i = 0; i < max_planes; i++) {
+		igt_plane_t *plane = igt_output_get_plane(data->output, i);
+
+		if (plane->type == DRM_PLANE_TYPE_PRIMARY)
+			continue;
+		else if (plane->type == DRM_PLANE_TYPE_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] = plane;
+
+		igt_create_color_fb(data->drm_fd,
+				    size[i], size[i],
+				    data->plane[i]->type == DRM_PLANE_TYPE_CURSOR ? DRM_FORMAT_ARGB8888 : DRM_FORMAT_XRGB8888,
+				    data->plane[i]->type == DRM_PLANE_TYPE_CURSOR ? LOCAL_DRM_FORMAT_MOD_NONE : LOCAL_I915_FORMAT_MOD_X_TILED,
+				    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[primary->index] = primary;
+	create_fb_for_mode_position(data, mode, color, x, y, size, size,
+				    LOCAL_I915_FORMAT_MOD_X_TILED, max_planes);
+	igt_plane_set_fb(data->plane[primary->index], &data->fb[primary->index]);
+}
+
+static void
+test_plane_position_with_output(data_t *data)
+{
+	igt_crc_t *crc;
+	color_t blue  = { 0.0f, 0.0f, 1.0f };
+	int i;
+	int iterations = opt.iterations < 1 ? 1 : opt.iterations;
+	bool loop_forever;
+	char info[256];
+	int max_planes = data->display.pipes[data->pipe].n_planes;
+
+	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(data->output), kmstest_pipe_name(data->pipe), max_planes,
+		 info, opt.seed);
+
+	i = 0;
+	while (i < iterations || loop_forever) {
+		prepare_planes(data, &blue, max_planes);
+
+		display_commit_mode(data, crc);
+
+		i++;
+	}
+}
+
+static drmModeConnector *
+get_connector_connected(int drm_fd)
+{
+	drmModeRes *resources = drmModeGetResources(drm_fd);
+	drmModeConnector *connector;
+	int i;
+
+	for (i = 0; i < resources->count_connectors; i++) {
+		connector = drmModeGetConnector(drm_fd,
+						resources->connectors[i]);
+
+		if (connector->connection == DRM_MODE_CONNECTED)
+			break;
+
+		drmModeFreeConnector(connector);
+		connector = NULL;
+	}
+
+	drmModeFreeResources(resources);
+
+	return connector;
+}
+
+static int get_crtc_for_encoder(drmModeRes *resources,
+				drmModeEncoder *encoder)
+{
+	int mask, id;
+	int i;
+	bool found;
+
+	for (i = 0; i < resources->count_crtcs; i++) {
+		mask = 1 << i;
+		id = resources->crtcs[i];
+
+		found = encoder->possible_crtcs & mask;
+		if (found)
+			break;
+	}
+
+	if (!found)
+		return -EINVAL;
+
+	return id;
+}
+
+static int get_crtc_for_connector(int drm_fd, drmModeRes *resources,
+				  drmModeConnector *connector)
+{
+	drmModeEncoder *encoder;
+	int encoder_id;
+	int crtc_id;
+	int i;
+
+	for (i = 0; i < connector->count_encoders; i++) {
+		encoder_id = connector->encoders[i];
+		encoder = drmModeGetEncoder(drm_fd, encoder_id);
+
+		if (encoder) {
+			crtc_id = get_crtc_for_encoder(resources, encoder);
+
+			drmModeFreeEncoder(encoder);
+
+			if (crtc_id != 0)
+				break;
+		}
+	}
+
+	if (crtc_id == 0)
+		return -EINVAL;
+
+	return crtc_id;
+}
+
+static int get_crtc(int drm_fd)
+{
+	drmModeRes *resources;
+	drmModeConnector *connector;
+	drmModeEncoder *encoder;
+	int i, id;
+
+	resources = drmModeGetResources(drm_fd);
+	connector = get_connector_connected(drm_fd);
+
+	for (i = 0; i < resources->count_encoders; i++) {
+		encoder = drmModeGetEncoder(drm_fd, resources->encoders[i]);
+
+		if (encoder->encoder_id == connector->encoder_id)
+			break;
+
+		drmModeFreeEncoder(encoder);
+		encoder = NULL;
+	}
+
+	if (encoder)
+		return encoder->crtc_id;
+
+	id = get_crtc_for_connector(drm_fd, resources, connector);
+	igt_assert(id != 0);
+
+	return id;
+}
+
+static drmModeModeInfo *
+get_lowres_mode(data_t *data, drmModeModeInfo *mode_default)
+{
+	drmModeRes *resources = drmModeGetResources(data->drm_fd);
+	drmModeModeInfo std_1024_mode = {
+		.clock = 65000,
+		.hdisplay = 1024,
+		.hsync_start = 1048,
+		.hsync_end = 1184,
+		.htotal = 1344,
+		.hskew = 0,
+		.vdisplay = 768,
+		.vsync_start = 771,
+		.vsync_end = 777,
+		.vtotal = 806,
+		.vscan = 0,
+		.vrefresh = 60,
+		.flags = 0xA,
+		.type = 0x40,
+		.name = "Custom 1024x768",
+	};
+	drmModeModeInfo *mode;
+	drmModeConnector *connector;
+	bool found;
+	int limit = mode_default->vdisplay-SIZE_PLANE;
+	int i, j;
+
+	if (!resources) {
+		igt_warn("drmModeGetResources failed: %s\n", strerror(errno));
+		return mode;
+	}
+
+	found = false;
+	for (i = 0; i < resources->count_connectors; i++) {
+
+		connector = drmModeGetConnectorCurrent(data->drm_fd,
+						       resources->connectors[i]);
+
+		if (!connector) {
+			igt_warn("could not get connector %i: %s\n",
+				 resources->connectors[i], strerror(errno));
+			continue;
+		}
+
+		if (!connector->count_modes)
+			continue;
+
+		for (j = 0; j < connector->count_modes; j++) {
+			mode = &connector->modes[j];
+
+			if (mode->vdisplay < limit) {
+				found = true;
+				break;
+			}
+		}
+
+		drmModeFreeConnector(connector);
+	}
+
+	drmModeFreeResources(resources);
+
+	if (!found)
+		mode = &std_1024_mode;
+
+	return mode;
+}
+
+static void
+test_resolution_with_output(data_t *data)
+{
+	drmModeModeInfo *mode_hi, *mode_lo;
+	int ret;
+	int iterations = opt.iterations < 1 ? 1 : opt.iterations;
+	bool loop_forever;
+	int i;
+
+	if (opt.iterations == LOOP_FOREVER)
+		loop_forever = true;
+	else
+		loop_forever = false;
+
+	igt_info("Testing resolution with connector %s using pipe %s with seed %d\n",
+		 igt_output_name(data->output), kmstest_pipe_name(data->pipe), opt.seed);
+
+	mode_hi = igt_output_get_mode(data->output);
+	mode_lo = get_lowres_mode(data, mode_hi);
+
+	i = 0;
+	while (i < iterations || loop_forever) {
+		/* switch to lower resolution */
+		ret = drmModeSetCrtc(data->drm_fd, data->crtc_id, data->fb->fb_id, 0, 0,
+				     &data->connector_id, 1, mode_lo);
+		igt_assert_eq(ret, 0);
+
+		/* switch back to higher resolution */
+		ret = drmModeSetCrtc(data->drm_fd, data->crtc_id, data->fb->fb_id, 0, 0,
+				     &data->connector_id, 1, mode_hi);
+		igt_assert_eq(ret, 0);
+
+		i++;
+	}
+}
+
+static void
+run_test(data_t *data, enum pipe pipe)
+{
+	color_t blue  = { 0.0f, 0.0f, 1.0f };
+	test_position_t test = { .data = data };
+	int connected_outs;
+	int max_planes = data->display.pipes[data->pipe].n_planes;
+
+	if (!opt.user_seed)
+		opt.seed = time(NULL);
+
+	connected_outs = 0;
+	for_each_valid_output_on_pipe(&data->display, pipe, data->output) {
+		data->pipe = pipe;
+
+		data->connector_id = get_connector_connected(data->drm_fd)->connector_id;
+		igt_assert(data->connector_id != -EINVAL);
+
+		data->crtc_id = get_crtc(data->drm_fd);
+		igt_assert(data->crtc_id != -EINVAL);
+
+		test_init(data, max_planes);
+
+		test_grab_crc(data, &blue, &test.reference_crc);
+
+		igt_fork(child, 1) {
+			test_plane_position_with_output(data);
+		}
+
+		test_resolution_with_output(data);
+
+		igt_waitchildren();
+
+		test_fini(data, data->output, max_planes);
+
+		connected_outs++;
+	}
+
+	igt_skip_on(connected_outs == 0);
+}
+
+static void
+run_tests_for_pipe(data_t *data, enum pipe pipe)
+{
+	igt_output_t *output;
+
+	igt_fixture {
+		int valid_tests = 0;
+
+		igt_skip_on(pipe >= data->display.n_pipes);
+
+		for_each_valid_output_on_pipe(&data->display, pipe, output)
+			valid_tests++;
+
+		igt_require_f(valid_tests, "no valid crtc/connector combinations found\n");
+		igt_require(data->display.pipes[pipe].n_planes > 0);
+		igt_require(data->display.is_atomic);
+	}
+
+	igt_subtest_f("pipe-%s-basic", kmstest_pipe_name(pipe))
+		for_each_valid_output_on_pipe(&data->display, pipe, output)
+			run_test(data, pipe);
+}
+
+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";
+
+static data_t data;
+
+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_display_init(&data.display, data.drm_fd);
+		igt_require(data.display.n_pipes > 0);
+	}
+
+	for (int pipe = 0; pipe < I915_MAX_PIPES; pipe++) {
+		igt_subtest_group
+			run_tests_for_pipe(&data, pipe);
+	}
+
+	igt_fixture {
+		igt_display_fini(&data.display);
+	}
+
+	igt_exit();
+}
-- 
2.7.4

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH i-g-t v2] tests/kms_concurrent: Concurrent and interruptible subtests for atomic
  2017-03-15  8:43 [PATCH i-g-t v2] tests/kms_concurrent: Concurrent and interruptible subtests for atomic Mika Kahola
@ 2017-03-29  9:53 ` Maarten Lankhorst
  2017-04-10 12:11   ` Mika Kahola
  0 siblings, 1 reply; 6+ messages in thread
From: Maarten Lankhorst @ 2017-03-29  9:53 UTC (permalink / raw)
  To: Mika Kahola, intel-gfx

Op 15-03-17 om 09:43 schreef Mika Kahola:
> This test case introduces concurrently running test cases for atomic
> modesetting.
>
> The first test or thread draws blue backround with black holes on it.
> These holes are covered by rectangular, blue planes that are placed
> randomly like in test case 'kms_plane_multiple'.
>
> The second thread changes resolution from higher to lower one and back.
> The delay between resolution changes is randomly selected between 20 and
> 50 milliseconds.
>
> The test runs by default 32 iterations to increase the coverage.
>
> v2: use igt_fork instead of pthreads to create concurrent test runs (Maarten)
>
> Signed-off-by: Mika Kahola <mika.kahola@intel.com>
> ---
>  tests/Makefile.sources |   1 +
>  tests/kms_concurrent.c | 630 +++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 631 insertions(+)
>  create mode 100644 tests/kms_concurrent.c
>
> <snip>
> +static int
> +display_commit_mode(data_t *data, igt_crc_t *crc)
> +{
> +	char buf[256];
> +	struct drm_event *e = (void *)buf;
> +	int n, ret;
> +	int flags = DRM_MODE_PAGE_FLIP_EVENT | DRM_MODE_ATOMIC_ALLOW_MODESET | DRM_MODE_ATOMIC_NONBLOCK;
> +
> +	ret = igt_display_try_commit_atomic(&data->display,
> +					    flags,
> +					    NULL);
> +	igt_skip_on(ret != 0);
> +
> +	igt_set_timeout(1, "Stuck on page flip");
> +	ret = read(data->display.drm_fd, buf, sizeof(buf));
> +	igt_assert(ret >= 0);
> +
> +	igt_assert_eq(e->type, DRM_EVENT_FLIP_COMPLETE);
> +	igt_reset_timeout();
> +
> +	return n;
> +}
> +
> +static void
> +test_grab_crc(data_t *data, color_t *color, igt_crc_t *crc /* out */)
> +{
> +	drmModeModeInfo *mode;
> +	igt_plane_t *primary;
> +	int ret;
> +
> +	igt_output_set_pipe(data->output, data->pipe);
> +
> +	primary = igt_output_get_plane_type(data->output, DRM_PLANE_TYPE_PRIMARY);
> +	data->plane[primary->index] = primary;
> +
> +	mode = igt_output_get_mode(data->output);
> +
> +	igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
> +			    DRM_FORMAT_XRGB8888,
> +			    LOCAL_I915_FORMAT_MOD_X_TILED,
> +			    color->red, color->green, color->blue,
> +			    &data->fb[primary->index]);
> +
> +	igt_plane_set_fb(data->plane[primary->index], &data->fb[primary->index]);
> +
> +	ret = igt_display_try_commit2(&data->display, COMMIT_ATOMIC);
> +	igt_skip_on(ret != 0);
> +}
> +
> +/*
> + * 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;
> +	igt_plane_t *primary;
> +
> +	primary = igt_output_get_plane_type(data->output, DRM_PLANE_TYPE_PRIMARY);
> +
> +	fb_id = igt_create_fb(data->drm_fd,
> +			      mode->hdisplay, mode->vdisplay,
> +			      DRM_FORMAT_XRGB8888,
> +			      tiling,
> +			      &data->fb[primary->index]);
> +	igt_assert(fb_id);
> +
> +	cr = igt_get_cairo_ctx(data->drm_fd, &data->fb[primary->index]);
> +	igt_paint_color(cr, rect_x[0], rect_y[0],
> +			mode->hdisplay, mode->vdisplay,
> +			color->red, color->green, color->blue);
> +
> +	for (int i = 0; i < max_planes; i++) {
> +		if (data->plane[i]->type == DRM_PLANE_TYPE_PRIMARY)
> +			continue;
> +		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
> +prepare_planes(data_t *data, color_t *color, int max_planes)
> +{
> +	drmModeModeInfo *mode;
> +	igt_pipe_t *pipe;
> +	igt_plane_t *primary;
> +	int *x;
> +	int *y;
> +	int *size;
> +	int i;
> +
> +	igt_output_set_pipe(data->output, data->pipe);
> +	primary = igt_output_get_plane_type(data->output, DRM_PLANE_TYPE_PRIMARY);
> +	pipe = primary->pipe;
> +
> +	x = malloc(pipe->n_planes * sizeof(*x));
> +	igt_assert_f(x, "Failed to allocate %ld bytes for variable x\n", (long int) (pipe->n_planes * sizeof(*x)));
> +	y = malloc(pipe->n_planes * sizeof(*y));
> +	igt_assert_f(y, "Failed to allocate %ld bytes for variable y\n", (long int) (pipe->n_planes * sizeof(*y)));
> +	size = malloc(pipe->n_planes * sizeof(*size));
> +	igt_assert_f(size, "Failed to allocate %ld bytes for variable size\n", (long int) (pipe->n_planes * sizeof(*size)));
> +
> +	mode = igt_output_get_mode(data->output);
> +
> +	/* planes with random positions */
> +	x[primary->index] = 0;
> +	y[primary->index] = 0;
> +	for (i = 0; i < max_planes; i++) {
> +		igt_plane_t *plane = igt_output_get_plane(data->output, i);
> +
> +		if (plane->type == DRM_PLANE_TYPE_PRIMARY)
> +			continue;
> +		else if (plane->type == DRM_PLANE_TYPE_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] = plane;
> +
> +		igt_create_color_fb(data->drm_fd,
> +				    size[i], size[i],
> +				    data->plane[i]->type == DRM_PLANE_TYPE_CURSOR ? DRM_FORMAT_ARGB8888 : DRM_FORMAT_XRGB8888,
> +				    data->plane[i]->type == DRM_PLANE_TYPE_CURSOR ? LOCAL_DRM_FORMAT_MOD_NONE : LOCAL_I915_FORMAT_MOD_X_TILED,
> +				    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[primary->index] = primary;
> +	create_fb_for_mode_position(data, mode, color, x, y, size, size,
> +				    LOCAL_I915_FORMAT_MOD_X_TILED, max_planes);
> +	igt_plane_set_fb(data->plane[primary->index], &data->fb[primary->index]);
> +}
> +
> +static void
> +test_plane_position_with_output(data_t *data)
> +{
> +	igt_crc_t *crc;
> +	color_t blue  = { 0.0f, 0.0f, 1.0f };
> +	int i;
> +	int iterations = opt.iterations < 1 ? 1 : opt.iterations;
> +	bool loop_forever;
> +	char info[256];
> +	int max_planes = data->display.pipes[data->pipe].n_planes;
> +
> +	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(data->output), kmstest_pipe_name(data->pipe), max_planes,
> +		 info, opt.seed);
> +
> +	i = 0;
> +	while (i < iterations || loop_forever) {
> +		prepare_planes(data, &blue, max_planes);
> +
> +		display_commit_mode(data, crc);
> +
> +		i++;
> +	}
> +}
> +
> +static drmModeConnector *
> +get_connector_connected(int drm_fd)
> +{
> +	drmModeRes *resources = drmModeGetResources(drm_fd);
> +	drmModeConnector *connector;
> +	int i;
> +
> +	for (i = 0; i < resources->count_connectors; i++) {
> +		connector = drmModeGetConnector(drm_fd,
> +						resources->connectors[i]);
> +
> +		if (connector->connection == DRM_MODE_CONNECTED)
> +			break;
> +
> +		drmModeFreeConnector(connector);
> +		connector = NULL;
> +	}
> +
> +	drmModeFreeResources(resources);
> +
> +	return connector;
> +}
> +
> +static int get_crtc_for_encoder(drmModeRes *resources,
> +				drmModeEncoder *encoder)
> +{
> +	int mask, id;
> +	int i;
> +	bool found;
> +
> +	for (i = 0; i < resources->count_crtcs; i++) {
> +		mask = 1 << i;
> +		id = resources->crtcs[i];
> +
> +		found = encoder->possible_crtcs & mask;
> +		if (found)
> +			break;
> +	}
> +
> +	if (!found)
> +		return -EINVAL;
> +
> +	return id;
> +}
> +
> +static int get_crtc_for_connector(int drm_fd, drmModeRes *resources,
> +				  drmModeConnector *connector)
> +{
> +	drmModeEncoder *encoder;
> +	int encoder_id;
> +	int crtc_id;
> +	int i;
> +
> +	for (i = 0; i < connector->count_encoders; i++) {
> +		encoder_id = connector->encoders[i];
> +		encoder = drmModeGetEncoder(drm_fd, encoder_id);
> +
> +		if (encoder) {
> +			crtc_id = get_crtc_for_encoder(resources, encoder);
> +
> +			drmModeFreeEncoder(encoder);
> +
> +			if (crtc_id != 0)
> +				break;
> +		}
> +	}
> +
> +	if (crtc_id == 0)
> +		return -EINVAL;
> +
> +	return crtc_id;
> +}
> +
> +static int get_crtc(int drm_fd)
> +{
> +	drmModeRes *resources;
> +	drmModeConnector *connector;
> +	drmModeEncoder *encoder;
> +	int i, id;
> +
> +	resources = drmModeGetResources(drm_fd);
> +	connector = get_connector_connected(drm_fd);
> +
> +	for (i = 0; i < resources->count_encoders; i++) {
> +		encoder = drmModeGetEncoder(drm_fd, resources->encoders[i]);
> +
> +		if (encoder->encoder_id == connector->encoder_id)
> +			break;
> +
> +		drmModeFreeEncoder(encoder);
> +		encoder = NULL;
> +	}
> +
> +	if (encoder)
> +		return encoder->crtc_id;
> +
> +	id = get_crtc_for_connector(drm_fd, resources, connector);
> +	igt_assert(id != 0);
> +
> +	return id;
> +}
> +
> +static drmModeModeInfo *
> +get_lowres_mode(data_t *data, drmModeModeInfo *mode_default)
> +{
> +	drmModeRes *resources = drmModeGetResources(data->drm_fd);
> +	drmModeModeInfo std_1024_mode = {
> +		.clock = 65000,
> +		.hdisplay = 1024,
> +		.hsync_start = 1048,
> +		.hsync_end = 1184,
> +		.htotal = 1344,
> +		.hskew = 0,
> +		.vdisplay = 768,
> +		.vsync_start = 771,
> +		.vsync_end = 777,
> +		.vtotal = 806,
> +		.vscan = 0,
> +		.vrefresh = 60,
> +		.flags = 0xA,
> +		.type = 0x40,
> +		.name = "Custom 1024x768",
> +	};
> +	drmModeModeInfo *mode;
> +	drmModeConnector *connector;
> +	bool found;
> +	int limit = mode_default->vdisplay-SIZE_PLANE;
> +	int i, j;
> +
> +	if (!resources) {
> +		igt_warn("drmModeGetResources failed: %s\n", strerror(errno));
> +		return mode;
> +	}
> +
> +	found = false;
> +	for (i = 0; i < resources->count_connectors; i++) {
> +
> +		connector = drmModeGetConnectorCurrent(data->drm_fd,
> +						       resources->connectors[i]);
> +
> +		if (!connector) {
> +			igt_warn("could not get connector %i: %s\n",
> +				 resources->connectors[i], strerror(errno));
> +			continue;
> +		}
> +
> +		if (!connector->count_modes)
> +			continue;
> +
> +		for (j = 0; j < connector->count_modes; j++) {
> +			mode = &connector->modes[j];
> +
> +			if (mode->vdisplay < limit) {
> +				found = true;
> +				break;
> +			}
> +		}
> +
> +		drmModeFreeConnector(connector);
> +	}
> +
> +	drmModeFreeResources(resources);
> +
> +	if (!found)
> +		mode = &std_1024_mode;
> +
> +	return mode;
> +}

Still not completely happy about this part.

I would look at data->output->config.connector for modes, and return 1024 mode if nothing's found.

Saves a whole lot of drm calls.

> +static void
> +test_resolution_with_output(data_t *data)
> +{
> +	drmModeModeInfo *mode_hi, *mode_lo;
> +	int ret;
> +	int iterations = opt.iterations < 1 ? 1 : opt.iterations;
> +	bool loop_forever;
> +	int i;
> +
> +	if (opt.iterations == LOOP_FOREVER)
> +		loop_forever = true;
> +	else
> +		loop_forever = false;
> +
> +	igt_info("Testing resolution with connector %s using pipe %s with seed %d\n",
> +		 igt_output_name(data->output), kmstest_pipe_name(data->pipe), opt.seed);
> +
> +	mode_hi = igt_output_get_mode(data->output);
> +	mode_lo = get_lowres_mode(data, mode_hi);
> +
> +	i = 0;
> +	while (i < iterations || loop_forever) {
> +		/* switch to lower resolution */
> +		ret = drmModeSetCrtc(data->drm_fd, data->crtc_id, data->fb->fb_id, 0, 0,
> +				     &data->connector_id, 1, mode_lo);
> +		igt_assert_eq(ret, 0);
> +
> +		/* switch back to higher resolution */
> +		ret = drmModeSetCrtc(data->drm_fd, data->crtc_id, data->fb->fb_id, 0, 0,
> +				     &data->connector_id, 1, mode_hi);
> +		igt_assert_eq(ret, 0);
> +
> +		i++;
> +	}
> +}
Use igt_output_override_mode + igt_display calls? With the thread being a fork now, you can use igt_display. :)
> +static void
> +run_test(data_t *data, enum pipe pipe)
> +{
> +	color_t blue  = { 0.0f, 0.0f, 1.0f };
> +	test_position_t test = { .data = data };
> +	int connected_outs;
> +	int max_planes = data->display.pipes[data->pipe].n_planes;
> +
> +	if (!opt.user_seed)
> +		opt.seed = time(NULL);
> +
> +	connected_outs = 0;
> +	for_each_valid_output_on_pipe(&data->display, pipe, data->output) {
> +		data->pipe = pipe;
> +
> +		data->connector_id = get_connector_connected(data->drm_fd)->connector_id;
data->output->config.connector->connector_id ? Though I don't think we still need it if you use the igt display calls.
> +		igt_assert(data->connector_id != -EINVAL);
> +
> +		data->crtc_id = get_crtc(data->drm_fd);
igt_output_set_pipe(output, pipe);

Again, shouldn't need crtc_id, but if you did display->pipes[pipe].crtc_id

With those fixed, I don't think you need raw drm calls in this test at all. :)

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH i-g-t v2] tests/kms_concurrent: Concurrent and interruptible subtests for atomic
  2017-03-29  9:53 ` Maarten Lankhorst
@ 2017-04-10 12:11   ` Mika Kahola
  2017-04-10 12:39     ` Maarten Lankhorst
  0 siblings, 1 reply; 6+ messages in thread
From: Mika Kahola @ 2017-04-10 12:11 UTC (permalink / raw)
  To: Maarten Lankhorst, intel-gfx

On Wed, 2017-03-29 at 11:53 +0200, Maarten Lankhorst wrote:
> Op 15-03-17 om 09:43 schreef Mika Kahola:
> > 
> > This test case introduces concurrently running test cases for
> > atomic
> > modesetting.
> > 
> > The first test or thread draws blue backround with black holes on
> > it.
> > These holes are covered by rectangular, blue planes that are placed
> > randomly like in test case 'kms_plane_multiple'.
> > 
> > The second thread changes resolution from higher to lower one and
> > back.
> > The delay between resolution changes is randomly selected between
> > 20 and
> > 50 milliseconds.
> > 
> > The test runs by default 32 iterations to increase the coverage.
> > 
> > v2: use igt_fork instead of pthreads to create concurrent test runs
> > (Maarten)
> > 
> > Signed-off-by: Mika Kahola <mika.kahola@intel.com>
> > ---
> >  tests/Makefile.sources |   1 +
> >  tests/kms_concurrent.c | 630
> > +++++++++++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 631 insertions(+)
> >  create mode 100644 tests/kms_concurrent.c
> > 
> > <snip>
> > +static int
> > +display_commit_mode(data_t *data, igt_crc_t *crc)
> > +{
> > +	char buf[256];
> > +	struct drm_event *e = (void *)buf;
> > +	int n, ret;
> > +	int flags = DRM_MODE_PAGE_FLIP_EVENT |
> > DRM_MODE_ATOMIC_ALLOW_MODESET | DRM_MODE_ATOMIC_NONBLOCK;
> > +
> > +	ret = igt_display_try_commit_atomic(&data->display,
> > +					    flags,
> > +					    NULL);
> > +	igt_skip_on(ret != 0);
> > +
> > +	igt_set_timeout(1, "Stuck on page flip");
> > +	ret = read(data->display.drm_fd, buf, sizeof(buf));
> > +	igt_assert(ret >= 0);
> > +
> > +	igt_assert_eq(e->type, DRM_EVENT_FLIP_COMPLETE);
> > +	igt_reset_timeout();
> > +
> > +	return n;
> > +}
> > +
> > +static void
> > +test_grab_crc(data_t *data, color_t *color, igt_crc_t *crc /* out
> > */)
> > +{
> > +	drmModeModeInfo *mode;
> > +	igt_plane_t *primary;
> > +	int ret;
> > +
> > +	igt_output_set_pipe(data->output, data->pipe);
> > +
> > +	primary = igt_output_get_plane_type(data->output,
> > DRM_PLANE_TYPE_PRIMARY);
> > +	data->plane[primary->index] = primary;
> > +
> > +	mode = igt_output_get_mode(data->output);
> > +
> > +	igt_create_color_fb(data->drm_fd, mode->hdisplay, mode-
> > >vdisplay,
> > +			    DRM_FORMAT_XRGB8888,
> > +			    LOCAL_I915_FORMAT_MOD_X_TILED,
> > +			    color->red, color->green, color->blue,
> > +			    &data->fb[primary->index]);
> > +
> > +	igt_plane_set_fb(data->plane[primary->index], &data-
> > >fb[primary->index]);
> > +
> > +	ret = igt_display_try_commit2(&data->display,
> > COMMIT_ATOMIC);
> > +	igt_skip_on(ret != 0);
> > +}
> > +
> > +/*
> > + * 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;
> > +	igt_plane_t *primary;
> > +
> > +	primary = igt_output_get_plane_type(data->output,
> > DRM_PLANE_TYPE_PRIMARY);
> > +
> > +	fb_id = igt_create_fb(data->drm_fd,
> > +			      mode->hdisplay, mode->vdisplay,
> > +			      DRM_FORMAT_XRGB8888,
> > +			      tiling,
> > +			      &data->fb[primary->index]);
> > +	igt_assert(fb_id);
> > +
> > +	cr = igt_get_cairo_ctx(data->drm_fd, &data->fb[primary-
> > >index]);
> > +	igt_paint_color(cr, rect_x[0], rect_y[0],
> > +			mode->hdisplay, mode->vdisplay,
> > +			color->red, color->green, color->blue);
> > +
> > +	for (int i = 0; i < max_planes; i++) {
> > +		if (data->plane[i]->type ==
> > DRM_PLANE_TYPE_PRIMARY)
> > +			continue;
> > +		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
> > +prepare_planes(data_t *data, color_t *color, int max_planes)
> > +{
> > +	drmModeModeInfo *mode;
> > +	igt_pipe_t *pipe;
> > +	igt_plane_t *primary;
> > +	int *x;
> > +	int *y;
> > +	int *size;
> > +	int i;
> > +
> > +	igt_output_set_pipe(data->output, data->pipe);
> > +	primary = igt_output_get_plane_type(data->output,
> > DRM_PLANE_TYPE_PRIMARY);
> > +	pipe = primary->pipe;
> > +
> > +	x = malloc(pipe->n_planes * sizeof(*x));
> > +	igt_assert_f(x, "Failed to allocate %ld bytes for variable
> > x\n", (long int) (pipe->n_planes * sizeof(*x)));
> > +	y = malloc(pipe->n_planes * sizeof(*y));
> > +	igt_assert_f(y, "Failed to allocate %ld bytes for variable
> > y\n", (long int) (pipe->n_planes * sizeof(*y)));
> > +	size = malloc(pipe->n_planes * sizeof(*size));
> > +	igt_assert_f(size, "Failed to allocate %ld bytes for
> > variable size\n", (long int) (pipe->n_planes * sizeof(*size)));
> > +
> > +	mode = igt_output_get_mode(data->output);
> > +
> > +	/* planes with random positions */
> > +	x[primary->index] = 0;
> > +	y[primary->index] = 0;
> > +	for (i = 0; i < max_planes; i++) {
> > +		igt_plane_t *plane = igt_output_get_plane(data-
> > >output, i);
> > +
> > +		if (plane->type == DRM_PLANE_TYPE_PRIMARY)
> > +			continue;
> > +		else if (plane->type == DRM_PLANE_TYPE_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] = plane;
> > +
> > +		igt_create_color_fb(data->drm_fd,
> > +				    size[i], size[i],
> > +				    data->plane[i]->type ==
> > DRM_PLANE_TYPE_CURSOR ? DRM_FORMAT_ARGB8888 : DRM_FORMAT_XRGB8888,
> > +				    data->plane[i]->type ==
> > DRM_PLANE_TYPE_CURSOR ? LOCAL_DRM_FORMAT_MOD_NONE :
> > LOCAL_I915_FORMAT_MOD_X_TILED,
> > +				    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[primary->index] = primary;
> > +	create_fb_for_mode_position(data, mode, color, x, y, size,
> > size,
> > +				    LOCAL_I915_FORMAT_MOD_X_TILED,
> > max_planes);
> > +	igt_plane_set_fb(data->plane[primary->index], &data-
> > >fb[primary->index]);
> > +}
> > +
> > +static void
> > +test_plane_position_with_output(data_t *data)
> > +{
> > +	igt_crc_t *crc;
> > +	color_t blue  = { 0.0f, 0.0f, 1.0f };
> > +	int i;
> > +	int iterations = opt.iterations < 1 ? 1 : opt.iterations;
> > +	bool loop_forever;
> > +	char info[256];
> > +	int max_planes = data->display.pipes[data->pipe].n_planes;
> > +
> > +	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(data->output),
> > kmstest_pipe_name(data->pipe), max_planes,
> > +		 info, opt.seed);
> > +
> > +	i = 0;
> > +	while (i < iterations || loop_forever) {
> > +		prepare_planes(data, &blue, max_planes);
> > +
> > +		display_commit_mode(data, crc);
> > +
> > +		i++;
> > +	}
> > +}
> > +
> > +static drmModeConnector *
> > +get_connector_connected(int drm_fd)
> > +{
> > +	drmModeRes *resources = drmModeGetResources(drm_fd);
> > +	drmModeConnector *connector;
> > +	int i;
> > +
> > +	for (i = 0; i < resources->count_connectors; i++) {
> > +		connector = drmModeGetConnector(drm_fd,
> > +						resources-
> > >connectors[i]);
> > +
> > +		if (connector->connection == DRM_MODE_CONNECTED)
> > +			break;
> > +
> > +		drmModeFreeConnector(connector);
> > +		connector = NULL;
> > +	}
> > +
> > +	drmModeFreeResources(resources);
> > +
> > +	return connector;
> > +}
> > +
> > +static int get_crtc_for_encoder(drmModeRes *resources,
> > +				drmModeEncoder *encoder)
> > +{
> > +	int mask, id;
> > +	int i;
> > +	bool found;
> > +
> > +	for (i = 0; i < resources->count_crtcs; i++) {
> > +		mask = 1 << i;
> > +		id = resources->crtcs[i];
> > +
> > +		found = encoder->possible_crtcs & mask;
> > +		if (found)
> > +			break;
> > +	}
> > +
> > +	if (!found)
> > +		return -EINVAL;
> > +
> > +	return id;
> > +}
> > +
> > +static int get_crtc_for_connector(int drm_fd, drmModeRes
> > *resources,
> > +				  drmModeConnector *connector)
> > +{
> > +	drmModeEncoder *encoder;
> > +	int encoder_id;
> > +	int crtc_id;
> > +	int i;
> > +
> > +	for (i = 0; i < connector->count_encoders; i++) {
> > +		encoder_id = connector->encoders[i];
> > +		encoder = drmModeGetEncoder(drm_fd, encoder_id);
> > +
> > +		if (encoder) {
> > +			crtc_id = get_crtc_for_encoder(resources,
> > encoder);
> > +
> > +			drmModeFreeEncoder(encoder);
> > +
> > +			if (crtc_id != 0)
> > +				break;
> > +		}
> > +	}
> > +
> > +	if (crtc_id == 0)
> > +		return -EINVAL;
> > +
> > +	return crtc_id;
> > +}
> > +
> > +static int get_crtc(int drm_fd)
> > +{
> > +	drmModeRes *resources;
> > +	drmModeConnector *connector;
> > +	drmModeEncoder *encoder;
> > +	int i, id;
> > +
> > +	resources = drmModeGetResources(drm_fd);
> > +	connector = get_connector_connected(drm_fd);
> > +
> > +	for (i = 0; i < resources->count_encoders; i++) {
> > +		encoder = drmModeGetEncoder(drm_fd, resources-
> > >encoders[i]);
> > +
> > +		if (encoder->encoder_id == connector->encoder_id)
> > +			break;
> > +
> > +		drmModeFreeEncoder(encoder);
> > +		encoder = NULL;
> > +	}
> > +
> > +	if (encoder)
> > +		return encoder->crtc_id;
> > +
> > +	id = get_crtc_for_connector(drm_fd, resources, connector);
> > +	igt_assert(id != 0);
> > +
> > +	return id;
> > +}
> > +
> > +static drmModeModeInfo *
> > +get_lowres_mode(data_t *data, drmModeModeInfo *mode_default)
> > +{
> > +	drmModeRes *resources = drmModeGetResources(data->drm_fd);
> > +	drmModeModeInfo std_1024_mode = {
> > +		.clock = 65000,
> > +		.hdisplay = 1024,
> > +		.hsync_start = 1048,
> > +		.hsync_end = 1184,
> > +		.htotal = 1344,
> > +		.hskew = 0,
> > +		.vdisplay = 768,
> > +		.vsync_start = 771,
> > +		.vsync_end = 777,
> > +		.vtotal = 806,
> > +		.vscan = 0,
> > +		.vrefresh = 60,
> > +		.flags = 0xA,
> > +		.type = 0x40,
> > +		.name = "Custom 1024x768",
> > +	};
> > +	drmModeModeInfo *mode;
> > +	drmModeConnector *connector;
> > +	bool found;
> > +	int limit = mode_default->vdisplay-SIZE_PLANE;
> > +	int i, j;
> > +
> > +	if (!resources) {
> > +		igt_warn("drmModeGetResources failed: %s\n",
> > strerror(errno));
> > +		return mode;
> > +	}
> > +
> > +	found = false;
> > +	for (i = 0; i < resources->count_connectors; i++) {
> > +
> > +		connector = drmModeGetConnectorCurrent(data-
> > >drm_fd,
> > +						       resources-
> > >connectors[i]);
> > +
> > +		if (!connector) {
> > +			igt_warn("could not get connector %i:
> > %s\n",
> > +				 resources->connectors[i],
> > strerror(errno));
> > +			continue;
> > +		}
> > +
> > +		if (!connector->count_modes)
> > +			continue;
> > +
> > +		for (j = 0; j < connector->count_modes; j++) {
> > +			mode = &connector->modes[j];
> > +
> > +			if (mode->vdisplay < limit) {
> > +				found = true;
> > +				break;
> > +			}
> > +		}
> > +
> > +		drmModeFreeConnector(connector);
> > +	}
> > +
> > +	drmModeFreeResources(resources);
> > +
> > +	if (!found)
> > +		mode = &std_1024_mode;
> > +
> > +	return mode;
> > +}
> Still not completely happy about this part.
> 
> I would look at data->output->config.connector for modes, and return
> 1024 mode if nothing's found.
> 
> Saves a whole lot of drm calls.
True. A lot of lines can be cleaned out.
> 
> > 
> > +static void
> > +test_resolution_with_output(data_t *data)
> > +{
> > +	drmModeModeInfo *mode_hi, *mode_lo;
> > +	int ret;
> > +	int iterations = opt.iterations < 1 ? 1 : opt.iterations;
> > +	bool loop_forever;
> > +	int i;
> > +
> > +	if (opt.iterations == LOOP_FOREVER)
> > +		loop_forever = true;
> > +	else
> > +		loop_forever = false;
> > +
> > +	igt_info("Testing resolution with connector %s using pipe
> > %s with seed %d\n",
> > +		 igt_output_name(data->output),
> > kmstest_pipe_name(data->pipe), opt.seed);
> > +
> > +	mode_hi = igt_output_get_mode(data->output);
> > +	mode_lo = get_lowres_mode(data, mode_hi);
> > +
> > +	i = 0;
> > +	while (i < iterations || loop_forever) {
> > +		/* switch to lower resolution */
> > +		ret = drmModeSetCrtc(data->drm_fd, data->crtc_id,
> > data->fb->fb_id, 0, 0,
> > +				     &data->connector_id, 1,
> > mode_lo);
> > +		igt_assert_eq(ret, 0);
> > +
> > +		/* switch back to higher resolution */
> > +		ret = drmModeSetCrtc(data->drm_fd, data->crtc_id,
> > data->fb->fb_id, 0, 0,
> > +				     &data->connector_id, 1,
> > mode_hi);
> > +		igt_assert_eq(ret, 0);
> > +
> > +		i++;
> > +	}
> > +}
> Use igt_output_override_mode + igt_display calls? With the thread
> being a fork now, you can use igt_display. :)

For some reason I keep receiving an error when using
igt_output_override_mode + igt_display calls. The error is

igt-kms-CRITICAL: Failed assertion: drmModeDestroyPropertyBlob(display-
>drm_fd, *blob) == 0
igt-kms-CRITICAL: Last errno: 1, Operation not permitted

Maybe both threads try to access this and this request is not granted?
With drmModeSetCrtc() call I don't see this behavior. Maybe stick with
raw calls instead?

> > 
> > +static void
> > +run_test(data_t *data, enum pipe pipe)
> > +{
> > +	color_t blue  = { 0.0f, 0.0f, 1.0f };
> > +	test_position_t test = { .data = data };
> > +	int connected_outs;
> > +	int max_planes = data->display.pipes[data->pipe].n_planes;
> > +
> > +	if (!opt.user_seed)
> > +		opt.seed = time(NULL);
> > +
> > +	connected_outs = 0;
> > +	for_each_valid_output_on_pipe(&data->display, pipe, data-
> > >output) {
> > +		data->pipe = pipe;
> > +
> > +		data->connector_id = get_connector_connected(data-
> > >drm_fd)->connector_id;
> data->output->config.connector->connector_id ? Though I don't think
> we still need it if you use the igt display calls.
> > 
> > +		igt_assert(data->connector_id != -EINVAL);
> > +
> > +		data->crtc_id = get_crtc(data->drm_fd);
> igt_output_set_pipe(output, pipe);
> 
> Again, shouldn't need crtc_id, but if you did display-
> >pipes[pipe].crtc_id
> 
> With those fixed, I don't think you need raw drm calls in this test
> at all. :)
> 
> ~Maarten
-- 
Mika Kahola - Intel OTC

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH i-g-t v2] tests/kms_concurrent: Concurrent and interruptible subtests for atomic
  2017-04-10 12:11   ` Mika Kahola
@ 2017-04-10 12:39     ` Maarten Lankhorst
  2017-04-11  7:42       ` Kahola, Mika
  0 siblings, 1 reply; 6+ messages in thread
From: Maarten Lankhorst @ 2017-04-10 12:39 UTC (permalink / raw)
  To: mika.kahola, intel-gfx

Op 10-04-17 om 14:11 schreef Mika Kahola:
> On Wed, 2017-03-29 at 11:53 +0200, Maarten Lankhorst wrote:
>> Op 15-03-17 om 09:43 schreef Mika Kahola:
>>> This test case introduces concurrently running test cases for
>>> atomic
>>> modesetting.
>>>
>>> The first test or thread draws blue backround with black holes on
>>> it.
>>> These holes are covered by rectangular, blue planes that are placed
>>> randomly like in test case 'kms_plane_multiple'.
>>>
>>> The second thread changes resolution from higher to lower one and
>>> back.
>>> The delay between resolution changes is randomly selected between
>>> 20 and
>>> 50 milliseconds.
>>>
>>> The test runs by default 32 iterations to increase the coverage.
>>>
>>> v2: use igt_fork instead of pthreads to create concurrent test runs
>>> (Maarten)
>>>
>>> Signed-off-by: Mika Kahola <mika.kahola@intel.com>
>>> ---
>>>  tests/Makefile.sources |   1 +
>>>  tests/kms_concurrent.c | 630
>>> +++++++++++++++++++++++++++++++++++++++++++++++++
>>>  2 files changed, 631 insertions(+)
>>>  create mode 100644 tests/kms_concurrent.c
>>>
>>> <snip>
>>> +static int
>>> +display_commit_mode(data_t *data, igt_crc_t *crc)
>>> +{
>>> +	char buf[256];
>>> +	struct drm_event *e = (void *)buf;
>>> +	int n, ret;
>>> +	int flags = DRM_MODE_PAGE_FLIP_EVENT |
>>> DRM_MODE_ATOMIC_ALLOW_MODESET | DRM_MODE_ATOMIC_NONBLOCK;
>>> +
>>> +	ret = igt_display_try_commit_atomic(&data->display,
>>> +					    flags,
>>> +					    NULL);
>>> +	igt_skip_on(ret != 0);
>>> +
>>> +	igt_set_timeout(1, "Stuck on page flip");
>>> +	ret = read(data->display.drm_fd, buf, sizeof(buf));
>>> +	igt_assert(ret >= 0);
>>> +
>>> +	igt_assert_eq(e->type, DRM_EVENT_FLIP_COMPLETE);
>>> +	igt_reset_timeout();
>>> +
>>> +	return n;
>>> +}
>>> +
>>> +static void
>>> +test_grab_crc(data_t *data, color_t *color, igt_crc_t *crc /* out
>>> */)
>>> +{
>>> +	drmModeModeInfo *mode;
>>> +	igt_plane_t *primary;
>>> +	int ret;
>>> +
>>> +	igt_output_set_pipe(data->output, data->pipe);
>>> +
>>> +	primary = igt_output_get_plane_type(data->output,
>>> DRM_PLANE_TYPE_PRIMARY);
>>> +	data->plane[primary->index] = primary;
>>> +
>>> +	mode = igt_output_get_mode(data->output);
>>> +
>>> +	igt_create_color_fb(data->drm_fd, mode->hdisplay, mode-
>>>> vdisplay,
>>> +			    DRM_FORMAT_XRGB8888,
>>> +			    LOCAL_I915_FORMAT_MOD_X_TILED,
>>> +			    color->red, color->green, color->blue,
>>> +			    &data->fb[primary->index]);
>>> +
>>> +	igt_plane_set_fb(data->plane[primary->index], &data-
>>>> fb[primary->index]);
>>> +
>>> +	ret = igt_display_try_commit2(&data->display,
>>> COMMIT_ATOMIC);
>>> +	igt_skip_on(ret != 0);
>>> +}
>>> +
>>> +/*
>>> + * 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;
>>> +	igt_plane_t *primary;
>>> +
>>> +	primary = igt_output_get_plane_type(data->output,
>>> DRM_PLANE_TYPE_PRIMARY);
>>> +
>>> +	fb_id = igt_create_fb(data->drm_fd,
>>> +			      mode->hdisplay, mode->vdisplay,
>>> +			      DRM_FORMAT_XRGB8888,
>>> +			      tiling,
>>> +			      &data->fb[primary->index]);
>>> +	igt_assert(fb_id);
>>> +
>>> +	cr = igt_get_cairo_ctx(data->drm_fd, &data->fb[primary-
>>>> index]);
>>> +	igt_paint_color(cr, rect_x[0], rect_y[0],
>>> +			mode->hdisplay, mode->vdisplay,
>>> +			color->red, color->green, color->blue);
>>> +
>>> +	for (int i = 0; i < max_planes; i++) {
>>> +		if (data->plane[i]->type ==
>>> DRM_PLANE_TYPE_PRIMARY)
>>> +			continue;
>>> +		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
>>> +prepare_planes(data_t *data, color_t *color, int max_planes)
>>> +{
>>> +	drmModeModeInfo *mode;
>>> +	igt_pipe_t *pipe;
>>> +	igt_plane_t *primary;
>>> +	int *x;
>>> +	int *y;
>>> +	int *size;
>>> +	int i;
>>> +
>>> +	igt_output_set_pipe(data->output, data->pipe);
>>> +	primary = igt_output_get_plane_type(data->output,
>>> DRM_PLANE_TYPE_PRIMARY);
>>> +	pipe = primary->pipe;
>>> +
>>> +	x = malloc(pipe->n_planes * sizeof(*x));
>>> +	igt_assert_f(x, "Failed to allocate %ld bytes for variable
>>> x\n", (long int) (pipe->n_planes * sizeof(*x)));
>>> +	y = malloc(pipe->n_planes * sizeof(*y));
>>> +	igt_assert_f(y, "Failed to allocate %ld bytes for variable
>>> y\n", (long int) (pipe->n_planes * sizeof(*y)));
>>> +	size = malloc(pipe->n_planes * sizeof(*size));
>>> +	igt_assert_f(size, "Failed to allocate %ld bytes for
>>> variable size\n", (long int) (pipe->n_planes * sizeof(*size)));
>>> +
>>> +	mode = igt_output_get_mode(data->output);
>>> +
>>> +	/* planes with random positions */
>>> +	x[primary->index] = 0;
>>> +	y[primary->index] = 0;
>>> +	for (i = 0; i < max_planes; i++) {
>>> +		igt_plane_t *plane = igt_output_get_plane(data-
>>>> output, i);
>>> +
>>> +		if (plane->type == DRM_PLANE_TYPE_PRIMARY)
>>> +			continue;
>>> +		else if (plane->type == DRM_PLANE_TYPE_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] = plane;
>>> +
>>> +		igt_create_color_fb(data->drm_fd,
>>> +				    size[i], size[i],
>>> +				    data->plane[i]->type ==
>>> DRM_PLANE_TYPE_CURSOR ? DRM_FORMAT_ARGB8888 : DRM_FORMAT_XRGB8888,
>>> +				    data->plane[i]->type ==
>>> DRM_PLANE_TYPE_CURSOR ? LOCAL_DRM_FORMAT_MOD_NONE :
>>> LOCAL_I915_FORMAT_MOD_X_TILED,
>>> +				    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[primary->index] = primary;
>>> +	create_fb_for_mode_position(data, mode, color, x, y, size,
>>> size,
>>> +				    LOCAL_I915_FORMAT_MOD_X_TILED,
>>> max_planes);
>>> +	igt_plane_set_fb(data->plane[primary->index], &data-
>>>> fb[primary->index]);
>>> +}
>>> +
>>> +static void
>>> +test_plane_position_with_output(data_t *data)
>>> +{
>>> +	igt_crc_t *crc;
>>> +	color_t blue  = { 0.0f, 0.0f, 1.0f };
>>> +	int i;
>>> +	int iterations = opt.iterations < 1 ? 1 : opt.iterations;
>>> +	bool loop_forever;
>>> +	char info[256];
>>> +	int max_planes = data->display.pipes[data->pipe].n_planes;
>>> +
>>> +	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(data->output),
>>> kmstest_pipe_name(data->pipe), max_planes,
>>> +		 info, opt.seed);
>>> +
>>> +	i = 0;
>>> +	while (i < iterations || loop_forever) {
>>> +		prepare_planes(data, &blue, max_planes);
>>> +
>>> +		display_commit_mode(data, crc);
>>> +
>>> +		i++;
>>> +	}
>>> +}
>>> +
>>> +static drmModeConnector *
>>> +get_connector_connected(int drm_fd)
>>> +{
>>> +	drmModeRes *resources = drmModeGetResources(drm_fd);
>>> +	drmModeConnector *connector;
>>> +	int i;
>>> +
>>> +	for (i = 0; i < resources->count_connectors; i++) {
>>> +		connector = drmModeGetConnector(drm_fd,
>>> +						resources-
>>>> connectors[i]);
>>> +
>>> +		if (connector->connection == DRM_MODE_CONNECTED)
>>> +			break;
>>> +
>>> +		drmModeFreeConnector(connector);
>>> +		connector = NULL;
>>> +	}
>>> +
>>> +	drmModeFreeResources(resources);
>>> +
>>> +	return connector;
>>> +}
>>> +
>>> +static int get_crtc_for_encoder(drmModeRes *resources,
>>> +				drmModeEncoder *encoder)
>>> +{
>>> +	int mask, id;
>>> +	int i;
>>> +	bool found;
>>> +
>>> +	for (i = 0; i < resources->count_crtcs; i++) {
>>> +		mask = 1 << i;
>>> +		id = resources->crtcs[i];
>>> +
>>> +		found = encoder->possible_crtcs & mask;
>>> +		if (found)
>>> +			break;
>>> +	}
>>> +
>>> +	if (!found)
>>> +		return -EINVAL;
>>> +
>>> +	return id;
>>> +}
>>> +
>>> +static int get_crtc_for_connector(int drm_fd, drmModeRes
>>> *resources,
>>> +				  drmModeConnector *connector)
>>> +{
>>> +	drmModeEncoder *encoder;
>>> +	int encoder_id;
>>> +	int crtc_id;
>>> +	int i;
>>> +
>>> +	for (i = 0; i < connector->count_encoders; i++) {
>>> +		encoder_id = connector->encoders[i];
>>> +		encoder = drmModeGetEncoder(drm_fd, encoder_id);
>>> +
>>> +		if (encoder) {
>>> +			crtc_id = get_crtc_for_encoder(resources,
>>> encoder);
>>> +
>>> +			drmModeFreeEncoder(encoder);
>>> +
>>> +			if (crtc_id != 0)
>>> +				break;
>>> +		}
>>> +	}
>>> +
>>> +	if (crtc_id == 0)
>>> +		return -EINVAL;
>>> +
>>> +	return crtc_id;
>>> +}
>>> +
>>> +static int get_crtc(int drm_fd)
>>> +{
>>> +	drmModeRes *resources;
>>> +	drmModeConnector *connector;
>>> +	drmModeEncoder *encoder;
>>> +	int i, id;
>>> +
>>> +	resources = drmModeGetResources(drm_fd);
>>> +	connector = get_connector_connected(drm_fd);
>>> +
>>> +	for (i = 0; i < resources->count_encoders; i++) {
>>> +		encoder = drmModeGetEncoder(drm_fd, resources-
>>>> encoders[i]);
>>> +
>>> +		if (encoder->encoder_id == connector->encoder_id)
>>> +			break;
>>> +
>>> +		drmModeFreeEncoder(encoder);
>>> +		encoder = NULL;
>>> +	}
>>> +
>>> +	if (encoder)
>>> +		return encoder->crtc_id;
>>> +
>>> +	id = get_crtc_for_connector(drm_fd, resources, connector);
>>> +	igt_assert(id != 0);
>>> +
>>> +	return id;
>>> +}
>>> +
>>> +static drmModeModeInfo *
>>> +get_lowres_mode(data_t *data, drmModeModeInfo *mode_default)
>>> +{
>>> +	drmModeRes *resources = drmModeGetResources(data->drm_fd);
>>> +	drmModeModeInfo std_1024_mode = {
>>> +		.clock = 65000,
>>> +		.hdisplay = 1024,
>>> +		.hsync_start = 1048,
>>> +		.hsync_end = 1184,
>>> +		.htotal = 1344,
>>> +		.hskew = 0,
>>> +		.vdisplay = 768,
>>> +		.vsync_start = 771,
>>> +		.vsync_end = 777,
>>> +		.vtotal = 806,
>>> +		.vscan = 0,
>>> +		.vrefresh = 60,
>>> +		.flags = 0xA,
>>> +		.type = 0x40,
>>> +		.name = "Custom 1024x768",
>>> +	};
>>> +	drmModeModeInfo *mode;
>>> +	drmModeConnector *connector;
>>> +	bool found;
>>> +	int limit = mode_default->vdisplay-SIZE_PLANE;
>>> +	int i, j;
>>> +
>>> +	if (!resources) {
>>> +		igt_warn("drmModeGetResources failed: %s\n",
>>> strerror(errno));
>>> +		return mode;
>>> +	}
>>> +
>>> +	found = false;
>>> +	for (i = 0; i < resources->count_connectors; i++) {
>>> +
>>> +		connector = drmModeGetConnectorCurrent(data-
>>>> drm_fd,
>>> +						       resources-
>>>> connectors[i]);
>>> +
>>> +		if (!connector) {
>>> +			igt_warn("could not get connector %i:
>>> %s\n",
>>> +				 resources->connectors[i],
>>> strerror(errno));
>>> +			continue;
>>> +		}
>>> +
>>> +		if (!connector->count_modes)
>>> +			continue;
>>> +
>>> +		for (j = 0; j < connector->count_modes; j++) {
>>> +			mode = &connector->modes[j];
>>> +
>>> +			if (mode->vdisplay < limit) {
>>> +				found = true;
>>> +				break;
>>> +			}
>>> +		}
>>> +
>>> +		drmModeFreeConnector(connector);
>>> +	}
>>> +
>>> +	drmModeFreeResources(resources);
>>> +
>>> +	if (!found)
>>> +		mode = &std_1024_mode;
>>> +
>>> +	return mode;
>>> +}
>> Still not completely happy about this part.
>>
>> I would look at data->output->config.connector for modes, and return
>> 1024 mode if nothing's found.
>>
>> Saves a whole lot of drm calls.
> True. A lot of lines can be cleaned out.
>>> +static void
>>> +test_resolution_with_output(data_t *data)
>>> +{
>>> +	drmModeModeInfo *mode_hi, *mode_lo;
>>> +	int ret;
>>> +	int iterations = opt.iterations < 1 ? 1 : opt.iterations;
>>> +	bool loop_forever;
>>> +	int i;
>>> +
>>> +	if (opt.iterations == LOOP_FOREVER)
>>> +		loop_forever = true;
>>> +	else
>>> +		loop_forever = false;
>>> +
>>> +	igt_info("Testing resolution with connector %s using pipe
>>> %s with seed %d\n",
>>> +		 igt_output_name(data->output),
>>> kmstest_pipe_name(data->pipe), opt.seed);
>>> +
>>> +	mode_hi = igt_output_get_mode(data->output);
>>> +	mode_lo = get_lowres_mode(data, mode_hi);
>>> +
>>> +	i = 0;
>>> +	while (i < iterations || loop_forever) {
>>> +		/* switch to lower resolution */
>>> +		ret = drmModeSetCrtc(data->drm_fd, data->crtc_id,
>>> data->fb->fb_id, 0, 0,
>>> +				     &data->connector_id, 1,
>>> mode_lo);
>>> +		igt_assert_eq(ret, 0);
>>> +
>>> +		/* switch back to higher resolution */
>>> +		ret = drmModeSetCrtc(data->drm_fd, data->crtc_id,
>>> data->fb->fb_id, 0, 0,
>>> +				     &data->connector_id, 1,
>>> mode_hi);
>>> +		igt_assert_eq(ret, 0);
>>> +
>>> +		i++;
>>> +	}
>>> +}
>> Use igt_output_override_mode + igt_display calls? With the thread
>> being a fork now, you can use igt_display. :)
> For some reason I keep receiving an error when using
> igt_output_override_mode + igt_display calls. The error is
>
> igt-kms-CRITICAL: Failed assertion: drmModeDestroyPropertyBlob(display-
>> drm_fd, *blob) == 0
> igt-kms-CRITICAL: Last errno: 1, Operation not permitted
>
> Maybe both threads try to access this and this request is not granted?
> With drmModeSetCrtc() call I don't see this behavior. Maybe stick with
> raw calls instead?

data->display.pipes[pipe].mode_blob = 0; in one of the forks of the test should fix it.

-EPERM means that the blob was already destroyed by this fd, but still used globally.

kms_rmfb does similar, maybe we should ignore failures?

~Maarten

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH i-g-t v2] tests/kms_concurrent: Concurrent and interruptible subtests for atomic
  2017-04-10 12:39     ` Maarten Lankhorst
@ 2017-04-11  7:42       ` Kahola, Mika
  2017-04-11  8:18         ` Maarten Lankhorst
  0 siblings, 1 reply; 6+ messages in thread
From: Kahola, Mika @ 2017-04-11  7:42 UTC (permalink / raw)
  To: Maarten Lankhorst, intel-gfx



> -----Original Message-----
> From: Maarten Lankhorst [mailto:maarten.lankhorst@linux.intel.com]
> Sent: Monday, April 10, 2017 3:39 PM
> To: Kahola, Mika <mika.kahola@intel.com>; intel-gfx@lists.freedesktop.org
> Subject: Re: [PATCH i-g-t v2] tests/kms_concurrent: Concurrent and interruptible
> subtests for atomic
> 
> Op 10-04-17 om 14:11 schreef Mika Kahola:
> > On Wed, 2017-03-29 at 11:53 +0200, Maarten Lankhorst wrote:
> >> Op 15-03-17 om 09:43 schreef Mika Kahola:
> >>> This test case introduces concurrently running test cases for atomic
> >>> modesetting.
> >>>
> >>> The first test or thread draws blue backround with black holes on
> >>> it.
> >>> These holes are covered by rectangular, blue planes that are placed
> >>> randomly like in test case 'kms_plane_multiple'.
> >>>
> >>> The second thread changes resolution from higher to lower one and
> >>> back.
> >>> The delay between resolution changes is randomly selected between
> >>> 20 and
> >>> 50 milliseconds.
> >>>
> >>> The test runs by default 32 iterations to increase the coverage.
> >>>
> >>> v2: use igt_fork instead of pthreads to create concurrent test runs
> >>> (Maarten)
> >>>
> >>> Signed-off-by: Mika Kahola <mika.kahola@intel.com>
> >>> ---
> >>>  tests/Makefile.sources |   1 +
> >>>  tests/kms_concurrent.c | 630
> >>> +++++++++++++++++++++++++++++++++++++++++++++++++
> >>>  2 files changed, 631 insertions(+)
> >>>  create mode 100644 tests/kms_concurrent.c
> >>>
> >>> <snip>
> >>> +static int
> >>> +display_commit_mode(data_t *data, igt_crc_t *crc) {
> >>> +	char buf[256];
> >>> +	struct drm_event *e = (void *)buf;
> >>> +	int n, ret;
> >>> +	int flags = DRM_MODE_PAGE_FLIP_EVENT |
> >>> DRM_MODE_ATOMIC_ALLOW_MODESET |
> DRM_MODE_ATOMIC_NONBLOCK;
> >>> +
> >>> +	ret = igt_display_try_commit_atomic(&data->display,
> >>> +					    flags,
> >>> +					    NULL);
> >>> +	igt_skip_on(ret != 0);
> >>> +
> >>> +	igt_set_timeout(1, "Stuck on page flip");
> >>> +	ret = read(data->display.drm_fd, buf, sizeof(buf));
> >>> +	igt_assert(ret >= 0);
> >>> +
> >>> +	igt_assert_eq(e->type, DRM_EVENT_FLIP_COMPLETE);
> >>> +	igt_reset_timeout();
> >>> +
> >>> +	return n;
> >>> +}
> >>> +
> >>> +static void
> >>> +test_grab_crc(data_t *data, color_t *color, igt_crc_t *crc /* out
> >>> */)
> >>> +{
> >>> +	drmModeModeInfo *mode;
> >>> +	igt_plane_t *primary;
> >>> +	int ret;
> >>> +
> >>> +	igt_output_set_pipe(data->output, data->pipe);
> >>> +
> >>> +	primary = igt_output_get_plane_type(data->output,
> >>> DRM_PLANE_TYPE_PRIMARY);
> >>> +	data->plane[primary->index] = primary;
> >>> +
> >>> +	mode = igt_output_get_mode(data->output);
> >>> +
> >>> +	igt_create_color_fb(data->drm_fd, mode->hdisplay, mode-
> >>>> vdisplay,
> >>> +			    DRM_FORMAT_XRGB8888,
> >>> +			    LOCAL_I915_FORMAT_MOD_X_TILED,
> >>> +			    color->red, color->green, color->blue,
> >>> +			    &data->fb[primary->index]);
> >>> +
> >>> +	igt_plane_set_fb(data->plane[primary->index], &data-
> >>>> fb[primary->index]);
> >>> +
> >>> +	ret = igt_display_try_commit2(&data->display,
> >>> COMMIT_ATOMIC);
> >>> +	igt_skip_on(ret != 0);
> >>> +}
> >>> +
> >>> +/*
> >>> + * 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;
> >>> +	igt_plane_t *primary;
> >>> +
> >>> +	primary = igt_output_get_plane_type(data->output,
> >>> DRM_PLANE_TYPE_PRIMARY);
> >>> +
> >>> +	fb_id = igt_create_fb(data->drm_fd,
> >>> +			      mode->hdisplay, mode->vdisplay,
> >>> +			      DRM_FORMAT_XRGB8888,
> >>> +			      tiling,
> >>> +			      &data->fb[primary->index]);
> >>> +	igt_assert(fb_id);
> >>> +
> >>> +	cr = igt_get_cairo_ctx(data->drm_fd, &data->fb[primary-
> >>>> index]);
> >>> +	igt_paint_color(cr, rect_x[0], rect_y[0],
> >>> +			mode->hdisplay, mode->vdisplay,
> >>> +			color->red, color->green, color->blue);
> >>> +
> >>> +	for (int i = 0; i < max_planes; i++) {
> >>> +		if (data->plane[i]->type ==
> >>> DRM_PLANE_TYPE_PRIMARY)
> >>> +			continue;
> >>> +		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
> >>> +prepare_planes(data_t *data, color_t *color, int max_planes) {
> >>> +	drmModeModeInfo *mode;
> >>> +	igt_pipe_t *pipe;
> >>> +	igt_plane_t *primary;
> >>> +	int *x;
> >>> +	int *y;
> >>> +	int *size;
> >>> +	int i;
> >>> +
> >>> +	igt_output_set_pipe(data->output, data->pipe);
> >>> +	primary = igt_output_get_plane_type(data->output,
> >>> DRM_PLANE_TYPE_PRIMARY);
> >>> +	pipe = primary->pipe;
> >>> +
> >>> +	x = malloc(pipe->n_planes * sizeof(*x));
> >>> +	igt_assert_f(x, "Failed to allocate %ld bytes for variable
> >>> x\n", (long int) (pipe->n_planes * sizeof(*x)));
> >>> +	y = malloc(pipe->n_planes * sizeof(*y));
> >>> +	igt_assert_f(y, "Failed to allocate %ld bytes for variable
> >>> y\n", (long int) (pipe->n_planes * sizeof(*y)));
> >>> +	size = malloc(pipe->n_planes * sizeof(*size));
> >>> +	igt_assert_f(size, "Failed to allocate %ld bytes for
> >>> variable size\n", (long int) (pipe->n_planes * sizeof(*size)));
> >>> +
> >>> +	mode = igt_output_get_mode(data->output);
> >>> +
> >>> +	/* planes with random positions */
> >>> +	x[primary->index] = 0;
> >>> +	y[primary->index] = 0;
> >>> +	for (i = 0; i < max_planes; i++) {
> >>> +		igt_plane_t *plane = igt_output_get_plane(data-
> >>>> output, i);
> >>> +
> >>> +		if (plane->type == DRM_PLANE_TYPE_PRIMARY)
> >>> +			continue;
> >>> +		else if (plane->type == DRM_PLANE_TYPE_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] = plane;
> >>> +
> >>> +		igt_create_color_fb(data->drm_fd,
> >>> +				    size[i], size[i],
> >>> +				    data->plane[i]->type ==
> >>> DRM_PLANE_TYPE_CURSOR ? DRM_FORMAT_ARGB8888 :
> DRM_FORMAT_XRGB8888,
> >>> +				    data->plane[i]->type ==
> >>> DRM_PLANE_TYPE_CURSOR ? LOCAL_DRM_FORMAT_MOD_NONE :
> >>> LOCAL_I915_FORMAT_MOD_X_TILED,
> >>> +				    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[primary->index] = primary;
> >>> +	create_fb_for_mode_position(data, mode, color, x, y, size,
> >>> size,
> >>> +				    LOCAL_I915_FORMAT_MOD_X_TILED,
> >>> max_planes);
> >>> +	igt_plane_set_fb(data->plane[primary->index], &data-
> >>>> fb[primary->index]);
> >>> +}
> >>> +
> >>> +static void
> >>> +test_plane_position_with_output(data_t *data) {
> >>> +	igt_crc_t *crc;
> >>> +	color_t blue  = { 0.0f, 0.0f, 1.0f };
> >>> +	int i;
> >>> +	int iterations = opt.iterations < 1 ? 1 : opt.iterations;
> >>> +	bool loop_forever;
> >>> +	char info[256];
> >>> +	int max_planes = data->display.pipes[data->pipe].n_planes;
> >>> +
> >>> +	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(data->output),
> >>> kmstest_pipe_name(data->pipe), max_planes,
> >>> +		 info, opt.seed);
> >>> +
> >>> +	i = 0;
> >>> +	while (i < iterations || loop_forever) {
> >>> +		prepare_planes(data, &blue, max_planes);
> >>> +
> >>> +		display_commit_mode(data, crc);
> >>> +
> >>> +		i++;
> >>> +	}
> >>> +}
> >>> +
> >>> +static drmModeConnector *
> >>> +get_connector_connected(int drm_fd) {
> >>> +	drmModeRes *resources = drmModeGetResources(drm_fd);
> >>> +	drmModeConnector *connector;
> >>> +	int i;
> >>> +
> >>> +	for (i = 0; i < resources->count_connectors; i++) {
> >>> +		connector = drmModeGetConnector(drm_fd,
> >>> +						resources-
> >>>> connectors[i]);
> >>> +
> >>> +		if (connector->connection == DRM_MODE_CONNECTED)
> >>> +			break;
> >>> +
> >>> +		drmModeFreeConnector(connector);
> >>> +		connector = NULL;
> >>> +	}
> >>> +
> >>> +	drmModeFreeResources(resources);
> >>> +
> >>> +	return connector;
> >>> +}
> >>> +
> >>> +static int get_crtc_for_encoder(drmModeRes *resources,
> >>> +				drmModeEncoder *encoder)
> >>> +{
> >>> +	int mask, id;
> >>> +	int i;
> >>> +	bool found;
> >>> +
> >>> +	for (i = 0; i < resources->count_crtcs; i++) {
> >>> +		mask = 1 << i;
> >>> +		id = resources->crtcs[i];
> >>> +
> >>> +		found = encoder->possible_crtcs & mask;
> >>> +		if (found)
> >>> +			break;
> >>> +	}
> >>> +
> >>> +	if (!found)
> >>> +		return -EINVAL;
> >>> +
> >>> +	return id;
> >>> +}
> >>> +
> >>> +static int get_crtc_for_connector(int drm_fd, drmModeRes
> >>> *resources,
> >>> +				  drmModeConnector *connector)
> >>> +{
> >>> +	drmModeEncoder *encoder;
> >>> +	int encoder_id;
> >>> +	int crtc_id;
> >>> +	int i;
> >>> +
> >>> +	for (i = 0; i < connector->count_encoders; i++) {
> >>> +		encoder_id = connector->encoders[i];
> >>> +		encoder = drmModeGetEncoder(drm_fd, encoder_id);
> >>> +
> >>> +		if (encoder) {
> >>> +			crtc_id = get_crtc_for_encoder(resources,
> >>> encoder);
> >>> +
> >>> +			drmModeFreeEncoder(encoder);
> >>> +
> >>> +			if (crtc_id != 0)
> >>> +				break;
> >>> +		}
> >>> +	}
> >>> +
> >>> +	if (crtc_id == 0)
> >>> +		return -EINVAL;
> >>> +
> >>> +	return crtc_id;
> >>> +}
> >>> +
> >>> +static int get_crtc(int drm_fd)
> >>> +{
> >>> +	drmModeRes *resources;
> >>> +	drmModeConnector *connector;
> >>> +	drmModeEncoder *encoder;
> >>> +	int i, id;
> >>> +
> >>> +	resources = drmModeGetResources(drm_fd);
> >>> +	connector = get_connector_connected(drm_fd);
> >>> +
> >>> +	for (i = 0; i < resources->count_encoders; i++) {
> >>> +		encoder = drmModeGetEncoder(drm_fd, resources-
> >>>> encoders[i]);
> >>> +
> >>> +		if (encoder->encoder_id == connector->encoder_id)
> >>> +			break;
> >>> +
> >>> +		drmModeFreeEncoder(encoder);
> >>> +		encoder = NULL;
> >>> +	}
> >>> +
> >>> +	if (encoder)
> >>> +		return encoder->crtc_id;
> >>> +
> >>> +	id = get_crtc_for_connector(drm_fd, resources, connector);
> >>> +	igt_assert(id != 0);
> >>> +
> >>> +	return id;
> >>> +}
> >>> +
> >>> +static drmModeModeInfo *
> >>> +get_lowres_mode(data_t *data, drmModeModeInfo *mode_default) {
> >>> +	drmModeRes *resources = drmModeGetResources(data->drm_fd);
> >>> +	drmModeModeInfo std_1024_mode = {
> >>> +		.clock = 65000,
> >>> +		.hdisplay = 1024,
> >>> +		.hsync_start = 1048,
> >>> +		.hsync_end = 1184,
> >>> +		.htotal = 1344,
> >>> +		.hskew = 0,
> >>> +		.vdisplay = 768,
> >>> +		.vsync_start = 771,
> >>> +		.vsync_end = 777,
> >>> +		.vtotal = 806,
> >>> +		.vscan = 0,
> >>> +		.vrefresh = 60,
> >>> +		.flags = 0xA,
> >>> +		.type = 0x40,
> >>> +		.name = "Custom 1024x768",
> >>> +	};
> >>> +	drmModeModeInfo *mode;
> >>> +	drmModeConnector *connector;
> >>> +	bool found;
> >>> +	int limit = mode_default->vdisplay-SIZE_PLANE;
> >>> +	int i, j;
> >>> +
> >>> +	if (!resources) {
> >>> +		igt_warn("drmModeGetResources failed: %s\n",
> >>> strerror(errno));
> >>> +		return mode;
> >>> +	}
> >>> +
> >>> +	found = false;
> >>> +	for (i = 0; i < resources->count_connectors; i++) {
> >>> +
> >>> +		connector = drmModeGetConnectorCurrent(data-
> >>>> drm_fd,
> >>> +						       resources-
> >>>> connectors[i]);
> >>> +
> >>> +		if (!connector) {
> >>> +			igt_warn("could not get connector %i:
> >>> %s\n",
> >>> +				 resources->connectors[i],
> >>> strerror(errno));
> >>> +			continue;
> >>> +		}
> >>> +
> >>> +		if (!connector->count_modes)
> >>> +			continue;
> >>> +
> >>> +		for (j = 0; j < connector->count_modes; j++) {
> >>> +			mode = &connector->modes[j];
> >>> +
> >>> +			if (mode->vdisplay < limit) {
> >>> +				found = true;
> >>> +				break;
> >>> +			}
> >>> +		}
> >>> +
> >>> +		drmModeFreeConnector(connector);
> >>> +	}
> >>> +
> >>> +	drmModeFreeResources(resources);
> >>> +
> >>> +	if (!found)
> >>> +		mode = &std_1024_mode;
> >>> +
> >>> +	return mode;
> >>> +}
> >> Still not completely happy about this part.
> >>
> >> I would look at data->output->config.connector for modes, and return
> >> 1024 mode if nothing's found.
> >>
> >> Saves a whole lot of drm calls.
> > True. A lot of lines can be cleaned out.
> >>> +static void
> >>> +test_resolution_with_output(data_t *data) {
> >>> +	drmModeModeInfo *mode_hi, *mode_lo;
> >>> +	int ret;
> >>> +	int iterations = opt.iterations < 1 ? 1 : opt.iterations;
> >>> +	bool loop_forever;
> >>> +	int i;
> >>> +
> >>> +	if (opt.iterations == LOOP_FOREVER)
> >>> +		loop_forever = true;
> >>> +	else
> >>> +		loop_forever = false;
> >>> +
> >>> +	igt_info("Testing resolution with connector %s using pipe
> >>> %s with seed %d\n",
> >>> +		 igt_output_name(data->output),
> >>> kmstest_pipe_name(data->pipe), opt.seed);
> >>> +
> >>> +	mode_hi = igt_output_get_mode(data->output);
> >>> +	mode_lo = get_lowres_mode(data, mode_hi);
> >>> +
> >>> +	i = 0;
> >>> +	while (i < iterations || loop_forever) {
> >>> +		/* switch to lower resolution */
> >>> +		ret = drmModeSetCrtc(data->drm_fd, data->crtc_id,
> >>> data->fb->fb_id, 0, 0,
> >>> +				     &data->connector_id, 1,
> >>> mode_lo);
> >>> +		igt_assert_eq(ret, 0);
> >>> +
> >>> +		/* switch back to higher resolution */
> >>> +		ret = drmModeSetCrtc(data->drm_fd, data->crtc_id,
> >>> data->fb->fb_id, 0, 0,
> >>> +				     &data->connector_id, 1,
> >>> mode_hi);
> >>> +		igt_assert_eq(ret, 0);
> >>> +
> >>> +		i++;
> >>> +	}
> >>> +}
> >> Use igt_output_override_mode + igt_display calls? With the thread
> >> being a fork now, you can use igt_display. :)
> > For some reason I keep receiving an error when using
> > igt_output_override_mode + igt_display calls. The error is
> >
> > igt-kms-CRITICAL: Failed assertion:
> > drmModeDestroyPropertyBlob(display-
> >> drm_fd, *blob) == 0
> > igt-kms-CRITICAL: Last errno: 1, Operation not permitted
> >
> > Maybe both threads try to access this and this request is not granted?
> > With drmModeSetCrtc() call I don't see this behavior. Maybe stick with
> > raw calls instead?
> 
> data->display.pipes[pipe].mode_blob = 0; in one of the forks of the test should
> fix it.
This seems to fix the issue. I'll throw a revised patch of the test shortly.

> 
> -EPERM means that the blob was already destroyed by this fd, but still used
> globally.
> 
> kms_rmfb does similar, maybe we should ignore failures?
Maybe we could ignore these failures. Any harm done elsewhere if we do so?

-Mika-
> 
> ~Maarten

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH i-g-t v2] tests/kms_concurrent: Concurrent and interruptible subtests for atomic
  2017-04-11  7:42       ` Kahola, Mika
@ 2017-04-11  8:18         ` Maarten Lankhorst
  0 siblings, 0 replies; 6+ messages in thread
From: Maarten Lankhorst @ 2017-04-11  8:18 UTC (permalink / raw)
  To: Kahola, Mika, intel-gfx

Op 11-04-17 om 09:42 schreef Kahola, Mika:
>
>> -----Original Message-----
>> From: Maarten Lankhorst [mailto:maarten.lankhorst@linux.intel.com]
>> Sent: Monday, April 10, 2017 3:39 PM
>> To: Kahola, Mika <mika.kahola@intel.com>; intel-gfx@lists.freedesktop.org
>> Subject: Re: [PATCH i-g-t v2] tests/kms_concurrent: Concurrent and interruptible
>> subtests for atomic
>>
>> Op 10-04-17 om 14:11 schreef Mika Kahola:
>>> On Wed, 2017-03-29 at 11:53 +0200, Maarten Lankhorst wrote:
>>>> Op 15-03-17 om 09:43 schreef Mika Kahola:
>>>>> This test case introduces concurrently running test cases for atomic
>>>>> modesetting.
>>>>>
>>>>> The first test or thread draws blue backround with black holes on
>>>>> it.
>>>>> These holes are covered by rectangular, blue planes that are placed
>>>>> randomly like in test case 'kms_plane_multiple'.
>>>>>
>>>>> The second thread changes resolution from higher to lower one and
>>>>> back.
>>>>> The delay between resolution changes is randomly selected between
>>>>> 20 and
>>>>> 50 milliseconds.
>>>>>
>>>>> The test runs by default 32 iterations to increase the coverage.
>>>>>
>>>>> v2: use igt_fork instead of pthreads to create concurrent test runs
>>>>> (Maarten)
>>>>>
>>>>> Signed-off-by: Mika Kahola <mika.kahola@intel.com>
>>>>> ---
>>>>>  tests/Makefile.sources |   1 +
>>>>>  tests/kms_concurrent.c | 630
>>>>> +++++++++++++++++++++++++++++++++++++++++++++++++
>>>>>  2 files changed, 631 insertions(+)
>>>>>  create mode 100644 tests/kms_concurrent.c
>>>>>
>>>>> <snip>
>>>>> +static int
>>>>> +display_commit_mode(data_t *data, igt_crc_t *crc) {
>>>>> +	char buf[256];
>>>>> +	struct drm_event *e = (void *)buf;
>>>>> +	int n, ret;
>>>>> +	int flags = DRM_MODE_PAGE_FLIP_EVENT |
>>>>> DRM_MODE_ATOMIC_ALLOW_MODESET |
>> DRM_MODE_ATOMIC_NONBLOCK;
>>>>> +
>>>>> +	ret = igt_display_try_commit_atomic(&data->display,
>>>>> +					    flags,
>>>>> +					    NULL);
>>>>> +	igt_skip_on(ret != 0);
>>>>> +
>>>>> +	igt_set_timeout(1, "Stuck on page flip");
>>>>> +	ret = read(data->display.drm_fd, buf, sizeof(buf));
>>>>> +	igt_assert(ret >= 0);
>>>>> +
>>>>> +	igt_assert_eq(e->type, DRM_EVENT_FLIP_COMPLETE);
>>>>> +	igt_reset_timeout();
>>>>> +
>>>>> +	return n;
>>>>> +}
>>>>> +
>>>>> +static void
>>>>> +test_grab_crc(data_t *data, color_t *color, igt_crc_t *crc /* out
>>>>> */)
>>>>> +{
>>>>> +	drmModeModeInfo *mode;
>>>>> +	igt_plane_t *primary;
>>>>> +	int ret;
>>>>> +
>>>>> +	igt_output_set_pipe(data->output, data->pipe);
>>>>> +
>>>>> +	primary = igt_output_get_plane_type(data->output,
>>>>> DRM_PLANE_TYPE_PRIMARY);
>>>>> +	data->plane[primary->index] = primary;
>>>>> +
>>>>> +	mode = igt_output_get_mode(data->output);
>>>>> +
>>>>> +	igt_create_color_fb(data->drm_fd, mode->hdisplay, mode-
>>>>>> vdisplay,
>>>>> +			    DRM_FORMAT_XRGB8888,
>>>>> +			    LOCAL_I915_FORMAT_MOD_X_TILED,
>>>>> +			    color->red, color->green, color->blue,
>>>>> +			    &data->fb[primary->index]);
>>>>> +
>>>>> +	igt_plane_set_fb(data->plane[primary->index], &data-
>>>>>> fb[primary->index]);
>>>>> +
>>>>> +	ret = igt_display_try_commit2(&data->display,
>>>>> COMMIT_ATOMIC);
>>>>> +	igt_skip_on(ret != 0);
>>>>> +}
>>>>> +
>>>>> +/*
>>>>> + * 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;
>>>>> +	igt_plane_t *primary;
>>>>> +
>>>>> +	primary = igt_output_get_plane_type(data->output,
>>>>> DRM_PLANE_TYPE_PRIMARY);
>>>>> +
>>>>> +	fb_id = igt_create_fb(data->drm_fd,
>>>>> +			      mode->hdisplay, mode->vdisplay,
>>>>> +			      DRM_FORMAT_XRGB8888,
>>>>> +			      tiling,
>>>>> +			      &data->fb[primary->index]);
>>>>> +	igt_assert(fb_id);
>>>>> +
>>>>> +	cr = igt_get_cairo_ctx(data->drm_fd, &data->fb[primary-
>>>>>> index]);
>>>>> +	igt_paint_color(cr, rect_x[0], rect_y[0],
>>>>> +			mode->hdisplay, mode->vdisplay,
>>>>> +			color->red, color->green, color->blue);
>>>>> +
>>>>> +	for (int i = 0; i < max_planes; i++) {
>>>>> +		if (data->plane[i]->type ==
>>>>> DRM_PLANE_TYPE_PRIMARY)
>>>>> +			continue;
>>>>> +		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
>>>>> +prepare_planes(data_t *data, color_t *color, int max_planes) {
>>>>> +	drmModeModeInfo *mode;
>>>>> +	igt_pipe_t *pipe;
>>>>> +	igt_plane_t *primary;
>>>>> +	int *x;
>>>>> +	int *y;
>>>>> +	int *size;
>>>>> +	int i;
>>>>> +
>>>>> +	igt_output_set_pipe(data->output, data->pipe);
>>>>> +	primary = igt_output_get_plane_type(data->output,
>>>>> DRM_PLANE_TYPE_PRIMARY);
>>>>> +	pipe = primary->pipe;
>>>>> +
>>>>> +	x = malloc(pipe->n_planes * sizeof(*x));
>>>>> +	igt_assert_f(x, "Failed to allocate %ld bytes for variable
>>>>> x\n", (long int) (pipe->n_planes * sizeof(*x)));
>>>>> +	y = malloc(pipe->n_planes * sizeof(*y));
>>>>> +	igt_assert_f(y, "Failed to allocate %ld bytes for variable
>>>>> y\n", (long int) (pipe->n_planes * sizeof(*y)));
>>>>> +	size = malloc(pipe->n_planes * sizeof(*size));
>>>>> +	igt_assert_f(size, "Failed to allocate %ld bytes for
>>>>> variable size\n", (long int) (pipe->n_planes * sizeof(*size)));
>>>>> +
>>>>> +	mode = igt_output_get_mode(data->output);
>>>>> +
>>>>> +	/* planes with random positions */
>>>>> +	x[primary->index] = 0;
>>>>> +	y[primary->index] = 0;
>>>>> +	for (i = 0; i < max_planes; i++) {
>>>>> +		igt_plane_t *plane = igt_output_get_plane(data-
>>>>>> output, i);
>>>>> +
>>>>> +		if (plane->type == DRM_PLANE_TYPE_PRIMARY)
>>>>> +			continue;
>>>>> +		else if (plane->type == DRM_PLANE_TYPE_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] = plane;
>>>>> +
>>>>> +		igt_create_color_fb(data->drm_fd,
>>>>> +				    size[i], size[i],
>>>>> +				    data->plane[i]->type ==
>>>>> DRM_PLANE_TYPE_CURSOR ? DRM_FORMAT_ARGB8888 :
>> DRM_FORMAT_XRGB8888,
>>>>> +				    data->plane[i]->type ==
>>>>> DRM_PLANE_TYPE_CURSOR ? LOCAL_DRM_FORMAT_MOD_NONE :
>>>>> LOCAL_I915_FORMAT_MOD_X_TILED,
>>>>> +				    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[primary->index] = primary;
>>>>> +	create_fb_for_mode_position(data, mode, color, x, y, size,
>>>>> size,
>>>>> +				    LOCAL_I915_FORMAT_MOD_X_TILED,
>>>>> max_planes);
>>>>> +	igt_plane_set_fb(data->plane[primary->index], &data-
>>>>>> fb[primary->index]);
>>>>> +}
>>>>> +
>>>>> +static void
>>>>> +test_plane_position_with_output(data_t *data) {
>>>>> +	igt_crc_t *crc;
>>>>> +	color_t blue  = { 0.0f, 0.0f, 1.0f };
>>>>> +	int i;
>>>>> +	int iterations = opt.iterations < 1 ? 1 : opt.iterations;
>>>>> +	bool loop_forever;
>>>>> +	char info[256];
>>>>> +	int max_planes = data->display.pipes[data->pipe].n_planes;
>>>>> +
>>>>> +	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(data->output),
>>>>> kmstest_pipe_name(data->pipe), max_planes,
>>>>> +		 info, opt.seed);
>>>>> +
>>>>> +	i = 0;
>>>>> +	while (i < iterations || loop_forever) {
>>>>> +		prepare_planes(data, &blue, max_planes);
>>>>> +
>>>>> +		display_commit_mode(data, crc);
>>>>> +
>>>>> +		i++;
>>>>> +	}
>>>>> +}
>>>>> +
>>>>> +static drmModeConnector *
>>>>> +get_connector_connected(int drm_fd) {
>>>>> +	drmModeRes *resources = drmModeGetResources(drm_fd);
>>>>> +	drmModeConnector *connector;
>>>>> +	int i;
>>>>> +
>>>>> +	for (i = 0; i < resources->count_connectors; i++) {
>>>>> +		connector = drmModeGetConnector(drm_fd,
>>>>> +						resources-
>>>>>> connectors[i]);
>>>>> +
>>>>> +		if (connector->connection == DRM_MODE_CONNECTED)
>>>>> +			break;
>>>>> +
>>>>> +		drmModeFreeConnector(connector);
>>>>> +		connector = NULL;
>>>>> +	}
>>>>> +
>>>>> +	drmModeFreeResources(resources);
>>>>> +
>>>>> +	return connector;
>>>>> +}
>>>>> +
>>>>> +static int get_crtc_for_encoder(drmModeRes *resources,
>>>>> +				drmModeEncoder *encoder)
>>>>> +{
>>>>> +	int mask, id;
>>>>> +	int i;
>>>>> +	bool found;
>>>>> +
>>>>> +	for (i = 0; i < resources->count_crtcs; i++) {
>>>>> +		mask = 1 << i;
>>>>> +		id = resources->crtcs[i];
>>>>> +
>>>>> +		found = encoder->possible_crtcs & mask;
>>>>> +		if (found)
>>>>> +			break;
>>>>> +	}
>>>>> +
>>>>> +	if (!found)
>>>>> +		return -EINVAL;
>>>>> +
>>>>> +	return id;
>>>>> +}
>>>>> +
>>>>> +static int get_crtc_for_connector(int drm_fd, drmModeRes
>>>>> *resources,
>>>>> +				  drmModeConnector *connector)
>>>>> +{
>>>>> +	drmModeEncoder *encoder;
>>>>> +	int encoder_id;
>>>>> +	int crtc_id;
>>>>> +	int i;
>>>>> +
>>>>> +	for (i = 0; i < connector->count_encoders; i++) {
>>>>> +		encoder_id = connector->encoders[i];
>>>>> +		encoder = drmModeGetEncoder(drm_fd, encoder_id);
>>>>> +
>>>>> +		if (encoder) {
>>>>> +			crtc_id = get_crtc_for_encoder(resources,
>>>>> encoder);
>>>>> +
>>>>> +			drmModeFreeEncoder(encoder);
>>>>> +
>>>>> +			if (crtc_id != 0)
>>>>> +				break;
>>>>> +		}
>>>>> +	}
>>>>> +
>>>>> +	if (crtc_id == 0)
>>>>> +		return -EINVAL;
>>>>> +
>>>>> +	return crtc_id;
>>>>> +}
>>>>> +
>>>>> +static int get_crtc(int drm_fd)
>>>>> +{
>>>>> +	drmModeRes *resources;
>>>>> +	drmModeConnector *connector;
>>>>> +	drmModeEncoder *encoder;
>>>>> +	int i, id;
>>>>> +
>>>>> +	resources = drmModeGetResources(drm_fd);
>>>>> +	connector = get_connector_connected(drm_fd);
>>>>> +
>>>>> +	for (i = 0; i < resources->count_encoders; i++) {
>>>>> +		encoder = drmModeGetEncoder(drm_fd, resources-
>>>>>> encoders[i]);
>>>>> +
>>>>> +		if (encoder->encoder_id == connector->encoder_id)
>>>>> +			break;
>>>>> +
>>>>> +		drmModeFreeEncoder(encoder);
>>>>> +		encoder = NULL;
>>>>> +	}
>>>>> +
>>>>> +	if (encoder)
>>>>> +		return encoder->crtc_id;
>>>>> +
>>>>> +	id = get_crtc_for_connector(drm_fd, resources, connector);
>>>>> +	igt_assert(id != 0);
>>>>> +
>>>>> +	return id;
>>>>> +}
>>>>> +
>>>>> +static drmModeModeInfo *
>>>>> +get_lowres_mode(data_t *data, drmModeModeInfo *mode_default) {
>>>>> +	drmModeRes *resources = drmModeGetResources(data->drm_fd);
>>>>> +	drmModeModeInfo std_1024_mode = {
>>>>> +		.clock = 65000,
>>>>> +		.hdisplay = 1024,
>>>>> +		.hsync_start = 1048,
>>>>> +		.hsync_end = 1184,
>>>>> +		.htotal = 1344,
>>>>> +		.hskew = 0,
>>>>> +		.vdisplay = 768,
>>>>> +		.vsync_start = 771,
>>>>> +		.vsync_end = 777,
>>>>> +		.vtotal = 806,
>>>>> +		.vscan = 0,
>>>>> +		.vrefresh = 60,
>>>>> +		.flags = 0xA,
>>>>> +		.type = 0x40,
>>>>> +		.name = "Custom 1024x768",
>>>>> +	};
>>>>> +	drmModeModeInfo *mode;
>>>>> +	drmModeConnector *connector;
>>>>> +	bool found;
>>>>> +	int limit = mode_default->vdisplay-SIZE_PLANE;
>>>>> +	int i, j;
>>>>> +
>>>>> +	if (!resources) {
>>>>> +		igt_warn("drmModeGetResources failed: %s\n",
>>>>> strerror(errno));
>>>>> +		return mode;
>>>>> +	}
>>>>> +
>>>>> +	found = false;
>>>>> +	for (i = 0; i < resources->count_connectors; i++) {
>>>>> +
>>>>> +		connector = drmModeGetConnectorCurrent(data-
>>>>>> drm_fd,
>>>>> +						       resources-
>>>>>> connectors[i]);
>>>>> +
>>>>> +		if (!connector) {
>>>>> +			igt_warn("could not get connector %i:
>>>>> %s\n",
>>>>> +				 resources->connectors[i],
>>>>> strerror(errno));
>>>>> +			continue;
>>>>> +		}
>>>>> +
>>>>> +		if (!connector->count_modes)
>>>>> +			continue;
>>>>> +
>>>>> +		for (j = 0; j < connector->count_modes; j++) {
>>>>> +			mode = &connector->modes[j];
>>>>> +
>>>>> +			if (mode->vdisplay < limit) {
>>>>> +				found = true;
>>>>> +				break;
>>>>> +			}
>>>>> +		}
>>>>> +
>>>>> +		drmModeFreeConnector(connector);
>>>>> +	}
>>>>> +
>>>>> +	drmModeFreeResources(resources);
>>>>> +
>>>>> +	if (!found)
>>>>> +		mode = &std_1024_mode;
>>>>> +
>>>>> +	return mode;
>>>>> +}
>>>> Still not completely happy about this part.
>>>>
>>>> I would look at data->output->config.connector for modes, and return
>>>> 1024 mode if nothing's found.
>>>>
>>>> Saves a whole lot of drm calls.
>>> True. A lot of lines can be cleaned out.
>>>>> +static void
>>>>> +test_resolution_with_output(data_t *data) {
>>>>> +	drmModeModeInfo *mode_hi, *mode_lo;
>>>>> +	int ret;
>>>>> +	int iterations = opt.iterations < 1 ? 1 : opt.iterations;
>>>>> +	bool loop_forever;
>>>>> +	int i;
>>>>> +
>>>>> +	if (opt.iterations == LOOP_FOREVER)
>>>>> +		loop_forever = true;
>>>>> +	else
>>>>> +		loop_forever = false;
>>>>> +
>>>>> +	igt_info("Testing resolution with connector %s using pipe
>>>>> %s with seed %d\n",
>>>>> +		 igt_output_name(data->output),
>>>>> kmstest_pipe_name(data->pipe), opt.seed);
>>>>> +
>>>>> +	mode_hi = igt_output_get_mode(data->output);
>>>>> +	mode_lo = get_lowres_mode(data, mode_hi);
>>>>> +
>>>>> +	i = 0;
>>>>> +	while (i < iterations || loop_forever) {
>>>>> +		/* switch to lower resolution */
>>>>> +		ret = drmModeSetCrtc(data->drm_fd, data->crtc_id,
>>>>> data->fb->fb_id, 0, 0,
>>>>> +				     &data->connector_id, 1,
>>>>> mode_lo);
>>>>> +		igt_assert_eq(ret, 0);
>>>>> +
>>>>> +		/* switch back to higher resolution */
>>>>> +		ret = drmModeSetCrtc(data->drm_fd, data->crtc_id,
>>>>> data->fb->fb_id, 0, 0,
>>>>> +				     &data->connector_id, 1,
>>>>> mode_hi);
>>>>> +		igt_assert_eq(ret, 0);
>>>>> +
>>>>> +		i++;
>>>>> +	}
>>>>> +}
>>>> Use igt_output_override_mode + igt_display calls? With the thread
>>>> being a fork now, you can use igt_display. :)
>>> For some reason I keep receiving an error when using
>>> igt_output_override_mode + igt_display calls. The error is
>>>
>>> igt-kms-CRITICAL: Failed assertion:
>>> drmModeDestroyPropertyBlob(display-
>>>> drm_fd, *blob) == 0
>>> igt-kms-CRITICAL: Last errno: 1, Operation not permitted
>>>
>>> Maybe both threads try to access this and this request is not granted?
>>> With drmModeSetCrtc() call I don't see this behavior. Maybe stick with
>>> raw calls instead?
>> data->display.pipes[pipe].mode_blob = 0; in one of the forks of the test should
>> fix it.
> This seems to fix the issue. I'll throw a revised patch of the test shortly.
>
>> -EPERM means that the blob was already destroyed by this fd, but still used
>> globally.
>>
>> kms_rmfb does similar, maybe we should ignore failures?
> Maybe we could ignore these failures. Any harm done elsewhere if we do so?

I'm hesitant to ignore them, for the same reason as calling free() twice is a bad idea, we may end up freeing a different unknown blob.

~Maarten

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-04-11  8:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-15  8:43 [PATCH i-g-t v2] tests/kms_concurrent: Concurrent and interruptible subtests for atomic Mika Kahola
2017-03-29  9:53 ` Maarten Lankhorst
2017-04-10 12:11   ` Mika Kahola
2017-04-10 12:39     ` Maarten Lankhorst
2017-04-11  7:42       ` Kahola, Mika
2017-04-11  8:18         ` Maarten Lankhorst

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.