build_lut_table() turns a per-pixel interpolation into a table lookup, so
a wrong entry changes the composed output with no other symptom.

Compare every entry against apply_lut_to_channel_value() for the same
channel and value, for a 4-entry LUT whose channels differ and for the
256-entry sRGB one. The check stops at the first mismatch and prints its
channel, value and both results.

The tables are built with apply_lut_to_channel_value(), so this proves the
lookup matches the interpolation, not that the LUT arithmetic is right;
vkms_color_srgb_inv_srgb() covers the latter.

Signed-off-by: Oarora Etimis <[email protected]>
---
 drivers/gpu/drm/vkms/tests/vkms_color_test.c | 54 ++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/drivers/gpu/drm/vkms/tests/vkms_color_test.c 
b/drivers/gpu/drm/vkms/tests/vkms_color_test.c
index 1a1c7cac2f15..cdbb74d16b5e 100644
--- a/drivers/gpu/drm/vkms/tests/vkms_color_test.c
+++ b/drivers/gpu/drm/vkms/tests/vkms_color_test.c
@@ -88,6 +88,21 @@ static const struct vkms_color_lut test_linear_lut = {
        .channel_value2index_ratio = 0xf000fll
 };
 
+/* Channels differ, so a table built with the wrong channel does not match. */
+static struct drm_color_lut test_distinct_array[] = {
+       { 0x0000, 0x0000, 0x0000, 0 },
+       { 0x1000, 0x6000, 0xb000, 0 },
+       { 0x2000, 0x4000, 0x9000, 0 },
+       { 0xffff, 0xffff, 0xffff, 0 },
+};
+
+static const struct vkms_color_lut test_distinct_lut = {
+       .base = test_distinct_array,
+       .lut_length = ARRAY_SIZE(test_distinct_array),
+       /* drm_fixp_div(drm_int2fixp(lut_length - 1), drm_int2fixp(0xffff)) */
+       .channel_value2index_ratio = 0x30003ll
+};
+
 static void vkms_color_test_get_lut_index(struct kunit *test)
 {
        s64 lut_index;
@@ -393,6 +408,44 @@ static void vkms_color_ctm_3x4_bt709(struct kunit *test)
        KUNIT_EXPECT_LT(test, out.b, 0x100);
 }
 
+static void vkms_color_test_check_lut_table(struct kunit *test,
+                                           const struct vkms_color_lut *lut,
+                                           const u16 *table)
+{
+       int i;
+
+       for (i = 0; i < LUT_RESERVED * LUT_TABLE_ENTRIES; i++) {
+               enum lut_channel channel = i / LUT_TABLE_ENTRIES;
+               u16 value = i % LUT_TABLE_ENTRIES;
+               u16 expected = apply_lut_to_channel_value(lut, value, channel);
+
+               if (table[i] != expected) {
+                       KUNIT_FAIL(test, "channel %d, value %#06x: 0x%04x != 
0x%04x",
+                                  channel, value, table[i], expected);
+                       return;
+               }
+       }
+}
+
+static void vkms_color_test_build_lut_table(struct kunit *test)
+{
+       const struct vkms_color_lut *luts[] = {
+               &test_distinct_lut,
+               &srgb_eotf,
+       };
+       u16 *table;
+       int l;
+
+       table = kunit_kzalloc(test, LUT_RESERVED * LUT_TABLE_ENTRIES * 
sizeof(*table),
+                             GFP_KERNEL);
+       KUNIT_ASSERT_NOT_NULL(test, table);
+
+       for (l = 0; l < ARRAY_SIZE(luts); l++) {
+               build_lut_table(luts[l], table);
+               vkms_color_test_check_lut_table(test, luts[l], table);
+       }
+}
+
 static struct kunit_case vkms_color_test_cases[] = {
        KUNIT_CASE(vkms_color_test_get_lut_index),
        KUNIT_CASE(vkms_color_test_lerp),
@@ -400,6 +453,7 @@ static struct kunit_case vkms_color_test_cases[] = {
        KUNIT_CASE(vkms_color_srgb_inv_srgb),
        KUNIT_CASE(vkms_color_ctm_3x4_50_desat),
        KUNIT_CASE(vkms_color_ctm_3x4_bt709),
+       KUNIT_CASE(vkms_color_test_build_lut_table),
        {}
 };
 

-- 
2.55.0

Reply via email to