Re: [PATCH v2 2/5] drm/tests: Test drm_rect_calc_hscale()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Arthur,

On 3/27/23 10:38, Arthur Grillo wrote:
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@xxxxxxxxxx>
---
  drivers/gpu/drm/tests/drm_rect_test.c | 57 +++++++++++++++++++++++++++
  1 file changed, 57 insertions(+)

diff --git a/drivers/gpu/drm/tests/drm_rect_test.c b/drivers/gpu/drm/tests/drm_rect_test.c
index 3654c0be3d6b..c282e1cf9c30 100644
--- a/drivers/gpu/drm/tests/drm_rect_test.c
+++ b/drivers/gpu/drm/tests/drm_rect_test.c
@@ -10,6 +10,7 @@
  #include <drm/drm_rect.h>
#include <linux/string_helpers.h>
+#include <linux/errno.h>
static void drm_rect_compare(struct kunit *test, const struct drm_rect *r,
  			     const struct drm_rect *expected)
@@ -334,12 +335,68 @@ static void drm_test_rect_intersect(struct kunit *test)
  	drm_rect_compare(test, &r1_aux, &params->expected_intersection);
  }
+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 << 16, 0);
+	drm_rect_init(&dst, 0, 0, 1 << 16, 0);

What about the case that dst_w == 0?

Best Regards,
- Maíra Canal

+
+	scaling_factor =  drm_rect_calc_hscale(&src, &dst, 0, 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 << 16, 0);
+	drm_rect_init(&dst, 0, 0, 1 << 16, 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 << 16, 0);
+	drm_rect_init(&dst, 0, 0, 1 << 16, 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 << 16, 0);
+	drm_rect_init(&dst, 0, 0, 1 << 16, 0);
+
+	scaling_factor = drm_rect_calc_hscale(&src, &dst, 0, INT_MAX);
+
+	KUNIT_EXPECT_EQ(test, scaling_factor, -EINVAL);
+
+	drm_rect_init(&src, 0, 0, 1 << 16, 0);
+	drm_rect_init(&dst, 0, 0, -1 << 16, 0);
+
+	scaling_factor = drm_rect_calc_hscale(&src, &dst, 0, 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_PARAM(drm_test_rect_intersect, drm_rect_intersect_gen_params),
+	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),
  	{ }
  };



[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux