Skip to contentSkip to conversation

drm/vkms: Add KUnit tests for packed RGB format conversions

PATCH New Sidharth Saha 2 participants 11 messages Nov 17

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover drm/vkms: Add KUnit tests for packed RGB format conversions

This series adds KUnit tests for the pixel format conversions touched by Matheus's series "drm/vkms: support more formats and fix RGB565 regression" [1], which it depends on.

The RGB565 writeback rounding fix in [1] restores a fix that was lost once before in a refactor. These tests are meant to keep it, and the new RGB332, BGR233 and BGR565 conversions, from regressing.

Each test is table-driven, with expected values computed by hand. With
[1] applied, all cases pass. Without it, the tests for the new formats don't build, the RGB565 writeback rounding cases fail, and the RGB565/BGR565 read cases pass unchanged.

Matheus offered to include these in a v2 of [1] if one is needed; otherwise they can be applied on top of it.

[1] https://lore.kernel.org/dri-devel/[email protected]/

---
Sidharth Saha (5):
drm/vkms: Add KUnit test for RGB565 writeback conversion drm/vkms: Add KUnit test for BGR565 writeback conversion drm/vkms: Add KUnit tests for RGB332 and BGR233 read conversion drm/vkms: Add KUnit tests for RGB332 and BGR233 writeback conversion drm/vkms: Add KUnit tests for RGB565 and BGR565 read conversion

 drivers/gpu/drm/vkms/tests/vkms_format_test.c | 202 ++++++++++++++++++++++++++
 drivers/gpu/drm/vkms/vkms_formats.c           |  24 ++-
 drivers/gpu/drm/vkms/vkms_formats.h           |  10 ++
 3 files changed, 228 insertions(+), 8 deletions(-)

---
base-commit: 66c571876c4634dc3258a75a6d49bd7e88ffcb35
change-id: 20261116-rgb565-test-3d8f9c3c9b3e
prerequisite-message-id: <[email protected]>
prerequisite-patch-id: 62056d93696db239d59a0ca486a7fba3f5ee204d
prerequisite-patch-id: a909d90a401095b0ad014f44f08b8c76563262b8
prerequisite-patch-id: 713b5a5532b2ec31d360132496e6f9980b91a16a
prerequisite-patch-id: fa0fda9d178c4b5a65d984a672f47ec90b86ea2a
prerequisite-patch-id: 8e173c420969c0943d31eec819288d9df4d39b5f

Best regards,

Signature · 1 line
Sidharth Saha <[email protected]>
#1 lore raw

PATCH 1/5 drm/vkms: Add KUnit test for RGB565 writeback conversion

argb_u16_to_RGB565() reduces each 16-bit channel to 5 or 6 bits. Its rounding was fixed in commit ab87f558dcfb ("drm/vkms: Fix RGB565 pixel conversion"), lost again in commit cc4fd2934d41 ("drm/vkms: Isolate writeback pixel conversion functions"), and restored by "drm/vkms: make argb_u16_to_RGB565 round resulting values". Add a KUnit test so it can't silently regress again.

The test checks hand-computed values for zero, maximum, the 0x8000 midpoint, inputs on either side of the first rounding step, and distinct per-channel values to catch channel placement errors.

Make argb_u16_to_RGB565() visible to KUnit so the test can call it.

---
 drivers/gpu/drm/vkms/tests/vkms_format_test.c | 38 ++++++++++++++++++++++++++-
 drivers/gpu/drm/vkms/vkms_formats.c           |  3 ++-
 drivers/gpu/drm/vkms/vkms_formats.h           |  1 +
 3 files changed, 40 insertions(+), 2 deletions(-)
drivers/gpu/drm/vkms/tests/vkms_format_test.c +37 -1
index bbb1ad18c99f..a8ef93b9c806 100644
@@ -265,9 +265,45 @@ KUNIT_ARRAY_PARAM(yuv_u16_to_argb_u16, yuv_u16_to_argb_u16_cases,
 		  vkms_format_test_yuv_u16_to_argb_u16_case_desc
 );
 
+struct rgb565_case {
+	const char *name;
+	struct pixel_argb_u16 in;
+	u16 r, g, b;		/* expected 5/6/5-bit outputs */
+};
+
+static struct rgb565_case rgb565_cases[] = {
+	{ "zero",       { .a = 0xffff, .r = 0,      .g = 0,      .b = 0      },  0,  0,  0 },
+	{ "max",        { .a = 0xffff, .r = 0xffff, .g = 0xffff, .b = 0xffff }, 31, 63, 31 },
+	{ "midpoint",   { .a = 0xffff, .r = 0x8000, .g = 0x8000, .b = 0x8000 }, 16, 32, 16 },
+	{ "below-step", { .a = 0xffff, .r = 1057,   .g = 0,      .b = 0      },  0,  0,  0 },
+	{ "above-step", { .a = 0xffff, .r = 1058,   .g = 0,      .b = 0      },  1,  0,  0 },
+	{ "distinct",   { .a = 0xffff, .r = 0xffff, .g = 0x8000, .b = 0      }, 31, 32,  0 },
+};
+
+static void vkms_format_test_rgb565_case_desc(struct rgb565_case *t, char *desc)
+{
+	snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s", t->name);
+}
+
+KUNIT_ARRAY_PARAM(rgb565, rgb565_cases, vkms_format_test_rgb565_case_desc);
+
+static void vkms_format_test_argb_u16_to_RGB565(struct kunit *test)
+{
+	const struct rgb565_case *c = test->param_value;
+	__le16 out;
+	u16 v;
+
+	argb_u16_to_RGB565((u8 *)&out, &c->in);
+	v = le16_to_cpu(out);
+
+	KUNIT_EXPECT_EQ(test, (v >> 11) & 0x1f, c->r);
+	KUNIT_EXPECT_EQ(test, (v >> 5) & 0x3f, c->g);
+	KUNIT_EXPECT_EQ(test, v & 0x1f, c->b);
+}
+
 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),
 };
 
 static struct kunit_suite vkms_format_test_suite = {
drivers/gpu/drm/vkms/vkms_formats.c +2 -1
index b0078d6efb90..c5ee2d6a920f 100644
@@ -685,7 +685,7 @@ static void argb_u16_to_channels(u16 *out_r, u16 *out_g, u16 *out_b, u16 *out_a,
 		*out_a = u16_to_channel(a_size, in_pixel->a);
 }
 
-static void argb_u16_to_RGB565(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel)
+VISIBLE_IF_KUNIT void argb_u16_to_RGB565(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel)
 {
 	__le16 *pixel = (__le16 *)out_pixel;
 	u16 r, g, b;
@@ -694,6 +694,7 @@ static void argb_u16_to_RGB565(u8 *out_pixel, const struct pixel_argb_u16 *in_pi
 
 	*pixel = cpu_to_le16(r << 11 | g << 5 | b);
 }
+EXPORT_SYMBOL_IF_KUNIT(argb_u16_to_RGB565);
 
 static void argb_u16_to_BGR565(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel)
 {
drivers/gpu/drm/vkms/vkms_formats.h +1 -0
index d969cc669a5e..2b8a1c4a5d46 100644
@@ -16,6 +16,7 @@ void get_conversion_matrix_to_argb_u16(u32 format, enum drm_color_encoding encod
 #if IS_ENABLED(CONFIG_KUNIT)
 struct pixel_argb_u16 argb_u16_from_yuv161616(const struct conversion_matrix *matrix,
 					      u16 y, u16 channel_1, u16 channel_2);
+void argb_u16_to_RGB565(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel);
 #endif
 
 #endif /* _VKMS_FORMATS_H_ */
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH 1/5] drm/vkms: Add KUnit test for RGB565 writeback conversion

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] drm/vkms: non-routable noreply email in Signed-off-by trailer - [Medium] drm/vkms: missing sentinel…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] drm/vkms: non-routable noreply email in Signed-off-by trailer
- [Medium] drm/vkms: missing sentinel in vkms_format_test_cases causes OOB read
It also noticed 1 related pre-existing issue this patch does not introduce:
- [Medium] drm/vkms: CPU stalls due to 64-bit division in argb_u16_to_RGB565() [1]
--

commit 7e8259d89165f4b4d4681ffd3d36be55b127f91e
Author: Sidharth Saha <[email protected]>

Quoted 9 lines

drm/vkms: Add KUnit test for RGB565 writeback conversion

argb_u16_to_RGB565() reduces each 16-bit channel to 5 or 6 bits. Its rounding was fixed in commit ab87f558dcfb ("drm/vkms: Fix RGB565 pixel conversion"), lost again in commit cc4fd2934d41 ("drm/vkms: Isolate writeback pixel conversion functions"), and restored by "drm/vkms: make argb_u16_to_RGB565 round resulting values". Add a KUnit test so it can't silently regress again.

Quoted 7 lines

The test checks hand-computed values for zero, maximum, the 0x8000 midpoint, inputs on either side of the first rounding step, and distinct per-channel values to catch channel placement errors.

Make argb_u16_to_RGB565() visible to KUnit so the test can call it.

[Severity: High]
The Signed-off-by trailer uses a non-routable GitHub noreply email address that does not match the commit Author address (<[email protected]>).

Quoted 4 lines
drivers/gpu/drm/vkms/tests/vkms_format_test.c +0 -0
index bbb1ad18c99ff..a8ef93b9c806c 100644

[ ... ]

drivers/gpu/drm/vkms/tests/vkms_format_test.c KUNIT_ARRAY_PARAM(yuv_u16_to_argb_u16, yuv_u16_to_argb_u16_cases, · line 268

Quoted 6 lines
drivers/gpu/drm/vkms/tests/vkms_format_test.c +1 -1
@@ -265,9 +265,45 @@ KUNIT_ARRAY_PARAM(yuv_u16_to_argb_u16, yuv_u16_to_argb_u16_cases,
 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),
 };

[Severity: Medium]
Does removing the trailing {} sentinel from vkms_format_test_cases[] cause an out-of-bounds read when KUnit iterates over the suite?

kunit_suite_for_each_test_case() walks suite->test_cases until it sees a NULL run_case pointer, so running or enumerating the vkms-format suite will read past the end of the array and treat adjacent memory as a test case. Note that a later patch in this series, commit "drm/vkms: Add KUnit tests for RGB565 and BGR565 read conversion", restores the trailing {} entry.

Quoted 14 lines
drivers/gpu/drm/vkms/vkms_formats.c +1 -1
index b0078d6efb908..c5ee2d6a920f6 100644
@@ -685,7 +685,7 @@ static void argb_u16_to_channels(u16 *out_r, u16 *out_g, u16 *out_b, u16 *out_a,
 		*out_a = u16_to_channel(a_size, in_pixel->a);
 }
 
-static void argb_u16_to_RGB565(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel)
+VISIBLE_IF_KUNIT void argb_u16_to_RGB565(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel)
 {
 	__le16 *pixel = (__le16 *)out_pixel;
 	u16 r, g, b;

drivers/gpu/drm/vkms/vkms_formats.c static void argb_u16_to_RGB565(u8 *out_pixel, const struct pixel_argb_u16 *in_pi · line 697

Quoted 4 lines
drivers/gpu/drm/vkms/vkms_formats.c +1 -0
@@ -694,6 +694,7 @@ static void argb_u16_to_RGB565(u8 *out_pixel, const struct pixel_argb_u16 *in_pi
 
 	*pixel = cpu_to_le16(r << 11 | g << 5 | b);
 }
+EXPORT_SYMBOL_IF_KUNIT(argb_u16_to_RGB565);

[Severity: Medium]
This problem wasn't introduced by this patch, but argb_u16_to_RGB565() (via argb_u16_to_channels() -> u16_to_channel()) and argb_u16_from_RGB565() perform 64-bit fixed-point divisions with drm_fixp_div() on every channel of every pixel [1]:

drivers/gpu/drm/vkms/vkms_formats.c:u16_to_channel() {
	s64 fp_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp((1 << size) - 1));
	s64 fp_channel = drm_int2fixp(in);

	return drm_fixp2int_round(drm_fixp_div(fp_channel, fp_ratio));
}

When vkms_writeback_row() or plane reading converts an entire framebuffer, running software-emulated 64-bit divisions per pixel causes severe CPU stalls and rendering performance degradation on 32-bit architectures.

[1] https://sashiko.dev/#/bug/linux-7999e4a9-b93f-4927-aea8-f7c41dab6826

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

PATCH 2/5 drm/vkms: Add KUnit test for BGR565 writeback conversion

In reply to Sidharth Saha

Reuse the RGB565 writeback cases to test argb_u16_to_BGR565(), which packs the same 5/6/5-bit channels with red and blue swapped. The distinct-channel case checks that red and blue land in the right bits.

Make argb_u16_to_BGR565() visible to KUnit so the test can call it.

---
 drivers/gpu/drm/vkms/tests/vkms_format_test.c | 15 +++++++++++++++
 drivers/gpu/drm/vkms/vkms_formats.c           |  3 ++-
 drivers/gpu/drm/vkms/vkms_formats.h           |  1 +
 3 files changed, 18 insertions(+), 1 deletion(-)
drivers/gpu/drm/vkms/tests/vkms_format_test.c +15 -0
index a8ef93b9c806..e7836664c788 100644
@@ -301,9 +301,24 @@ static void vkms_format_test_argb_u16_to_RGB565(struct kunit *test)
 	KUNIT_EXPECT_EQ(test, v & 0x1f, c->b);
 }
 
+static void vkms_format_test_argb_u16_to_BGR565(struct kunit *test)
+{
+	const struct rgb565_case *c = test->param_value;
+	__le16 out;
+	u16 v;
+
+	argb_u16_to_BGR565((u8 *)&out, &c->in);
+	v = le16_to_cpu(out);
+
+	KUNIT_EXPECT_EQ(test, v & 0x1f, c->r);		/* red: low bits */
+	KUNIT_EXPECT_EQ(test, (v >> 5) & 0x3f, c->g);
+	KUNIT_EXPECT_EQ(test, (v >> 11) & 0x1f, c->b);	/* blue: high bits */
+}
+
 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),
 };
 
 static struct kunit_suite vkms_format_test_suite = {
drivers/gpu/drm/vkms/vkms_formats.c +2 -1
index c5ee2d6a920f..7950751c4890 100644
@@ -696,7 +696,7 @@ VISIBLE_IF_KUNIT void argb_u16_to_RGB565(u8 *out_pixel, const struct pixel_argb_
 }
 EXPORT_SYMBOL_IF_KUNIT(argb_u16_to_RGB565);
 
-static void argb_u16_to_BGR565(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel)
+VISIBLE_IF_KUNIT void argb_u16_to_BGR565(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel)
 {
 	__le16 *pixel = (__le16 *)out_pixel;
 	u16 r, g, b;
@@ -705,6 +705,7 @@ static void argb_u16_to_BGR565(u8 *out_pixel, const struct pixel_argb_u16 *in_pi
 
 	*pixel = cpu_to_le16(b << 11 | g << 5 | r);
 }
+EXPORT_SYMBOL_IF_KUNIT(argb_u16_to_BGR565);
 
 static void argb_u16_to_RGB332(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel)
 {
drivers/gpu/drm/vkms/vkms_formats.h +1 -0
index 2b8a1c4a5d46..135bb60a554b 100644
@@ -17,6 +17,7 @@ void get_conversion_matrix_to_argb_u16(u32 format, enum drm_color_encoding encod
 struct pixel_argb_u16 argb_u16_from_yuv161616(const struct conversion_matrix *matrix,
 					      u16 y, u16 channel_1, u16 channel_2);
 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);
 #endif
 
 #endif /* _VKMS_FORMATS_H_ */
Signature · 1 line
2.53.0
#4 lore raw

Re: [PATCH 2/5] drm/vkms: Add KUnit test for BGR565 writeback conversion

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] drm/vkms: unroutable GitHub noreply email in Signed-off-by trailer --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] drm/vkms: unroutable GitHub noreply email in Signed-off-by trailer
--

commit f9d2ab12880eb54ad84218efebd8fde44f4e329b
Author: Sidharth Saha <[email protected]>

Quoted 9 lines

drm/vkms: Add KUnit test for BGR565 writeback conversion

Reuse the RGB565 writeback cases to test argb_u16_to_BGR565(), which packs the same 5/6/5-bit channels with red and blue swapped. The distinct-channel case checks that red and blue land in the right bits.

Make argb_u16_to_BGR565() visible to KUnit so the test can call it.

[Severity: High]
Should the Signed-off-by trailer use the commit author's routable email address ([email protected]) instead of an unroutable GitHub noreply address? The current trailer does not match the Author header and does not satisfy the Developer's Certificate of Origin requirements in Documentation/process/submitting-patches.rst.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#5 lore raw

PATCH 3/5 drm/vkms: Add KUnit tests for RGB332 and BGR233 read conversion

In reply to Sidharth Saha

Test argb_u16_from_RGB332() and argb_u16_from_BGR233(), which expand 3/3/2-bit channels to 16 bits. Each case holds the same color packed both ways, with expected values computed by hand, including channel values 4-6, where the result must be rounded up.

Make both functions visible to KUnit so the tests can call them.

---
 drivers/gpu/drm/vkms/tests/vkms_format_test.c | 49 +++++++++++++++++++++++++++
 drivers/gpu/drm/vkms/vkms_formats.c           |  6 ++--
 drivers/gpu/drm/vkms/vkms_formats.h           |  4 +++
 3 files changed, 57 insertions(+), 2 deletions(-)
drivers/gpu/drm/vkms/tests/vkms_format_test.c +49 -0
index e7836664c788..ab95d6c3d2d5 100644
@@ -315,10 +315,59 @@ static void vkms_format_test_argb_u16_to_BGR565(struct kunit *test)
 	KUNIT_EXPECT_EQ(test, (v >> 11) & 0x1f, c->b);	/* blue: high bits */
 }
 
+struct u8_read_case {
+	const char *name;
+	u8 rgb332, bgr233;	/* the same color packed both ways */
+	u16 r, g, b;		/* expected 16-bit outputs */
+};
+
+static struct u8_read_case u8_read_cases[] = {
+	/*  name          RGB332 BGR233   r       g       b     */
+	{ "zero",         0x00,  0x00,    0,      0,      0     },
+	{ "max",          0xff,  0xff,    65535,  65535,  65535 },
+	{ "red-only",     0xe0,  0x07,    65535,  0,      0     },
+	{ "green-only",   0x1c,  0x38,    0,      65535,  0     },
+	{ "blue-only",    0x03,  0xc0,    0,      0,      65535 },
+	{ "low-steps",    0x29,  0x51,    9362,   18724,  21845 },  /* r=1 g=2 b=1 */
+	{ "round-up",     0x96,  0xac,    37449,  46811,  43690 },  /* r=4 g=5 b=2 */
+	{ "mixed",        0xcc,  0x1e,    56173,  28086,  0     },  /* r=6 g=3 b=0 */
+};
+
+static void vkms_format_test_u8_read_case_desc(struct u8_read_case *t, char *desc)
+{
+	snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s", t->name);
+}
+
+KUNIT_ARRAY_PARAM(u8_read, u8_read_cases, vkms_format_test_u8_read_case_desc);
+
+static void vkms_format_test_argb_u16_from_RGB332(struct kunit *test)
+{
+	const struct u8_read_case *c = test->param_value;
+	struct pixel_argb_u16 out = argb_u16_from_RGB332(c->rgb332);
+
+	KUNIT_EXPECT_EQ(test, out.r, c->r);
+	KUNIT_EXPECT_EQ(test, out.g, c->g);
+	KUNIT_EXPECT_EQ(test, out.b, c->b);
+	KUNIT_EXPECT_EQ(test, out.a, 0xffff);	/* no alpha channel: always opaque */
+}
+
+static void vkms_format_test_argb_u16_from_BGR233(struct kunit *test)
+{
+	const struct u8_read_case *c = test->param_value;
+	struct pixel_argb_u16 out = argb_u16_from_BGR233(c->bgr233);
+
+	KUNIT_EXPECT_EQ(test, out.r, c->r);
+	KUNIT_EXPECT_EQ(test, out.g, c->g);
+	KUNIT_EXPECT_EQ(test, out.b, c->b);
+	KUNIT_EXPECT_EQ(test, out.a, 0xffff);
+}
+
 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),
 };
 
 static struct kunit_suite vkms_format_test_suite = {
drivers/gpu/drm/vkms/vkms_formats.c +4 -2
index 7950751c4890..eccca25f51d4 100644
@@ -267,17 +267,19 @@ static struct pixel_argb_u16 argb_u16_from_BGR565(const __le16 *pixel)
 				    (bgr_565 >> 11) & 0x1f, 0xffff, 5, 6, 5, 0);
 }
 
-static struct pixel_argb_u16 argb_u16_from_RGB332(u8 pixel)
+VISIBLE_IF_KUNIT struct pixel_argb_u16 argb_u16_from_RGB332(u8 pixel)
 {
 	return channels_to_argb_u16((pixel >> 5) & 0x7, (pixel >> 2) & 0x7,
 				    pixel & 0x3, 0xffff, 3, 3, 2, 0);
 }
+EXPORT_SYMBOL_IF_KUNIT(argb_u16_from_RGB332);
 
-static struct pixel_argb_u16 argb_u16_from_BGR233(u8 pixel)
+VISIBLE_IF_KUNIT struct pixel_argb_u16 argb_u16_from_BGR233(u8 pixel)
 {
 	return channels_to_argb_u16(pixel & 0x7, (pixel >> 3) & 0x7,
 				    (pixel >> 6) & 0x3, 0xffff, 3, 3, 2, 0);
 }
+EXPORT_SYMBOL_IF_KUNIT(argb_u16_from_BGR233);
 
 static struct pixel_argb_u16 argb_u16_from_gray8(u8 gray)
 {
drivers/gpu/drm/vkms/vkms_formats.h +4 -0
index 135bb60a554b..90006325a87e 100644
@@ -18,6 +18,10 @@ struct pixel_argb_u16 argb_u16_from_yuv161616(const struct conversion_matrix *ma
 					      u16 y, u16 channel_1, u16 channel_2);
 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);
+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);
 #endif
 
 #endif /* _VKMS_FORMATS_H_ */
Signature · 1 line
2.53.0
#6 lore raw

Re: [PATCH 3/5] drm/vkms: Add KUnit tests for RGB332 and BGR233 read conversion

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] drm/vkms: duplicate RGB565/BGR565 declarations in vkms_formats.h --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] drm/vkms: duplicate RGB565/BGR565 declarations in vkms_formats.h --

commit 9f63eb8da7a8714b37e3f9813c3cd23126f306f7
Author: Sidharth Saha <[email protected]>

drm/vkms: Add KUnit tests for RGB332 and BGR233 read conversion

This commit exports argb_u16_from_RGB332() and argb_u16_from_BGR233() for KUnit builds and adds parameterized KUnit tests covering RGB332 and BGR233 to 16-bit ARGB conversion.

[ ... ]

drivers/gpu/drm/vkms/vkms_formats.h struct pixel_argb_u16 argb_u16_from_yuv161616(const struct conversion_matrix *ma · line 22

Quoted 10 lines
drivers/gpu/drm/vkms/vkms_formats.h +2 -0
index 135bb60a554b4..90006325a87ea 100644
@@ -18,6 +18,10 @@ struct pixel_argb_u16 argb_u16_from_yuv161616(const struct conversion_matrix *ma
 					      u16 y, u16 channel_1, u16 channel_2);
 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);
+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);

[Severity: Low]
Were the second declarations of argb_u16_to_RGB565() and argb_u16_to_BGR565() added by mistake? They duplicate the prototypes directly above and trigger -Wredundant-decls warnings under W=2 builds with CONFIG_KUNIT enabled.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#7 lore raw

PATCH 4/5 drm/vkms: Add KUnit tests for RGB332 and BGR233 writeback conversion

In reply to Sidharth Saha

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.

---
 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(-)
drivers/gpu/drm/vkms/tests/vkms_format_test.c +51 -0
index ab95d6c3d2d5..0683a74fc623 100644
@@ -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 = {
drivers/gpu/drm/vkms/vkms_formats.c +4 -2
index eccca25f51d4..a5d04f922a94 100644
@@ -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
drivers/gpu/drm/vkms/vkms_formats.h +2 -0
index 90006325a87e..8565b2ca86c3 100644
@@ -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_ */
Signature · 1 line
2.53.0
#8 lore raw

Re: [PATCH 4/5] drm/vkms: Add KUnit tests for RGB332 and BGR233 writeback conversion

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] drm/vkms: invalid noreply and mismatched email in Signed-off-by trailer --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] drm/vkms: invalid noreply and mismatched email in Signed-off-by trailer
--

commit 029ee38d1c5f0c8b5a4e5b775f76588cc0eb383e
Author: Sidharth Saha <[email protected]>

Quoted 10 lines

drm/vkms: Add KUnit tests for RGB332 and BGR233 writeback conversion

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.

[Severity: High]
The Signed-off-by trailer uses a non-routable GitHub noreply address that does not match the commit Author address ([email protected]). Should the Signed-off-by line use the routable [email protected] address to satisfy DCO requirements?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#9 lore raw

PATCH 5/5 drm/vkms: Add KUnit tests for RGB565 and BGR565 read conversion

In reply to Sidharth Saha

argb_u16_from_RGB565() and argb_u16_from_BGR565() were converted to the new channels_to_argb_u16() helper. Test them against hand-computed values; the tests pass both before and after that conversion, showing it didn't change behavior.

Make both functions visible to KUnit so the tests can call them.

---
 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(-)
drivers/gpu/drm/vkms/tests/vkms_format_test.c +51 -0
index 0683a74fc623..841f2c840ed8 100644
@@ -411,6 +411,54 @@ static void vkms_format_test_argb_u16_to_BGR233(struct kunit *test)
 	KUNIT_EXPECT_EQ(test, out, c->bgr233);
 }
 
+struct u16_565_read_case {
+	const char *name;
+	u16 rgb565, bgr565;	/* the same color packed both ways */
+	u16 r, g, b;
+};
+
+static struct u16_565_read_case u16_565_read_cases[] = {
+	{ "zero",       0x0000, 0x0000,     0,     0,     0 },
+	{ "max",        0xffff, 0xffff, 65535, 65535, 65535 },
+	{ "red-only",   0xf800, 0x001f, 65535,     0,     0 },
+	{ "green-only", 0x07e0, 0x07e0,     0, 65535,     0 },
+	{ "blue-only",  0x001f, 0xf800,     0,     0, 65535 },
+	{ "low",        0x0821, 0x0821,  2114,  1040,  2114 },	/* 1,1,1 */
+	{ "mid",        0x8410, 0x8410, 33825, 33288, 33825 },	/* 16,32,16 */
+	{ "distinct",   0xfc00, 0x041f, 65535, 33288,     0 },	/* 31,32,0 */
+};
+
+static void vkms_format_test_u16_565_read_case_desc(struct u16_565_read_case *t, char *desc)
+{
+	snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s", t->name);
+}
+
+KUNIT_ARRAY_PARAM(u16_565_read, u16_565_read_cases, vkms_format_test_u16_565_read_case_desc);
+
+static void vkms_format_test_argb_u16_from_RGB565(struct kunit *test)
+{
+	const struct u16_565_read_case *c = test->param_value;
+	__le16 px = cpu_to_le16(c->rgb565);
+	struct pixel_argb_u16 out = argb_u16_from_RGB565(&px);
+
+	KUNIT_EXPECT_EQ(test, out.r, c->r);
+	KUNIT_EXPECT_EQ(test, out.g, c->g);
+	KUNIT_EXPECT_EQ(test, out.b, c->b);
+	KUNIT_EXPECT_EQ(test, out.a, 0xffff);
+}
+
+static void vkms_format_test_argb_u16_from_BGR565(struct kunit *test)
+{
+	const struct u16_565_read_case *c = test->param_value;
+	__le16 px = cpu_to_le16(c->bgr565);
+	struct pixel_argb_u16 out = argb_u16_from_BGR565(&px);
+
+	KUNIT_EXPECT_EQ(test, out.r, c->r);
+	KUNIT_EXPECT_EQ(test, out.g, c->g);
+	KUNIT_EXPECT_EQ(test, out.b, c->b);
+	KUNIT_EXPECT_EQ(test, out.a, 0xffff);
+}
+
 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),
@@ -419,6 +467,9 @@ static struct kunit_case vkms_format_test_cases[] = {
 	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),
+	KUNIT_CASE_PARAM(vkms_format_test_argb_u16_from_RGB565, u16_565_read_gen_params),
+	KUNIT_CASE_PARAM(vkms_format_test_argb_u16_from_BGR565, u16_565_read_gen_params),
+	{}
 };
 
 static struct kunit_suite vkms_format_test_suite = {
drivers/gpu/drm/vkms/vkms_formats.c +4 -2
index a5d04f922a94..95456ac9d003 100644
@@ -251,21 +251,23 @@ static struct pixel_argb_u16 channels_to_argb_u16(u16 in_r, u16 in_g, u16 in_b,
 	return out_pixel;
 }
 
-static struct pixel_argb_u16 argb_u16_from_RGB565(const __le16 *pixel)
+VISIBLE_IF_KUNIT struct pixel_argb_u16 argb_u16_from_RGB565(const __le16 *pixel)
 {
 	u16 rgb_565 = le16_to_cpu(*pixel);
 
 	return channels_to_argb_u16((rgb_565 >> 11) & 0x1f, (rgb_565 >> 5) & 0x3f,
 				    rgb_565 & 0x1f, 0xffff, 5, 6, 5, 0);
 }
+EXPORT_SYMBOL_IF_KUNIT(argb_u16_from_RGB565);
 
-static struct pixel_argb_u16 argb_u16_from_BGR565(const __le16 *pixel)
+VISIBLE_IF_KUNIT struct pixel_argb_u16 argb_u16_from_BGR565(const __le16 *pixel)
 {
 	u16 bgr_565 = le16_to_cpu(*pixel);
 
 	return channels_to_argb_u16(bgr_565 & 0x1f, (bgr_565 >> 5) & 0x3f,
 				    (bgr_565 >> 11) & 0x1f, 0xffff, 5, 6, 5, 0);
 }
+EXPORT_SYMBOL_IF_KUNIT(argb_u16_from_BGR565);
 
 VISIBLE_IF_KUNIT struct pixel_argb_u16 argb_u16_from_RGB332(u8 pixel)
 {
drivers/gpu/drm/vkms/vkms_formats.h +2 -0
index 8565b2ca86c3..d7a42771fd4c 100644
@@ -24,6 +24,8 @@ 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);
+struct pixel_argb_u16 argb_u16_from_RGB565(const __le16 *pixel);
+struct pixel_argb_u16 argb_u16_from_BGR565(const __le16 *pixel);
 #endif
 
 #endif /* _VKMS_FORMATS_H_ */
Signature · 1 line
2.53.0
#10 lore raw

Re: [PATCH 5/5] drm/vkms: Add KUnit tests for RGB565 and BGR565 read conversion

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] drm/vkms: non-routable GitHub noreply email in Signed-off-by trailer --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] drm/vkms: non-routable GitHub noreply email in Signed-off-by trailer
--

commit ae58f1df1e3854cf85fe440504baa5b724769237
Author: Sidharth Saha <[email protected]>

Quoted 10 lines

drm/vkms: Add KUnit tests for RGB565 and BGR565 read conversion

argb_u16_from_RGB565() and argb_u16_from_BGR565() were converted to the new channels_to_argb_u16() helper. Test them against hand-computed values; the tests pass both before and after that conversion, showing it didn't change behavior.

Make both functions visible to KUnit so the tests can call them.

[Severity: High]
The Signed-off-by trailer uses a non-routable GitHub noreply email address instead of a valid, routable address matching the Author line ([email protected]).

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5