From: Sidharth Saha via B4 Relay <devnull+ssaha2000.gmail.com@kernel.org>
To: Louis Chauvet <louis.chauvet@bootlin.com>,
Haneen Mohammed <hamohammed.sa@gmail.com>,
Simona Vetter <simona@ffwll.ch>,
Melissa Wen <melissa.srw@gmail.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
Sidharth Saha <40047656+Sidharth-Saha@users.noreply.github.com>
Subject: [PATCH 4/5] drm/vkms: Add KUnit tests for RGB332 and BGR233 writeback conversion
Date: Mon, 16 Nov 2026 18:21:35 -0700 [thread overview]
Message-ID: <20261116-rgb565-test-v1-4-27f49c1aa694@gmail.com> (raw)
In-Reply-To: <20261116-rgb565-test-v1-0-27f49c1aa694@gmail.com>
From: Sidharth Saha <ssaha2000@gmail.com>
Test argb_u16_to_RGB332() and argb_u16_to_BGR233(), which reduce 16-bit
channels to 3/3/2 bits. Cases cover the 0x8000 midpoint, inputs on
either side of the first rounding step for both 3- and 2-bit channels,
and a round trip using values produced by the read conversion.
Make both functions visible to KUnit so the tests can call them.
Signed-off-by: Sidharth Saha <40047656+Sidharth-Saha@users.noreply.github.com>
---
drivers/gpu/drm/vkms/tests/vkms_format_test.c | 51 +++++++++++++++++++++++++++
drivers/gpu/drm/vkms/vkms_formats.c | 6 ++--
drivers/gpu/drm/vkms/vkms_formats.h | 2 ++
3 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/vkms/tests/vkms_format_test.c b/drivers/gpu/drm/vkms/tests/vkms_format_test.c
index ab95d6c3d2d5..0683a74fc623 100644
--- a/drivers/gpu/drm/vkms/tests/vkms_format_test.c
+++ b/drivers/gpu/drm/vkms/tests/vkms_format_test.c
@@ -362,12 +362,63 @@ static void vkms_format_test_argb_u16_from_BGR233(struct kunit *test)
KUNIT_EXPECT_EQ(test, out.a, 0xffff);
}
+struct u8_write_case {
+ const char *name;
+ struct pixel_argb_u16 in;
+ u8 rgb332, bgr233; /* expected output, packed both ways */
+};
+
+static struct u8_write_case u8_write_cases[] = {
+ { "zero", { .a = 0xffff, .r = 0, .g = 0, .b = 0 }, 0x00, 0x00 },
+ { "max", { .a = 0xffff, .r = 0xffff, .g = 0xffff, .b = 0xffff }, 0xff, 0xff },
+ { "red-only", { .a = 0xffff, .r = 0xffff, .g = 0, .b = 0 }, 0xe0, 0x07 },
+ { "green-only", { .a = 0xffff, .r = 0, .g = 0xffff, .b = 0 }, 0x1c, 0x38 },
+ { "blue-only", { .a = 0xffff, .r = 0, .g = 0, .b = 0xffff }, 0x03, 0xc0 },
+ /* r=4, g=4, b=2 */
+ { "midpoint", { .a = 0xffff, .r = 0x8000, .g = 0x8000, .b = 0x8000 }, 0x92, 0xa4 },
+ /* r=1, g=0, b=0 */
+ { "steps-1", { .a = 0xffff, .r = 4682, .g = 4681, .b = 10922 }, 0x20, 0x01 },
+ /* r=0, g=1, b=1 */
+ { "steps-2", { .a = 0xffff, .r = 4681, .g = 4682, .b = 10923 }, 0x05, 0x48 },
+ /* r=4, g=5, b=2 */
+ { "round-trip", { .a = 0xffff, .r = 37449, .g = 46811, .b = 43690 }, 0x96, 0xac },
+ /* r=7, g=4, b=0 */
+ { "distinct", { .a = 0xffff, .r = 0xffff, .g = 0x8000, .b = 0 }, 0xf0, 0x27 },
+};
+
+static void vkms_format_test_u8_write_case_desc(struct u8_write_case *t, char *desc)
+{
+ snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s", t->name);
+}
+
+KUNIT_ARRAY_PARAM(u8_write, u8_write_cases, vkms_format_test_u8_write_case_desc);
+
+static void vkms_format_test_argb_u16_to_RGB332(struct kunit *test)
+{
+ const struct u8_write_case *c = test->param_value;
+ u8 out;
+
+ argb_u16_to_RGB332(&out, &c->in);
+ KUNIT_EXPECT_EQ(test, out, c->rgb332);
+}
+
+static void vkms_format_test_argb_u16_to_BGR233(struct kunit *test)
+{
+ const struct u8_write_case *c = test->param_value;
+ u8 out;
+
+ argb_u16_to_BGR233(&out, &c->in);
+ KUNIT_EXPECT_EQ(test, out, c->bgr233);
+}
+
static struct kunit_case vkms_format_test_cases[] = {
KUNIT_CASE_PARAM(vkms_format_test_yuv_u16_to_argb_u16, yuv_u16_to_argb_u16_gen_params),
KUNIT_CASE_PARAM(vkms_format_test_argb_u16_to_RGB565, rgb565_gen_params),
KUNIT_CASE_PARAM(vkms_format_test_argb_u16_to_BGR565, rgb565_gen_params),
KUNIT_CASE_PARAM(vkms_format_test_argb_u16_from_RGB332, u8_read_gen_params),
KUNIT_CASE_PARAM(vkms_format_test_argb_u16_from_BGR233, u8_read_gen_params),
+ KUNIT_CASE_PARAM(vkms_format_test_argb_u16_to_RGB332, u8_write_gen_params),
+ KUNIT_CASE_PARAM(vkms_format_test_argb_u16_to_BGR233, u8_write_gen_params),
};
static struct kunit_suite vkms_format_test_suite = {
diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c
index eccca25f51d4..a5d04f922a94 100644
--- a/drivers/gpu/drm/vkms/vkms_formats.c
+++ b/drivers/gpu/drm/vkms/vkms_formats.c
@@ -709,7 +709,7 @@ VISIBLE_IF_KUNIT void argb_u16_to_BGR565(u8 *out_pixel, const struct pixel_argb_
}
EXPORT_SYMBOL_IF_KUNIT(argb_u16_to_BGR565);
-static void argb_u16_to_RGB332(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel)
+VISIBLE_IF_KUNIT void argb_u16_to_RGB332(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel)
{
u16 r, g, b;
@@ -717,8 +717,9 @@ static void argb_u16_to_RGB332(u8 *out_pixel, const struct pixel_argb_u16 *in_pi
*out_pixel = r << 5 | g << 2 | b;
}
+EXPORT_SYMBOL_IF_KUNIT(argb_u16_to_RGB332);
-static void argb_u16_to_BGR233(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel)
+VISIBLE_IF_KUNIT void argb_u16_to_BGR233(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel)
{
u16 r, g, b;
@@ -726,6 +727,7 @@ static void argb_u16_to_BGR233(u8 *out_pixel, const struct pixel_argb_u16 *in_pi
*out_pixel = b << 6 | g << 3 | r;
}
+EXPORT_SYMBOL_IF_KUNIT(argb_u16_to_BGR233);
/**
* vkms_writeback_row() - Generic loop for all supported writeback format. It is executed just
diff --git a/drivers/gpu/drm/vkms/vkms_formats.h b/drivers/gpu/drm/vkms/vkms_formats.h
index 90006325a87e..8565b2ca86c3 100644
--- a/drivers/gpu/drm/vkms/vkms_formats.h
+++ b/drivers/gpu/drm/vkms/vkms_formats.h
@@ -22,6 +22,8 @@ void argb_u16_to_RGB565(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel);
void argb_u16_to_BGR565(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel);
struct pixel_argb_u16 argb_u16_from_RGB332(u8 pixel);
struct pixel_argb_u16 argb_u16_from_BGR233(u8 pixel);
+void argb_u16_to_RGB332(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel);
+void argb_u16_to_BGR233(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel);
#endif
#endif /* _VKMS_FORMATS_H_ */
--
2.53.0
next prev parent reply other threads:[~2026-11-17 1:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 1:21 [PATCH 0/5] drm/vkms: Add KUnit tests for packed RGB format conversions Sidharth Saha via B4 Relay
2026-11-17 1:21 ` [PATCH 1/5] drm/vkms: Add KUnit test for RGB565 writeback conversion Sidharth Saha via B4 Relay
2026-11-17 1:21 ` [PATCH 2/5] drm/vkms: Add KUnit test for BGR565 " Sidharth Saha via B4 Relay
2026-11-17 1:21 ` [PATCH 3/5] drm/vkms: Add KUnit tests for RGB332 and BGR233 read conversion Sidharth Saha via B4 Relay
2026-11-17 1:21 ` Sidharth Saha via B4 Relay [this message]
2026-11-17 1:21 ` [PATCH 5/5] drm/vkms: Add KUnit tests for RGB565 and BGR565 " Sidharth Saha via B4 Relay
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=20261116-rgb565-test-v1-4-27f49c1aa694@gmail.com \
--to=devnull+ssaha2000.gmail.com@kernel.org \
--cc=40047656+Sidharth-Saha@users.noreply.github.com \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=hamohammed.sa@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=louis.chauvet@bootlin.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=melissa.srw@gmail.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=ssaha2000@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®