[PATCH i-g-t] tests/kms_dirtyfb: Add new test for dirtyfb ioctl

Jouni Högander jouni.hogander at intel.com
Mon Mar 13 13:51:49 UTC 2023


Add new test to validate dirtyfb ioctl is working properly with
GPU frontbuffer rendering

Signed-off-by: Jouni Högander <jouni.hogander at intel.com>
---
 tests/i915/kms_dirtyfb.c | 197 +++++++++++++++++++++++++++++++++++++++
 tests/meson.build        |   1 +
 2 files changed, 198 insertions(+)
 create mode 100644 tests/i915/kms_dirtyfb.c

diff --git a/tests/i915/kms_dirtyfb.c b/tests/i915/kms_dirtyfb.c
new file mode 100644
index 00000000..9b606c86
--- /dev/null
+++ b/tests/i915/kms_dirtyfb.c
@@ -0,0 +1,197 @@
+/*
+ * Copyright © 2023 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.
+ *
+ * Authors: Jouni Högander <jouni.hogander at intel.com>
+ *
+ */
+
+#include <sys/types.h>
+
+#include "igt.h"
+
+IGT_TEST_DESCRIPTION("Test the DIRTYFB ioctl is working properly with "
+		     "its related features: FBC, PSR and DRRS");
+
+#define NUM_OF_RECTS 5
+
+typedef struct {
+	int drm_fd;
+	int debugfs_fd;
+	igt_display_t display;
+	drmModeModeInfo *mode;
+	igt_output_t *output;
+	igt_pipe_crc_t *pipe_crc;
+	enum pipe pipe;
+
+	struct igt_fb fbs[2];
+
+	igt_crc_t ref_crc;
+
+	struct buf_ops *bops;
+} data_t;
+
+static void setup_output(data_t *data)
+{
+	igt_display_t *display = &data->display;
+	igt_output_t *output;
+	enum pipe pipe;
+
+	for_each_pipe_with_valid_output(display, pipe, output) {
+		drmModeConnectorPtr c = output->config.connector;
+
+		if (c->connector_type != DRM_MODE_CONNECTOR_eDP)
+			continue;
+
+		igt_output_set_pipe(output, pipe);
+		data->output = output;
+		data->mode = igt_output_get_mode(output);
+		data->pipe = pipe;
+
+		return;
+	}
+}
+
+static void draw_rects(data_t *data, struct igt_fb *fb)
+{
+	int count = 5, w = data->mode->hdisplay / count,
+		h = data->mode->vdisplay / count, i, x, y;
+	for (i = 1; i <= count; i++) {
+		switch(i) {
+		case 1:
+			x = 0;
+			y = 0;
+			break;
+		case 2:
+			x = data->mode->hdisplay - w;
+			y = 0;
+			break;
+		case 3:
+			x = data->mode->hdisplay - w;
+			y = data->mode->vdisplay - h;
+			break;
+		case 4:
+			x = 0;
+			y = data->mode->vdisplay - h;
+			break;
+		case 5:
+			x = data->mode->hdisplay / 2 - w / 2;
+			y = data->mode->vdisplay / 2 - h / 2;
+		default:
+			break;
+		}
+
+		igt_draw_rect_fb(data->drm_fd, data->bops, 0, fb, IGT_DRAW_RENDER,
+				 x, y, w, h, 0xFF);
+	}
+}
+
+static void prepare(data_t *data)
+{
+	igt_plane_t *primary;
+
+	igt_create_color_fb(data->drm_fd, data->mode->hdisplay,
+			    data->mode->hdisplay, DRM_FORMAT_XRGB8888,
+			    DRM_FORMAT_MOD_LINEAR, 0.0, 1.0, 0.0,
+			    &data->fbs[0]);
+	draw_rects(data, &data->fbs[0]);
+	primary = igt_output_get_plane_type(data->output,
+					    DRM_PLANE_TYPE_PRIMARY);
+
+	igt_plane_set_fb(primary, &data->fbs[0]);
+
+	igt_display_commit2(&data->display, COMMIT_ATOMIC);
+
+	igt_pipe_crc_collect_crc(data->pipe_crc, &data->ref_crc);
+
+	igt_create_color_fb(data->drm_fd, data->mode->hdisplay,
+			    data->mode->hdisplay, DRM_FORMAT_XRGB8888,
+			    DRM_FORMAT_MOD_LINEAR, 0.0, 1.0, 0.0,
+			    &data->fbs[1]);
+
+	igt_plane_set_fb(primary, &data->fbs[1]);
+	igt_display_commit2(&data->display, COMMIT_ATOMIC);
+}
+
+static void cleanup(data_t *data)
+{
+	igt_remove_fb(data->drm_fd, &data->fbs[0]);
+	igt_remove_fb(data->drm_fd, &data->fbs[1]);
+}
+
+static void run_test(data_t *data)
+{
+	igt_crc_t crc;
+	igt_spin_t *spin;
+	uint64_t ahnd = get_reloc_ahnd(data->drm_fd, 0);
+	int r;
+
+	spin = igt_spin_new(data->drm_fd,
+			    .ahnd = ahnd);
+
+	draw_rects(data, &data->fbs[1]);
+
+	r = drmModeDirtyFB(data->drm_fd, data->fbs[1].fb_id, NULL, 0);
+	igt_assert(r == 0 || r == -ENOSYS);
+
+	igt_pipe_crc_collect_crc(data->pipe_crc, &crc);
+	igt_assert_crc_equal(&crc, &data->ref_crc);
+
+	igt_spin_free(data->drm_fd, spin);
+}
+
+igt_main
+{
+	data_t data = {};
+
+	igt_fixture {
+		data.drm_fd = drm_open_driver_master(DRIVER_INTEL);
+		data.debugfs_fd = igt_debugfs_dir(data.drm_fd);
+
+		kmstest_set_vt_graphics_mode();
+		igt_display_require(&data.display, data.drm_fd);
+
+		data.bops = buf_ops_create(data.drm_fd);
+
+		igt_display_require(&data.display, data.drm_fd);
+		igt_display_reset(&data.display);
+
+		setup_output(&data);
+
+		data.pipe_crc = igt_pipe_crc_new(data.drm_fd, data.pipe,
+						 IGT_PIPE_CRC_SOURCE_AUTO);
+	}
+
+	igt_describe("Test dirtyFB ioctl");
+	igt_subtest("dirtyfb-ioctl") {
+		prepare(&data);
+		run_test(&data);
+		cleanup(&data);
+	}
+
+	igt_fixture {
+		igt_pipe_crc_free(data.pipe_crc);
+		buf_ops_destroy(data.bops);
+		igt_display_fini(&data.display);
+		close(data.drm_fd);
+	}
+}
+
diff --git a/tests/meson.build b/tests/meson.build
index 4a1722b3..b1b4c1ea 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -228,6 +228,7 @@ i915_progs = [
 	'kms_flip_scaled_crc',
 	'kms_flip_tiling',
 	'kms_frontbuffer_tracking',
+	'kms_dirtyfb',
 	'kms_legacy_colorkey',
 	'kms_mmap_write_crc',
 	'kms_pipe_b_c_ivb',
-- 
2.34.1



More information about the Intel-gfx-trybot mailing list