From: "José Expósito" <jose.exposito89@gmail.com>
To: javierm@redhat.com
Cc: davidgow@google.com, dlatypov@google.com, tzimmermann@suse.de,
mripard@kernel.org, daniel@ffwll.ch, airlied@linux.ie,
maarten.lankhorst@linux.intel.com, jani.nikula@linux.intel.com,
maira.canal@usp.br, isabbasso@riseup.net,
magalilemes00@gmail.com, tales.aparecida@gmail.com,
dri-devel@lists.freedesktop.org, kunit-dev@googlegroups.com,
linux-kernel@vger.kernel.org,
"José Expósito" <jose.exposito89@gmail.com>
Subject: [PATCH 2/4] drm/format-helper: Transform tests to be agnostic of target format
Date: Mon, 27 Jun 2022 18:11:30 +0200 [thread overview]
Message-ID: <20220627161132.33256-3-jose.exposito89@gmail.com> (raw)
In-Reply-To: <20220627161132.33256-1-jose.exposito89@gmail.com>
In order to support multiple destination format conversions, store the
target format, conversion function, parameters and expected result in
its own structure.
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
---
.../gpu/drm/tests/drm_format_helper_test.c | 88 ++++++++++++++-----
1 file changed, 64 insertions(+), 24 deletions(-)
diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c
index de8cf525109e..732d945e7f4e 100644
--- a/drivers/gpu/drm/tests/drm_format_helper_test.c
+++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
@@ -16,34 +16,55 @@
#define TEST_BUF_SIZE 50
+struct convert_xrgb8888_result {
+ u32 dst_format;
+ void (*conv_func)(void *dst, unsigned int dst_pitch,
+ const void *src,
+ const struct drm_framebuffer *fb,
+ const struct drm_rect *clip);
+ unsigned int dst_pitch;
+ const u8 expected[4 * 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_xrgb8888_result results[1];
};
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 },
+ .results = {
+ {
+ .dst_format = DRM_FORMAT_RGB332,
+ .conv_func = drm_fb_xrgb8888_to_rgb332,
+ .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 },
+ .results = {
+ {
+ .dst_format = DRM_FORMAT_RGB332,
+ .conv_func = drm_fb_xrgb8888_to_rgb332,
+ .dst_pitch = 0,
+ .expected = { 0xE0 },
+ },
+ },
},
{
/* Well known colors: White, black, red, green, blue, magenta,
@@ -52,7 +73,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 +81,41 @@ 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,
+ .results = {
+ {
+ .dst_format = DRM_FORMAT_RGB332,
+ .conv_func = drm_fb_xrgb8888_to_rgb332,
+ .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,
+ .results = {
+ {
+ .dst_format = DRM_FORMAT_RGB332,
+ .conv_func = drm_fb_xrgb8888_to_rgb332,
+ .dst_pitch = 5,
+ .expected = {
+ 0x0A, 0x08, 0xA0, 0x00, 0x00,
+ 0x6D, 0x0A, 0x08, 0x00, 0x00,
+ 0xA0, 0x6D, 0x0A, 0x00, 0x00,
+ },
+ },
},
},
};
@@ -123,24 +156,31 @@ KUNIT_ARRAY_PARAM(convert_xrgb8888, convert_xrgb8888_cases,
static void convert_xrgb8888_test(struct kunit *test)
{
const struct convert_xrgb8888_case *params = test->param_value;
+ const struct convert_xrgb8888_result *result;
size_t dst_size;
__u8 *dst = NULL;
+ int n;
struct drm_framebuffer fb = {
.format = drm_format_info(DRM_FORMAT_XRGB8888),
.pitches = { params->pitch, 0, 0 },
};
- dst_size = conversion_buf_size(DRM_FORMAT_RGB332, params->dst_pitch,
- ¶ms->clip);
- KUNIT_ASSERT_GT(test, dst_size, 0);
+ for (n = 0; n < ARRAY_SIZE(params->results); n++) {
+ result = ¶ms->results[n];
+
+ dst_size = conversion_buf_size(result->dst_format,
+ result->dst_pitch,
+ ¶ms->clip);
+ KUNIT_ASSERT_GT(test, dst_size, 0);
- dst = kunit_kzalloc(test, dst_size, GFP_KERNEL);
- KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dst);
+ 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,
+ result->conv_func(dst, result->dst_pitch, params->xrgb8888,
&fb, ¶ms->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
next prev parent reply other threads:[~2022-06-27 16:13 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-27 16:11 [PATCH 0/4] KUnit tests for RGB565 conversion José Expósito
2022-06-27 16:11 ` [PATCH 1/4] drm/format-helper: Rename test cases to make them more generic José Expósito
2022-06-27 16:11 ` José Expósito [this message]
2022-06-27 16:11 ` [PATCH 3/4] drm/format-helper: Add support for conversion functions with swab José Expósito
2022-06-27 16:11 ` [PATCH 4/4] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb565() José Expósito
2022-06-29 7:34 ` Thomas Zimmermann
2022-06-28 18:47 ` [PATCH 0/4] KUnit tests for RGB565 conversion Tales
2022-06-29 7:27 ` David Gow
2022-07-03 15:19 ` José Expósito
2022-06-29 7:37 ` Thomas Zimmermann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220627161132.33256-3-jose.exposito89@gmail.com \
--to=jose.exposito89@gmail.com \
--cc=airlied@linux.ie \
--cc=daniel@ffwll.ch \
--cc=davidgow@google.com \
--cc=dlatypov@google.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=isabbasso@riseup.net \
--cc=jani.nikula@linux.intel.com \
--cc=javierm@redhat.com \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=magalilemes00@gmail.com \
--cc=maira.canal@usp.br \
--cc=mripard@kernel.org \
--cc=tales.aparecida@gmail.com \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®