diff mbox series

[v4,3/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_gray8()

Message ID 20220919071531.105124-4-jose.exposito89@gmail.com (mailing list archive)
State New, archived
Headers show
Series KUnit tests for RGB888, XRGB2101010 and grayscale | expand

Commit Message

José Expósito Sept. 19, 2022, 7:15 a.m. UTC
Extend the existing test cases to test the conversion from XRGB8888 to
grayscale.

Tested-by: Maíra Canal <mairacanal@riseup.net>
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
---
 .../gpu/drm/tests/drm_format_helper_test.c    | 62 +++++++++++++++++++
 1 file changed, 62 insertions(+)

Comments

Maxime Ripard Sept. 19, 2022, 7:36 a.m. UTC | #1
Hi,

On Mon, Sep 19, 2022 at 09:15:31AM +0200, José Expósito wrote:
> Extend the existing test cases to test the conversion from XRGB8888 to
> grayscale.
> 
> Tested-by: Maíra Canal <mairacanal@riseup.net>
> Reviewed-by: David Gow <davidgow@google.com>
> Signed-off-by: José Expósito <jose.exposito89@gmail.com>
> ---
>  .../gpu/drm/tests/drm_format_helper_test.c    | 62 +++++++++++++++++++
>  1 file changed, 62 insertions(+)
> 
> diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c
> index 09d358b54da0..71722e828abe 100644
> --- a/drivers/gpu/drm/tests/drm_format_helper_test.c
> +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
> @@ -37,6 +37,11 @@ struct convert_to_xrgb2101010_result {
>  	const u32 expected[TEST_BUF_SIZE];
>  };
>  
> +struct convert_to_gray8_result {
> +	unsigned int dst_pitch;
> +	const u8 expected[TEST_BUF_SIZE];
> +};
> +
>  struct convert_xrgb8888_case {
>  	const char *name;
>  	unsigned int pitch;
> @@ -46,6 +51,7 @@ struct convert_xrgb8888_case {
>  	struct convert_to_rgb565_result rgb565_result;
>  	struct convert_to_rgb888_result rgb888_result;
>  	struct convert_to_xrgb2101010_result xrgb2101010_result;
> +	struct convert_to_gray8_result gray8_result;
>  };
>  
>  static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
> @@ -71,6 +77,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
>  			.dst_pitch = 0,
>  			.expected = { 0x3FF00000 },
>  		},
> +		.gray8_result = {
> +			.dst_pitch = 0,
> +			.expected = { 0x4C },
> +		},
>  	},
>  	{
>  		.name = "single_pixel_clip_rectangle",
> @@ -97,6 +107,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
>  			.dst_pitch = 0,
>  			.expected = { 0x3FF00000 },
>  		},
> +		.gray8_result = {
> +			.dst_pitch = 0,
> +			.expected = { 0x4C },
> +		},
>  	},
>  	{
>  		/* Well known colors: White, black, red, green, blue, magenta,
> @@ -155,6 +169,15 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
>  				0x3FFFFC00, 0x000FFFFF,
>  			},
>  		},
> +		.gray8_result = {
> +			.dst_pitch = 0,
> +			.expected = {
> +				0xFF, 0x00,
> +				0x4C, 0x99,
> +				0x19, 0x66,
> +				0xE5, 0xB2,
> +			},
> +		},
>  	},
>  	{
>  		/* Randomly picked colors. Full buffer within the clip area. */
> @@ -206,6 +229,14 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
>  				0x2A20300C, 0x1B1705CD, 0x03844672, 0x00000000, 0x00000000,
>  			},
>  		},
> +		.gray8_result = {
> +			.dst_pitch = 5,
> +			.expected = {
> +				0x3C, 0x33, 0x34, 0x00, 0x00,
> +				0x6F, 0x3C, 0x33, 0x00, 0x00,
> +				0x34, 0x6F, 0x3C, 0x00, 0x00,
> +			},
> +		},
>  	},
>  };
>  
> @@ -381,11 +412,42 @@ static void drm_test_fb_xrgb8888_to_xrgb2101010_test(struct kunit *test)
>  	KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0);
>  }
>  
> +static void drm_test_fb_xrgb8888_to_gray8_test(struct kunit *test)
> +{
> +	const struct convert_xrgb8888_case *params = test->param_value;
> +	const struct convert_to_gray8_result *result = &params->gray8_result;
> +	size_t dst_size;
> +	__u8 *buf = NULL;
> +	__u32 *xrgb8888 = NULL;
> +	struct iosys_map dst, src;
> +
> +	struct drm_framebuffer fb = {
> +		.format = drm_format_info(DRM_FORMAT_XRGB8888),
> +		.pitches = { params->pitch, 0, 0 },
> +	};
> +
> +	dst_size = conversion_buf_size(DRM_FORMAT_R8, result->dst_pitch,
> +				       &params->clip);
> +	KUNIT_ASSERT_GT(test, dst_size, 0);
> +
> +	buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
> +	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
> +	iosys_map_set_vaddr(&dst, buf);
> +
> +	xrgb8888 = le32buf_to_cpu(test, params->xrgb8888, TEST_BUF_SIZE);
> +	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
> +	iosys_map_set_vaddr(&src, xrgb8888);
> +
> +	drm_fb_xrgb8888_to_gray8(&dst, &result->dst_pitch, &src, &fb, &params->clip);
> +	KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0);
> +}
> +
>  static struct kunit_case drm_format_helper_test_cases[] = {
>  	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb332, convert_xrgb8888_gen_params),
>  	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb565, convert_xrgb8888_gen_params),
>  	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb888_test, convert_xrgb8888_gen_params),
>  	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_xrgb2101010_test, convert_xrgb8888_gen_params),
> +	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_gray8_test, convert_xrgb8888_gen_params),

The trailing test feels redundant, and we should order them
alphabetically to avoid conflicts as much as possible.

Feel free to add my
Acked-by: Maxime Ripard <maxime@cerno.tech>

And fix this while applying

Maxime
José Expósito Sept. 19, 2022, 8:18 a.m. UTC | #2
Hi Maxime,

Thanks for looking into the patches.

On Mon, Sep 19, 2022 at 09:36:45AM +0200, Maxime Ripard wrote:
> Hi,
> 
> On Mon, Sep 19, 2022 at 09:15:31AM +0200, José Expósito wrote:
> > Extend the existing test cases to test the conversion from XRGB8888 to
> > grayscale.
> > 
> > Tested-by: Maíra Canal <mairacanal@riseup.net>
> > Reviewed-by: David Gow <davidgow@google.com>
> > Signed-off-by: José Expósito <jose.exposito89@gmail.com>
> > ---
> >  .../gpu/drm/tests/drm_format_helper_test.c    | 62 +++++++++++++++++++
> >  1 file changed, 62 insertions(+)
> > 
> > diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c
> > index 09d358b54da0..71722e828abe 100644
> > --- a/drivers/gpu/drm/tests/drm_format_helper_test.c
> > +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
> > @@ -37,6 +37,11 @@ struct convert_to_xrgb2101010_result {
> >  	const u32 expected[TEST_BUF_SIZE];
> >  };
> >  
> > +struct convert_to_gray8_result {
> > +	unsigned int dst_pitch;
> > +	const u8 expected[TEST_BUF_SIZE];
> > +};
> > +
> >
> > [...]
> >
> >  static struct kunit_case drm_format_helper_test_cases[] = {
> >  	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb332, convert_xrgb8888_gen_params),
> >  	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb565, convert_xrgb8888_gen_params),
> >  	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb888_test, convert_xrgb8888_gen_params),
> >  	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_xrgb2101010_test, convert_xrgb8888_gen_params),
> > +	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_gray8_test, convert_xrgb8888_gen_params),
> 
> The trailing test feels redundant,

Why do you feel like it is redundant? Under the hood, most conversion
functions reuse the same code, but the *_line() function is unique and
I think that it is worth testing it.

> and we should order them
> alphabetically to avoid conflicts as much as possible.

Good point, I'll sort them alphabetically.

> Feel free to add my
> Acked-by: Maxime Ripard <maxime@cerno.tech>
> 
> And fix this while applying
> 
> Maxime

Thanks!
Jose
Maxime Ripard Sept. 19, 2022, 8:25 a.m. UTC | #3
On Mon, Sep 19, 2022 at 10:18:01AM +0200, José Expósito wrote:
> Hi Maxime,
> 
> Thanks for looking into the patches.
> 
> On Mon, Sep 19, 2022 at 09:36:45AM +0200, Maxime Ripard wrote:
> > Hi,
> > 
> > On Mon, Sep 19, 2022 at 09:15:31AM +0200, José Expósito wrote:
> > > Extend the existing test cases to test the conversion from XRGB8888 to
> > > grayscale.
> > > 
> > > Tested-by: Maíra Canal <mairacanal@riseup.net>
> > > Reviewed-by: David Gow <davidgow@google.com>
> > > Signed-off-by: José Expósito <jose.exposito89@gmail.com>
> > > ---
> > >  .../gpu/drm/tests/drm_format_helper_test.c    | 62 +++++++++++++++++++
> > >  1 file changed, 62 insertions(+)
> > > 
> > > diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c
> > > index 09d358b54da0..71722e828abe 100644
> > > --- a/drivers/gpu/drm/tests/drm_format_helper_test.c
> > > +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
> > > @@ -37,6 +37,11 @@ struct convert_to_xrgb2101010_result {
> > >  	const u32 expected[TEST_BUF_SIZE];
> > >  };
> > >  
> > > +struct convert_to_gray8_result {
> > > +	unsigned int dst_pitch;
> > > +	const u8 expected[TEST_BUF_SIZE];
> > > +};
> > > +
> > >
> > > [...]
> > >
> > >  static struct kunit_case drm_format_helper_test_cases[] = {
> > >  	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb332, convert_xrgb8888_gen_params),
> > >  	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb565, convert_xrgb8888_gen_params),
> > >  	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb888_test, convert_xrgb8888_gen_params),
> > >  	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_xrgb2101010_test, convert_xrgb8888_gen_params),
> > > +	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_gray8_test, convert_xrgb8888_gen_params),
> > 
> > The trailing test feels redundant,
> 
> Why do you feel like it is redundant? Under the hood, most conversion
> functions reuse the same code, but the *_line() function is unique and
> I think that it is worth testing it.

Sure, I wasn't commenting on the code itself, but the trailing "test" in
the test name: drm_test_fb_xrgb8888_to_gray8_test
                                             ^

Which is redundant since we already have "test" in the prefix.

Maxime
José Expósito Sept. 19, 2022, 8:29 a.m. UTC | #4
On Mon, Sep 19, 2022 at 10:25:19AM +0200, Maxime Ripard wrote:
> On Mon, Sep 19, 2022 at 10:18:01AM +0200, José Expósito wrote:
> > Hi Maxime,
> > 
> > Thanks for looking into the patches.
> > 
> > On Mon, Sep 19, 2022 at 09:36:45AM +0200, Maxime Ripard wrote:
> > > Hi,
> > > 
> > > On Mon, Sep 19, 2022 at 09:15:31AM +0200, José Expósito wrote:
> > > > Extend the existing test cases to test the conversion from XRGB8888 to
> > > > grayscale.
> > > > 
> > > > Tested-by: Maíra Canal <mairacanal@riseup.net>
> > > > Reviewed-by: David Gow <davidgow@google.com>
> > > > Signed-off-by: José Expósito <jose.exposito89@gmail.com>
> > > > ---
> > > >  .../gpu/drm/tests/drm_format_helper_test.c    | 62 +++++++++++++++++++
> > > >  1 file changed, 62 insertions(+)
> > > > 
> > > > diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c
> > > > index 09d358b54da0..71722e828abe 100644
> > > > --- a/drivers/gpu/drm/tests/drm_format_helper_test.c
> > > > +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
> > > > @@ -37,6 +37,11 @@ struct convert_to_xrgb2101010_result {
> > > >  	const u32 expected[TEST_BUF_SIZE];
> > > >  };
> > > >  
> > > > +struct convert_to_gray8_result {
> > > > +	unsigned int dst_pitch;
> > > > +	const u8 expected[TEST_BUF_SIZE];
> > > > +};
> > > > +
> > > >
> > > > [...]
> > > >
> > > >  static struct kunit_case drm_format_helper_test_cases[] = {
> > > >  	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb332, convert_xrgb8888_gen_params),
> > > >  	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb565, convert_xrgb8888_gen_params),
> > > >  	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb888_test, convert_xrgb8888_gen_params),
> > > >  	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_xrgb2101010_test, convert_xrgb8888_gen_params),
> > > > +	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_gray8_test, convert_xrgb8888_gen_params),
> > > 
> > > The trailing test feels redundant,
> > 
> > Why do you feel like it is redundant? Under the hood, most conversion
> > functions reuse the same code, but the *_line() function is unique and
> > I think that it is worth testing it.
> 
> Sure, I wasn't commenting on the code itself, but the trailing "test" in
> the test name: drm_test_fb_xrgb8888_to_gray8_test
>                                              ^
> 
> Which is redundant since we already have "test" in the prefix.
> 
> Maxime

Ah! OK, I misunderstood your first sentence. Indeed, the _test sufix
should be removed, added to my TODO list.

Thanks!!
diff mbox series

Patch

diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c
index 09d358b54da0..71722e828abe 100644
--- a/drivers/gpu/drm/tests/drm_format_helper_test.c
+++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
@@ -37,6 +37,11 @@  struct convert_to_xrgb2101010_result {
 	const u32 expected[TEST_BUF_SIZE];
 };
 
+struct convert_to_gray8_result {
+	unsigned int dst_pitch;
+	const u8 expected[TEST_BUF_SIZE];
+};
+
 struct convert_xrgb8888_case {
 	const char *name;
 	unsigned int pitch;
@@ -46,6 +51,7 @@  struct convert_xrgb8888_case {
 	struct convert_to_rgb565_result rgb565_result;
 	struct convert_to_rgb888_result rgb888_result;
 	struct convert_to_xrgb2101010_result xrgb2101010_result;
+	struct convert_to_gray8_result gray8_result;
 };
 
 static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
@@ -71,6 +77,10 @@  static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
 			.dst_pitch = 0,
 			.expected = { 0x3FF00000 },
 		},
+		.gray8_result = {
+			.dst_pitch = 0,
+			.expected = { 0x4C },
+		},
 	},
 	{
 		.name = "single_pixel_clip_rectangle",
@@ -97,6 +107,10 @@  static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
 			.dst_pitch = 0,
 			.expected = { 0x3FF00000 },
 		},
+		.gray8_result = {
+			.dst_pitch = 0,
+			.expected = { 0x4C },
+		},
 	},
 	{
 		/* Well known colors: White, black, red, green, blue, magenta,
@@ -155,6 +169,15 @@  static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
 				0x3FFFFC00, 0x000FFFFF,
 			},
 		},
+		.gray8_result = {
+			.dst_pitch = 0,
+			.expected = {
+				0xFF, 0x00,
+				0x4C, 0x99,
+				0x19, 0x66,
+				0xE5, 0xB2,
+			},
+		},
 	},
 	{
 		/* Randomly picked colors. Full buffer within the clip area. */
@@ -206,6 +229,14 @@  static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
 				0x2A20300C, 0x1B1705CD, 0x03844672, 0x00000000, 0x00000000,
 			},
 		},
+		.gray8_result = {
+			.dst_pitch = 5,
+			.expected = {
+				0x3C, 0x33, 0x34, 0x00, 0x00,
+				0x6F, 0x3C, 0x33, 0x00, 0x00,
+				0x34, 0x6F, 0x3C, 0x00, 0x00,
+			},
+		},
 	},
 };
 
@@ -381,11 +412,42 @@  static void drm_test_fb_xrgb8888_to_xrgb2101010_test(struct kunit *test)
 	KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0);
 }
 
+static void drm_test_fb_xrgb8888_to_gray8_test(struct kunit *test)
+{
+	const struct convert_xrgb8888_case *params = test->param_value;
+	const struct convert_to_gray8_result *result = &params->gray8_result;
+	size_t dst_size;
+	__u8 *buf = NULL;
+	__u32 *xrgb8888 = NULL;
+	struct iosys_map dst, src;
+
+	struct drm_framebuffer fb = {
+		.format = drm_format_info(DRM_FORMAT_XRGB8888),
+		.pitches = { params->pitch, 0, 0 },
+	};
+
+	dst_size = conversion_buf_size(DRM_FORMAT_R8, result->dst_pitch,
+				       &params->clip);
+	KUNIT_ASSERT_GT(test, dst_size, 0);
+
+	buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
+	iosys_map_set_vaddr(&dst, buf);
+
+	xrgb8888 = le32buf_to_cpu(test, params->xrgb8888, TEST_BUF_SIZE);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
+	iosys_map_set_vaddr(&src, xrgb8888);
+
+	drm_fb_xrgb8888_to_gray8(&dst, &result->dst_pitch, &src, &fb, &params->clip);
+	KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0);
+}
+
 static struct kunit_case drm_format_helper_test_cases[] = {
 	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb332, convert_xrgb8888_gen_params),
 	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb565, convert_xrgb8888_gen_params),
 	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb888_test, convert_xrgb8888_gen_params),
 	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_xrgb2101010_test, convert_xrgb8888_gen_params),
+	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_gray8_test, convert_xrgb8888_gen_params),
 	{}
 };