#include <drm/drm_atomic_helper.h>
 #include <drm/drm_framebuffer.h>
 #include <drm/drm_modes.h>
+#include <drm/drm_rect.h>
 
 static void set_src(struct drm_plane_state *plane_state,
                    unsigned int src_x, unsigned int src_y,
        plane_state->src_h = src_h;
 }
 
-static bool check_src_eq(struct drm_plane_state *plane_state,
+static bool check_src_eq(struct kunit *test, struct drm_plane_state *plane_state,
                         unsigned int src_x, unsigned int src_y,
                         unsigned int src_w, unsigned int src_h)
 {
+       struct drm_rect expected = DRM_RECT_INIT(src_x, src_y, src_w, 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);
+               kunit_err(test,
+                         "src x coordinate %x should never be below 0, src: " DRM_RECT_FP_FMT,
+                         plane_state->src.x1, DRM_RECT_FP_ARG(&plane_state->src));
                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);
+               kunit_err(test,
+                         "src y coordinate %x should never be below 0, src: " DRM_RECT_FP_FMT,
+                         plane_state->src.y1, DRM_RECT_FP_ARG(&plane_state->src));
                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);
+       if (plane_state->src.x1 != expected.x1 ||
+           plane_state->src.y1 != expected.y1 ||
+           drm_rect_width(&plane_state->src) != drm_rect_width(&expected) ||
+           drm_rect_height(&plane_state->src) != drm_rect_height(&expected)) {
+               kunit_err(test, "src: " DRM_RECT_FP_FMT ", expected: " DRM_RECT_FP_FMT,
+                         DRM_RECT_FP_ARG(&plane_state->src), DRM_RECT_FP_ARG(&expected));
+
                return false;
        }
 
        plane_state->crtc_h = crtc_h;
 }
 
-static bool check_crtc_eq(struct drm_plane_state *plane_state,
+static bool check_crtc_eq(struct kunit *test, 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);
+       struct drm_rect expected = DRM_RECT_INIT(crtc_x, crtc_y, crtc_w, crtc_h);
+
+       if (plane_state->dst.x1 != expected.x1 ||
+           plane_state->dst.y1 != expected.y1 ||
+           drm_rect_width(&plane_state->dst) != drm_rect_width(&expected) ||
+           drm_rect_height(&plane_state->dst) != drm_rect_height(&expected)) {
+               kunit_err(test, "dst: " DRM_RECT_FMT ", expected: " DRM_RECT_FMT,
+                         DRM_RECT_ARG(&plane_state->dst), DRM_RECT_ARG(&expected));
 
                return false;
        }
                                                  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));
+       KUNIT_EXPECT_TRUE(test, check_src_eq(test, &plane_state, 0, 0, 1024 << 16, 768 << 16));
+       KUNIT_EXPECT_TRUE(test, check_crtc_eq(test, &plane_state, 0, 0, 1024, 768));
 
        /* Rotated clipping + reflection, no scaling. */
        plane_state.rotation = DRM_MODE_ROTATE_90 | DRM_MODE_REFLECT_X;
                                                  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));
+       KUNIT_EXPECT_TRUE(test, check_src_eq(test, &plane_state, 0, 0, 768 << 16, 1024 << 16));
+       KUNIT_EXPECT_TRUE(test, check_crtc_eq(test, &plane_state, 0, 0, 1024, 768));
        plane_state.rotation = DRM_MODE_ROTATE_0;
 
        /* Check whether positioning works correctly. */
                                                  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));
+       KUNIT_EXPECT_TRUE(test, check_src_eq(test, &plane_state, 0, 0, 1023 << 16, 767 << 16));
+       KUNIT_EXPECT_TRUE(test, check_crtc_eq(test, &plane_state, 0, 0, 1023, 767));
 
        /* Simple scaling tests. */
        set_src(&plane_state, 0, 0, 512 << 16, 384 << 16);
                                                  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));
+       KUNIT_EXPECT_TRUE(test, check_src_eq(test, &plane_state, 0, 0, 512 << 16, 384 << 16));
+       KUNIT_EXPECT_TRUE(test, check_crtc_eq(test, &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,
                                                  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));
+       KUNIT_EXPECT_TRUE(test, check_src_eq(test, &plane_state, 0, 0, 2048 << 16, 1536 << 16));
+       KUNIT_EXPECT_TRUE(test, check_crtc_eq(test, &plane_state, 0, 0, 1024, 768));
 
        /* Testing rounding errors. */
        set_src(&plane_state, 0, 0, 0x40001, 0x40001);
                                                  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));
+       KUNIT_EXPECT_TRUE(test, check_src_eq(test, &plane_state, 0, 0, 2 << 16, 2 << 16));
+       KUNIT_EXPECT_TRUE(test, check_crtc_eq(test, &plane_state, 1022, 766, 2, 2));
 
        set_src(&plane_state, 0x20001, 0x20001, 0x4040001, 0x3040001);
        set_crtc(&plane_state, -2, -2, 1028, 772);
                                                  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,
+       KUNIT_EXPECT_TRUE(test, check_src_eq(test, &plane_state, 0x40002, 0x40002,
                                             1024 << 16, 768 << 16));
-       KUNIT_EXPECT_TRUE(test, check_crtc_eq(&plane_state, 0, 0, 1024, 768));
+       KUNIT_EXPECT_TRUE(test, check_crtc_eq(test, &plane_state, 0, 0, 1024, 768));
 
        set_src(&plane_state, 0, 0, 0x3ffff, 0x3ffff);
        set_crtc(&plane_state, 1022, 766, 4, 4);
        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));
+       KUNIT_EXPECT_TRUE(test, check_src_eq(test, &plane_state, 0, 0, 2 << 16, 2 << 16));
+       KUNIT_EXPECT_TRUE(test, check_crtc_eq(test, &plane_state, 1022, 766, 2, 2));
 
        set_src(&plane_state, 0x1ffff, 0x1ffff, 0x403ffff, 0x303ffff);
        set_crtc(&plane_state, -2, -2, 1028, 772);
                                                  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,
+       KUNIT_EXPECT_TRUE(test, check_src_eq(test, &plane_state, 0x3fffe, 0x3fffe,
                                             1024 << 16, 768 << 16));
-       KUNIT_EXPECT_TRUE(test, check_crtc_eq(&plane_state, 0, 0, 1024, 768));
+       KUNIT_EXPECT_TRUE(test, check_crtc_eq(test, &plane_state, 0, 0, 1024, 768));
 }
 
 static struct kunit_case drm_plane_helper_test[] = {