Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/vkms: Add kunit tests for linear and sRGB LUTs

Two tests are added to VKMS LUT handling:
- linear
- inv_srgb

Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
Signed-off-by: Alex Hung <alex.hung@amd.com>
Signed-off-by: Harry Wentland <harry.wentland@amd.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Signed-off-by: Simon Ser <contact@emersion.fr>
Link: https://patch.msgid.link/20251115000237.3561250-18-alex.hung@amd.com

authored by

Harry Wentland and committed by
Simon Ser
cb500b4c 9b5c7e8b

+55 -13
+38
drivers/gpu/drm/vkms/tests/vkms_color_test.c
··· 6 6 #include <drm/drm_mode.h> 7 7 #include "../vkms_composer.h" 8 8 #include "../vkms_drv.h" 9 + #include "../vkms_luts.h" 9 10 10 11 #define TEST_LUT_SIZE 16 11 12 ··· 100 99 lut_index = get_lut_index(&test_linear_lut, test_linear_array[i].red); 101 100 KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(lut_index), i); 102 101 } 102 + 103 + KUNIT_EXPECT_EQ(test, drm_fixp2int(get_lut_index(&srgb_eotf, 0x0)), 0x0); 104 + KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_eotf, 0x0)), 0x0); 105 + KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_eotf, 0x101)), 0x1); 106 + KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_eotf, 0x202)), 0x2); 107 + 108 + KUNIT_EXPECT_EQ(test, drm_fixp2int(get_lut_index(&srgb_inv_eotf, 0x0)), 0x0); 109 + KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_inv_eotf, 0x0)), 0x0); 110 + KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_inv_eotf, 0x101)), 0x1); 111 + KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_inv_eotf, 0x202)), 0x2); 112 + 113 + KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_eotf, 0xfefe)), 0xfe); 114 + KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_eotf, 0xffff)), 0xff); 103 115 } 104 116 105 117 static void vkms_color_test_lerp(struct kunit *test) ··· 126 112 } 127 113 } 128 114 115 + static void vkms_color_test_linear(struct kunit *test) 116 + { 117 + for (int i = 0; i < LUT_SIZE; i++) { 118 + int linear = apply_lut_to_channel_value(&linear_eotf, i * 0x101, LUT_RED); 119 + 120 + KUNIT_EXPECT_EQ(test, DIV_ROUND_CLOSEST(linear, 0x101), i); 121 + } 122 + } 123 + 124 + static void vkms_color_srgb_inv_srgb(struct kunit *test) 125 + { 126 + u16 srgb, final; 127 + 128 + for (int i = 0; i < LUT_SIZE; i++) { 129 + srgb = apply_lut_to_channel_value(&srgb_eotf, i * 0x101, LUT_RED); 130 + final = apply_lut_to_channel_value(&srgb_inv_eotf, srgb, LUT_RED); 131 + 132 + KUNIT_EXPECT_GE(test, final / 0x101, i - 1); 133 + KUNIT_EXPECT_LE(test, final / 0x101, i + 1); 134 + } 135 + } 136 + 129 137 static struct kunit_case vkms_color_test_cases[] = { 130 138 KUNIT_CASE(vkms_color_test_get_lut_index), 131 139 KUNIT_CASE(vkms_color_test_lerp), 140 + KUNIT_CASE(vkms_color_test_linear), 141 + KUNIT_CASE(vkms_color_srgb_inv_srgb), 132 142 {} 133 143 }; 134 144
+4 -13
drivers/gpu/drm/vkms/vkms_composer.c
··· 82 82 } 83 83 EXPORT_SYMBOL_IF_KUNIT(get_lut_index); 84 84 85 - /* 86 - * This enum is related to the positions of the variables inside 87 - * `struct drm_color_lut`, so the order of both needs to be the same. 88 - */ 89 - enum lut_channel { 90 - LUT_RED = 0, 91 - LUT_GREEN, 92 - LUT_BLUE, 93 - LUT_RESERVED 94 - }; 95 - 96 - static u16 apply_lut_to_channel_value(const struct vkms_color_lut *lut, u16 channel_value, 97 - enum lut_channel channel) 85 + VISIBLE_IF_KUNIT u16 apply_lut_to_channel_value(const struct vkms_color_lut *lut, u16 channel_value, 86 + enum lut_channel channel) 98 87 { 99 88 s64 lut_index = get_lut_index(lut, channel_value); 100 89 u16 *floor_lut_value, *ceil_lut_value; ··· 108 119 return lerp_u16(floor_channel_value, ceil_channel_value, 109 120 lut_index & DRM_FIXED_DECIMAL_MASK); 110 121 } 122 + EXPORT_SYMBOL_IF_KUNIT(apply_lut_to_channel_value); 123 + 111 124 112 125 static void apply_lut(const struct vkms_crtc_state *crtc_state, struct line_buffer *output_buffer) 113 126 {
+13
drivers/gpu/drm/vkms/vkms_composer.h
··· 6 6 #include <kunit/visibility.h> 7 7 #include "vkms_drv.h" 8 8 9 + /* 10 + * This enum is related to the positions of the variables inside 11 + * `struct drm_color_lut`, so the order of both needs to be the same. 12 + */ 13 + enum lut_channel { 14 + LUT_RED = 0, 15 + LUT_GREEN, 16 + LUT_BLUE, 17 + LUT_RESERVED 18 + }; 19 + 9 20 #if IS_ENABLED(CONFIG_KUNIT) 10 21 u16 lerp_u16(u16 a, u16 b, s64 t); 11 22 s64 get_lut_index(const struct vkms_color_lut *lut, u16 channel_value); 23 + u16 apply_lut_to_channel_value(const struct vkms_color_lut *lut, u16 channel_value, 24 + enum lut_channel channel); 12 25 #endif 13 26 14 27 #endif /* _VKMS_COMPOSER_H_ */