diff mbox series

[v4,3/5] drm/tests: Add test cases for drm_rect_calc_vscale()

Message ID 20230406115338.36228-4-arthurgrillo@riseup.net (mailing list archive)
State New, archived
Headers show
Series Create tests for the drm_rect functions | expand

Commit Message

Arthur Grillo April 6, 2023, 11:53 a.m. UTC
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 <arthurgrillo@riseup.net>
---
 drivers/gpu/drm/tests/drm_rect_test.c | 59 +++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

Comments

Maíra Canal April 17, 2023, 4:19 p.m. UTC | #1
On 4/6/23 08:53, Arthur Grillo wrote:
> 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 <arthurgrillo@riseup.net>
> ---
>   drivers/gpu/drm/tests/drm_rect_test.c | 59 +++++++++++++++++++++++++++
>   1 file changed, 59 insertions(+)
> 
> diff --git a/drivers/gpu/drm/tests/drm_rect_test.c b/drivers/gpu/drm/tests/drm_rect_test.c
> index 44150545c1bc..a1fd9b2c5128 100644
> --- a/drivers/gpu/drm/tests/drm_rect_test.c
> +++ b/drivers/gpu/drm/tests/drm_rect_test.c
> @@ -414,6 +414,64 @@ static void drm_test_rect_calc_hscale(struct kunit *test)
>   	KUNIT_EXPECT_EQ(test, scaling_factor, params->expected_scaling_factor);
>   }
>   
> +static const struct drm_rect_scale_case drm_rect_vscale_cases[] = {
> +	{
> +		.name = "normal use",
> +		.src = DRM_RECT_INIT(0, 0, 0, 2 << 16),
> +		.dst = DRM_RECT_INIT(0, 0, 0, 1 << 16),
> +		.min_range = 0, .max_range = INT_MAX,
> +		.expected_scaling_factor = 2,
> +	},
> +	{
> +		.name = "out of max range",
> +		.src = DRM_RECT_INIT(0, 0, 0, 10 << 16),
> +		.dst = DRM_RECT_INIT(0, 0, 0, 1 << 16),
> +		.min_range = 3, .max_range = 5,
> +		.expected_scaling_factor = -ERANGE,
> +	},
> +	{
> +		.name = "out of min range",
> +		.src = DRM_RECT_INIT(0, 0, 0, 2 << 16),
> +		.dst = DRM_RECT_INIT(0, 0, 0, 1 << 16),
> +		.min_range = 3, .max_range = 5,
> +		.expected_scaling_factor = -ERANGE,
> +	},
> +	{
> +		.name = "zero dst height",
> +		.src = DRM_RECT_INIT(0, 0, 0, 2 << 16),
> +		.dst = DRM_RECT_INIT(0, 0, 0, 0 << 16),
> +		.min_range = 0, .max_range = INT_MAX,
> +		.expected_scaling_factor = 0,
> +	},
> +	{
> +		.name = "negative src height",
> +		.src = DRM_RECT_INIT(0, 0, 0, -(1 << 16)),
> +		.dst = DRM_RECT_INIT(0, 0, 0, 1 << 16),
> +		.min_range = 0, .max_range = INT_MAX,
> +		.expected_scaling_factor = -EINVAL,
> +	},
> +	{
> +		.name = "negative dst height",
> +		.src = DRM_RECT_INIT(0, 0, 0, 1 << 16),
> +		.dst = DRM_RECT_INIT(0, 0, 0, -(1 << 16)),
> +		.min_range = 0, .max_range = INT_MAX,
> +		.expected_scaling_factor = -EINVAL,
> +	},
> +};
> +

Would it possible to use the same parameter array for vscale and hscale?

Best Regards,
- Maíra Canal

> +KUNIT_ARRAY_PARAM(drm_rect_vscale, drm_rect_vscale_cases, drm_rect_scale_case_desc);
> +
> +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(&params->src, &params->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 +479,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_hscale_gen_params),
> +	KUNIT_CASE_PARAM(drm_test_rect_calc_vscale, drm_rect_vscale_gen_params),
>   	{ }
>   };
>
Arthur Grillo April 18, 2023, 1:42 a.m. UTC | #2
On 17/04/23 13:19, Maíra Canal wrote:
> On 4/6/23 08:53, Arthur Grillo wrote:
>> 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 <arthurgrillo@riseup.net>
>> ---
>>   drivers/gpu/drm/tests/drm_rect_test.c | 59 +++++++++++++++++++++++++++
>>   1 file changed, 59 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/tests/drm_rect_test.c b/drivers/gpu/drm/tests/drm_rect_test.c
>> index 44150545c1bc..a1fd9b2c5128 100644
>> --- a/drivers/gpu/drm/tests/drm_rect_test.c
>> +++ b/drivers/gpu/drm/tests/drm_rect_test.c
>> @@ -414,6 +414,64 @@ static void drm_test_rect_calc_hscale(struct kunit *test)
>>       KUNIT_EXPECT_EQ(test, scaling_factor, params->expected_scaling_factor);
>>   }
>>   +static const struct drm_rect_scale_case drm_rect_vscale_cases[] = {
>> +    {
>> +        .name = "normal use",
>> +        .src = DRM_RECT_INIT(0, 0, 0, 2 << 16),
>> +        .dst = DRM_RECT_INIT(0, 0, 0, 1 << 16),
>> +        .min_range = 0, .max_range = INT_MAX,
>> +        .expected_scaling_factor = 2,
>> +    },
>> +    {
>> +        .name = "out of max range",
>> +        .src = DRM_RECT_INIT(0, 0, 0, 10 << 16),
>> +        .dst = DRM_RECT_INIT(0, 0, 0, 1 << 16),
>> +        .min_range = 3, .max_range = 5,
>> +        .expected_scaling_factor = -ERANGE,
>> +    },
>> +    {
>> +        .name = "out of min range",
>> +        .src = DRM_RECT_INIT(0, 0, 0, 2 << 16),
>> +        .dst = DRM_RECT_INIT(0, 0, 0, 1 << 16),
>> +        .min_range = 3, .max_range = 5,
>> +        .expected_scaling_factor = -ERANGE,
>> +    },
>> +    {
>> +        .name = "zero dst height",
>> +        .src = DRM_RECT_INIT(0, 0, 0, 2 << 16),
>> +        .dst = DRM_RECT_INIT(0, 0, 0, 0 << 16),
>> +        .min_range = 0, .max_range = INT_MAX,
>> +        .expected_scaling_factor = 0,
>> +    },
>> +    {
>> +        .name = "negative src height",
>> +        .src = DRM_RECT_INIT(0, 0, 0, -(1 << 16)),
>> +        .dst = DRM_RECT_INIT(0, 0, 0, 1 << 16),
>> +        .min_range = 0, .max_range = INT_MAX,
>> +        .expected_scaling_factor = -EINVAL,
>> +    },
>> +    {
>> +        .name = "negative dst height",
>> +        .src = DRM_RECT_INIT(0, 0, 0, 1 << 16),
>> +        .dst = DRM_RECT_INIT(0, 0, 0, -(1 << 16)),
>> +        .min_range = 0, .max_range = INT_MAX,
>> +        .expected_scaling_factor = -EINVAL,
>> +    },
>> +};
>> +
> 
> Would it possible to use the same parameter array for vscale and hscale?
> 
> Best Regards,
> - Maíra Canal
> 

Instead of having drm_rect directly, I could create an src and dst
length. Or maybe have drm_rects that increase on both sizes.

Regards,
~Arthur Grillo

>> +KUNIT_ARRAY_PARAM(drm_rect_vscale, drm_rect_vscale_cases, drm_rect_scale_case_desc);
>> +
>> +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(&params->src, &params->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 +479,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_hscale_gen_params),
>> +    KUNIT_CASE_PARAM(drm_test_rect_calc_vscale, drm_rect_vscale_gen_params),
>>       { }
>>   };
>>
Maíra Canal April 18, 2023, 9:35 a.m. UTC | #3
On 4/17/23 22:42, Arthur Grillo Queiroz Cabral wrote:
> 
> 
> On 17/04/23 13:19, Maíra Canal wrote:
>> On 4/6/23 08:53, Arthur Grillo wrote:
>>> 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 <arthurgrillo@riseup.net>
>>> ---
>>>    drivers/gpu/drm/tests/drm_rect_test.c | 59 +++++++++++++++++++++++++++
>>>    1 file changed, 59 insertions(+)
>>>
>>> diff --git a/drivers/gpu/drm/tests/drm_rect_test.c b/drivers/gpu/drm/tests/drm_rect_test.c
>>> index 44150545c1bc..a1fd9b2c5128 100644
>>> --- a/drivers/gpu/drm/tests/drm_rect_test.c
>>> +++ b/drivers/gpu/drm/tests/drm_rect_test.c
>>> @@ -414,6 +414,64 @@ static void drm_test_rect_calc_hscale(struct kunit *test)
>>>        KUNIT_EXPECT_EQ(test, scaling_factor, params->expected_scaling_factor);
>>>    }
>>>    +static const struct drm_rect_scale_case drm_rect_vscale_cases[] = {
>>> +    {
>>> +        .name = "normal use",
>>> +        .src = DRM_RECT_INIT(0, 0, 0, 2 << 16),
>>> +        .dst = DRM_RECT_INIT(0, 0, 0, 1 << 16),
>>> +        .min_range = 0, .max_range = INT_MAX,
>>> +        .expected_scaling_factor = 2,
>>> +    },
>>> +    {
>>> +        .name = "out of max range",
>>> +        .src = DRM_RECT_INIT(0, 0, 0, 10 << 16),
>>> +        .dst = DRM_RECT_INIT(0, 0, 0, 1 << 16),
>>> +        .min_range = 3, .max_range = 5,
>>> +        .expected_scaling_factor = -ERANGE,
>>> +    },
>>> +    {
>>> +        .name = "out of min range",
>>> +        .src = DRM_RECT_INIT(0, 0, 0, 2 << 16),
>>> +        .dst = DRM_RECT_INIT(0, 0, 0, 1 << 16),
>>> +        .min_range = 3, .max_range = 5,
>>> +        .expected_scaling_factor = -ERANGE,
>>> +    },
>>> +    {
>>> +        .name = "zero dst height",
>>> +        .src = DRM_RECT_INIT(0, 0, 0, 2 << 16),
>>> +        .dst = DRM_RECT_INIT(0, 0, 0, 0 << 16),
>>> +        .min_range = 0, .max_range = INT_MAX,
>>> +        .expected_scaling_factor = 0,
>>> +    },
>>> +    {
>>> +        .name = "negative src height",
>>> +        .src = DRM_RECT_INIT(0, 0, 0, -(1 << 16)),
>>> +        .dst = DRM_RECT_INIT(0, 0, 0, 1 << 16),
>>> +        .min_range = 0, .max_range = INT_MAX,
>>> +        .expected_scaling_factor = -EINVAL,
>>> +    },
>>> +    {
>>> +        .name = "negative dst height",
>>> +        .src = DRM_RECT_INIT(0, 0, 0, 1 << 16),
>>> +        .dst = DRM_RECT_INIT(0, 0, 0, -(1 << 16)),
>>> +        .min_range = 0, .max_range = INT_MAX,
>>> +        .expected_scaling_factor = -EINVAL,
>>> +    },
>>> +};
>>> +
>>
>> Would it possible to use the same parameter array for vscale and hscale?
>>
>> Best Regards,
>> - Maíra Canal
>>
> 
> Instead of having drm_rect directly, I could create an src and dst
> length. Or maybe have drm_rects that increase on both sizes.

I believe that any of those options would be okay. Thanks for improving the
tests!

Best Regards,
- Maíra Canal

> 
> Regards,
> ~Arthur Grillo
> 
>>> +KUNIT_ARRAY_PARAM(drm_rect_vscale, drm_rect_vscale_cases, drm_rect_scale_case_desc);
>>> +
>>> +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(&params->src, &params->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 +479,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_hscale_gen_params),
>>> +    KUNIT_CASE_PARAM(drm_test_rect_calc_vscale, drm_rect_vscale_gen_params),
>>>        { }
>>>    };
>>>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/tests/drm_rect_test.c b/drivers/gpu/drm/tests/drm_rect_test.c
index 44150545c1bc..a1fd9b2c5128 100644
--- a/drivers/gpu/drm/tests/drm_rect_test.c
+++ b/drivers/gpu/drm/tests/drm_rect_test.c
@@ -414,6 +414,64 @@  static void drm_test_rect_calc_hscale(struct kunit *test)
 	KUNIT_EXPECT_EQ(test, scaling_factor, params->expected_scaling_factor);
 }
 
+static const struct drm_rect_scale_case drm_rect_vscale_cases[] = {
+	{
+		.name = "normal use",
+		.src = DRM_RECT_INIT(0, 0, 0, 2 << 16),
+		.dst = DRM_RECT_INIT(0, 0, 0, 1 << 16),
+		.min_range = 0, .max_range = INT_MAX,
+		.expected_scaling_factor = 2,
+	},
+	{
+		.name = "out of max range",
+		.src = DRM_RECT_INIT(0, 0, 0, 10 << 16),
+		.dst = DRM_RECT_INIT(0, 0, 0, 1 << 16),
+		.min_range = 3, .max_range = 5,
+		.expected_scaling_factor = -ERANGE,
+	},
+	{
+		.name = "out of min range",
+		.src = DRM_RECT_INIT(0, 0, 0, 2 << 16),
+		.dst = DRM_RECT_INIT(0, 0, 0, 1 << 16),
+		.min_range = 3, .max_range = 5,
+		.expected_scaling_factor = -ERANGE,
+	},
+	{
+		.name = "zero dst height",
+		.src = DRM_RECT_INIT(0, 0, 0, 2 << 16),
+		.dst = DRM_RECT_INIT(0, 0, 0, 0 << 16),
+		.min_range = 0, .max_range = INT_MAX,
+		.expected_scaling_factor = 0,
+	},
+	{
+		.name = "negative src height",
+		.src = DRM_RECT_INIT(0, 0, 0, -(1 << 16)),
+		.dst = DRM_RECT_INIT(0, 0, 0, 1 << 16),
+		.min_range = 0, .max_range = INT_MAX,
+		.expected_scaling_factor = -EINVAL,
+	},
+	{
+		.name = "negative dst height",
+		.src = DRM_RECT_INIT(0, 0, 0, 1 << 16),
+		.dst = DRM_RECT_INIT(0, 0, 0, -(1 << 16)),
+		.min_range = 0, .max_range = INT_MAX,
+		.expected_scaling_factor = -EINVAL,
+	},
+};
+
+KUNIT_ARRAY_PARAM(drm_rect_vscale, drm_rect_vscale_cases, drm_rect_scale_case_desc);
+
+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(&params->src, &params->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 +479,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_hscale_gen_params),
+	KUNIT_CASE_PARAM(drm_test_rect_calc_vscale, drm_rect_vscale_gen_params),
 	{ }
 };