From: "Maíra Canal" <maira.canal@usp.br>
To: "Isabella Basso" <isabbasso@riseup.net>,
magalilemes00@gmail.com, tales.aparecida@gmail.com,
mwen@igalia.com, andrealmeid@riseup.net,
siqueirajordao@riseup.net, "Trevor Woerner" <twoerner@gmail.com>,
leandro.ribeiro@collabora.com, n@nfraprado.net,
"Daniel Vetter" <daniel@ffwll.ch>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"David Airlie" <airlied@linux.ie>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
michal.winiarski@intel.com,
"Javier Martinez Canillas" <javierm@redhat.com>,
"José Expósito" <jose.exposito89@gmail.com>,
"David Gow" <davidgow@google.com>,
"Daniel Latypov" <dlatypov@google.com>,
brendanhiggins@google.com
Cc: "Carlos Veras" <carlos.craveiro@usp.br>,
"Maíra Canal" <maira.canal@usp.br>,
linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
"Matheus Vieira" <matheus.vieira.g@usp.br>,
linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com
Subject: [PATCH v5 3/9] drm: selftest: convert drm_rect selftest to KUnit
Date: Fri, 8 Jul 2022 17:30:46 -0300 [thread overview]
Message-ID: <20220708203052.236290-4-maira.canal@usp.br> (raw)
In-Reply-To: <20220708203052.236290-1-maira.canal@usp.br>
Considering the current adoption of the KUnit framework, convert the
DRM rect selftest to the KUnit API.
Co-developed-by: Carlos Veras <carlos.craveiro@usp.br>
Signed-off-by: Carlos Veras <carlos.craveiro@usp.br>
Co-developed-by: Matheus Vieira <matheus.vieira.g@usp.br>
Signed-off-by: Matheus Vieira <matheus.vieira.g@usp.br>
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>
---
drivers/gpu/drm/selftests/Makefile | 2 +-
.../gpu/drm/selftests/drm_modeset_selftests.h | 4 -
.../drm/selftests/test-drm_modeset_common.h | 4 -
drivers/gpu/drm/selftests/test-drm_rect.c | 223 ------------------
drivers/gpu/drm/tests/Makefile | 2 +-
drivers/gpu/drm/tests/drm_rect_test.c | 214 +++++++++++++++++
6 files changed, 216 insertions(+), 233 deletions(-)
delete mode 100644 drivers/gpu/drm/selftests/test-drm_rect.c
create mode 100644 drivers/gpu/drm/tests/drm_rect_test.c
diff --git a/drivers/gpu/drm/selftests/Makefile b/drivers/gpu/drm/selftests/Makefile
index 8633bb9ea717..8a794914e328 100644
--- a/drivers/gpu/drm/selftests/Makefile
+++ b/drivers/gpu/drm/selftests/Makefile
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-only
test-drm_modeset-y := test-drm_modeset_common.o test-drm_plane_helper.o \
test-drm_format.o test-drm_framebuffer.o \
- test-drm_dp_mst_helper.o test-drm_rect.o
+ test-drm_dp_mst_helper.o
obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o \
test-drm_buddy.o
diff --git a/drivers/gpu/drm/selftests/drm_modeset_selftests.h b/drivers/gpu/drm/selftests/drm_modeset_selftests.h
index 4787b3b70709..a3ca90307364 100644
--- a/drivers/gpu/drm/selftests/drm_modeset_selftests.h
+++ b/drivers/gpu/drm/selftests/drm_modeset_selftests.h
@@ -6,10 +6,6 @@
*
* Tests are executed in order by igt/drm_selftests_helper
*/
-selftest(drm_rect_clip_scaled_div_by_zero, igt_drm_rect_clip_scaled_div_by_zero)
-selftest(drm_rect_clip_scaled_not_clipped, igt_drm_rect_clip_scaled_not_clipped)
-selftest(drm_rect_clip_scaled_clipped, igt_drm_rect_clip_scaled_clipped)
-selftest(drm_rect_clip_scaled_signed_vs_unsigned, igt_drm_rect_clip_scaled_signed_vs_unsigned)
selftest(check_plane_state, igt_check_plane_state)
selftest(check_drm_format_block_width, igt_check_drm_format_block_width)
selftest(check_drm_format_block_height, igt_check_drm_format_block_height)
diff --git a/drivers/gpu/drm/selftests/test-drm_modeset_common.h b/drivers/gpu/drm/selftests/test-drm_modeset_common.h
index c29354e59cec..42a10d7da51c 100644
--- a/drivers/gpu/drm/selftests/test-drm_modeset_common.h
+++ b/drivers/gpu/drm/selftests/test-drm_modeset_common.h
@@ -16,10 +16,6 @@
#define FAIL_ON(x) FAIL((x), "%s", "FAIL_ON(" __stringify(x) ")\n")
-int igt_drm_rect_clip_scaled_div_by_zero(void *ignored);
-int igt_drm_rect_clip_scaled_not_clipped(void *ignored);
-int igt_drm_rect_clip_scaled_clipped(void *ignored);
-int igt_drm_rect_clip_scaled_signed_vs_unsigned(void *ignored);
int igt_check_plane_state(void *ignored);
int igt_check_drm_format_block_width(void *ignored);
int igt_check_drm_format_block_height(void *ignored);
diff --git a/drivers/gpu/drm/selftests/test-drm_rect.c b/drivers/gpu/drm/selftests/test-drm_rect.c
deleted file mode 100644
index 3a5ff38321f4..000000000000
--- a/drivers/gpu/drm/selftests/test-drm_rect.c
+++ /dev/null
@@ -1,223 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * Test cases for the drm_rect functions
- */
-
-#define pr_fmt(fmt) "drm_rect: " fmt
-
-#include <linux/limits.h>
-
-#include <drm/drm_rect.h>
-
-#include "test-drm_modeset_common.h"
-
-int igt_drm_rect_clip_scaled_div_by_zero(void *ignored)
-{
- struct drm_rect src, dst, clip;
- bool visible;
-
- /*
- * Make sure we don't divide by zero when dst
- * width/height is zero and dst and clip do not intersect.
- */
- drm_rect_init(&src, 0, 0, 0, 0);
- drm_rect_init(&dst, 0, 0, 0, 0);
- drm_rect_init(&clip, 1, 1, 1, 1);
- visible = drm_rect_clip_scaled(&src, &dst, &clip);
- FAIL(visible, "Destination not be visible\n");
- FAIL(drm_rect_visible(&src), "Source should not be visible\n");
-
- drm_rect_init(&src, 0, 0, 0, 0);
- drm_rect_init(&dst, 3, 3, 0, 0);
- drm_rect_init(&clip, 1, 1, 1, 1);
- visible = drm_rect_clip_scaled(&src, &dst, &clip);
- FAIL(visible, "Destination not be visible\n");
- FAIL(drm_rect_visible(&src), "Source should not be visible\n");
-
- return 0;
-}
-
-int igt_drm_rect_clip_scaled_not_clipped(void *ignored)
-{
- struct drm_rect src, dst, clip;
- bool visible;
-
- /* 1:1 scaling */
- drm_rect_init(&src, 0, 0, 1 << 16, 1 << 16);
- drm_rect_init(&dst, 0, 0, 1, 1);
- drm_rect_init(&clip, 0, 0, 1, 1);
-
- visible = drm_rect_clip_scaled(&src, &dst, &clip);
-
- FAIL(src.x1 != 0 || src.x2 != 1 << 16 ||
- src.y1 != 0 || src.y2 != 1 << 16,
- "Source badly clipped\n");
- FAIL(dst.x1 != 0 || dst.x2 != 1 ||
- dst.y1 != 0 || dst.y2 != 1,
- "Destination badly clipped\n");
- FAIL(!visible, "Destination should be visible\n");
- FAIL(!drm_rect_visible(&src), "Source should be visible\n");
-
- /* 2:1 scaling */
- drm_rect_init(&src, 0, 0, 2 << 16, 2 << 16);
- drm_rect_init(&dst, 0, 0, 1, 1);
- drm_rect_init(&clip, 0, 0, 1, 1);
-
- visible = drm_rect_clip_scaled(&src, &dst, &clip);
-
- FAIL(src.x1 != 0 || src.x2 != 2 << 16 ||
- src.y1 != 0 || src.y2 != 2 << 16,
- "Source badly clipped\n");
- FAIL(dst.x1 != 0 || dst.x2 != 1 ||
- dst.y1 != 0 || dst.y2 != 1,
- "Destination badly clipped\n");
- FAIL(!visible, "Destination should be visible\n");
- FAIL(!drm_rect_visible(&src), "Source should be visible\n");
-
- /* 1:2 scaling */
- drm_rect_init(&src, 0, 0, 1 << 16, 1 << 16);
- drm_rect_init(&dst, 0, 0, 2, 2);
- drm_rect_init(&clip, 0, 0, 2, 2);
-
- visible = drm_rect_clip_scaled(&src, &dst, &clip);
-
- FAIL(src.x1 != 0 || src.x2 != 1 << 16 ||
- src.y1 != 0 || src.y2 != 1 << 16,
- "Source badly clipped\n");
- FAIL(dst.x1 != 0 || dst.x2 != 2 ||
- dst.y1 != 0 || dst.y2 != 2,
- "Destination badly clipped\n");
- FAIL(!visible, "Destination should be visible\n");
- FAIL(!drm_rect_visible(&src), "Source should be visible\n");
-
- return 0;
-}
-
-int igt_drm_rect_clip_scaled_clipped(void *ignored)
-{
- struct drm_rect src, dst, clip;
- bool visible;
-
- /* 1:1 scaling top/left clip */
- drm_rect_init(&src, 0, 0, 2 << 16, 2 << 16);
- drm_rect_init(&dst, 0, 0, 2, 2);
- drm_rect_init(&clip, 0, 0, 1, 1);
-
- visible = drm_rect_clip_scaled(&src, &dst, &clip);
-
- FAIL(src.x1 != 0 || src.x2 != 1 << 16 ||
- src.y1 != 0 || src.y2 != 1 << 16,
- "Source badly clipped\n");
- FAIL(dst.x1 != 0 || dst.x2 != 1 ||
- dst.y1 != 0 || dst.y2 != 1,
- "Destination badly clipped\n");
- FAIL(!visible, "Destination should be visible\n");
- FAIL(!drm_rect_visible(&src), "Source should be visible\n");
-
- /* 1:1 scaling bottom/right clip */
- drm_rect_init(&src, 0, 0, 2 << 16, 2 << 16);
- drm_rect_init(&dst, 0, 0, 2, 2);
- drm_rect_init(&clip, 1, 1, 1, 1);
-
- visible = drm_rect_clip_scaled(&src, &dst, &clip);
-
- FAIL(src.x1 != 1 << 16 || src.x2 != 2 << 16 ||
- src.y1 != 1 << 16 || src.y2 != 2 << 16,
- "Source badly clipped\n");
- FAIL(dst.x1 != 1 || dst.x2 != 2 ||
- dst.y1 != 1 || dst.y2 != 2,
- "Destination badly clipped\n");
- FAIL(!visible, "Destination should be visible\n");
- FAIL(!drm_rect_visible(&src), "Source should be visible\n");
-
- /* 2:1 scaling top/left clip */
- drm_rect_init(&src, 0, 0, 4 << 16, 4 << 16);
- drm_rect_init(&dst, 0, 0, 2, 2);
- drm_rect_init(&clip, 0, 0, 1, 1);
-
- visible = drm_rect_clip_scaled(&src, &dst, &clip);
-
- FAIL(src.x1 != 0 || src.x2 != 2 << 16 ||
- src.y1 != 0 || src.y2 != 2 << 16,
- "Source badly clipped\n");
- FAIL(dst.x1 != 0 || dst.x2 != 1 ||
- dst.y1 != 0 || dst.y2 != 1,
- "Destination badly clipped\n");
- FAIL(!visible, "Destination should be visible\n");
- FAIL(!drm_rect_visible(&src), "Source should be visible\n");
-
- /* 2:1 scaling bottom/right clip */
- drm_rect_init(&src, 0, 0, 4 << 16, 4 << 16);
- drm_rect_init(&dst, 0, 0, 2, 2);
- drm_rect_init(&clip, 1, 1, 1, 1);
-
- visible = drm_rect_clip_scaled(&src, &dst, &clip);
-
- FAIL(src.x1 != 2 << 16 || src.x2 != 4 << 16 ||
- src.y1 != 2 << 16 || src.y2 != 4 << 16,
- "Source badly clipped\n");
- FAIL(dst.x1 != 1 || dst.x2 != 2 ||
- dst.y1 != 1 || dst.y2 != 2,
- "Destination badly clipped\n");
- FAIL(!visible, "Destination should be visible\n");
- FAIL(!drm_rect_visible(&src), "Source should be visible\n");
-
- /* 1:2 scaling top/left clip */
- drm_rect_init(&src, 0, 0, 2 << 16, 2 << 16);
- drm_rect_init(&dst, 0, 0, 4, 4);
- drm_rect_init(&clip, 0, 0, 2, 2);
-
- visible = drm_rect_clip_scaled(&src, &dst, &clip);
-
- FAIL(src.x1 != 0 || src.x2 != 1 << 16 ||
- src.y1 != 0 || src.y2 != 1 << 16,
- "Source badly clipped\n");
- FAIL(dst.x1 != 0 || dst.x2 != 2 ||
- dst.y1 != 0 || dst.y2 != 2,
- "Destination badly clipped\n");
- FAIL(!visible, "Destination should be visible\n");
- FAIL(!drm_rect_visible(&src), "Source should be visible\n");
-
- /* 1:2 scaling bottom/right clip */
- drm_rect_init(&src, 0, 0, 2 << 16, 2 << 16);
- drm_rect_init(&dst, 0, 0, 4, 4);
- drm_rect_init(&clip, 2, 2, 2, 2);
-
- visible = drm_rect_clip_scaled(&src, &dst, &clip);
-
- FAIL(src.x1 != 1 << 16 || src.x2 != 2 << 16 ||
- src.y1 != 1 << 16 || src.y2 != 2 << 16,
- "Source badly clipped\n");
- FAIL(dst.x1 != 2 || dst.x2 != 4 ||
- dst.y1 != 2 || dst.y2 != 4,
- "Destination badly clipped\n");
- FAIL(!visible, "Destination should be visible\n");
- FAIL(!drm_rect_visible(&src), "Source should be visible\n");
-
- return 0;
-}
-
-int igt_drm_rect_clip_scaled_signed_vs_unsigned(void *ignored)
-{
- struct drm_rect src, dst, clip;
- bool visible;
-
- /*
- * 'clip.x2 - dst.x1 >= dst width' could result a negative
- * src rectangle width which is no longer expected by the
- * code as it's using unsigned types. This could lead to
- * the clipped source rectangle appering visible when it
- * should have been fully clipped. Make sure both rectangles
- * end up invisible.
- */
- drm_rect_init(&src, 0, 0, INT_MAX, INT_MAX);
- drm_rect_init(&dst, 0, 0, 2, 2);
- drm_rect_init(&clip, 3, 3, 1, 1);
-
- visible = drm_rect_clip_scaled(&src, &dst, &clip);
-
- FAIL(visible, "Destination should not be visible\n");
- FAIL(drm_rect_visible(&src), "Source should not be visible\n");
-
- return 0;
-}
diff --git a/drivers/gpu/drm/tests/Makefile b/drivers/gpu/drm/tests/Makefile
index b3e73d674c67..f2eced30a955 100644
--- a/drivers/gpu/drm/tests/Makefile
+++ b/drivers/gpu/drm/tests/Makefile
@@ -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_cmdline_parser_test.o drm_rect_test.o
diff --git a/drivers/gpu/drm/tests/drm_rect_test.c b/drivers/gpu/drm/tests/drm_rect_test.c
new file mode 100644
index 000000000000..c1dbefd49a4c
--- /dev/null
+++ b/drivers/gpu/drm/tests/drm_rect_test.c
@@ -0,0 +1,214 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Test cases for the drm_rect functions
+ *
+ * Copyright (c) 2022 Maíra Canal <mairacanal@riseup.net>
+ */
+
+#include <kunit/test.h>
+
+#include <drm/drm_rect.h>
+
+static void igt_drm_rect_clip_scaled_div_by_zero(struct kunit *test)
+{
+ struct drm_rect src, dst, clip;
+ bool visible;
+
+ /*
+ * Make sure we don't divide by zero when dst
+ * width/height is zero and dst and clip do not intersect.
+ */
+ drm_rect_init(&src, 0, 0, 0, 0);
+ drm_rect_init(&dst, 0, 0, 0, 0);
+ drm_rect_init(&clip, 1, 1, 1, 1);
+ visible = drm_rect_clip_scaled(&src, &dst, &clip);
+
+ KUNIT_EXPECT_FALSE_MSG(test, visible, "Destination not be visible\n");
+ KUNIT_EXPECT_FALSE_MSG(test, drm_rect_visible(&src), "Source should not be visible\n");
+
+ drm_rect_init(&src, 0, 0, 0, 0);
+ drm_rect_init(&dst, 3, 3, 0, 0);
+ drm_rect_init(&clip, 1, 1, 1, 1);
+ visible = drm_rect_clip_scaled(&src, &dst, &clip);
+
+ KUNIT_EXPECT_FALSE_MSG(test, visible, "Destination not be visible\n");
+ KUNIT_EXPECT_FALSE_MSG(test, drm_rect_visible(&src), "Source should not be visible\n");
+}
+
+static void igt_drm_rect_clip_scaled_not_clipped(struct kunit *test)
+{
+ struct drm_rect src, dst, clip;
+ bool visible;
+
+ /* 1:1 scaling */
+ drm_rect_init(&src, 0, 0, 1 << 16, 1 << 16);
+ drm_rect_init(&dst, 0, 0, 1, 1);
+ drm_rect_init(&clip, 0, 0, 1, 1);
+
+ visible = drm_rect_clip_scaled(&src, &dst, &clip);
+
+ KUNIT_EXPECT_FALSE_MSG(test, src.x1 != 0 || src.x2 != 1 << 16 ||
+ src.y1 != 0 || src.y2 != 1 << 16, "Source badly clipped\n");
+ KUNIT_EXPECT_FALSE_MSG(test, dst.x1 != 0 || dst.x2 != 1 ||
+ dst.y1 != 0 || dst.y2 != 1, "Destination badly clipped\n");
+ KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible\n");
+ KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible\n");
+
+ /* 2:1 scaling */
+ drm_rect_init(&src, 0, 0, 2 << 16, 2 << 16);
+ drm_rect_init(&dst, 0, 0, 1, 1);
+ drm_rect_init(&clip, 0, 0, 1, 1);
+
+ visible = drm_rect_clip_scaled(&src, &dst, &clip);
+
+ KUNIT_EXPECT_FALSE_MSG(test, src.x1 != 0 || src.x2 != 2 << 16 ||
+ src.y1 != 0 || src.y2 != 2 << 16, "Source badly clipped\n");
+ KUNIT_EXPECT_FALSE_MSG(test, dst.x1 != 0 || dst.x2 != 1 ||
+ dst.y1 != 0 || dst.y2 != 1, "Destination badly clipped\n");
+ KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible\n");
+ KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible\n");
+
+ /* 1:2 scaling */
+ drm_rect_init(&src, 0, 0, 1 << 16, 1 << 16);
+ drm_rect_init(&dst, 0, 0, 2, 2);
+ drm_rect_init(&clip, 0, 0, 2, 2);
+
+ visible = drm_rect_clip_scaled(&src, &dst, &clip);
+
+ KUNIT_EXPECT_FALSE_MSG(test, src.x1 != 0 || src.x2 != 1 << 16 ||
+ src.y1 != 0 || src.y2 != 1 << 16, "Source badly clipped\n");
+ KUNIT_EXPECT_FALSE_MSG(test, dst.x1 != 0 || dst.x2 != 2 ||
+ dst.y1 != 0 || dst.y2 != 2, "Destination badly clipped\n");
+ KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible\n");
+ KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible\n");
+}
+
+static void igt_drm_rect_clip_scaled_clipped(struct kunit *test)
+{
+ struct drm_rect src, dst, clip;
+ bool visible;
+
+ /* 1:1 scaling top/left clip */
+ drm_rect_init(&src, 0, 0, 2 << 16, 2 << 16);
+ drm_rect_init(&dst, 0, 0, 2, 2);
+ drm_rect_init(&clip, 0, 0, 1, 1);
+
+ visible = drm_rect_clip_scaled(&src, &dst, &clip);
+
+ KUNIT_EXPECT_FALSE_MSG(test, src.x1 != 0 || src.x2 != 1 << 16 ||
+ src.y1 != 0 || src.y2 != 1 << 16, "Source badly clipped\n");
+ KUNIT_EXPECT_FALSE_MSG(test, dst.x1 != 0 || dst.x2 != 1 ||
+ dst.y1 != 0 || dst.y2 != 1, "Destination badly clipped\n");
+ KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible\n");
+ KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible\n");
+
+ /* 1:1 scaling bottom/right clip */
+ drm_rect_init(&src, 0, 0, 2 << 16, 2 << 16);
+ drm_rect_init(&dst, 0, 0, 2, 2);
+ drm_rect_init(&clip, 1, 1, 1, 1);
+
+ visible = drm_rect_clip_scaled(&src, &dst, &clip);
+
+ KUNIT_EXPECT_FALSE_MSG(test, src.x1 != 1 << 16 || src.x2 != 2 << 16 ||
+ src.y1 != 1 << 16 || src.y2 != 2 << 16, "Source badly clipped\n");
+ KUNIT_EXPECT_FALSE_MSG(test, dst.x1 != 1 || dst.x2 != 2 || dst.y1 != 1 ||
+ dst.y2 != 2, "Destination badly clipped\n");
+ KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible\n");
+ KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible\n");
+
+ /* 2:1 scaling top/left clip */
+ drm_rect_init(&src, 0, 0, 4 << 16, 4 << 16);
+ drm_rect_init(&dst, 0, 0, 2, 2);
+ drm_rect_init(&clip, 0, 0, 1, 1);
+
+ visible = drm_rect_clip_scaled(&src, &dst, &clip);
+
+ KUNIT_EXPECT_FALSE_MSG(test, src.x1 != 0 || src.x2 != 2 << 16 ||
+ src.y1 != 0 || src.y2 != 2 << 16, "Source badly clipped\n");
+ KUNIT_EXPECT_FALSE_MSG(test, dst.x1 != 0 || dst.x2 != 1 || dst.y1 != 0 ||
+ dst.y2 != 1, "Destination badly clipped\n");
+ KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible\n");
+ KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible\n");
+
+ /* 2:1 scaling bottom/right clip */
+ drm_rect_init(&src, 0, 0, 4 << 16, 4 << 16);
+ drm_rect_init(&dst, 0, 0, 2, 2);
+ drm_rect_init(&clip, 1, 1, 1, 1);
+
+ visible = drm_rect_clip_scaled(&src, &dst, &clip);
+
+ KUNIT_EXPECT_FALSE_MSG(test, src.x1 != 2 << 16 || src.x2 != 4 << 16 ||
+ src.y1 != 2 << 16 || src.y2 != 4 << 16, "Source badly clipped\n");
+ KUNIT_EXPECT_FALSE_MSG(test, dst.x1 != 1 || dst.x2 != 2 || dst.y1 != 1 ||
+ dst.y2 != 2, "Destination badly clipped\n");
+ KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible\n");
+ KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible\n");
+
+ /* 1:2 scaling top/left clip */
+ drm_rect_init(&src, 0, 0, 2 << 16, 2 << 16);
+ drm_rect_init(&dst, 0, 0, 4, 4);
+ drm_rect_init(&clip, 0, 0, 2, 2);
+
+ visible = drm_rect_clip_scaled(&src, &dst, &clip);
+
+ KUNIT_EXPECT_FALSE_MSG(test, src.x1 != 0 || src.x2 != 1 << 16 ||
+ src.y1 != 0 || src.y2 != 1 << 16, "Source badly clipped\n");
+ KUNIT_EXPECT_FALSE_MSG(test, dst.x1 != 0 || dst.x2 != 2 || dst.y1 != 0 ||
+ dst.y2 != 2, "Destination badly clipped\n");
+ KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible\n");
+ KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible\n");
+
+ /* 1:2 scaling bottom/right clip */
+ drm_rect_init(&src, 0, 0, 2 << 16, 2 << 16);
+ drm_rect_init(&dst, 0, 0, 4, 4);
+ drm_rect_init(&clip, 2, 2, 2, 2);
+
+ visible = drm_rect_clip_scaled(&src, &dst, &clip);
+
+ KUNIT_EXPECT_FALSE_MSG(test, src.x1 != 1 << 16 || src.x2 != 2 << 16 ||
+ src.y1 != 1 << 16 || src.y2 != 2 << 16, "Source badly clipped\n");
+ KUNIT_EXPECT_FALSE_MSG(test, dst.x1 != 2 || dst.x2 != 4 || dst.y1 != 2 ||
+ dst.y2 != 4, "Destination badly clipped\n");
+ KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible\n");
+ KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible\n");
+}
+
+static void igt_drm_rect_clip_scaled_signed_vs_unsigned(struct kunit *test)
+{
+ struct drm_rect src, dst, clip;
+ bool visible;
+
+ /*
+ * 'clip.x2 - dst.x1 >= dst width' could result a negative
+ * src rectangle width which is no longer expected by the
+ * code as it's using unsigned types. This could lead to
+ * the clipped source rectangle appering visible when it
+ * should have been fully clipped. Make sure both rectangles
+ * end up invisible.
+ */
+ drm_rect_init(&src, 0, 0, INT_MAX, INT_MAX);
+ drm_rect_init(&dst, 0, 0, 2, 2);
+ drm_rect_init(&clip, 3, 3, 1, 1);
+
+ visible = drm_rect_clip_scaled(&src, &dst, &clip);
+
+ KUNIT_EXPECT_FALSE_MSG(test, visible, "Destination should not be visible\n");
+ KUNIT_EXPECT_FALSE_MSG(test, drm_rect_visible(&src), "Source should not be visible\n");
+}
+
+static struct kunit_case drm_rect_tests[] = {
+ KUNIT_CASE(igt_drm_rect_clip_scaled_div_by_zero),
+ KUNIT_CASE(igt_drm_rect_clip_scaled_not_clipped),
+ KUNIT_CASE(igt_drm_rect_clip_scaled_clipped),
+ KUNIT_CASE(igt_drm_rect_clip_scaled_signed_vs_unsigned),
+ { }
+};
+
+static struct kunit_suite drm_rect_test_suite = {
+ .name = "drm_rect",
+ .test_cases = drm_rect_tests,
+};
+
+kunit_test_suite(drm_rect_test_suite);
+
+MODULE_LICENSE("GPL");
--
2.35.3
next prev parent reply other threads:[~2022-07-08 20:31 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-08 20:30 [PATCH v5 0/9] drm: selftest: Convert to KUnit Maíra Canal
2022-07-08 20:30 ` [PATCH v5 1/9] drm: selftest: convert drm_damage_helper selftest " Maíra Canal
2022-07-08 20:30 ` [PATCH v5 2/9] drm: selftest: convert drm_cmdline_parser " Maíra Canal
2022-07-08 20:30 ` Maíra Canal [this message]
2022-07-08 20:30 ` [PATCH v5 4/9] drm: selftest: convert drm_format " Maíra Canal
2022-07-14 23:51 ` Guenter Roeck
2022-07-15 0:03 ` Daniel Latypov
2022-07-15 6:59 ` Javier Martinez Canillas
2022-07-15 11:43 ` Maíra Canal
2022-07-17 17:48 ` Maíra Canal
2022-07-15 0:04 ` Guenter Roeck
2022-07-08 20:30 ` [PATCH v5 5/9] drm: selftest: convert drm_plane_helper " Maíra Canal
2022-07-08 20:30 ` [PATCH v5 6/9] drm: selftest: convert drm_dp_mst_helper " Maíra Canal
2022-07-08 20:30 ` [PATCH v5 7/9] drm: selftest: convert drm_framebuffer " Maíra Canal
2022-07-08 20:30 ` [PATCH v5 8/9] drm: selftest: convert drm_buddy " Maíra Canal
2022-07-08 20:30 ` [PATCH v5 9/9] drm: selftest: convert drm_mm " Maíra Canal
2022-07-22 10:35 ` Matthew Auld
2022-07-22 11:04 ` Maíra Canal
2022-07-22 16:25 ` Michał Winiarski
2022-08-21 22:22 ` Isabella Basso
2022-08-24 0:46 ` Michał Winiarski
2023-04-27 13:14 ` Maxime Ripard
2023-07-25 8:38 ` Maxime Ripard
2023-07-25 9:54 ` David Gow
2023-07-31 12:18 ` Maxime Ripard
2022-07-11 16:56 ` [PATCH v5 0/9] drm: selftest: Convert " Javier Martinez Canillas
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=20220708203052.236290-4-maira.canal@usp.br \
--to=maira.canal@usp.br \
--cc=airlied@linux.ie \
--cc=andrealmeid@riseup.net \
--cc=brendanhiggins@google.com \
--cc=carlos.craveiro@usp.br \
--cc=daniel@ffwll.ch \
--cc=davidgow@google.com \
--cc=dlatypov@google.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=isabbasso@riseup.net \
--cc=javierm@redhat.com \
--cc=jose.exposito89@gmail.com \
--cc=kunit-dev@googlegroups.com \
--cc=leandro.ribeiro@collabora.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=magalilemes00@gmail.com \
--cc=matheus.vieira.g@usp.br \
--cc=michal.winiarski@intel.com \
--cc=mripard@kernel.org \
--cc=mwen@igalia.com \
--cc=n@nfraprado.net \
--cc=siqueirajordao@riseup.net \
--cc=skhan@linuxfoundation.org \
--cc=tales.aparecida@gmail.com \
--cc=twoerner@gmail.com \
--cc=tzimmermann@suse.de \
/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;
as well as URLs for NNTP newsgroup(s).