Create tests for the drm_rect functions
Subsystems (2)
v5 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.
If you want to see the coverage report, I uploaded on the link below:
https://grillo-0.github.io/coverage-reports/more-rect-tests/drivers/gpu/drm/drm_rect.c.gcov.html
Thanks for reviewing!
Best regards,
~Arthur Grillo
---
v1->v2: https://lore.kernel.org/all/[email protected]/
- Create parameterized tests for drm_rect_intersect().
- Use .16 binary fixed point values on the drm_rect_calc_hscale() and drm_rect_calc_vscale() tests.
- Replace INT_MIN for 0 on the on the drm_rect_calc_hscale() and drm_rect_calc_vscale() tests.
- Assign nonzero values to the width and height parameters of the drm_rect_rotate() and drm_rect_rotate_inv() tests.
- Switch memcpy to a simple variable assignment on the drm_rect_rotate() and drm_rect_rotate_inv() tests.
v2->v3: https://lore.kernel.org/all/[email protected]/
- Change "x" to lowercase on the drm_rect_intersect() cases.
- Remove the option for no description on the drm_rect_intersect() cases.
- Add a test for rects with zero height and width on the drm_rect_intersect().
- Switch to parameterized tests for drm_rect_calc_hscale() and drm_rect_calc_vscale().
- Add a test for a dst drm_rect with zero width for drm_rect_calc_hscale() and zero height for drm_rect_calc_vscale().
- Place an "-" on the drm_rect_rotate case names to match the userspace.
- s/drm_rect_case_desc/drm_rect_rotate_case_desc/
- Improve the commit messages.
v3->v4: https://lore.kernel.org/all/[email protected]/
- Place parenthesis around .16 fixed point values before making it negative to avoid error when generating tests coverages.
v4->v5: https://lore.kernel.org/all/[email protected]/
- Use the same parameters for drm_rect_calc_hscale() and drm_rect_calc_vscale() by scaling both sides at the same time.
- Place nonzero values for .x1 and .y1 on the drm_rect_rotate() test cases.
---
[1]: https://gcc.gnu.org/onlinedocs/gcc/Gcov.html#Gcov
---
Arthur Grillo (5):
drm/tests: Add test cases for drm_rect_intersect() drm/tests: Add test cases for drm_rect_calc_hscale() drm/tests: Add test cases for drm_rect_calc_vscale() drm/tests: Add test cases for drm_rect_rotate() drm/test: Add test cases for drm_rect_rotate_inv()
drivers/gpu/drm/tests/drm_rect_test.c | 315 ++++++++++++++++++++++++++ 1 file changed, 315 insertions(+)
Signature · 1 line
2.40.0
PATCH v5 1/5 drm/tests: Add test cases for drm_rect_intersect()
Insert parameterized tests for the drm_rect_intersect() to ensure correctness and prevent future regressions.
Also, create a helper for testing if two drm_rects are equal.
--- drivers/gpu/drm/tests/drm_rect_test.c | 148 ++++++++++++++++++++++++++ 1 file changed, 148 insertions(+)
drivers/gpu/drm/tests/drm_rect_test.c +148 -0
@@ -9,6 +9,17 @@#include <drm/drm_rect.h> +#include <linux/string_helpers.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 +207,148 @@ 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" ); } +struct drm_rect_intersect_case { +const char *description; +struct drm_rect r1, r2; +bool should_be_visible; +struct drm_rect expected_intersection; +}; + +static const struct drm_rect_intersect_case drm_rect_intersect_cases[] = { + { + .description ="top-left x bottom-right" , + .r1 =DRM_RECT_INIT (1 ,1 ,2 ,2 ), + .r2 =DRM_RECT_INIT (0 ,0 ,2 ,2 ), + .should_be_visible = true, + .expected_intersection =DRM_RECT_INIT (1 ,1 ,1 ,1 ), + }, + { + .description ="top-right x bottom-left" , + .r1 =DRM_RECT_INIT (0 ,0 ,2 ,2 ), + .r2 =DRM_RECT_INIT (1 ,-1 ,2 ,2 ), + .should_be_visible = true, + .expected_intersection =DRM_RECT_INIT (1 ,0 ,1 ,1 ), + }, + { + .description ="bottom-left x top-right" , + .r1 =DRM_RECT_INIT (1 ,-1 ,2 ,2 ), + .r2 =DRM_RECT_INIT (0 ,0 ,2 ,2 ), + .should_be_visible = true, + .expected_intersection =DRM_RECT_INIT (1 ,0 ,1 ,1 ), + }, + { + .description ="bottom-right x top-left" , + .r1 =DRM_RECT_INIT (0 ,0 ,2 ,2 ), + .r2 =DRM_RECT_INIT (1 ,1 ,2 ,2 ), + .should_be_visible = true, + .expected_intersection =DRM_RECT_INIT (1 ,1 ,1 ,1 ), + }, + { + .description ="right x left" , + .r1 =DRM_RECT_INIT (0 ,0 ,2 ,1 ), + .r2 =DRM_RECT_INIT (1 ,0 ,3 ,1 ), + .should_be_visible = true, + .expected_intersection =DRM_RECT_INIT (1 ,0 ,1 ,1 ), + }, + { + .description ="left x right" , + .r1 =DRM_RECT_INIT (1 ,0 ,3 ,1 ), + .r2 =DRM_RECT_INIT (0 ,0 ,2 ,1 ), + .should_be_visible = true, + .expected_intersection =DRM_RECT_INIT (1 ,0 ,1 ,1 ), + }, + { + .description ="up x bottom" , + .r1 =DRM_RECT_INIT (0 ,0 ,1 ,2 ), + .r2 =DRM_RECT_INIT (0 ,-1 ,1 ,3 ), + .should_be_visible = true, + .expected_intersection =DRM_RECT_INIT (0 ,0 ,1 ,2 ), + }, + { + .description ="bottom x up" , + .r1 =DRM_RECT_INIT (0 ,-1 ,1 ,3 ), + .r2 =DRM_RECT_INIT (0 ,0 ,1 ,2 ), + .should_be_visible = true, + .expected_intersection =DRM_RECT_INIT (0 ,0 ,1 ,2 ), + }, + { + .description ="touching corner" , + .r1 =DRM_RECT_INIT (0 ,0 ,1 ,1 ), + .r2 =DRM_RECT_INIT (1 ,1 ,2 ,2 ), + .should_be_visible = false, + .expected_intersection =DRM_RECT_INIT (1 ,1 ,0 ,0 ), + }, + { + .description ="touching side" , + .r1 =DRM_RECT_INIT (0 ,0 ,1 ,1 ), + .r2 =DRM_RECT_INIT (1 ,0 ,1 ,1 ), + .should_be_visible = false, + .expected_intersection =DRM_RECT_INIT (1 ,0 ,0 ,1 ), + }, + { + .description ="equal rects" , + .r1 =DRM_RECT_INIT (0 ,0 ,2 ,2 ), + .r2 =DRM_RECT_INIT (0 ,0 ,2 ,2 ), + .should_be_visible = true, + .expected_intersection =DRM_RECT_INIT (0 ,0 ,2 ,2 ), + }, + { + .description ="inside another" , + .r1 =DRM_RECT_INIT (0 ,0 ,2 ,2 ), + .r2 =DRM_RECT_INIT (1 ,1 ,1 ,1 ), + .should_be_visible = true, + .expected_intersection =DRM_RECT_INIT (1 ,1 ,1 ,1 ), + }, + { + .description ="far away" , + .r1 =DRM_RECT_INIT (0 ,0 ,1 ,1 ), + .r2 =DRM_RECT_INIT (3 ,6 ,1 ,1 ), + .should_be_visible = false, + .expected_intersection =DRM_RECT_INIT (3 ,6 ,-2 ,-5 ), + }, + { + .description ="points intersecting" , + .r1 =DRM_RECT_INIT (5 ,10 ,0 ,0 ), + .r2 =DRM_RECT_INIT (5 ,10 ,0 ,0 ), + .should_be_visible = false, + .expected_intersection =DRM_RECT_INIT (5 ,10 ,0 ,0 ), + }, + { + .description ="points not intersecting" , + .r1 =DRM_RECT_INIT (0 ,0 ,0 ,0 ), + .r2 =DRM_RECT_INIT (5 ,10 ,0 ,0 ), + .should_be_visible = false, + .expected_intersection =DRM_RECT_INIT (5 ,10 ,-5 ,-10 ), + }, +}; + +static void drm_rect_intersect_case_desc (const struct drm_rect_intersect_case *t,char *desc) +{ +snprintf (desc,KUNIT_PARAM_DESC_SIZE , +"%s: " DRM_RECT_FMT " x " DRM_RECT_FMT , + t->description,DRM_RECT_ARG (&t->r1),DRM_RECT_ARG (&t->r2)); +} + +KUNIT_ARRAY_PARAM (drm_rect_intersect, drm_rect_intersect_cases, drm_rect_intersect_case_desc); + +static void drm_test_rect_intersect (struct kunit *test) +{ +const struct drm_rect_intersect_case *params = test->param_value; +struct drm_rect r1_aux = params->r1; +bool visible; + + visible =drm_rect_intersect (&r1_aux, ¶ms->r2); + +KUNIT_EXPECT_EQ (test, visible, params->should_be_visible); +drm_rect_compare (test, &r1_aux, ¶ms->expected_intersection); +} +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), { } };
Signature · 1 line
2.40.0
PATCH v5 2/5 drm/tests: Add test cases for drm_rect_calc_hscale()
In reply to Arthur GrilloInsert parameterized test for the drm_rect_calc_hscale() to ensure correctness and prevent future regressions. Besides the test for the usual case, tests the exceptions.
--- drivers/gpu/drm/tests/drm_rect_test.c | 72 +++++++++++++++++++++++++++ 1 file changed, 72 insertions(+)
drivers/gpu/drm/tests/drm_rect_test.c +72 -0
@@ -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)
@@ -343,12 +344,83 @@ static void drm_test_rect_intersect(struct kunit *test)drm_rect_compare (test, &r1_aux, ¶ms->expected_intersection); } +struct drm_rect_scale_case { +const char *name; +struct drm_rect src, dst; +int min_range, max_range; +int expected_scaling_factor; +}; + +static const struct drm_rect_scale_case drm_rect_scale_cases[] = { + { + .name ="normal use" , + .src =DRM_RECT_INIT (0 ,0 ,2 <<16 ,2 <<16 ), + .dst =DRM_RECT_INIT (0 ,0 ,1 <<16 ,1 <<16 ), + .min_range =0 , .max_range =INT_MAX , + .expected_scaling_factor =2 , + }, + { + .name ="out of max range" , + .src =DRM_RECT_INIT (0 ,0 ,10 <<16 ,10 <<16 ), + .dst =DRM_RECT_INIT (0 ,0 ,1 <<16 ,1 <<16 ), + .min_range =3 , .max_range =5 , + .expected_scaling_factor = -ERANGE , + }, + { + .name ="out of min range" , + .src =DRM_RECT_INIT (0 ,0 ,2 <<16 ,2 <<16 ), + .dst =DRM_RECT_INIT (0 ,0 ,1 <<16 ,1 <<16 ), + .min_range =3 , .max_range =5 , + .expected_scaling_factor = -ERANGE , + }, + { + .name ="zero dst" , + .src =DRM_RECT_INIT (0 ,0 ,2 <<16 ,2 <<16 ), + .dst =DRM_RECT_INIT (0 ,0 ,0 <<16 ,0 <<16 ), + .min_range =0 , .max_range =INT_MAX , + .expected_scaling_factor =0 , + }, + { + .name ="negative src" , + .src =DRM_RECT_INIT (0 ,0 , -(1 <<16 ), -(1 <<16 )), + .dst =DRM_RECT_INIT (0 ,0 ,1 <<16 ,1 <<16 ), + .min_range =0 , .max_range =INT_MAX , + .expected_scaling_factor = -EINVAL , + }, + { + .name ="negative dst" , + .src =DRM_RECT_INIT (0 ,0 ,1 <<16 ,1 <<16 ), + .dst =DRM_RECT_INIT (0 ,0 , -(1 <<16 ), -(1 <<16 )), + .min_range =0 , .max_range =INT_MAX , + .expected_scaling_factor = -EINVAL , + }, +}; + +static void drm_rect_scale_case_desc (const struct drm_rect_scale_case *t,char *desc) +{ +strscpy (desc, t->name,KUNIT_PARAM_DESC_SIZE ); +} + +KUNIT_ARRAY_PARAM (drm_rect_scale, drm_rect_scale_cases, drm_rect_scale_case_desc); + +static void drm_test_rect_calc_hscale (struct kunit *test) +{ +const struct drm_rect_scale_case *params = test->param_value; +int scaling_factor; + + scaling_factor =drm_rect_calc_hscale (¶ms->src, ¶ms->dst, + params->min_range, params->max_range); + +KUNIT_EXPECT_EQ (test, scaling_factor, params->expected_scaling_factor); +} +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_PARAM (drm_test_rect_calc_hscale, drm_rect_scale_gen_params), { } };
Signature · 1 line
2.40.0
Re: [PATCH v5 2/5] drm/tests: Add test cases for drm_rect_calc_hscale()
Quoted 5 lines · Arthur Grillo
Insert parameterized test for the
drm_rect_calc_hscale()to ensure correctness and prevent future regressions. Besides the test for the usual case, tests the exceptions.Signed-off-by Arthur Grillo <[email protected]>
Thanks for the quick fix!
Best Regards,
- Maíra Canal
Quoted 100 lines
--- drivers/gpu/drm/tests/drm_rect_test.c | 72 +++++++++++++++++++++++++++ 1 file changed, 72 insertions(+)drivers/gpu/drm/tests/drm_rect_test.c +72
-0@@ -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)@@ -343,12 +344,83 @@ static void drm_test_rect_intersect(struct kunit *test)drm_rect_compare (test, &r1_aux, ¶ms->expected_intersection); } +struct drm_rect_scale_case { +const char *name; +struct drm_rect src, dst; +int min_range, max_range; +int expected_scaling_factor; +}; + +static const struct drm_rect_scale_case drm_rect_scale_cases[] = { + { + .name ="normal use" , + .src =DRM_RECT_INIT (0 ,0 ,2 <<16 ,2 <<16 ), + .dst =DRM_RECT_INIT (0 ,0 ,1 <<16 ,1 <<16 ), + .min_range =0 , .max_range =INT_MAX , + .expected_scaling_factor =2 , + }, + { + .name ="out of max range" , + .src =DRM_RECT_INIT (0 ,0 ,10 <<16 ,10 <<16 ), + .dst =DRM_RECT_INIT (0 ,0 ,1 <<16 ,1 <<16 ), + .min_range =3 , .max_range =5 , + .expected_scaling_factor = -ERANGE , + }, + { + .name ="out of min range" , + .src =DRM_RECT_INIT (0 ,0 ,2 <<16 ,2 <<16 ), + .dst =DRM_RECT_INIT (0 ,0 ,1 <<16 ,1 <<16 ), + .min_range =3 , .max_range =5 , + .expected_scaling_factor = -ERANGE , + }, + { + .name ="zero dst" , + .src =DRM_RECT_INIT (0 ,0 ,2 <<16 ,2 <<16 ), + .dst =DRM_RECT_INIT (0 ,0 ,0 <<16 ,0 <<16 ), + .min_range =0 , .max_range =INT_MAX , + .expected_scaling_factor =0 , + }, + { + .name ="negative src" , + .src =DRM_RECT_INIT (0 ,0 , -(1 <<16 ), -(1 <<16 )), + .dst =DRM_RECT_INIT (0 ,0 ,1 <<16 ,1 <<16 ), + .min_range =0 , .max_range =INT_MAX , + .expected_scaling_factor = -EINVAL , + }, + { + .name ="negative dst" , + .src =DRM_RECT_INIT (0 ,0 ,1 <<16 ,1 <<16 ), + .dst =DRM_RECT_INIT (0 ,0 , -(1 <<16 ), -(1 <<16 )), + .min_range =0 , .max_range =INT_MAX , + .expected_scaling_factor = -EINVAL , + }, +}; + +static void drm_rect_scale_case_desc (const struct drm_rect_scale_case *t,char *desc) +{ +strscpy (desc, t->name,KUNIT_PARAM_DESC_SIZE ); +} + +KUNIT_ARRAY_PARAM (drm_rect_scale, drm_rect_scale_cases, drm_rect_scale_case_desc); + +static void drm_test_rect_calc_hscale (struct kunit *test) +{ +const struct drm_rect_scale_case *params = test->param_value; +int scaling_factor; + + scaling_factor =drm_rect_calc_hscale (¶ms->src, ¶ms->dst, + params->min_range, params->max_range); + +KUNIT_EXPECT_EQ (test, scaling_factor, params->expected_scaling_factor); +} +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_PARAM (drm_test_rect_calc_hscale, drm_rect_scale_gen_params), { } };
PATCH v5 3/5 drm/tests: Add test cases for drm_rect_calc_vscale()
In reply to Arthur GrilloInsert parameterized test for the drm_rect_calc_vscale() to ensure correctness and prevent future regressions. Besides the test for the usual case, tests the exceptions.
It uses the same struct from drm_rect_calc_hscale().
--- drivers/gpu/drm/tests/drm_rect_test.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/gpu/drm/tests/drm_rect_test.c +12 -0
@@ -414,6 +414,17 @@ static void drm_test_rect_calc_hscale(struct kunit *test)KUNIT_EXPECT_EQ (test, scaling_factor, params->expected_scaling_factor); } +static void drm_test_rect_calc_vscale (struct kunit *test) +{ +const struct drm_rect_scale_case *params = test->param_value; +int scaling_factor; + + scaling_factor =drm_rect_calc_vscale (¶ms->src, ¶ms->dst, + params->min_range, params->max_range); + +KUNIT_EXPECT_EQ (test, scaling_factor, params->expected_scaling_factor); +} +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),
@@ -421,6 +432,7 @@ static struct kunit_case drm_rect_tests[] = {KUNIT_CASE (drm_test_rect_clip_scaled_signed_vs_unsigned),KUNIT_CASE_PARAM (drm_test_rect_intersect, drm_rect_intersect_gen_params),KUNIT_CASE_PARAM (drm_test_rect_calc_hscale, drm_rect_scale_gen_params), + KUNIT_CASE_PARAM(drm_test_rect_calc_vscale, drm_rect_scale_gen_params), { } };
Signature · 1 line
2.40.0
Re: [PATCH v5 3/5] drm/tests: Add test cases for drm_rect_calc_vscale()
Quoted 7 lines · Arthur Grillo
Insert parameterized test for the
drm_rect_calc_vscale()to ensure correctness and prevent future regressions. Besides the test for the usual case, tests the exceptions.It uses the same struct from
drm_rect_calc_hscale().Signed-off-by Arthur Grillo <[email protected]>
Thanks for the quick fix!
Best Regards,
- Maíra Canal
Quoted 34 lines
--- drivers/gpu/drm/tests/drm_rect_test.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/gpu/drm/tests/drm_rect_test.c +12
-0@@ -414,6 +414,17 @@ static void drm_test_rect_calc_hscale(struct kunit *test)KUNIT_EXPECT_EQ (test, scaling_factor, params->expected_scaling_factor); } +static void drm_test_rect_calc_vscale (struct kunit *test) +{ +const struct drm_rect_scale_case *params = test->param_value; +int scaling_factor; + + scaling_factor =drm_rect_calc_vscale (¶ms->src, ¶ms->dst, + params->min_range, params->max_range); + +KUNIT_EXPECT_EQ (test, scaling_factor, params->expected_scaling_factor); +} +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),@@ -421,6 +432,7 @@ static struct kunit_case drm_rect_tests[] = {KUNIT_CASE (drm_test_rect_clip_scaled_signed_vs_unsigned),KUNIT_CASE_PARAM (drm_test_rect_intersect, drm_rect_intersect_gen_params),KUNIT_CASE_PARAM (drm_test_rect_calc_hscale, drm_rect_scale_gen_params), + KUNIT_CASE_PARAM(drm_test_rect_calc_vscale, drm_rect_scale_gen_params), { } };
PATCH v5 4/5 drm/tests: Add test cases for drm_rect_rotate()
In reply to Arthur GrilloInsert a parameterized test for the drm_rect_rotate() to ensure correctness and prevent future regressions.
All possible rotation modes are covered by the test.
--- drivers/gpu/drm/tests/drm_rect_test.c | 72 +++++++++++++++++++++++++++ 1 file changed, 72 insertions(+)
drivers/gpu/drm/tests/drm_rect_test.c +72 -0
@@ -8,6 +8,7 @@#include <kunit/test.h> #include <drm/drm_rect.h> +#include <drm/drm_mode.h> #include <linux/string_helpers.h> #include <linux/errno.h>
@@ -425,6 +426,76 @@ static void drm_test_rect_calc_vscale(struct kunit *test)KUNIT_EXPECT_EQ (test, scaling_factor, params->expected_scaling_factor); } +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 =5 , .height =10 , + .expected =DRM_RECT_INIT (0 ,0 ,5 ,5 ), + }, + { + .name ="reflect-y" , + .rotation =DRM_MODE_REFLECT_Y , + .rect =DRM_RECT_INIT (2 ,0 ,5 ,5 ), + .width =5 , .height =10 , + .expected =DRM_RECT_INIT (2 ,5 ,5 ,5 ), + }, + { + .name ="rotate-0" , + .rotation =DRM_MODE_ROTATE_0 , + .rect =DRM_RECT_INIT (0 ,2 ,5 ,5 ), + .width =5 , .height =10 , + .expected =DRM_RECT_INIT (0 ,2 ,5 ,5 ), + }, + { + .name ="rotate-90" , + .rotation =DRM_MODE_ROTATE_90 , + .rect =DRM_RECT_INIT (0 ,0 ,5 ,10 ), + .width =5 , .height =10 , + .expected =DRM_RECT_INIT (0 ,0 ,10 ,5 ), + }, + { + .name ="rotate-180" , + .rotation =DRM_MODE_ROTATE_180 , + .rect =DRM_RECT_INIT (11 ,3 ,5 ,10 ), + .width =5 , .height =10 , + .expected =DRM_RECT_INIT (-11 ,-3 ,5 ,10 ), + }, + { + .name ="rotate-270" , + .rotation =DRM_MODE_ROTATE_270 , + .rect =DRM_RECT_INIT (6 ,3 ,5 ,10 ), + .width =5 , .height =10 , + .expected =DRM_RECT_INIT (-3 ,6 ,10 ,5 ), + }, +}; + +static void drm_rect_rotate_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_rotate_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 = params->rect; + +drm_rect_rotate (&r, params->width, params->height, params->rotation); + +drm_rect_compare (test, &r, ¶ms->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),
@@ -433,6 +504,7 @@ static struct kunit_case drm_rect_tests[] = {KUNIT_CASE_PARAM (drm_test_rect_intersect, drm_rect_intersect_gen_params),KUNIT_CASE_PARAM (drm_test_rect_calc_hscale, drm_rect_scale_gen_params),KUNIT_CASE_PARAM (drm_test_rect_calc_vscale, drm_rect_scale_gen_params), + KUNIT_CASE_PARAM(drm_test_rect_rotate, drm_rect_rotate_gen_params), { } };
Signature · 1 line
2.40.0
PATCH v5 5/5 drm/test: Add test cases for drm_rect_rotate_inv()
In reply to Arthur GrilloInsert a parameterized test for the drm_rect_rotate_inv() to ensure its correctness and prevent future regressions. The test covers all rotation modes.
It uses the same test cases from drm_test_rect_rotate().
--- drivers/gpu/drm/tests/drm_rect_test.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/gpu/drm/tests/drm_rect_test.c +11 -0
@@ -496,6 +496,16 @@ static void drm_test_rect_rotate(struct kunit *test)drm_rect_compare (test, &r, ¶ms->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 = params->expected; + +drm_rect_rotate_inv (&r, params->width, params->height, params->rotation); + +drm_rect_compare (test, &r, ¶ms->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),
@@ -505,6 +515,7 @@ static struct kunit_case drm_rect_tests[] = {KUNIT_CASE_PARAM (drm_test_rect_calc_hscale, drm_rect_scale_gen_params),KUNIT_CASE_PARAM (drm_test_rect_calc_vscale, drm_rect_scale_gen_params),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.40.0
Quoted 7 lines · Arthur Grillo
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.cfile. This would be very good for future development on the file.
Quoted 7 lines
If you want to see the coverage report, I uploaded on the link below:
https://grillo-0.github.io/coverage-reports/more-rect-tests/drivers/gpu/drm/drm_rect.c.gcov.htmlThanks for reviewing!
Best regards,
~Arthur Grillo
I just applied the series to drm/drm-misc (drm-misc-next).
Thanks for improving the tests!
Best Regards,
- Maíra Canal
Quoted 53 lines
---
v1->v2: https://lore.kernel.org/all/[email protected]/
- Create parameterized tests fordrm_rect_intersect().
- Use .16 binary fixed point values on thedrm_rect_calc_hscale()anddrm_rect_calc_vscale()tests.
- ReplaceINT_MINfor 0 on the on thedrm_rect_calc_hscale()anddrm_rect_calc_vscale()tests.
- Assign nonzero values to the width and height parameters of thedrm_rect_rotate()anddrm_rect_rotate_inv()tests.
- Switch memcpy to a simple variable assignment on thedrm_rect_rotate()anddrm_rect_rotate_inv()tests.
v2->v3: https://lore.kernel.org/all/[email protected]/
- Change "x" to lowercase on thedrm_rect_intersect()cases.
- Remove the option for no description on thedrm_rect_intersect()cases.
- Add a test for rects with zero height and width on thedrm_rect_intersect().
- Switch to parameterized tests fordrm_rect_calc_hscale()anddrm_rect_calc_vscale().
- Add a test for a dstdrm_rectwith zero width fordrm_rect_calc_hscale()and zero height fordrm_rect_calc_vscale().
- Place an "-" on thedrm_rect_rotatecase names to match the userspace.
- s/drm_rect_case_desc/drm_rect_rotate_case_desc/
- Improve the commit messages.
v3->v4: https://lore.kernel.org/all/[email protected]/
- Place parenthesis around .16 fixed point values before making it negative to avoid error when generating tests coverages.
v4->v5: https://lore.kernel.org/all/[email protected]/
- Use the same parameters fordrm_rect_calc_hscale()anddrm_rect_calc_vscale()by scaling both sides at the same time.
- Place nonzero values for .x1 and .y1 on thedrm_rect_rotate()test cases.---
[1]: https://gcc.gnu.org/onlinedocs/gcc/Gcov.html#Gcov
---
Arthur Grillo (5):
drm/tests: Add test cases fordrm_rect_intersect()drm/tests: Add test cases fordrm_rect_calc_hscale()drm/tests: Add test cases fordrm_rect_calc_vscale()drm/tests: Add test cases fordrm_rect_rotate()drm/test: Add test cases fordrm_rect_rotate_inv()drivers/gpu/drm/tests/drm_rect_test.c | 315 ++++++++++++++++++++++++++ 1 file changed, 315 insertions(+)