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

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

 



On Wed, Mar 22, 2023 at 11:07:00AM -0300, Arthur Grillo wrote:
> Insert test for the drm_rect_rotate() function, create test cases
> for all the rotation modes.
> 
> Signed-off-by: Arthur Grillo <arthurgrillo@xxxxxxxxxx>
> ---
>  drivers/gpu/drm/tests/drm_rect_test.c | 74 +++++++++++++++++++++++++++
>  1 file changed, 74 insertions(+)
> 
> diff --git a/drivers/gpu/drm/tests/drm_rect_test.c b/drivers/gpu/drm/tests/drm_rect_test.c
> index 0f7736073390..46139e796f3f 100644
> --- a/drivers/gpu/drm/tests/drm_rect_test.c
> +++ b/drivers/gpu/drm/tests/drm_rect_test.c
> @@ -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,

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

> +		.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));

r = params->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),
>  	{ }
>  };
>  
> -- 
> 2.39.2

-- 
Ville Syrjälä
Intel



[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