On 22/03/23 11:26, Ville Syrjälä wrote: > On Wed, Mar 22, 2023 at 11:06:57AM -0300, Arthur Grillo wrote: >> Insert test for the drm_rect_intersect() function, it also create a >> helper for comparing drm_rects more easily. >> >> Signed-off-by: Arthur Grillo <arthurgri...@riseup.net> >> --- >> drivers/gpu/drm/tests/drm_rect_test.c | 30 +++++++++++++++++++++++++++ >> 1 file changed, 30 insertions(+) >> >> diff --git a/drivers/gpu/drm/tests/drm_rect_test.c >> b/drivers/gpu/drm/tests/drm_rect_test.c >> index e9809ea32696..f700984f70a8 100644 >> --- a/drivers/gpu/drm/tests/drm_rect_test.c >> +++ b/drivers/gpu/drm/tests/drm_rect_test.c >> @@ -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)); >> +} > > 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. >> + >> 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); >> + > > I would re-init r2 here too to make it easier to see what we're > actually testing. Great idea. > > 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. >> + 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), >> { } >> }; >> >> -- >> 2.39.2 > Thank you for your review! Regards, ~Arthur Grillo
Re: [PATCH 1/5] drm/tests: Test drm_rect_intersect()
Arthur Grillo Queiroz Cabral Wed, 22 Mar 2023 12:39:37 -0700
- [PATCH 0/5] Create tests for the drm_rect fun... Arthur Grillo
- [PATCH 1/5] drm/tests: Test drm_rect_int... Arthur Grillo
- Re: [PATCH 1/5] drm/tests: Test drm_... Ville Syrjälä
- Re: [PATCH 1/5] drm/tests: Test ... Arthur Grillo Queiroz Cabral
- [PATCH 2/5] drm/tests: Test drm_rect_cal... Arthur Grillo
- Re: [PATCH 2/5] drm/tests: Test drm_... Ville Syrjälä
- [PATCH 3/5] drm/tests: Test drm_rect_cal... Arthur Grillo
- [PATCH 4/5] drm/tests: Test drm_rect_rot... Arthur Grillo
- Re: [PATCH 4/5] drm/tests: Test drm_... Ville Syrjälä
- [PATCH 5/5] drm/test: Test drm_rect_rota... Arthur Grillo