diff mbox series

[v3,1/2] drm/format-helper: Add Kunit tests for drm_fb_xrgb8888_to_mono()

Message ID 20230311125141.564801-2-arthurgrillo@riseup.net (mailing list archive)
State New, archived
Headers show
Series drm/format-helper: Add Kunit tests for drm_fb_xrgb8888_to_mono() | expand

Commit Message

Arthur Grillo March 11, 2023, 12:51 p.m. UTC
Extend the existing test cases to test the conversion from XRGB8888 to
monochromatic.

Signed-off-by: Arthur Grillo <arthurgrillo@riseup.net>
---
 .../gpu/drm/tests/drm_format_helper_test.c    | 62 +++++++++++++++++++
 1 file changed, 62 insertions(+)

Comments

Javier Martinez Canillas March 14, 2023, 7:08 p.m. UTC | #1
Arthur Grillo <arthurgrillo@riseup.net> writes:

Hello Arthur,

> Extend the existing test cases to test the conversion from XRGB8888 to
> monochromatic.
>
> Signed-off-by: Arthur Grillo <arthurgrillo@riseup.net>
> ---

Patch looks good to me:

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>

Please let me know if you need someone to push this to the drm-misc tree.
Arthur Grillo March 14, 2023, 10:17 p.m. UTC | #2
Hello Javier,

On 14/03/23 16:08, Javier Martinez Canillas wrote:
> Arthur Grillo <arthurgrillo@riseup.net> writes:
> 
> Hello Arthur,
> 
>> Extend the existing test cases to test the conversion from XRGB8888 to
>> monochromatic.
>>
>> Signed-off-by: Arthur Grillo <arthurgrillo@riseup.net>
>> ---
> 
> Patch looks good to me:
> 
> Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
> 
> Please let me know if you need someone to push this to the drm-misc tree.
> 

It would be nice if you did, as I don't have commit rights on this tree.
Javier Martinez Canillas March 16, 2023, 8:04 p.m. UTC | #3
Arthur Grillo Queiroz Cabral <arthurgrillo@riseup.net> writes:

> Hello Javier,
>
> On 14/03/23 16:08, Javier Martinez Canillas wrote:
>> Arthur Grillo <arthurgrillo@riseup.net> writes:
>> 
>> Hello Arthur,
>> 
>>> Extend the existing test cases to test the conversion from XRGB8888 to
>>> monochromatic.
>>>
>>> Signed-off-by: Arthur Grillo <arthurgrillo@riseup.net>
>>> ---
>> 
>> Patch looks good to me:
>> 
>> Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
>> 
>> Please let me know if you need someone to push this to the drm-misc tree.
>> 
>
> It would be nice if you did, as I don't have commit rights on this tree.
>

Sure, pushed patch #1 and #2 to drm-misc (drm-misc-next). 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 84b5cc29c8fc..041b3d2f100f 100644
--- a/drivers/gpu/drm/tests/drm_format_helper_test.c
+++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
@@ -67,6 +67,11 @@  struct convert_to_argb2101010_result {
 	const u32 expected[TEST_BUF_SIZE];
 };
 
+struct convert_to_mono_result {
+	unsigned int dst_pitch;
+	const u8 expected[TEST_BUF_SIZE];
+};
+
 struct convert_xrgb8888_case {
 	const char *name;
 	unsigned int pitch;
@@ -82,6 +87,7 @@  struct convert_xrgb8888_case {
 	struct convert_to_argb8888_result argb8888_result;
 	struct convert_to_xrgb2101010_result xrgb2101010_result;
 	struct convert_to_argb2101010_result argb2101010_result;
+	struct convert_to_mono_result mono_result;
 };
 
 static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
@@ -131,6 +137,10 @@  static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
 			.dst_pitch = 0,
 			.expected = { 0xFFF00000 },
 		},
+		.mono_result = {
+			.dst_pitch = 0,
+			.expected = { 0b0 },
+		},
 	},
 	{
 		.name = "single_pixel_clip_rectangle",
@@ -181,6 +191,10 @@  static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
 			.dst_pitch = 0,
 			.expected = { 0xFFF00000 },
 		},
+		.mono_result = {
+			.dst_pitch = 0,
+			.expected = { 0b0 },
+		},
 	},
 	{
 		/* Well known colors: White, black, red, green, blue, magenta,
@@ -293,6 +307,15 @@  static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
 				0xFFFFFC00, 0xC00FFFFF,
 			},
 		},
+		.mono_result = {
+			.dst_pitch = 0,
+			.expected = {
+				0b01,
+				0b10,
+				0b00,
+				0b11,
+			},
+		},
 	},
 	{
 		/* Randomly picked colors. Full buffer within the clip area. */
@@ -392,6 +415,14 @@  static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
 				0xEA20300C, 0xDB1705CD, 0xC3844672, 0x00000000, 0x00000000,
 			},
 		},
+		.mono_result = {
+			.dst_pitch = 2,
+			.expected = {
+				0b000, 0b000,
+				0b000, 0b000,
+				0b000, 0b000,
+			},
+		},
 	},
 };
 
@@ -792,6 +823,36 @@  static void drm_test_fb_xrgb8888_to_argb2101010(struct kunit *test)
 	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
 }
 
+static void drm_test_fb_xrgb8888_to_mono(struct kunit *test)
+{
+	const struct convert_xrgb8888_case *params = test->param_value;
+	const struct convert_to_mono_result *result = &params->mono_result;
+	size_t dst_size;
+	u8 *buf = NULL;
+	__le32 *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_C1, 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 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
+	iosys_map_set_vaddr(&src, xrgb8888);
+
+	drm_fb_xrgb8888_to_mono(&dst, &result->dst_pitch, &src, &fb, &params->clip);
+	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
+}
+
 static struct kunit_case drm_format_helper_test_cases[] = {
 	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_gray8, convert_xrgb8888_gen_params),
 	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb332, convert_xrgb8888_gen_params),
@@ -803,6 +864,7 @@  static struct kunit_case drm_format_helper_test_cases[] = {
 	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_argb8888, convert_xrgb8888_gen_params),
 	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_xrgb2101010, convert_xrgb8888_gen_params),
 	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_argb2101010, convert_xrgb8888_gen_params),
+	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_mono, convert_xrgb8888_gen_params),
 	{}
 };