[PATCH v3 0/4] KUnit tests for RGB565 conversion

1 view
Skip to first unread message

José Expósito

unread,
Jul 26, 2022, 7:09:27 PMJul 26
to jav...@redhat.com, davi...@google.com, dlat...@google.com, tzimm...@suse.de, mri...@kernel.org, dan...@ffwll.ch, air...@linux.ie, maarten....@linux.intel.com, jani....@linux.intel.com, maira...@usp.br, isab...@riseup.net, magali...@gmail.com, tales.a...@gmail.com, ge...@linux-m68k.org, dri-...@lists.freedesktop.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, José Expósito
Hello everyone,

This series is a follow up of the XRGB8888 to RGB332 conversion KUnit
tests.

As I mentioned in v2 [1] I suspected that the inconsistency handling
the endian might need to be fixed.
Fortunately, Geert Uytterhoeven fixed it in commit 4d9db10576ff
("drm/format-helper: Fix endianness in drm_fb_*_to_*() conversion
helpers"), so I updated the tests to reflect his change.

Changes since v1:

- Fix a bug reported by David Gow in the XRGB8888 to RGB332 tests
- Simplify the test structure as suggested by David Gow
- Add Tested-by Tales L. Aparecida and Acked-by Thomas Zimmermann
- Fix link in the last patch (Thomas Zimmermann)

Changes since v2:

- Test endian as fixed in commit 4d9db10576ff ("drm/format-helper: Fix
endianness in drm_fb_*_to_*() conversion helpers")
- Fix Sparse warning reported by David Gow
- Add Reviewed-by David Gow

[1] https://lore.kernel.org/dri-devel/20220709115837.5608...@gmail.com/

José Expósito (4):
drm/format-helper: Fix test on big endian architectures
drm/format-helper: Rename test cases to make them more generic
drm/format-helper: Support multiple target formats results
drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb565()

.../gpu/drm/tests/drm_format_helper_test.c | 169 ++++++++++++++----
1 file changed, 139 insertions(+), 30 deletions(-)

--
2.25.1

José Expósito

unread,
Jul 26, 2022, 7:09:29 PMJul 26
to jav...@redhat.com, davi...@google.com, dlat...@google.com, tzimm...@suse.de, mri...@kernel.org, dan...@ffwll.ch, air...@linux.ie, maarten....@linux.intel.com, jani....@linux.intel.com, maira...@usp.br, isab...@riseup.net, magali...@gmail.com, tales.a...@gmail.com, ge...@linux-m68k.org, dri-...@lists.freedesktop.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, José Expósito
The tests fail on big endian architectures, like PowerPC:

$ ./tools/testing/kunit/kunit.py run \
--kunitconfig=drivers/gpu/drm/tests \
--arch=powerpc --cross_compile=powerpc64-linux-gnu-

Transform the XRGB8888 buffer from little endian to the CPU endian
before calling the conversion function to avoid this error.

Fixes: 8f456104915f ("drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb332()")
Reported-by: David Gow <davi...@google.com>
Reviewed-by: David Gow <davi...@google.com>
Signed-off-by: José Expósito <jose.ex...@gmail.com>
---
.../gpu/drm/tests/drm_format_helper_test.c | 23 +++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c
index 98583bf56044..eefaba3aaea2 100644
--- a/drivers/gpu/drm/tests/drm_format_helper_test.c
+++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
@@ -111,6 +111,21 @@ static size_t conversion_buf_size(u32 dst_format, unsigned int dst_pitch,
return dst_pitch * drm_rect_height(clip);
}

+static u32 *le32buf_to_cpu(struct kunit *test, const u32 *buf, size_t buf_size)
+{
+ u32 *dst = NULL;
+ int n;
+
+ dst = kunit_kzalloc(test, sizeof(*dst) * buf_size, GFP_KERNEL);
+ if (!dst)
+ return NULL;
+
+ for (n = 0; n < buf_size; n++)
+ dst[n] = le32_to_cpu((__force __le32)buf[n]);
+
+ return dst;
+}
+
static void xrgb8888_to_rgb332_case_desc(struct xrgb8888_to_rgb332_case *t,
char *desc)
{
@@ -125,6 +140,7 @@ static void xrgb8888_to_rgb332_test(struct kunit *test)
const struct xrgb8888_to_rgb332_case *params = test->param_value;
size_t dst_size;
__u8 *dst = NULL;
+ __u32 *src = NULL;

struct drm_framebuffer fb = {
.format = drm_format_info(DRM_FORMAT_XRGB8888),
@@ -138,8 +154,11 @@ static void xrgb8888_to_rgb332_test(struct kunit *test)
dst = kunit_kzalloc(test, dst_size, GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dst);

- drm_fb_xrgb8888_to_rgb332(dst, params->dst_pitch, params->xrgb8888,
- &fb, &params->clip);
+ src = le32buf_to_cpu(test, params->xrgb8888, TEST_BUF_SIZE);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, src);
+
+ drm_fb_xrgb8888_to_rgb332(dst, params->dst_pitch, src, &fb,
+ &params->clip);
KUNIT_EXPECT_EQ(test, memcmp(dst, params->expected, dst_size), 0);
}

--
2.25.1

José Expósito

unread,
Jul 26, 2022, 7:09:34 PMJul 26
to jav...@redhat.com, davi...@google.com, dlat...@google.com, tzimm...@suse.de, mri...@kernel.org, dan...@ffwll.ch, air...@linux.ie, maarten....@linux.intel.com, jani....@linux.intel.com, maira...@usp.br, isab...@riseup.net, magali...@gmail.com, tales.a...@gmail.com, ge...@linux-m68k.org, dri-...@lists.freedesktop.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, José Expósito
The tests available at the moment only check the conversion from
XRGB8888 to RGB332. However, more conversions will be tested in the
future.

In order to make the struct and functions present in the tests more
generic, rename xrgb8888_to_rgb332_* to convert_xrgb8888_*.

Tested-by: Tales L. Aparecida <tales.a...@gmail.com>
Acked-by: Thomas Zimmermann <tzimm...@suse.de>
Reviewed-by: David Gow <davi...@google.com>
Signed-off-by: José Expósito <jose.ex...@gmail.com>
---
drivers/gpu/drm/tests/drm_format_helper_test.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c
index eefaba3aaea2..97fccd0a948b 100644
--- a/drivers/gpu/drm/tests/drm_format_helper_test.c
+++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
@@ -16,7 +16,7 @@

#define TEST_BUF_SIZE 50

-struct xrgb8888_to_rgb332_case {
+struct convert_xrgb8888_case {
const char *name;
unsigned int pitch;
unsigned int dst_pitch;
@@ -25,7 +25,7 @@ struct xrgb8888_to_rgb332_case {
const u8 expected[4 * TEST_BUF_SIZE];
};

-static struct xrgb8888_to_rgb332_case xrgb8888_to_rgb332_cases[] = {
+static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
{
.name = "single_pixel_source_buffer",
.pitch = 1 * 4,
@@ -126,18 +126,18 @@ static u32 *le32buf_to_cpu(struct kunit *test, const u32 *buf, size_t buf_size)
return dst;
}

-static void xrgb8888_to_rgb332_case_desc(struct xrgb8888_to_rgb332_case *t,
- char *desc)
+static void convert_xrgb8888_case_desc(struct convert_xrgb8888_case *t,
+ char *desc)
{
strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE);
}

-KUNIT_ARRAY_PARAM(xrgb8888_to_rgb332, xrgb8888_to_rgb332_cases,
- xrgb8888_to_rgb332_case_desc);
+KUNIT_ARRAY_PARAM(convert_xrgb8888, convert_xrgb8888_cases,
+ convert_xrgb8888_case_desc);

static void xrgb8888_to_rgb332_test(struct kunit *test)
{
- const struct xrgb8888_to_rgb332_case *params = test->param_value;
+ const struct convert_xrgb8888_case *params = test->param_value;
size_t dst_size;
__u8 *dst = NULL;
__u32 *src = NULL;
@@ -163,8 +163,7 @@ static void xrgb8888_to_rgb332_test(struct kunit *test)
}

static struct kunit_case drm_format_helper_test_cases[] = {
- KUNIT_CASE_PARAM(xrgb8888_to_rgb332_test,
- xrgb8888_to_rgb332_gen_params),
+ KUNIT_CASE_PARAM(xrgb8888_to_rgb332_test, convert_xrgb8888_gen_params),
{}
};

--
2.25.1

José Expósito

unread,
Jul 26, 2022, 7:09:38 PMJul 26
to jav...@redhat.com, davi...@google.com, dlat...@google.com, tzimm...@suse.de, mri...@kernel.org, dan...@ffwll.ch, air...@linux.ie, maarten....@linux.intel.com, jani....@linux.intel.com, maira...@usp.br, isab...@riseup.net, magali...@gmail.com, tales.a...@gmail.com, ge...@linux-m68k.org, dri-...@lists.freedesktop.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, José Expósito
In order to support multiple destination format conversions, store the
destination pitch and the expected result in its own structure.

Tested-by: Tales L. Aparecida <tales.a...@gmail.com>
Acked-by: Thomas Zimmermann <tzimm...@suse.de>
Reviewed-by: David Gow <davi...@google.com>
Signed-off-by: José Expósito <jose.ex...@gmail.com>
---
.../gpu/drm/tests/drm_format_helper_test.c | 53 ++++++++++++-------
1 file changed, 33 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c
index 97fccd0a948b..bbe9e9f57e2b 100644
--- a/drivers/gpu/drm/tests/drm_format_helper_test.c
+++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
@@ -16,34 +16,42 @@

#define TEST_BUF_SIZE 50

+struct convert_to_rgb332_result {
+ unsigned int dst_pitch;
+ const u8 expected[TEST_BUF_SIZE];
+};
+
struct convert_xrgb8888_case {
const char *name;
unsigned int pitch;
- unsigned int dst_pitch;
struct drm_rect clip;
const u32 xrgb8888[TEST_BUF_SIZE];
- const u8 expected[4 * TEST_BUF_SIZE];
+ struct convert_to_rgb332_result rgb332_result;
};

static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
{
.name = "single_pixel_source_buffer",
.pitch = 1 * 4,
- .dst_pitch = 0,
.clip = DRM_RECT_INIT(0, 0, 1, 1),
.xrgb8888 = { 0x01FF0000 },
- .expected = { 0xE0 },
+ .rgb332_result = {
+ .dst_pitch = 0,
+ .expected = { 0xE0 },
+ },
},
{
.name = "single_pixel_clip_rectangle",
.pitch = 2 * 4,
- .dst_pitch = 0,
.clip = DRM_RECT_INIT(1, 1, 1, 1),
.xrgb8888 = {
0x00000000, 0x00000000,
0x00000000, 0x10FF0000,
},
- .expected = { 0xE0 },
+ .rgb332_result = {
+ .dst_pitch = 0,
+ .expected = { 0xE0 },
+ },
},
{
/* Well known colors: White, black, red, green, blue, magenta,
@@ -52,7 +60,6 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
*/
.name = "well_known_colors",
.pitch = 4 * 4,
- .dst_pitch = 0,
.clip = DRM_RECT_INIT(1, 1, 2, 4),
.xrgb8888 = {
0x00000000, 0x00000000, 0x00000000, 0x00000000,
@@ -61,28 +68,33 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
0x00000000, 0x550000FF, 0x66FF00FF, 0x00000000,
0x00000000, 0x77FFFF00, 0x8800FFFF, 0x00000000,
},
- .expected = {
- 0xFF, 0x00,
- 0xE0, 0x1C,
- 0x03, 0xE3,
- 0xFC, 0x1F,
+ .rgb332_result = {
+ .dst_pitch = 0,
+ .expected = {
+ 0xFF, 0x00,
+ 0xE0, 0x1C,
+ 0x03, 0xE3,
+ 0xFC, 0x1F,
+ },
},
},
{
/* Randomly picked colors. Full buffer within the clip area. */
.name = "destination_pitch",
.pitch = 3 * 4,
- .dst_pitch = 5,
.clip = DRM_RECT_INIT(0, 0, 3, 3),
.xrgb8888 = {
0xA10E449C, 0xB1114D05, 0xC1A80303,
0xD16C7073, 0xA20E449C, 0xB2114D05,
0xC2A80303, 0xD26C7073, 0xA30E449C,
},
- .expected = {
- 0x0A, 0x08, 0xA0, 0x00, 0x00,
- 0x6D, 0x0A, 0x08, 0x00, 0x00,
- 0xA0, 0x6D, 0x0A, 0x00, 0x00,
+ .rgb332_result = {
+ .dst_pitch = 5,
+ .expected = {
+ 0x0A, 0x08, 0xA0, 0x00, 0x00,
+ 0x6D, 0x0A, 0x08, 0x00, 0x00,
+ 0xA0, 0x6D, 0x0A, 0x00, 0x00,
+ },
},
},
};
@@ -138,6 +150,7 @@ KUNIT_ARRAY_PARAM(convert_xrgb8888, convert_xrgb8888_cases,
static void xrgb8888_to_rgb332_test(struct kunit *test)
{
const struct convert_xrgb8888_case *params = test->param_value;
+ const struct convert_to_rgb332_result *result = &params->rgb332_result;
size_t dst_size;
__u8 *dst = NULL;
__u32 *src = NULL;
@@ -147,7 +160,7 @@ static void xrgb8888_to_rgb332_test(struct kunit *test)
.pitches = { params->pitch, 0, 0 },
};

- dst_size = conversion_buf_size(DRM_FORMAT_RGB332, params->dst_pitch,
+ dst_size = conversion_buf_size(DRM_FORMAT_RGB332, result->dst_pitch,
&params->clip);
KUNIT_ASSERT_GT(test, dst_size, 0);

@@ -157,9 +170,9 @@ static void xrgb8888_to_rgb332_test(struct kunit *test)
src = le32buf_to_cpu(test, params->xrgb8888, TEST_BUF_SIZE);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, src);

- drm_fb_xrgb8888_to_rgb332(dst, params->dst_pitch, src, &fb,
+ drm_fb_xrgb8888_to_rgb332(dst, result->dst_pitch, src, &fb,
&params->clip);
- KUNIT_EXPECT_EQ(test, memcmp(dst, params->expected, dst_size), 0);
+ KUNIT_EXPECT_EQ(test, memcmp(dst, result->expected, dst_size), 0);
}

static struct kunit_case drm_format_helper_test_cases[] = {
--
2.25.1

José Expósito

unread,
Jul 26, 2022, 7:09:41 PMJul 26
to jav...@redhat.com, davi...@google.com, dlat...@google.com, tzimm...@suse.de, mri...@kernel.org, dan...@ffwll.ch, air...@linux.ie, maarten....@linux.intel.com, jani....@linux.intel.com, maira...@usp.br, isab...@riseup.net, magali...@gmail.com, tales.a...@gmail.com, ge...@linux-m68k.org, dri-...@lists.freedesktop.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, José Expósito
Extend the existing test cases to test the conversion from XRGB8888 to
RGB565.

The documentation and the color picker available on [1] are useful
resources to understand this patch and validate the values returned by
the conversion function.

Tested-by: Tales L. Aparecida <tales.a...@gmail.com>
Acked-by: Thomas Zimmermann <tzimm...@suse.de>
Reviewed-by: David Gow <davi...@google.com>
Signed-off-by: José Expósito <jose.ex...@gmail.com>
Link: http://www.barth-dev.de/online/rgb565-color-picker/ # [1]
---
.../gpu/drm/tests/drm_format_helper_test.c | 78 +++++++++++++++++++
1 file changed, 78 insertions(+)

diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c
index bbe9e9f57e2b..26ecf3b4b137 100644
--- a/drivers/gpu/drm/tests/drm_format_helper_test.c
+++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
@@ -21,12 +21,19 @@ struct convert_to_rgb332_result {
const u8 expected[TEST_BUF_SIZE];
};

+struct convert_to_rgb565_result {
+ unsigned int dst_pitch;
+ const u16 expected[TEST_BUF_SIZE];
+ const u16 expected_swab[TEST_BUF_SIZE];
+};
+
struct convert_xrgb8888_case {
const char *name;
unsigned int pitch;
struct drm_rect clip;
const u32 xrgb8888[TEST_BUF_SIZE];
struct convert_to_rgb332_result rgb332_result;
+ struct convert_to_rgb565_result rgb565_result;
};

static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
@@ -39,6 +46,11 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
.dst_pitch = 0,
.expected = { 0xE0 },
},
+ .rgb565_result = {
+ .dst_pitch = 0,
+ .expected = { 0xF800 },
+ .expected_swab = { 0x00F8 },
+ },
},
{
.name = "single_pixel_clip_rectangle",
@@ -52,6 +64,11 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
.dst_pitch = 0,
.expected = { 0xE0 },
},
+ .rgb565_result = {
+ .dst_pitch = 0,
+ .expected = { 0xF800 },
+ .expected_swab = { 0x00F8 },
+ },
},
{
/* Well known colors: White, black, red, green, blue, magenta,
@@ -77,6 +94,21 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
0xFC, 0x1F,
},
},
+ .rgb565_result = {
+ .dst_pitch = 0,
+ .expected = {
+ 0xFFFF, 0x0000,
+ 0xF800, 0x07E0,
+ 0x001F, 0xF81F,
+ 0xFFE0, 0x07FF,
+ },
+ .expected_swab = {
+ 0xFFFF, 0x0000,
+ 0x00F8, 0xE007,
+ 0x1F00, 0x1FF8,
+ 0xE0FF, 0xFF07,
+ },
+ },
},
{
/* Randomly picked colors. Full buffer within the clip area. */
@@ -96,6 +128,19 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
0xA0, 0x6D, 0x0A, 0x00, 0x00,
},
},
+ .rgb565_result = {
+ .dst_pitch = 10,
+ .expected = {
+ 0x0A33, 0x1260, 0xA800, 0x0000, 0x0000,
+ 0x6B8E, 0x0A33, 0x1260, 0x0000, 0x0000,
+ 0xA800, 0x6B8E, 0x0A33, 0x0000, 0x0000,
+ },
+ .expected_swab = {
+ 0x330A, 0x6012, 0x00A8, 0x0000, 0x0000,
+ 0x8E6B, 0x330A, 0x6012, 0x0000, 0x0000,
+ 0x00A8, 0x8E6B, 0x330A, 0x0000, 0x0000,
+ },
+ },
},
};

@@ -175,8 +220,41 @@ static void xrgb8888_to_rgb332_test(struct kunit *test)
KUNIT_EXPECT_EQ(test, memcmp(dst, result->expected, dst_size), 0);
}

+static void xrgb8888_to_rgb565_test(struct kunit *test)
+{
+ const struct convert_xrgb8888_case *params = test->param_value;
+ const struct convert_to_rgb565_result *result = &params->rgb565_result;
+ size_t dst_size;
+ __u16 *dst = NULL;
+ __u32 *src = NULL;
+
+ struct drm_framebuffer fb = {
+ .format = drm_format_info(DRM_FORMAT_XRGB8888),
+ .pitches = { params->pitch, 0, 0 },
+ };
+
+ dst_size = conversion_buf_size(DRM_FORMAT_RGB565, result->dst_pitch,
+ &params->clip);
+ KUNIT_ASSERT_GT(test, dst_size, 0);
+
+ dst = kunit_kzalloc(test, dst_size, GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dst);
+
+ src = le32buf_to_cpu(test, params->xrgb8888, TEST_BUF_SIZE);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, src);
+
+ drm_fb_xrgb8888_to_rgb565(dst, result->dst_pitch, src, &fb,
+ &params->clip, false);
+ KUNIT_EXPECT_EQ(test, memcmp(dst, result->expected, dst_size), 0);
+
+ drm_fb_xrgb8888_to_rgb565(dst, result->dst_pitch, src, &fb,
+ &params->clip, true);
+ KUNIT_EXPECT_EQ(test, memcmp(dst, result->expected_swab, 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),
{}
};

--
2.25.1

José Expósito

unread,
Jul 28, 2022, 1:51:13 PMJul 28
to jav...@redhat.com, davi...@google.com, dlat...@google.com, tzimm...@suse.de, mri...@kernel.org, dan...@ffwll.ch, air...@linux.ie, maarten....@linux.intel.com, jani....@linux.intel.com, maira...@usp.br, isab...@riseup.net, magali...@gmail.com, tales.a...@gmail.com, ge...@linux-m68k.org, dri-...@lists.freedesktop.org, kuni...@googlegroups.com, linux-...@vger.kernel.org
As suggested by Thomas [1] I pushed the series to drm-misc-next.

I've found some conflicts in drm-tip in unreleated files I'm trying to
figure out on IRC though :(

Jose

[1] https://lore.kernel.org/dri-devel/4ba57f80-5025-c3a0...@suse.de/
Reply all
Reply to author
Forward
0 new messages