Skip to contentSkip to conversation

Create tests for the drm_rect functions

PATCH Superseded Arthur Grillo 2 participants 10 messages Mar 22, 2023

Subsystems (2)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover Create tests for the drm_rect functions

This patchset seeks to add unit tests for the rest of the functions on the drm_rect.c.

The test coverage report generated by the gcov[1] tool states that this set reaches 100% of coverage on the drm_rect.c file. This would be very good for future development on the file.

Thanks for reviewing!

Best regards,
~Arthur Grillo

---

[1]: https://gcc.gnu.org/onlinedocs/gcc/Gcov.html#Gcov

---

Arthur Grillo (5):
drm/tests: Test drm_rect_intersect()
drm/tests: Test drm_rect_calc_hscale()
drm/tests: Test drm_rect_calc_vscale()
drm/tests: Test drm_rect_rotate()
drm/test: Test drm_rect_rotate_inv()

 drivers/gpu/drm/tests/drm_rect_test.c | 231 ++++++++++++++++++++++++++
 1 file changed, 231 insertions(+)
Signature · 1 line
2.39.2
#1 lore raw

PATCH 1/5 drm/tests: Test drm_rect_intersect()

Insert test for the drm_rect_intersect() function, it also create a helper for comparing drm_rects more easily.

---
 drivers/gpu/drm/tests/drm_rect_test.c | 30 +++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
drivers/gpu/drm/tests/drm_rect_test.c +30 -0
index e9809ea32696..f700984f70a8 100644
@@ -9,6 +9,15 @@
 
 #include <drm/drm_rect.h>
 
+static void drm_rect_compare(struct kunit *test, const struct drm_rect *r,
+			     const struct drm_rect *expected)
+{
+	KUNIT_EXPECT_EQ(test, r->x1, expected->x1);
+	KUNIT_EXPECT_EQ(test, r->y1, expected->y1);
+	KUNIT_EXPECT_EQ(test, drm_rect_width(r), drm_rect_width(expected));
+	KUNIT_EXPECT_EQ(test, drm_rect_height(r), drm_rect_height(expected));
+}
+
 static void drm_test_rect_clip_scaled_div_by_zero(struct kunit *test)
 {
 	struct drm_rect src, dst, clip;
@@ -196,11 +205,32 @@ static void drm_test_rect_clip_scaled_signed_vs_unsigned(struct kunit *test)
 	KUNIT_EXPECT_FALSE_MSG(test, drm_rect_visible(&src), "Source should not be visible\n");
 }
 
+static void drm_test_rect_intersect(struct kunit *test)
+{
+	struct drm_rect r1, r2;
+	bool visible;
+
+	drm_rect_init(&r1, 0, 0, 2, 2);
+	drm_rect_init(&r2, 1, 1, 2, 2);
+
+	visible = drm_rect_intersect(&r1, &r2);
+
+	KUNIT_EXPECT_TRUE_MSG(test, visible, "Interserction should be a visible rect");
+	drm_rect_compare(test, &r1, &DRM_RECT_INIT(1, 1, 1, 1));
+
+	drm_rect_init(&r1, 0, 0, 1, 1);
+
+	visible = drm_rect_intersect(&r1, &r2);
+
+	KUNIT_EXPECT_FALSE_MSG(test, visible, "Interserction should not be a visible rect");
+}
+
 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),
 	{ }
 };
 
Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH 1/5] drm/tests: Test drm_rect_intersect()

Quoted 14 lines · Arthur Grillo

Insert test for the drm_rect_intersect() function, it also create a helper for comparing drm_rects more easily.

---
 drivers/gpu/drm/tests/drm_rect_test.c | 30 +++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
drivers/gpu/drm/tests/drm_rect_test.c +0 -0
index e9809ea32696..f700984f70a8 100644
@@ -9,6 +9,15 @@
 

drivers/gpu/drm/tests/drm_rect_test.c line 19

Quoted 10 lines
drivers/gpu/drm/tests/drm_rect_test.c +8 -0
 #include <drm/drm_rect.h>
 
+static void drm_rect_compare(struct kunit *test, const struct drm_rect *r,
+			     const struct drm_rect *expected)
+{
+	KUNIT_EXPECT_EQ(test, r->x1, expected->x1);
+	KUNIT_EXPECT_EQ(test, r->y1, expected->y1);
+	KUNIT_EXPECT_EQ(test, drm_rect_width(r), drm_rect_width(expected));
+	KUNIT_EXPECT_EQ(test, drm_rect_height(r), drm_rect_height(expected));
+}

We already have a drm_rect_equals().

Quoted 13 lines
drivers/gpu/drm/tests/drm_rect_test.c +6 -0
+
 static void drm_test_rect_clip_scaled_div_by_zero(struct kunit *test)
 {
 	struct drm_rect src, dst, clip;
@@ -196,11 +205,32 @@ static void drm_test_rect_clip_scaled_signed_vs_unsigned(struct kunit *test)
 	KUNIT_EXPECT_FALSE_MSG(test, drm_rect_visible(&src), "Source should not be visible\n");
 }
 
+static void drm_test_rect_intersect(struct kunit *test)
+{
+	struct drm_rect r1, r2;
+	bool visible;
+

drivers/gpu/drm/tests/drm_rect_test.c static void drm_test_rect_clip_scaled_signed_vs_unsigned(struct kunit *test) · line 222

Quoted 10 lines
drivers/gpu/drm/tests/drm_rect_test.c +10 -0
+	drm_rect_init(&r1, 0, 0, 2, 2);
+	drm_rect_init(&r2, 1, 1, 2, 2);
+
+	visible = drm_rect_intersect(&r1, &r2);
+
+	KUNIT_EXPECT_TRUE_MSG(test, visible, "Interserction should be a visible rect");
+	drm_rect_compare(test, &r1, &DRM_RECT_INIT(1, 1, 1, 1));
+
+	drm_rect_init(&r1, 0, 0, 1, 1);
+

I would re-init r2 here too to make it easier to see what we're actually testing.

I would probably test a few more variations of the overlap between the rectangles, eg: equal rectangles, one smaller one fully inside the bigger one, overlaps across different edges/corners.

Quoted 16 lines
drivers/gpu/drm/tests/drm_rect_test.c +6 -0
+	visible = drm_rect_intersect(&r1, &r2);
+
+	KUNIT_EXPECT_FALSE_MSG(test, visible, "Interserction should not be a visible rect");
+}
+
 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),
 	{ }
 };
 
Signature · 1 line
2.39.2
Signature · 2 lines
Ville Syrjälä
Intel
#3 lore raw

Re: [PATCH 1/5] drm/tests: Test drm_rect_intersect()

Quoted 17 lines · Ville Syrjälä
Quoted 16 lines · Arthur Grillo

Insert test for the drm_rect_intersect() function, it also create a helper for comparing drm_rects more easily.

---
 drivers/gpu/drm/tests/drm_rect_test.c | 30 +++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
drivers/gpu/drm/tests/drm_rect_test.c +0 -0
index e9809ea32696..f700984f70a8 100644
@@ -9,6 +9,15 @@
 
 #include <drm/drm_rect.h>
 
Quoted 11 lines

drivers/gpu/drm/tests/drm_rect_test.c line 19

Quoted 8 lines
drivers/gpu/drm/tests/drm_rect_test.c +8 -0
+static void drm_rect_compare(struct kunit *test, const struct drm_rect *r,
+			     const struct drm_rect *expected)
+{
+	KUNIT_EXPECT_EQ(test, r->x1, expected->x1);
+	KUNIT_EXPECT_EQ(test, r->y1, expected->y1);
+	KUNIT_EXPECT_EQ(test, drm_rect_width(r), drm_rect_width(expected));
+	KUNIT_EXPECT_EQ(test, drm_rect_height(r), drm_rect_height(expected));
+}

We already have a drm_rect_equals().

I knew about drm_rect_equals(), but it only returns a boolean value, I thought that it would be better to test each attribute independently to find errors easily in the tested functions.

Quoted 18 lines
Quoted 18 lines
drivers/gpu/drm/tests/drm_rect_test.c +11 -0
+
 static void drm_test_rect_clip_scaled_div_by_zero(struct kunit *test)
 {
 	struct drm_rect src, dst, clip;
@@ -196,11 +205,32 @@ static void drm_test_rect_clip_scaled_signed_vs_unsigned(struct kunit *test)
 	KUNIT_EXPECT_FALSE_MSG(test, drm_rect_visible(&src), "Source should not be visible\n");
 }
 
+static void drm_test_rect_intersect(struct kunit *test)
+{
+	struct drm_rect r1, r2;
+	bool visible;
+
+	drm_rect_init(&r1, 0, 0, 2, 2);
+	drm_rect_init(&r2, 1, 1, 2, 2);
+
+	visible = drm_rect_intersect(&r1, &r2);
+
Quoted 8 lines

drivers/gpu/drm/tests/drm_rect_test.c static void drm_test_rect_clip_scaled_signed_vs_unsigned(struct kunit *test) · line 222

Quoted 5 lines
drivers/gpu/drm/tests/drm_rect_test.c +5 -0
+	KUNIT_EXPECT_TRUE_MSG(test, visible, "Interserction should be a visible rect");
+	drm_rect_compare(test, &r1, &DRM_RECT_INIT(1, 1, 1, 1));
+
+	drm_rect_init(&r1, 0, 0, 1, 1);
+

I would re-init r2 here too to make it easier to see what we're actually testing.

Great idea.

Quoted 5 lines

I would probably test a few more variations of the overlap between the rectangles, eg: equal rectangles, one smaller one fully inside the bigger one, overlaps across different edges/corners.

Okay, I will make more tests for this function.

Quoted 14 lines
Quoted 14 lines
drivers/gpu/drm/tests/drm_rect_test.c +6 -0
+	visible = drm_rect_intersect(&r1, &r2);
+
+	KUNIT_EXPECT_FALSE_MSG(test, visible, "Interserction should not be a visible rect");
+}
+
 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),
 	{ }
 };
 
Quoted 3 lines
Quoted 2 lines
Signature · 1 line
2.39.2

Thank you for your review!

Regards,
~Arthur Grillo

#4 lore raw

PATCH 2/5 drm/tests: Test drm_rect_calc_hscale()

In reply to Arthur Grillo

Insert test for the drm_rect_hscale() function, besides the test for the usual case it also test for the exceptions.

---
 drivers/gpu/drm/tests/drm_rect_test.c | 58 +++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
drivers/gpu/drm/tests/drm_rect_test.c +58 -0
index f700984f70a8..7e02393092fa 100644
@@ -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),
 	{ }
 };
 
Signature · 1 line
2.39.2
#5 lore raw

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

Quoted 22 lines · Arthur Grillo

Insert test for the drm_rect_hscale() function, besides the test for the usual case it also test for the exceptions.

---
 drivers/gpu/drm/tests/drm_rect_test.c | 58 +++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
drivers/gpu/drm/tests/drm_rect_test.c +2 -0
index f700984f70a8..7e02393092fa 100644
@@ -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)
 {

drivers/gpu/drm/tests/drm_rect_test.c static void drm_test_rect_intersect(struct kunit *test) · line 235

Quoted 9 lines
drivers/gpu/drm/tests/drm_rect_test.c +6 -0
@@ -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);

I think we have a few places in the code that make the assumption that src uses .16 binary fixed point. Not many, but few.

drivers/gpu/drm/tests/drm_rect_test.c static void drm_test_rect_intersect(struct kunit *test) · line 238

Quoted 3 lines
drivers/gpu/drm/tests/drm_rect_test.c +3 -0
+	drm_rect_init(&dst, 0, 0, 1, 0);
+
+	scaling_factor =  drm_rect_calc_hscale(&src, &dst, INT_MIN, INT_MAX);

The negative min scale factor is nonsensical.

Quoted 58 lines
drivers/gpu/drm/tests/drm_rect_test.c +47 -0
+
+	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),
 	{ }
 };
 
Signature · 1 line
2.39.2
Signature · 2 lines
Ville Syrjälä
Intel
#6 lore raw

PATCH 3/5 drm/tests: Test drm_rect_calc_vscale()

In reply to Arthur Grillo

Insert test for the drm_rect_vscale() function, besides the test for the usual case it also test for the exceptions.

---
 drivers/gpu/drm/tests/drm_rect_test.c | 56 +++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
drivers/gpu/drm/tests/drm_rect_test.c +56 -0
index 7e02393092fa..0f7736073390 100644
@@ -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),
 	{ }
 };
 
Signature · 1 line
2.39.2
#7 lore raw

PATCH 4/5 drm/tests: Test drm_rect_rotate()

In reply to Arthur Grillo

Insert test for the drm_rect_rotate() function, create test cases for all the rotation modes.

---
 drivers/gpu/drm/tests/drm_rect_test.c | 74 +++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
drivers/gpu/drm/tests/drm_rect_test.c +74 -0
index 0f7736073390..46139e796f3f 100644
@@ -8,6 +8,7 @@
 #include <kunit/test.h>
 
 #include <drm/drm_rect.h>
+#include <drm/drm_mode.h>
 
 #include <linux/errno.h>
 
@@ -333,6 +334,78 @@ static void drm_test_rect_calc_vscale_negative_args(struct kunit *test)
 	KUNIT_EXPECT_EQ(test, scaling_factor, -EINVAL);
 }
 
+struct drm_rect_rotate_case {
+	const char *name;
+	unsigned int rotation;
+	struct drm_rect rect;
+	int width, height;
+	struct drm_rect expected;
+};
+
+static const struct drm_rect_rotate_case drm_rect_rotate_cases[] = {
+	{
+		.name = "reflect x",
+		.rotation = DRM_MODE_REFLECT_X,
+		.rect = DRM_RECT_INIT(0, 0, 5, 5),
+		.width = 0, .height = 0,
+		.expected = DRM_RECT_INIT(-5, 0, 5, 5),
+	},
+	{
+		.name = "reflect y",
+		.rotation = DRM_MODE_REFLECT_Y,
+		.rect = DRM_RECT_INIT(0, 0, 5, 5),
+		.width = 0, .height = 0,
+		.expected = DRM_RECT_INIT(0, -5, 5, 5),
+	},
+	{
+		.name = "rotate 0",
+		.rotation = DRM_MODE_ROTATE_0,
+		.rect = DRM_RECT_INIT(0, 0, 5, 5),
+		.width = 0, .height = 0,
+		.expected = DRM_RECT_INIT(0, 0, 5, 5),
+	},
+	{
+		.name = "rotate 90",
+		.rotation = DRM_MODE_ROTATE_90,
+		.rect = DRM_RECT_INIT(0, 0, 5, 10),
+		.width = 0, .height = 0,
+		.expected = DRM_RECT_INIT(0, -5, 10, 5),
+	},
+	{
+		.name = "rotate 180",
+		.rotation = DRM_MODE_ROTATE_180,
+		.rect = DRM_RECT_INIT(0, 0, 5, 10),
+		.width = 0, .height = 0,
+		.expected = DRM_RECT_INIT(-5, -10, 5, 10),
+	},
+	{
+		.name = "rotate 270",
+		.rotation = DRM_MODE_ROTATE_270,
+		.rect = DRM_RECT_INIT(0, 0, 5, 10),
+		.width = 0, .height = 0,
+		.expected = DRM_RECT_INIT(-10, 0, 10, 5),
+	},
+};
+
+static void drm_rect_case_desc(const struct drm_rect_rotate_case *t, char *desc)
+{
+	strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE);
+}
+
+KUNIT_ARRAY_PARAM(drm_rect_rotate, drm_rect_rotate_cases, drm_rect_case_desc);
+
+static void drm_test_rect_rotate(struct kunit *test)
+{
+	const struct drm_rect_rotate_case *params = test->param_value;
+	struct drm_rect r;
+
+	memcpy(&r, &params->rect, sizeof(struct drm_rect));
+
+	drm_rect_rotate(&r, params->width, params->height, params->rotation);
+
+	drm_rect_compare(test, &r, &params->expected);
+}
+
 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),
@@ -345,6 +418,7 @@ static struct kunit_case drm_rect_tests[] = {
 	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),
+	KUNIT_CASE_PARAM(drm_test_rect_rotate, drm_rect_rotate_gen_params),
 	{ }
 };
 
Signature · 1 line
2.39.2
#8 lore raw

Re: [PATCH 4/5] drm/tests: Test drm_rect_rotate()

Quoted 28 lines · Arthur Grillo

Insert test for the drm_rect_rotate() function, create test cases for all the rotation modes.

---
 drivers/gpu/drm/tests/drm_rect_test.c | 74 +++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
drivers/gpu/drm/tests/drm_rect_test.c +5 -0
index 0f7736073390..46139e796f3f 100644
@@ -8,6 +8,7 @@
 #include <kunit/test.h>
 
 #include <drm/drm_rect.h>
+#include <drm/drm_mode.h>
 
 #include <linux/errno.h>
 
@@ -333,6 +334,78 @@ static void drm_test_rect_calc_vscale_negative_args(struct kunit *test)
 	KUNIT_EXPECT_EQ(test, scaling_factor, -EINVAL);
 }
 
+struct drm_rect_rotate_case {
+	const char *name;
+	unsigned int rotation;
+	struct drm_rect rect;

drivers/gpu/drm/tests/drm_rect_test.c static void drm_test_rect_calc_vscale_negative_args(struct kunit *test) · line 350

Quoted 10 lines
drivers/gpu/drm/tests/drm_rect_test.c +10 -0
+	int width, height;
+	struct drm_rect expected;
+};
+
+static const struct drm_rect_rotate_case drm_rect_rotate_cases[] = {
+	{
+		.name = "reflect x",
+		.rotation = DRM_MODE_REFLECT_X,
+		.rect = DRM_RECT_INIT(0, 0, 5, 5),
+		.width = 0, .height = 0,

These zero width/height don't really make any sense.

Quoted 42 lines
drivers/gpu/drm/tests/drm_rect_test.c +42 -0
+		.expected = DRM_RECT_INIT(-5, 0, 5, 5),
+	},
+	{
+		.name = "reflect y",
+		.rotation = DRM_MODE_REFLECT_Y,
+		.rect = DRM_RECT_INIT(0, 0, 5, 5),
+		.width = 0, .height = 0,
+		.expected = DRM_RECT_INIT(0, -5, 5, 5),
+	},
+	{
+		.name = "rotate 0",
+		.rotation = DRM_MODE_ROTATE_0,
+		.rect = DRM_RECT_INIT(0, 0, 5, 5),
+		.width = 0, .height = 0,
+		.expected = DRM_RECT_INIT(0, 0, 5, 5),
+	},
+	{
+		.name = "rotate 90",
+		.rotation = DRM_MODE_ROTATE_90,
+		.rect = DRM_RECT_INIT(0, 0, 5, 10),
+		.width = 0, .height = 0,
+		.expected = DRM_RECT_INIT(0, -5, 10, 5),
+	},
+	{
+		.name = "rotate 180",
+		.rotation = DRM_MODE_ROTATE_180,
+		.rect = DRM_RECT_INIT(0, 0, 5, 10),
+		.width = 0, .height = 0,
+		.expected = DRM_RECT_INIT(-5, -10, 5, 10),
+	},
+	{
+		.name = "rotate 270",
+		.rotation = DRM_MODE_ROTATE_270,
+		.rect = DRM_RECT_INIT(0, 0, 5, 10),
+		.width = 0, .height = 0,
+		.expected = DRM_RECT_INIT(-10, 0, 10, 5),
+	},
+};
+
+static void drm_rect_case_desc(const struct drm_rect_rotate_case *t, char *desc)
+{
+	strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE);

drivers/gpu/drm/tests/drm_rect_test.c static void drm_test_rect_calc_vscale_negative_args(struct kunit *test) · line 402

Quoted 10 lines
drivers/gpu/drm/tests/drm_rect_test.c +10 -0
+}
+
+KUNIT_ARRAY_PARAM(drm_rect_rotate, drm_rect_rotate_cases, drm_rect_case_desc);
+
+static void drm_test_rect_rotate(struct kunit *test)
+{
+	const struct drm_rect_rotate_case *params = test->param_value;
+	struct drm_rect r;
+
+	memcpy(&r, &params->rect, sizeof(struct drm_rect));

r = params->rect;

Quoted 19 lines
drivers/gpu/drm/tests/drm_rect_test.c +7 -0
+
+	drm_rect_rotate(&r, params->width, params->height, params->rotation);
+
+	drm_rect_compare(test, &r, &params->expected);
+}
+
 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),
@@ -345,6 +418,7 @@ static struct kunit_case drm_rect_tests[] = {
 	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),
+	KUNIT_CASE_PARAM(drm_test_rect_rotate, drm_rect_rotate_gen_params),
 	{ }
 };
 
Signature · 1 line
2.39.2
Signature · 2 lines
Ville Syrjälä
Intel
#9 lore raw

PATCH 5/5 drm/test: Test drm_rect_rotate_inv()

In reply to Arthur Grillo

Insert test for the drm_rect_rotate_inv() function, by expanding the existing test framework for the drm_rect_rotate().

---
 drivers/gpu/drm/tests/drm_rect_test.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/gpu/drm/tests/drm_rect_test.c +13 -0
index 46139e796f3f..6d41c0a3cae0 100644
@@ -406,6 +406,18 @@ static void drm_test_rect_rotate(struct kunit *test)
 	drm_rect_compare(test, &r, &params->expected);
 }
 
+static void drm_test_rect_rotate_inv(struct kunit *test)
+{
+	const struct drm_rect_rotate_case *params = test->param_value;
+	struct drm_rect r;
+
+	memcpy(&r, &params->expected, sizeof(struct drm_rect));
+
+	drm_rect_rotate_inv(&r, params->width, params->height, params->rotation);
+
+	drm_rect_compare(test, &r, &params->rect);
+}
+
 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),
@@ -419,6 +431,7 @@ static struct kunit_case drm_rect_tests[] = {
 	KUNIT_CASE(drm_test_rect_calc_vscale_out_of_range),
 	KUNIT_CASE(drm_test_rect_calc_vscale_negative_args),
 	KUNIT_CASE_PARAM(drm_test_rect_rotate, drm_rect_rotate_gen_params),
+	KUNIT_CASE_PARAM(drm_test_rect_rotate_inv, drm_rect_rotate_gen_params),
 	{ }
 };
 
Signature · 1 line
2.39.2