diff mbox series

[3/5] drm/tests: Test drm_rect_calc_vscale()

Message ID 20230322140701.69852-4-arthurgrillo@riseup.net (mailing list archive)
State New, archived
Headers show
Series Create tests for the drm_rect functions | expand

Commit Message

Arthur Grillo March 22, 2023, 2:06 p.m. UTC
Insert test for the drm_rect_vscale() function, besides the test
for the usual case it also test for the exceptions.

Signed-off-by: Arthur Grillo <arthurgrillo@riseup.net>
---
 drivers/gpu/drm/tests/drm_rect_test.c | 56 +++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/tests/drm_rect_test.c b/drivers/gpu/drm/tests/drm_rect_test.c
index 7e02393092fa..0f7736073390 100644
--- a/drivers/gpu/drm/tests/drm_rect_test.c
+++ b/drivers/gpu/drm/tests/drm_rect_test.c
@@ -280,6 +280,59 @@  static void drm_test_rect_calc_hscale_negative_args(struct kunit *test)
 	KUNIT_EXPECT_EQ(test, scaling_factor, -EINVAL);
 }
 
+static void drm_test_rect_calc_vscale(struct kunit *test)
+{
+	struct drm_rect src, dst;
+	int scaling_factor;
+
+	drm_rect_init(&src, 0, 0, 0, 2);
+	drm_rect_init(&dst, 0, 0, 0, 1);
+
+	scaling_factor =  drm_rect_calc_vscale(&src, &dst, INT_MIN, INT_MAX);
+
+	KUNIT_EXPECT_EQ(test, scaling_factor, 2);
+}
+
+static void drm_test_rect_calc_vscale_out_of_range(struct kunit *test)
+{
+	struct drm_rect src, dst;
+	int scaling_factor;
+
+	drm_rect_init(&src, 0, 0, 0, 10);
+	drm_rect_init(&dst, 0, 0, 0, 1);
+
+	scaling_factor =  drm_rect_calc_vscale(&src, &dst, 3, 5);
+
+	KUNIT_EXPECT_EQ(test, scaling_factor, -ERANGE);
+
+	drm_rect_init(&src, 0, 0, 0, 2);
+	drm_rect_init(&dst, 0, 0, 0, 1);
+
+	scaling_factor =  drm_rect_calc_vscale(&src, &dst, 3, 5);
+
+	KUNIT_EXPECT_EQ(test, scaling_factor, -ERANGE);
+}
+
+static void drm_test_rect_calc_vscale_negative_args(struct kunit *test)
+{
+	struct drm_rect src, dst;
+	int scaling_factor;
+
+	drm_rect_init(&src, 0, 0, 0, -1);
+	drm_rect_init(&dst, 0, 0, 0, 1);
+
+	scaling_factor = drm_rect_calc_vscale(&src, &dst, INT_MIN, INT_MAX);
+
+	KUNIT_EXPECT_EQ(test, scaling_factor, -EINVAL);
+
+	drm_rect_init(&src, 0, 0, 0, 1);
+	drm_rect_init(&dst, 0, 0, 0, -1);
+
+	scaling_factor = drm_rect_calc_vscale(&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),
@@ -289,6 +342,9 @@  static struct kunit_case drm_rect_tests[] = {
 	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),
+	KUNIT_CASE(drm_test_rect_calc_vscale),
+	KUNIT_CASE(drm_test_rect_calc_vscale_out_of_range),
+	KUNIT_CASE(drm_test_rect_calc_vscale_negative_args),
 	{ }
 };