[PATCH 2/5] drm/tests: Test drm_rect_calc_hscale()
Arthur Grillo
arthurgrillo at riseup.net
Wed Mar 22 14:06:58 UTC 2023
Insert test for the drm_rect_hscale() function, besides the test
for the usual case it also test for the exceptions.
Signed-off-by: Arthur Grillo <arthurgrillo at riseup.net>
---
drivers/gpu/drm/tests/drm_rect_test.c | 58 +++++++++++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/drivers/gpu/drm/tests/drm_rect_test.c b/drivers/gpu/drm/tests/drm_rect_test.c
index f700984f70a8..7e02393092fa 100644
--- a/drivers/gpu/drm/tests/drm_rect_test.c
+++ b/drivers/gpu/drm/tests/drm_rect_test.c
@@ -9,6 +9,8 @@
#include <drm/drm_rect.h>
+#include <linux/errno.h>
+
static void drm_rect_compare(struct kunit *test, const struct drm_rect *r,
const struct drm_rect *expected)
{
@@ -225,12 +227,68 @@ static void drm_test_rect_intersect(struct kunit *test)
KUNIT_EXPECT_FALSE_MSG(test, visible, "Interserction should not be a visible rect");
}
+static void drm_test_rect_calc_hscale(struct kunit *test)
+{
+ struct drm_rect src, dst;
+ int scaling_factor;
+
+ drm_rect_init(&src, 0, 0, 2, 0);
+ drm_rect_init(&dst, 0, 0, 1, 0);
+
+ scaling_factor = drm_rect_calc_hscale(&src, &dst, INT_MIN, INT_MAX);
+
+ KUNIT_EXPECT_EQ(test, scaling_factor, 2);
+}
+
+static void drm_test_rect_calc_hscale_out_of_range(struct kunit *test)
+{
+ struct drm_rect src, dst;
+ int scaling_factor;
+
+ drm_rect_init(&src, 0, 0, 10, 0);
+ drm_rect_init(&dst, 0, 0, 1, 0);
+
+ scaling_factor = drm_rect_calc_hscale(&src, &dst, 3, 5);
+
+ KUNIT_EXPECT_EQ(test, scaling_factor, -ERANGE);
+
+ drm_rect_init(&src, 0, 0, 2, 0);
+ drm_rect_init(&dst, 0, 0, 1, 0);
+
+ scaling_factor = drm_rect_calc_hscale(&src, &dst, 3, 5);
+
+ KUNIT_EXPECT_EQ(test, scaling_factor, -ERANGE);
+}
+
+static void drm_test_rect_calc_hscale_negative_args(struct kunit *test)
+{
+ struct drm_rect src, dst;
+ int scaling_factor;
+
+ drm_rect_init(&src, 0, 0, -1, 0);
+ drm_rect_init(&dst, 0, 0, 1, 0);
+
+ scaling_factor = drm_rect_calc_hscale(&src, &dst, INT_MIN, INT_MAX);
+
+ KUNIT_EXPECT_EQ(test, scaling_factor, -EINVAL);
+
+ drm_rect_init(&src, 0, 0, 1, 0);
+ drm_rect_init(&dst, 0, 0, -1, 0);
+
+ scaling_factor = drm_rect_calc_hscale(&src, &dst, INT_MIN, INT_MAX);
+
+ KUNIT_EXPECT_EQ(test, scaling_factor, -EINVAL);
+}
+
static struct kunit_case drm_rect_tests[] = {
KUNIT_CASE(drm_test_rect_clip_scaled_div_by_zero),
KUNIT_CASE(drm_test_rect_clip_scaled_not_clipped),
KUNIT_CASE(drm_test_rect_clip_scaled_clipped),
KUNIT_CASE(drm_test_rect_clip_scaled_signed_vs_unsigned),
KUNIT_CASE(drm_test_rect_intersect),
+ KUNIT_CASE(drm_test_rect_calc_hscale),
+ KUNIT_CASE(drm_test_rect_calc_hscale_out_of_range),
+ KUNIT_CASE(drm_test_rect_calc_hscale_negative_args),
{ }
};
--
2.39.2
More information about the dri-devel
mailing list