diff mbox series

[1/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb888()

Message ID 20220816102903.276879-2-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 Aug. 16, 2022, 10:29 a.m. UTC
Extend the existing test cases to test the conversion from XRGB8888 to
RGB888.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
---
 .../gpu/drm/tests/drm_format_helper_test.c    | 65 +++++++++++++++++++
 1 file changed, 65 insertions(+)

Comments

David Gow Aug. 17, 2022, 6:34 a.m. UTC | #1
On Tue, Aug 16, 2022 at 6:29 PM José Expósito <jose.exposito89@gmail.com> wrote:
>
> Extend the existing test cases to test the conversion from XRGB8888 to
> RGB888.
>
> Signed-off-by: José Expósito <jose.exposito89@gmail.com>
> ---

On the whole, this looks good to me. I'd like to see these tests use
KUNIT_EXPECT_MEMEQ(), but that might have to wait.

One other nitpick below, but otherwise:
Reviewed-by: David Gow <davidgow@google.com>

Cheers,
-- David

>  .../gpu/drm/tests/drm_format_helper_test.c    | 65 +++++++++++++++++++
>  1 file changed, 65 insertions(+)
>
> diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c
> index 828487071796..08d08e7ab19a 100644
> --- a/drivers/gpu/drm/tests/drm_format_helper_test.c
> +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
> @@ -27,6 +27,11 @@ struct convert_to_rgb565_result {
>         const u16 expected_swab[TEST_BUF_SIZE];
>  };
>
> +struct convert_to_rgb888_result {
> +       unsigned int dst_pitch;
> +       const u8 expected[TEST_BUF_SIZE];

Could this maybe be 3*TEST_BUF_SIZE? That should match the other,
existing formats, which have room for TEST_BUF_SIZE pixels worth of
data, not TEST_BUF_SIZE bytes.


> +};
> +
>  struct convert_xrgb8888_case {
>         const char *name;
>         unsigned int pitch;
> @@ -34,6 +39,7 @@ struct convert_xrgb8888_case {
>         const u32 xrgb8888[TEST_BUF_SIZE];
>         struct convert_to_rgb332_result rgb332_result;
>         struct convert_to_rgb565_result rgb565_result;
> +       struct convert_to_rgb888_result rgb888_result;
>  };
>
>  static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
> @@ -51,6 +57,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
>                         .expected = { 0xF800 },
>                         .expected_swab = { 0x00F8 },
>                 },
> +               .rgb888_result = {
> +                       .dst_pitch = 0,
> +                       .expected = { 0x00, 0x00, 0xFF },
> +               },
>         },
>         {
>                 .name = "single_pixel_clip_rectangle",
> @@ -69,6 +79,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
>                         .expected = { 0xF800 },
>                         .expected_swab = { 0x00F8 },
>                 },
> +               .rgb888_result = {
> +                       .dst_pitch = 0,
> +                       .expected = { 0x00, 0x00, 0xFF },
> +               },
>         },
>         {
>                 /* Well known colors: White, black, red, green, blue, magenta,
> @@ -109,6 +123,15 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
>                                 0xE0FF, 0xFF07,
>                         },
>                 },
> +               .rgb888_result = {
> +                       .dst_pitch = 0,
> +                       .expected = {
> +                               0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
> +                               0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00,
> +                               0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF,
> +                               0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
> +                       },
> +               },
>         },
>         {
>                 /* Randomly picked colors. Full buffer within the clip area. */
> @@ -141,6 +164,17 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
>                                 0x00A8, 0x8E6B, 0x330A, 0x0000, 0x0000,
>                         },
>                 },
> +               .rgb888_result = {
> +                       .dst_pitch = 15,
> +                       .expected = {
> +                               0x9C, 0x44, 0x0E, 0x05, 0x4D, 0x11, 0x03, 0x03, 0xA8,
> +                               0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> +                               0x73, 0x70, 0x6C, 0x9C, 0x44, 0x0E, 0x05, 0x4D, 0x11,
> +                               0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> +                               0x03, 0x03, 0xA8, 0x73, 0x70, 0x6C, 0x9C, 0x44, 0x0E,
> +                               0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> +                       },
> +               },
>         },
>  };
>
> @@ -255,9 +289,40 @@ static void xrgb8888_to_rgb565_test(struct kunit *test)
>         KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected_swab, dst_size), 0);
>  }
>
> +static void xrgb8888_to_rgb888_test(struct kunit *test)
> +{
> +       const struct convert_xrgb8888_case *params = test->param_value;
> +       const struct convert_to_rgb888_result *result = &params->rgb888_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_RGB888, 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_rgb888(&dst, &result->dst_pitch, &src, &fb, &params->clip);
> +       KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0);

At some point, this should use KUNIT_EXPECT_MEMEQ() rather than
KUNIT_EXPECT_EQ(..., memcmp(...), 0):
https://lore.kernel.org/all/20220808125237.277126-1-mairacanal@riseup.net/

Of course, since that's not upstream yet (and  probably will go in via
a different tree), it's fine to leave this as-is in this patch, and
tidy it up after they're merged.

> +}
> +
>  static struct kunit_case drm_format_helper_test_cases[] = {
>         KUNIT_CASE_PARAM(xrgb8888_to_rgb332_test, convert_xrgb8888_gen_params),
>         KUNIT_CASE_PARAM(xrgb8888_to_rgb565_test, convert_xrgb8888_gen_params),
> +       KUNIT_CASE_PARAM(xrgb8888_to_rgb888_test, convert_xrgb8888_gen_params),
>         {}
>  };
>
> --
> 2.25.1
>
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 828487071796..08d08e7ab19a 100644
--- a/drivers/gpu/drm/tests/drm_format_helper_test.c
+++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
@@ -27,6 +27,11 @@  struct convert_to_rgb565_result {
 	const u16 expected_swab[TEST_BUF_SIZE];
 };
 
+struct convert_to_rgb888_result {
+	unsigned int dst_pitch;
+	const u8 expected[TEST_BUF_SIZE];
+};
+
 struct convert_xrgb8888_case {
 	const char *name;
 	unsigned int pitch;
@@ -34,6 +39,7 @@  struct convert_xrgb8888_case {
 	const u32 xrgb8888[TEST_BUF_SIZE];
 	struct convert_to_rgb332_result rgb332_result;
 	struct convert_to_rgb565_result rgb565_result;
+	struct convert_to_rgb888_result rgb888_result;
 };
 
 static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
@@ -51,6 +57,10 @@  static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
 			.expected = { 0xF800 },
 			.expected_swab = { 0x00F8 },
 		},
+		.rgb888_result = {
+			.dst_pitch = 0,
+			.expected = { 0x00, 0x00, 0xFF },
+		},
 	},
 	{
 		.name = "single_pixel_clip_rectangle",
@@ -69,6 +79,10 @@  static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
 			.expected = { 0xF800 },
 			.expected_swab = { 0x00F8 },
 		},
+		.rgb888_result = {
+			.dst_pitch = 0,
+			.expected = { 0x00, 0x00, 0xFF },
+		},
 	},
 	{
 		/* Well known colors: White, black, red, green, blue, magenta,
@@ -109,6 +123,15 @@  static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
 				0xE0FF, 0xFF07,
 			},
 		},
+		.rgb888_result = {
+			.dst_pitch = 0,
+			.expected = {
+				0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
+				0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00,
+				0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF,
+				0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
+			},
+		},
 	},
 	{
 		/* Randomly picked colors. Full buffer within the clip area. */
@@ -141,6 +164,17 @@  static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
 				0x00A8, 0x8E6B, 0x330A, 0x0000, 0x0000,
 			},
 		},
+		.rgb888_result = {
+			.dst_pitch = 15,
+			.expected = {
+				0x9C, 0x44, 0x0E, 0x05, 0x4D, 0x11, 0x03, 0x03, 0xA8,
+				0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+				0x73, 0x70, 0x6C, 0x9C, 0x44, 0x0E, 0x05, 0x4D, 0x11,
+				0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+				0x03, 0x03, 0xA8, 0x73, 0x70, 0x6C, 0x9C, 0x44, 0x0E,
+				0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			},
+		},
 	},
 };
 
@@ -255,9 +289,40 @@  static void xrgb8888_to_rgb565_test(struct kunit *test)
 	KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected_swab, dst_size), 0);
 }
 
+static void xrgb8888_to_rgb888_test(struct kunit *test)
+{
+	const struct convert_xrgb8888_case *params = test->param_value;
+	const struct convert_to_rgb888_result *result = &params->rgb888_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_RGB888, 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_rgb888(&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(xrgb8888_to_rgb332_test, convert_xrgb8888_gen_params),
 	KUNIT_CASE_PARAM(xrgb8888_to_rgb565_test, convert_xrgb8888_gen_params),
+	KUNIT_CASE_PARAM(xrgb8888_to_rgb888_test, convert_xrgb8888_gen_params),
 	{}
 };