[igt-dev] [PATCH v2] tests/kms_closefb: add CLOSEFB IOCTL test
Simon Ser
contact at emersion.fr
Wed Oct 18 12:32:08 UTC 2023
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.
Signed-off-by: Simon Ser <contact at emersion.fr>
Cc: Kamil Konieczny <kamil.konieczny at linux.intel.com>
Cc: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
Cc: Bhanuprakash Modem <bhanuprakash.modem at intel.com>
---
tests/kms_closefb.c | 115 ++++++++++++++++++++++++++++++++++++++++++++
tests/meson.build | 1 +
2 files changed, 116 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..eee09e071367
--- /dev/null
+++ b/tests/kms_closefb.c
@@ -0,0 +1,115 @@
+// 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
+#define DRM_IOCTL_MODE_CLOSEFB DRM_IOWR(0xD0, unsigned int)
+#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;
+
+ 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);
+
+ ret = drmIoctl(*drm_fd, DRM_IOCTL_MODE_CLOSEFB, &fb.fb_id);
+ 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 at 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;
+ uint32_t fb_id = 0;
+ 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 */
+ ret = drmIoctl(drm_fd, DRM_IOCTL_MODE_CLOSEFB, &fb_id);
+ 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 2c2e1ca9acad..6b1b15973bde 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',
base-commit: 93c5ec2105500f7083d0cb50db3fbb3bca3776bb
--
2.42.0
More information about the igt-dev
mailing list