drm: selftest: convert drm_plane_helper selftest to KUnit
authorMaíra Canal <maira.canal@usp.br>
Fri, 8 Jul 2022 20:30:48 +0000 (17:30 -0300)
committerJavier Martinez Canillas <javierm@redhat.com>
Mon, 11 Jul 2022 11:59:58 +0000 (13:59 +0200)
Considering the current adoption of the KUnit framework, convert the
DRM plane helper selftest to the KUnit API.

Co-developed-by: Djakson C. G. Filho <djakson.filho@gmail.com>
Signed-off-by: Djakson C. G. Filho <djakson.filho@gmail.com>
Co-developed-by: Anderson Fraga <aaafraga@gmail.com>
Signed-off-by: Anderson Fraga <aaafraga@gmail.com>
Tested-by: David Gow <davidgow@google.com>
Acked-by: Daniel Latypov <dlatypov@google.com>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Signed-off-by: Maíra Canal <maira.canal@usp.br>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220708203052.236290-6-maira.canal@usp.br
drivers/gpu/drm/selftests/Makefile
drivers/gpu/drm/selftests/drm_modeset_selftests.h
drivers/gpu/drm/selftests/test-drm_modeset_common.h
drivers/gpu/drm/selftests/test-drm_plane_helper.c [deleted file]
drivers/gpu/drm/tests/Makefile
drivers/gpu/drm/tests/drm_plane_helper_test.c [new file with mode: 0644]

index b7f252d886d0c43af7cbba0d92cec9c4606ae608..9e0ccb482841c59e830939f4077bc708070fde00 100644 (file)
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
-test-drm_modeset-y := test-drm_modeset_common.o test-drm_plane_helper.o \
-                      test-drm_framebuffer.o test-drm_dp_mst_helper.o
+test-drm_modeset-y := test-drm_modeset_common.o test-drm_framebuffer.o \
+                                       test-drm_dp_mst_helper.o
 
 obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o \
                                    test-drm_buddy.o
index 63061ef55eff5ebe88810ebf3c748b457da3fc24..22e467f6465a82e446d0085727a8cf37b9f9321e 100644 (file)
@@ -6,7 +6,6 @@
  *
  * Tests are executed in order by igt/drm_selftests_helper
  */
-selftest(check_plane_state, igt_check_plane_state)
 selftest(check_drm_framebuffer_create, igt_check_drm_framebuffer_create)
 selftest(dp_mst_calc_pbn_mode, igt_dp_mst_calc_pbn_mode)
 selftest(dp_mst_sideband_msg_req_decode, igt_dp_mst_sideband_msg_req_decode)
index 5709d967a5c4e27f29c4fa3a37f26c2ce68c89f5..790f3cf31f0d900fc9e6e4a99776ab20f3625081 100644 (file)
@@ -16,7 +16,6 @@
 
 #define FAIL_ON(x) FAIL((x), "%s", "FAIL_ON(" __stringify(x) ")\n")
 
-int igt_check_plane_state(void *ignored);
 int igt_check_drm_framebuffer_create(void *ignored);
 int igt_dp_mst_calc_pbn_mode(void *ignored);
 int igt_dp_mst_sideband_msg_req_decode(void *ignored);
diff --git a/drivers/gpu/drm/selftests/test-drm_plane_helper.c b/drivers/gpu/drm/selftests/test-drm_plane_helper.c
deleted file mode 100644 (file)
index 64e8938..0000000
+++ /dev/null
@@ -1,224 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * Test cases for the drm_plane_helper functions
- */
-
-#define pr_fmt(fmt) "drm_plane_helper: " fmt
-
-#include <drm/drm_atomic_helper.h>
-#include <drm/drm_framebuffer.h>
-#include <drm/drm_plane_helper.h>
-#include <drm/drm_modes.h>
-
-#include "test-drm_modeset_common.h"
-
-static void set_src(struct drm_plane_state *plane_state,
-                   unsigned src_x, unsigned src_y,
-                   unsigned src_w, unsigned src_h)
-{
-       plane_state->src_x = src_x;
-       plane_state->src_y = src_y;
-       plane_state->src_w = src_w;
-       plane_state->src_h = src_h;
-}
-
-static bool check_src_eq(struct drm_plane_state *plane_state,
-                        unsigned src_x, unsigned src_y,
-                        unsigned src_w, unsigned src_h)
-{
-       if (plane_state->src.x1 < 0) {
-               pr_err("src x coordinate %x should never be below 0.\n", plane_state->src.x1);
-               drm_rect_debug_print("src: ", &plane_state->src, true);
-               return false;
-       }
-       if (plane_state->src.y1 < 0) {
-               pr_err("src y coordinate %x should never be below 0.\n", plane_state->src.y1);
-               drm_rect_debug_print("src: ", &plane_state->src, true);
-               return false;
-       }
-
-       if (plane_state->src.x1 != src_x ||
-           plane_state->src.y1 != src_y ||
-           drm_rect_width(&plane_state->src) != src_w ||
-           drm_rect_height(&plane_state->src) != src_h) {
-               drm_rect_debug_print("src: ", &plane_state->src, true);
-               return false;
-       }
-
-       return true;
-}
-
-static void set_crtc(struct drm_plane_state *plane_state,
-                    int crtc_x, int crtc_y,
-                    unsigned crtc_w, unsigned crtc_h)
-{
-       plane_state->crtc_x = crtc_x;
-       plane_state->crtc_y = crtc_y;
-       plane_state->crtc_w = crtc_w;
-       plane_state->crtc_h = crtc_h;
-}
-
-static bool check_crtc_eq(struct drm_plane_state *plane_state,
-                         int crtc_x, int crtc_y,
-                         unsigned crtc_w, unsigned crtc_h)
-{
-       if (plane_state->dst.x1 != crtc_x ||
-           plane_state->dst.y1 != crtc_y ||
-           drm_rect_width(&plane_state->dst) != crtc_w ||
-           drm_rect_height(&plane_state->dst) != crtc_h) {
-               drm_rect_debug_print("dst: ", &plane_state->dst, false);
-
-               return false;
-       }
-
-       return true;
-}
-
-int igt_check_plane_state(void *ignored)
-{
-       int ret;
-
-       static const struct drm_crtc_state crtc_state = {
-               .crtc = ZERO_SIZE_PTR,
-               .enable = true,
-               .active = true,
-               .mode = {
-                       DRM_MODE("1024x768", 0, 65000, 1024, 1048,
-                               1184, 1344, 0, 768, 771, 777, 806, 0,
-                               DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC)
-               },
-       };
-       static struct drm_plane plane = {
-               .dev = NULL
-       };
-       static struct drm_framebuffer fb = {
-               .width = 2048,
-               .height = 2048
-       };
-       static struct drm_plane_state plane_state = {
-               .plane = &plane,
-               .crtc = ZERO_SIZE_PTR,
-               .fb = &fb,
-               .rotation = DRM_MODE_ROTATE_0
-       };
-
-       /* Simple clipping, no scaling. */
-       set_src(&plane_state, 0, 0, fb.width << 16, fb.height << 16);
-       set_crtc(&plane_state, 0, 0, fb.width, fb.height);
-       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
-                                                 DRM_PLANE_HELPER_NO_SCALING,
-                                                 DRM_PLANE_HELPER_NO_SCALING,
-                                                 false, false);
-       FAIL(ret < 0, "Simple clipping check should pass\n");
-       FAIL_ON(!plane_state.visible);
-       FAIL_ON(!check_src_eq(&plane_state, 0, 0, 1024 << 16, 768 << 16));
-       FAIL_ON(!check_crtc_eq(&plane_state, 0, 0, 1024, 768));
-
-       /* Rotated clipping + reflection, no scaling. */
-       plane_state.rotation = DRM_MODE_ROTATE_90 | DRM_MODE_REFLECT_X;
-       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
-                                                 DRM_PLANE_HELPER_NO_SCALING,
-                                                 DRM_PLANE_HELPER_NO_SCALING,
-                                                 false, false);
-       FAIL(ret < 0, "Rotated clipping check should pass\n");
-       FAIL_ON(!plane_state.visible);
-       FAIL_ON(!check_src_eq(&plane_state, 0, 0, 768 << 16, 1024 << 16));
-       FAIL_ON(!check_crtc_eq(&plane_state, 0, 0, 1024, 768));
-       plane_state.rotation = DRM_MODE_ROTATE_0;
-
-       /* Check whether positioning works correctly. */
-       set_src(&plane_state, 0, 0, 1023 << 16, 767 << 16);
-       set_crtc(&plane_state, 0, 0, 1023, 767);
-       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
-                                                 DRM_PLANE_HELPER_NO_SCALING,
-                                                 DRM_PLANE_HELPER_NO_SCALING,
-                                                 false, false);
-       FAIL(!ret, "Should not be able to position on the crtc with can_position=false\n");
-
-       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
-                                                 DRM_PLANE_HELPER_NO_SCALING,
-                                                 DRM_PLANE_HELPER_NO_SCALING,
-                                                 true, false);
-       FAIL(ret < 0, "Simple positioning should work\n");
-       FAIL_ON(!plane_state.visible);
-       FAIL_ON(!check_src_eq(&plane_state, 0, 0, 1023 << 16, 767 << 16));
-       FAIL_ON(!check_crtc_eq(&plane_state, 0, 0, 1023, 767));
-
-       /* Simple scaling tests. */
-       set_src(&plane_state, 0, 0, 512 << 16, 384 << 16);
-       set_crtc(&plane_state, 0, 0, 1024, 768);
-       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
-                                                 0x8001,
-                                                 DRM_PLANE_HELPER_NO_SCALING,
-                                                 false, false);
-       FAIL(!ret, "Upscaling out of range should fail.\n");
-       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
-                                                 0x8000,
-                                                 DRM_PLANE_HELPER_NO_SCALING,
-                                                 false, false);
-       FAIL(ret < 0, "Upscaling exactly 2x should work\n");
-       FAIL_ON(!plane_state.visible);
-       FAIL_ON(!check_src_eq(&plane_state, 0, 0, 512 << 16, 384 << 16));
-       FAIL_ON(!check_crtc_eq(&plane_state, 0, 0, 1024, 768));
-
-       set_src(&plane_state, 0, 0, 2048 << 16, 1536 << 16);
-       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
-                                                 DRM_PLANE_HELPER_NO_SCALING,
-                                                 0x1ffff, false, false);
-       FAIL(!ret, "Downscaling out of range should fail.\n");
-       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
-                                                 DRM_PLANE_HELPER_NO_SCALING,
-                                                 0x20000, false, false);
-       FAIL(ret < 0, "Should succeed with exact scaling limit\n");
-       FAIL_ON(!plane_state.visible);
-       FAIL_ON(!check_src_eq(&plane_state, 0, 0, 2048 << 16, 1536 << 16));
-       FAIL_ON(!check_crtc_eq(&plane_state, 0, 0, 1024, 768));
-
-       /* Testing rounding errors. */
-       set_src(&plane_state, 0, 0, 0x40001, 0x40001);
-       set_crtc(&plane_state, 1022, 766, 4, 4);
-       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
-                                                 DRM_PLANE_HELPER_NO_SCALING,
-                                                 0x10001,
-                                                 true, false);
-       FAIL(ret < 0, "Should succeed by clipping to exact multiple");
-       FAIL_ON(!plane_state.visible);
-       FAIL_ON(!check_src_eq(&plane_state, 0, 0, 2 << 16, 2 << 16));
-       FAIL_ON(!check_crtc_eq(&plane_state, 1022, 766, 2, 2));
-
-       set_src(&plane_state, 0x20001, 0x20001, 0x4040001, 0x3040001);
-       set_crtc(&plane_state, -2, -2, 1028, 772);
-       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
-                                                 DRM_PLANE_HELPER_NO_SCALING,
-                                                 0x10001,
-                                                 false, false);
-       FAIL(ret < 0, "Should succeed by clipping to exact multiple");
-       FAIL_ON(!plane_state.visible);
-       FAIL_ON(!check_src_eq(&plane_state, 0x40002, 0x40002, 1024 << 16, 768 << 16));
-       FAIL_ON(!check_crtc_eq(&plane_state, 0, 0, 1024, 768));
-
-       set_src(&plane_state, 0, 0, 0x3ffff, 0x3ffff);
-       set_crtc(&plane_state, 1022, 766, 4, 4);
-       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
-                                                 0xffff,
-                                                 DRM_PLANE_HELPER_NO_SCALING,
-                                                 true, false);
-       FAIL(ret < 0, "Should succeed by clipping to exact multiple");
-       FAIL_ON(!plane_state.visible);
-       /* Should not be rounded to 0x20001, which would be upscaling. */
-       FAIL_ON(!check_src_eq(&plane_state, 0, 0, 2 << 16, 2 << 16));
-       FAIL_ON(!check_crtc_eq(&plane_state, 1022, 766, 2, 2));
-
-       set_src(&plane_state, 0x1ffff, 0x1ffff, 0x403ffff, 0x303ffff);
-       set_crtc(&plane_state, -2, -2, 1028, 772);
-       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
-                                                 0xffff,
-                                                 DRM_PLANE_HELPER_NO_SCALING,
-                                                 false, false);
-       FAIL(ret < 0, "Should succeed by clipping to exact multiple");
-       FAIL_ON(!plane_state.visible);
-       FAIL_ON(!check_src_eq(&plane_state, 0x3fffe, 0x3fffe, 1024 << 16, 768 << 16));
-       FAIL_ON(!check_crtc_eq(&plane_state, 0, 0, 1024, 768));
-
-       return 0;
-}
index 1aa1627cb5e6cbb92041176ea73d5a228dd436d8..4d44006a4f2376da4469a9dd40fc336bed3a42db 100644 (file)
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 
 obj-$(CONFIG_DRM_KUNIT_TEST) += drm_format_helper_test.o drm_damage_helper_test.o \
-       drm_cmdline_parser_test.o drm_rect_test.o drm_format_test.o
+       drm_cmdline_parser_test.o drm_rect_test.o drm_format_test.o drm_plane_helper_test.o
diff --git a/drivers/gpu/drm/tests/drm_plane_helper_test.c b/drivers/gpu/drm/tests/drm_plane_helper_test.c
new file mode 100644 (file)
index 0000000..e298766
--- /dev/null
@@ -0,0 +1,238 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Test cases for the drm_plane_helper functions
+ *
+ * Copyright (c) 2022 Maíra Canal <mairacanal@riseup.net>
+ */
+
+#include <kunit/test.h>
+
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_framebuffer.h>
+#include <drm/drm_plane_helper.h>
+#include <drm/drm_modes.h>
+
+static void set_src(struct drm_plane_state *plane_state,
+                   unsigned int src_x, unsigned int src_y,
+                   unsigned int src_w, unsigned int src_h)
+{
+       plane_state->src_x = src_x;
+       plane_state->src_y = src_y;
+       plane_state->src_w = src_w;
+       plane_state->src_h = src_h;
+}
+
+static bool check_src_eq(struct drm_plane_state *plane_state,
+                        unsigned int src_x, unsigned int src_y,
+                        unsigned int src_w, unsigned int src_h)
+{
+       if (plane_state->src.x1 < 0) {
+               pr_err("src x coordinate %x should never be below 0.\n", plane_state->src.x1);
+               drm_rect_debug_print("src: ", &plane_state->src, true);
+               return false;
+       }
+       if (plane_state->src.y1 < 0) {
+               pr_err("src y coordinate %x should never be below 0.\n", plane_state->src.y1);
+               drm_rect_debug_print("src: ", &plane_state->src, true);
+               return false;
+       }
+
+       if (plane_state->src.x1 != src_x ||
+           plane_state->src.y1 != src_y ||
+           drm_rect_width(&plane_state->src) != src_w ||
+           drm_rect_height(&plane_state->src) != src_h) {
+               drm_rect_debug_print("src: ", &plane_state->src, true);
+               return false;
+       }
+
+       return true;
+}
+
+static void set_crtc(struct drm_plane_state *plane_state,
+                    int crtc_x, int crtc_y,
+                    unsigned int crtc_w, unsigned int crtc_h)
+{
+       plane_state->crtc_x = crtc_x;
+       plane_state->crtc_y = crtc_y;
+       plane_state->crtc_w = crtc_w;
+       plane_state->crtc_h = crtc_h;
+}
+
+static bool check_crtc_eq(struct drm_plane_state *plane_state,
+                         int crtc_x, int crtc_y,
+                         unsigned int crtc_w, unsigned int crtc_h)
+{
+       if (plane_state->dst.x1 != crtc_x ||
+           plane_state->dst.y1 != crtc_y ||
+           drm_rect_width(&plane_state->dst) != crtc_w ||
+           drm_rect_height(&plane_state->dst) != crtc_h) {
+               drm_rect_debug_print("dst: ", &plane_state->dst, false);
+
+               return false;
+       }
+
+       return true;
+}
+
+static void igt_check_plane_state(struct kunit *test)
+{
+       int ret;
+
+       static const struct drm_crtc_state crtc_state = {
+               .crtc = ZERO_SIZE_PTR,
+               .enable = true,
+               .active = true,
+               .mode = {
+                       DRM_MODE("1024x768", 0, 65000, 1024, 1048, 1184, 1344, 0, 768, 771,
+                                777, 806, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC)
+               },
+       };
+       static struct drm_plane plane = {
+               .dev = NULL
+       };
+       static struct drm_framebuffer fb = {
+               .width = 2048,
+               .height = 2048
+       };
+       static struct drm_plane_state plane_state = {
+               .plane = &plane,
+               .crtc = ZERO_SIZE_PTR,
+               .fb = &fb,
+               .rotation = DRM_MODE_ROTATE_0
+       };
+
+       /* Simple clipping, no scaling. */
+       set_src(&plane_state, 0, 0, fb.width << 16, fb.height << 16);
+       set_crtc(&plane_state, 0, 0, fb.width, fb.height);
+       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 false, false);
+       KUNIT_EXPECT_FALSE_MSG(test, ret, 0, "Simple clipping check should pass\n");
+       KUNIT_EXPECT_TRUE(test, plane_state.visible);
+       KUNIT_EXPECT_TRUE(test, check_src_eq(&plane_state, 0, 0, 1024 << 16, 768 << 16));
+       KUNIT_EXPECT_TRUE(test, check_crtc_eq(&plane_state, 0, 0, 1024, 768));
+
+       /* Rotated clipping + reflection, no scaling. */
+       plane_state.rotation = DRM_MODE_ROTATE_90 | DRM_MODE_REFLECT_X;
+       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 false, false);
+       KUNIT_EXPECT_FALSE_MSG(test, ret, 0, "Rotated clipping check should pass\n");
+       KUNIT_EXPECT_TRUE(test, plane_state.visible);
+       KUNIT_EXPECT_TRUE(test, check_src_eq(&plane_state, 0, 0, 768 << 16, 1024 << 16));
+       KUNIT_EXPECT_TRUE(test, check_crtc_eq(&plane_state, 0, 0, 1024, 768));
+       plane_state.rotation = DRM_MODE_ROTATE_0;
+
+       /* Check whether positioning works correctly. */
+       set_src(&plane_state, 0, 0, 1023 << 16, 767 << 16);
+       set_crtc(&plane_state, 0, 0, 1023, 767);
+       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 false, false);
+       KUNIT_EXPECT_TRUE_MSG(test, ret,
+                             "Should not be able to position on the crtc with can_position=false\n");
+
+       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 true, false);
+       KUNIT_EXPECT_FALSE_MSG(test, ret, 0, "Simple positioning should work\n");
+       KUNIT_EXPECT_TRUE(test, plane_state.visible);
+       KUNIT_EXPECT_TRUE(test, check_src_eq(&plane_state, 0, 0, 1023 << 16, 767 << 16));
+       KUNIT_EXPECT_TRUE(test, check_crtc_eq(&plane_state, 0, 0, 1023, 767));
+
+       /* Simple scaling tests. */
+       set_src(&plane_state, 0, 0, 512 << 16, 384 << 16);
+       set_crtc(&plane_state, 0, 0, 1024, 768);
+       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
+                                                 0x8001,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 false, false);
+       KUNIT_EXPECT_TRUE_MSG(test, ret, "Upscaling out of range should fail.\n");
+       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
+                                                 0x8000,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 false, false);
+       KUNIT_EXPECT_FALSE_MSG(test, ret, 0, "Upscaling exactly 2x should work\n");
+       KUNIT_EXPECT_TRUE(test, plane_state.visible);
+       KUNIT_EXPECT_TRUE(test, check_src_eq(&plane_state, 0, 0, 512 << 16, 384 << 16));
+       KUNIT_EXPECT_TRUE(test, check_crtc_eq(&plane_state, 0, 0, 1024, 768));
+
+       set_src(&plane_state, 0, 0, 2048 << 16, 1536 << 16);
+       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 0x1ffff, false, false);
+       KUNIT_EXPECT_TRUE_MSG(test, ret, "Downscaling out of range should fail.\n");
+       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 0x20000, false, false);
+       KUNIT_EXPECT_FALSE_MSG(test, ret, 0, "Should succeed with exact scaling limit\n");
+       KUNIT_EXPECT_TRUE(test, plane_state.visible);
+       KUNIT_EXPECT_TRUE(test, check_src_eq(&plane_state, 0, 0, 2048 << 16, 1536 << 16));
+       KUNIT_EXPECT_TRUE(test, check_crtc_eq(&plane_state, 0, 0, 1024, 768));
+
+       /* Testing rounding errors. */
+       set_src(&plane_state, 0, 0, 0x40001, 0x40001);
+       set_crtc(&plane_state, 1022, 766, 4, 4);
+       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 0x10001,
+                                                 true, false);
+       KUNIT_EXPECT_FALSE_MSG(test, ret, 0, "Should succeed by clipping to exact multiple");
+       KUNIT_EXPECT_TRUE(test, plane_state.visible);
+       KUNIT_EXPECT_TRUE(test, check_src_eq(&plane_state, 0, 0, 2 << 16, 2 << 16));
+       KUNIT_EXPECT_TRUE(test, check_crtc_eq(&plane_state, 1022, 766, 2, 2));
+
+       set_src(&plane_state, 0x20001, 0x20001, 0x4040001, 0x3040001);
+       set_crtc(&plane_state, -2, -2, 1028, 772);
+       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 0x10001,
+                                                 false, false);
+       KUNIT_EXPECT_FALSE_MSG(test, ret, 0, "Should succeed by clipping to exact multiple");
+       KUNIT_EXPECT_TRUE(test, plane_state.visible);
+       KUNIT_EXPECT_TRUE(test, check_src_eq(&plane_state, 0x40002, 0x40002,
+                                            1024 << 16, 768 << 16));
+       KUNIT_EXPECT_TRUE(test, check_crtc_eq(&plane_state, 0, 0, 1024, 768));
+
+       set_src(&plane_state, 0, 0, 0x3ffff, 0x3ffff);
+       set_crtc(&plane_state, 1022, 766, 4, 4);
+       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
+                                                 0xffff,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 true, false);
+       KUNIT_EXPECT_FALSE_MSG(test, ret, 0, "Should succeed by clipping to exact multiple");
+       KUNIT_EXPECT_TRUE(test, plane_state.visible);
+       /* Should not be rounded to 0x20001, which would be upscaling. */
+       KUNIT_EXPECT_TRUE(test, check_src_eq(&plane_state, 0, 0, 2 << 16, 2 << 16));
+       KUNIT_EXPECT_TRUE(test, check_crtc_eq(&plane_state, 1022, 766, 2, 2));
+
+       set_src(&plane_state, 0x1ffff, 0x1ffff, 0x403ffff, 0x303ffff);
+       set_crtc(&plane_state, -2, -2, 1028, 772);
+       ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state,
+                                                 0xffff,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 false, false);
+       KUNIT_EXPECT_FALSE_MSG(test, ret, 0, "Should succeed by clipping to exact multiple");
+       KUNIT_EXPECT_TRUE(test, plane_state.visible);
+       KUNIT_EXPECT_TRUE(test, check_src_eq(&plane_state, 0x3fffe, 0x3fffe,
+                                            1024 << 16, 768 << 16));
+       KUNIT_EXPECT_TRUE(test, check_crtc_eq(&plane_state, 0, 0, 1024, 768));
+}
+
+static struct kunit_case drm_plane_helper_test[] = {
+       KUNIT_CASE(igt_check_plane_state),
+       {}
+};
+
+static struct kunit_suite drm_plane_helper_test_suite = {
+       .name = "drm_plane_helper",
+       .test_cases = drm_plane_helper_test,
+};
+
+kunit_test_suite(drm_plane_helper_test_suite);
+
+MODULE_LICENSE("GPL");