[PATCH v1 2/4] drm/vkms: Make LUT test reusable

From: Robert Mader

Date: Fri Dec 04 2026 - 08:53:23 EST


Factor out the logic so we can reuse it for other LUTs and, While on it,
add an average error which will become useful in follow-up commits.

Signed-off-by: Robert Mader <robert.mader@xxxxxxxxxxxxx>
---
drivers/gpu/drm/vkms/tests/vkms_color_test.c | 29 +++++++++++++++-----
1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/vkms/tests/vkms_color_test.c b/drivers/gpu/drm/vkms/tests/vkms_color_test.c
index c3c61037cb71..409e7a7d6861 100644
--- a/drivers/gpu/drm/vkms/tests/vkms_color_test.c
+++ b/drivers/gpu/drm/vkms/tests/vkms_color_test.c
@@ -120,20 +120,35 @@ static void vkms_color_test_linear(struct kunit *test)
}
}

-static void vkms_color_srgb_inv_srgb(struct kunit *test)
+static void vkms_color_test_inv_lut(struct kunit *test,
+ const struct vkms_color_lut *lut,
+ const struct vkms_color_lut *inv_lut,
+ u16 tolerance_max,
+ u16 tolerance_avg)
{
- u16 srgb, final;
- u16 tolerance = 11;
+ u16 sum = 0;
+ u16 count = 0;
+ u16 tmp, final;
u32 x;

for (u32 i = 0; i <= 4095; i++) {
x = i * U16_MAX / 4095;
- srgb = apply_lut_to_channel_value(&srgb_eotf, x, LUT_RED);
- final = apply_lut_to_channel_value(&srgb_inv_eotf, srgb, LUT_RED);
+ tmp = apply_lut_to_channel_value(lut, x, LUT_RED);
+ final = apply_lut_to_channel_value(inv_lut, tmp, LUT_RED);
+
+ KUNIT_EXPECT_GE(test, final, (int)x - tolerance_max);
+ KUNIT_EXPECT_LE(test, final, (int)x + tolerance_max);

- KUNIT_EXPECT_GE(test, final, (int)x - tolerance);
- KUNIT_EXPECT_LE(test, final, (int)x + tolerance);
+ sum += abs((int)x - final);
+ count++;
}
+
+ KUNIT_EXPECT_LE(test, sum / count, tolerance_avg);
+}
+
+static void vkms_color_srgb_inv_srgb(struct kunit *test)
+{
+ vkms_color_test_inv_lut(test, &srgb_eotf, &srgb_inv_eotf, 11, 0);
}

#define FIXPT_HALF (DRM_FIXED_ONE >> 1)
--
2.56.1