Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Ser <contact@emersion.fr>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH v3] tests/kms_closefb: add CLOSEFB IOCTL test
Date: Fri, 27 Oct 2023 10:44:01 +0000	[thread overview]
Message-ID: <20231027104351.449765-1-contact@emersion.fr> (raw)

CLOSEFB is the same as RMFB but keeps the FB alive as long as any
plane is using it. Check the behavior of that IOCTL.

See https://patchwork.freedesktop.org/patch/563722/

v2: address Kamil's code style comments

v3: update for minor uAPI update with new struct

Signed-off-by: Simon Ser <contact@emersion.fr>
Cc: Kamil Konieczny <kamil.konieczny@linux.intel.com>
Cc: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com>
Cc: Bhanuprakash Modem <bhanuprakash.modem@intel.com>
---
 tests/kms_closefb.c | 124 ++++++++++++++++++++++++++++++++++++++++++++
 tests/meson.build   |   1 +
 2 files changed, 125 insertions(+)
 create mode 100644 tests/kms_closefb.c

diff --git a/tests/kms_closefb.c b/tests/kms_closefb.c
new file mode 100644
index 000000000000..2a684ad83fdf
--- /dev/null
+++ b/tests/kms_closefb.c
@@ -0,0 +1,124 @@
+// SPDX-License-Identifier: MIT
+// Copyright © 2023 Simon Ser
+
+#include "igt.h"
+
+/**
+ * TEST: kms closefb
+ * Category: Display
+ * Description: This tests CLOSEFB behavior. Contrary to RMFB, the
+ *              framebuffers should not be removed from the CRTC.
+ *
+ * SUBTEST: closefb-ioctl
+ * Description: CLOSEFB is supposed to leave all planes intact.
+ */
+
+IGT_TEST_DESCRIPTION("This tests CLOSEFB behavior. Contrary to RMFB, the"
+		     "framebuffers should not be removed from the CRTC.");
+
+// TODO: drop when shipped in kernel header
+#ifndef DRM_IOCTL_MODE_CLOSEFB
+struct drm_mode_closefb {
+	__u32 fb_id;
+	__u32 pad;
+};
+#define DRM_IOCTL_MODE_CLOSEFB DRM_IOWR(0xD0, struct drm_mode_closefb)
+#endif
+
+/* 1. Set primary plane to a known FB.
+ * 2. Make sure GETCRTC returns the correct FB ID.
+ * 3. Call CLOSEFB on the FB.
+ * 4. Make sure GETCRTC returns non-0 FB ID.
+ */
+static void
+test_closefb(int *drm_fd, igt_display_t *display, igt_output_t *output,
+	     enum pipe pipe)
+{
+	struct igt_fb fb;
+	drmModeModeInfo *mode;
+	igt_plane_t *plane;
+	drmModeCrtc *crtc;
+	int ret;
+	struct drm_mode_closefb closefb;
+
+	mode = igt_output_get_mode(output);
+	plane = igt_pipe_get_plane_type(&display->pipes[pipe], DRM_PLANE_TYPE_PRIMARY);
+
+	igt_create_fb(*drm_fd, mode->hdisplay, mode->vdisplay,
+		      DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_LINEAR, &fb);
+	igt_plane_set_fb(plane, &fb);
+	igt_display_commit2(display, display->is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY);
+
+	crtc = drmModeGetCrtc(*drm_fd, output->config.crtc->crtc_id);
+	igt_assert_eq(crtc->buffer_id, fb.fb_id);
+	drmModeFreeCrtc(crtc);
+
+	closefb.fb_id = fb.fb_id;
+	closefb.pad = 0;
+	ret = drmIoctl(*drm_fd, DRM_IOCTL_MODE_CLOSEFB, &closefb);
+	igt_assert_eq(ret, 0);
+
+	/* Re-open our DRM FD. Without CLOSEFB, this would implicitly turn off
+	 * the CRTC and remove the FB (see test kms_rmfb@close-fd). */
+	drm_close_driver(*drm_fd);
+	*drm_fd = drm_open_driver_master(DRIVER_ANY);
+	drmSetClientCap(*drm_fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
+	drmSetClientCap(*drm_fd, DRM_CLIENT_CAP_ATOMIC, 1);
+	igt_pipe_refresh(display, pipe, true);
+
+	/* Check that our CRTC still has the FB attached */
+	crtc = drmModeGetCrtc(*drm_fd, output->config.crtc->crtc_id);
+	igt_assert_eq(crtc->buffer_id, fb.fb_id);
+	drmModeFreeCrtc(crtc);
+}
+
+static void
+run_closefb_test(int *drm_fd, igt_display_t *display)
+{
+	igt_output_t *output;
+	enum pipe pipe;
+
+	for_each_pipe_with_single_output(display, pipe, output) {
+		igt_display_reset(display);
+
+		igt_output_set_pipe(output, pipe);
+
+		igt_dynamic_f("pipe-%s-%s", kmstest_pipe_name(pipe),
+			      igt_output_name(output))
+			test_closefb(drm_fd, display, output, pipe);
+	}
+}
+
+igt_main
+{
+	int drm_fd;
+	igt_display_t display;
+	struct drm_mode_closefb closefb;
+	int ret;
+
+	igt_fixture {
+		drm_fd = drm_open_driver_master(DRIVER_ANY);
+
+		kmstest_set_vt_graphics_mode();
+
+		igt_display_require(&display, drm_fd);
+		igt_display_require_output(&display);
+
+		/* Detect kernel support for CLOSEFB */
+		closefb.fb_id = 0;
+		closefb.pad = 0;
+		ret = drmIoctl(drm_fd, DRM_IOCTL_MODE_CLOSEFB, &closefb);
+		igt_require(ret != 0 && errno == ENOENT);
+	}
+
+	igt_describe("CLOSEFB is supposed to not touch any plane the FB is "
+		     "currently attached to. Check that behavior.");
+	igt_subtest_with_dynamic("closefb-ioctl") {
+		run_closefb_test(&drm_fd, &display);
+	}
+
+	igt_fixture {
+		igt_display_fini(&display);
+		drm_close_driver(drm_fd);
+	}
+}
diff --git a/tests/meson.build b/tests/meson.build
index a8a7115e3a25..b35bc068cbd8 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -21,6 +21,7 @@ test_progs = [
 	'kms_atomic_interruptible',
 	'kms_atomic_transition',
 	'kms_bw',
+	'kms_closefb',
 	'kms_color',
 	'kms_concurrent',
 	'kms_content_protection',
-- 
2.42.0


             reply	other threads:[~2023-10-27 10:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-27 10:44 Simon Ser [this message]
2023-10-27 11:07 ` [igt-dev] [PATCH v3] tests/kms_closefb: add CLOSEFB IOCTL test Daniel Stone
2023-10-27 14:03 ` [igt-dev] ✓ Fi.CI.BAT: success for tests/kms_closefb: add CLOSEFB IOCTL test (rev3) Patchwork
2023-10-27 14:37 ` [igt-dev] ✗ CI.xeBAT: failure " Patchwork
2023-10-29 19:06 ` [igt-dev] ✗ Fi.CI.IGT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231027104351.449765-1-contact@emersion.fr \
    --to=contact@emersion.fr \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox