2022-08-16 11:24:17

by José Expósito

[permalink] [raw]
Subject: [PATCH 0/3] KUnit tests for RGB888, XRGB2101010 and grayscale

Hello everyone,

This series is a follow up on my work adding KUnit test to the XRGB8888
conversion functions. This time RGB888, XRGB2101010 and gray8 are added.

Best wishes,
Jose

José Expósito (3):
drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb888()
drm/format-helper: Add KUnit tests for
drm_fb_xrgb8888_to_xrgb2101010()
drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_gray8()

.../gpu/drm/tests/drm_format_helper_test.c | 190 ++++++++++++++++++
1 file changed, 190 insertions(+)

--
2.25.1


2022-08-16 11:25:30

by José Expósito

[permalink] [raw]
Subject: [PATCH 3/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_gray8()

Extend the existing test cases to test the conversion from XRGB8888 to
grayscale.

Signed-off-by: José Expósito <[email protected]>
---
.../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 d8536db4de1e..2f548aa51a30 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 xrgb8888_to_xrgb2101010_test(struct kunit *test)
KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0);
}

+static void 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(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),
KUNIT_CASE_PARAM(xrgb8888_to_xrgb2101010_test, convert_xrgb8888_gen_params),
+ KUNIT_CASE_PARAM(xrgb8888_to_gray8_test, convert_xrgb8888_gen_params),
{}
};

--
2.25.1

2022-08-16 11:44:18

by José Expósito

[permalink] [raw]
Subject: [PATCH 2/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_xrgb2101010()

Extend the existing test cases to test the conversion from XRGB8888 to
XRGB2101010.

Signed-off-by: José Expósito <[email protected]>
---
.../gpu/drm/tests/drm_format_helper_test.c | 63 +++++++++++++++++++
1 file changed, 63 insertions(+)

diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c
index 08d08e7ab19a..d8536db4de1e 100644
--- a/drivers/gpu/drm/tests/drm_format_helper_test.c
+++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
@@ -32,6 +32,11 @@ struct convert_to_rgb888_result {
const u8 expected[TEST_BUF_SIZE];
};

+struct convert_to_xrgb2101010_result {
+ unsigned int dst_pitch;
+ const u32 expected[TEST_BUF_SIZE];
+};
+
struct convert_xrgb8888_case {
const char *name;
unsigned int pitch;
@@ -40,6 +45,7 @@ struct convert_xrgb8888_case {
struct convert_to_rgb332_result rgb332_result;
struct convert_to_rgb565_result rgb565_result;
struct convert_to_rgb888_result rgb888_result;
+ struct convert_to_xrgb2101010_result xrgb2101010_result;
};

static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
@@ -61,6 +67,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
.dst_pitch = 0,
.expected = { 0x00, 0x00, 0xFF },
},
+ .xrgb2101010_result = {
+ .dst_pitch = 0,
+ .expected = { 0x3FF00000 },
+ },
},
{
.name = "single_pixel_clip_rectangle",
@@ -83,6 +93,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
.dst_pitch = 0,
.expected = { 0x00, 0x00, 0xFF },
},
+ .xrgb2101010_result = {
+ .dst_pitch = 0,
+ .expected = { 0x3FF00000 },
+ },
},
{
/* Well known colors: White, black, red, green, blue, magenta,
@@ -132,6 +146,15 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
},
},
+ .xrgb2101010_result = {
+ .dst_pitch = 0,
+ .expected = {
+ 0x3FFFFFFF, 0x00000000,
+ 0x3FF00000, 0x000FFC00,
+ 0x000003FF, 0x3FF003FF,
+ 0x3FFFFC00, 0x000FFFFF,
+ },
+ },
},
{
/* Randomly picked colors. Full buffer within the clip area. */
@@ -175,6 +198,14 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
},
+ .xrgb2101010_result = {
+ .dst_pitch = 20,
+ .expected = {
+ 0x03844672, 0x0444D414, 0x2A20300C, 0x00000000, 0x00000000,
+ 0x1B1705CD, 0x03844672, 0x0444D414, 0x00000000, 0x00000000,
+ 0x2A20300C, 0x1B1705CD, 0x03844672, 0x00000000, 0x00000000,
+ },
+ },
},
};

@@ -319,10 +350,42 @@ static void xrgb8888_to_rgb888_test(struct kunit *test)
KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0);
}

+static void xrgb8888_to_xrgb2101010_test(struct kunit *test)
+{
+ const struct convert_xrgb8888_case *params = test->param_value;
+ const struct convert_to_xrgb2101010_result *result = &params->xrgb2101010_result;
+ size_t dst_size;
+ __u32 *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_XRGB2101010,
+ 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_xrgb2101010(&dst, &result->dst_pitch, &src, &fb, &params->clip);
+ buf = le32buf_to_cpu(test, buf, TEST_BUF_SIZE);
+ 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),
+ KUNIT_CASE_PARAM(xrgb8888_to_xrgb2101010_test, convert_xrgb8888_gen_params),
{}
};

--
2.25.1

2022-08-16 11:50:54

by José Expósito

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

Extend the existing test cases to test the conversion from XRGB8888 to
RGB888.

Signed-off-by: José Expósito <[email protected]>
---
.../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];
+};
+
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),
{}
};

--
2.25.1

2022-08-16 13:55:09

by Maira Canal

[permalink] [raw]
Subject: Re: [PATCH 0/3] KUnit tests for RGB888, XRGB2101010 and grayscale

Hi José,

Tested the whole series on UML, x86, i386 and PPC. All looks fine!

Tested-by: Maíra Canal <[email protected]>

Best Regards,
- Maíra Canal

On 8/16/22 07:29, José Expósito wrote:
> Hello everyone,
>
> This series is a follow up on my work adding KUnit test to the XRGB8888
> conversion functions. This time RGB888, XRGB2101010 and gray8 are added.
>
> Best wishes,
> Jose
>
> José Expósito (3):
> drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb888()
> drm/format-helper: Add KUnit tests for
> drm_fb_xrgb8888_to_xrgb2101010()
> drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_gray8()
>
> .../gpu/drm/tests/drm_format_helper_test.c | 190 ++++++++++++++++++
> 1 file changed, 190 insertions(+)
>

2022-08-17 06:59:58

by David Gow

[permalink] [raw]
Subject: Re: [PATCH 3/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_gray8()

On Tue, Aug 16, 2022 at 6:29 PM José Expósito <[email protected]> wrote:
>
> Extend the existing test cases to test the conversion from XRGB8888 to
> grayscale.
>
> Signed-off-by: José Expósito <[email protected]>
> ---

This looks good to me as well. The grey8 conversion is a bit trickier
to eyeball due to ITU BT.601 giving the components different weights,
but it seems sensible and passes here.

Again, KUNIT_EXPECT_MEMEQ() will be nice one day, but shouldn't hold this up.

Reviewed-by: David Gow <[email protected]>

Cheers,
-- David

> .../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 d8536db4de1e..2f548aa51a30 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 xrgb8888_to_xrgb2101010_test(struct kunit *test)
> KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0);
> }
>
> +static void 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(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),
> KUNIT_CASE_PARAM(xrgb8888_to_xrgb2101010_test, convert_xrgb8888_gen_params),
> + KUNIT_CASE_PARAM(xrgb8888_to_gray8_test, convert_xrgb8888_gen_params),
> {}
> };
>
> --
> 2.25.1
>


Attachments:
smime.p7s (3.91 kB)
S/MIME Cryptographic Signature

2022-08-17 07:00:25

by David Gow

[permalink] [raw]
Subject: Re: [PATCH 2/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_xrgb2101010()

On Tue, Aug 16, 2022 at 6:29 PM José Expósito <[email protected]> wrote:
>
> Extend the existing test cases to test the conversion from XRGB8888 to
> XRGB2101010.
>
> Signed-off-by: José Expósito <[email protected]>
> ---

This looks good.

Again, it'd be nice to use KUNIT_EXPECT_MEMEQ() when it's available,
but if you don't want to add a dependency on that patchset now,
keeping it as-is in this patch and fixing it later is also fine.

Reviewed-by: David Gow <[email protected]>

Cheers,
-- David

> .../gpu/drm/tests/drm_format_helper_test.c | 63 +++++++++++++++++++
> 1 file changed, 63 insertions(+)
>
> diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c
> index 08d08e7ab19a..d8536db4de1e 100644
> --- a/drivers/gpu/drm/tests/drm_format_helper_test.c
> +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
> @@ -32,6 +32,11 @@ struct convert_to_rgb888_result {
> const u8 expected[TEST_BUF_SIZE];
> };
>
> +struct convert_to_xrgb2101010_result {
> + unsigned int dst_pitch;
> + const u32 expected[TEST_BUF_SIZE];
> +};
> +
> struct convert_xrgb8888_case {
> const char *name;
> unsigned int pitch;
> @@ -40,6 +45,7 @@ struct convert_xrgb8888_case {
> struct convert_to_rgb332_result rgb332_result;
> struct convert_to_rgb565_result rgb565_result;
> struct convert_to_rgb888_result rgb888_result;
> + struct convert_to_xrgb2101010_result xrgb2101010_result;
> };
>
> static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
> @@ -61,6 +67,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
> .dst_pitch = 0,
> .expected = { 0x00, 0x00, 0xFF },
> },
> + .xrgb2101010_result = {
> + .dst_pitch = 0,
> + .expected = { 0x3FF00000 },
> + },
> },
> {
> .name = "single_pixel_clip_rectangle",
> @@ -83,6 +93,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
> .dst_pitch = 0,
> .expected = { 0x00, 0x00, 0xFF },
> },
> + .xrgb2101010_result = {
> + .dst_pitch = 0,
> + .expected = { 0x3FF00000 },
> + },
> },
> {
> /* Well known colors: White, black, red, green, blue, magenta,
> @@ -132,6 +146,15 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
> 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
> },
> },
> + .xrgb2101010_result = {
> + .dst_pitch = 0,
> + .expected = {
> + 0x3FFFFFFF, 0x00000000,
> + 0x3FF00000, 0x000FFC00,
> + 0x000003FF, 0x3FF003FF,
> + 0x3FFFFC00, 0x000FFFFF,
> + },
> + },
> },
> {
> /* Randomly picked colors. Full buffer within the clip area. */
> @@ -175,6 +198,14 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
> 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> },
> },
> + .xrgb2101010_result = {
> + .dst_pitch = 20,
> + .expected = {
> + 0x03844672, 0x0444D414, 0x2A20300C, 0x00000000, 0x00000000,
> + 0x1B1705CD, 0x03844672, 0x0444D414, 0x00000000, 0x00000000,
> + 0x2A20300C, 0x1B1705CD, 0x03844672, 0x00000000, 0x00000000,
> + },
> + },
> },
> };
>
> @@ -319,10 +350,42 @@ static void xrgb8888_to_rgb888_test(struct kunit *test)
> KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0);
> }
>
> +static void xrgb8888_to_xrgb2101010_test(struct kunit *test)
> +{
> + const struct convert_xrgb8888_case *params = test->param_value;
> + const struct convert_to_xrgb2101010_result *result = &params->xrgb2101010_result;
> + size_t dst_size;
> + __u32 *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_XRGB2101010,
> + 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_xrgb2101010(&dst, &result->dst_pitch, &src, &fb, &params->clip);
> + buf = le32buf_to_cpu(test, buf, TEST_BUF_SIZE);
> + 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),
> + KUNIT_CASE_PARAM(xrgb8888_to_xrgb2101010_test, convert_xrgb8888_gen_params),
> {}
> };
>
> --
> 2.25.1
>


Attachments:
smime.p7s (3.91 kB)
S/MIME Cryptographic Signature

2022-08-17 07:01:00

by David Gow

[permalink] [raw]
Subject: Re: [PATCH 1/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb888()

On Tue, Aug 16, 2022 at 6:29 PM José Expósito <[email protected]> wrote:
>
> Extend the existing test cases to test the conversion from XRGB8888 to
> RGB888.
>
> Signed-off-by: José Expósito <[email protected]>
> ---

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 <[email protected]>

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/[email protected]/

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
>


Attachments:
smime.p7s (3.91 kB)
S/MIME Cryptographic Signature

2022-08-17 08:32:34

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 2/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_xrgb2101010()

Hi "Jos?,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on drm-tip/drm-tip]
[cannot apply to drm/drm-next drm-exynos/exynos-drm-next drm-intel/for-linux-next linus/master v6.0-rc1 next-20220817]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Jos-Exp-sito/KUnit-tests-for-RGB888-XRGB2101010-and-grayscale/20220816-183253
base: git://anongit.freedesktop.org/drm/drm-misc drm-misc-next
config: x86_64-rhel-8.3-kunit
compiler: gcc-11 (Debian 11.3.0-5) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/eea55ae63365de29a15eb95504bbca668ddab276
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Jos-Exp-sito/KUnit-tests-for-RGB888-XRGB2101010-and-grayscale/20220816-183253
git checkout eea55ae63365de29a15eb95504bbca668ddab276
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: "drm_fb_xrgb8888_to_xrgb2101010" [drivers/gpu/drm/tests/drm_format_helper_test.ko] undefined!

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (1.62 kB)
config (167.59 kB)
Download all attachments

2022-08-28 09:00:46

by José Expósito

[permalink] [raw]
Subject: Re: [PATCH 0/3] KUnit tests for RGB888, XRGB2101010 and grayscale

On Tue, Aug 16, 2022 at 10:37:49AM -0300, Ma?ra Canal wrote:
> Hi Jos?,
>
> Tested the whole series on UML, x86, i386 and PPC. All looks fine!
>
> Tested-by: Ma?ra Canal <[email protected]>
>
> Best Regards,
> - Ma?ra Canal
>
> On 8/16/22 07:29, Jos? Exp?sito wrote:
> > Hello everyone,
> >
> > This series is a follow up on my work adding KUnit test to the XRGB8888
> > conversion functions. This time RGB888, XRGB2101010 and gray8 are added.
> >
> > Best wishes,
> > Jose
> >
> > Jos? Exp?sito (3):
> > drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb888()
> > drm/format-helper: Add KUnit tests for
> > drm_fb_xrgb8888_to_xrgb2101010()
> > drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_gray8()
> >
> > .../gpu/drm/tests/drm_format_helper_test.c | 190 ++++++++++++++++++
> > 1 file changed, 190 insertions(+)
> >

Thanks a lot for testing the series Ma?ra and for the code review
David.

I added a note to my ToDo list to use KUNIT_EXPECT_MEMEQ once it gets
merged.

For the moment, I'll send v2 :)

Best wishes,
Jose