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

Configure Feed

Select the types of activity you want to include in your feed.

drm/vkms: Add kunit tests for VKMS LUT handling

Debugging LUT math is much easier when we can unit test
it. Add kunit functionality to VKMS and add tests for
- get_lut_index
- lerp_u16

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>
Cc: Arthur Grillo <arthurgrillo@riseup.net>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Signed-off-by: Simon Ser <contact@emersion.fr>
Link: https://patch.msgid.link/20251115000237.3561250-3-alex.hung@amd.com

authored by

Harry Wentland and committed by
Simon Ser
303e9bf1 4fc18382

+151 -4
+2 -1
drivers/gpu/drm/vkms/tests/Makefile
··· 2 2 3 3 vkms-kunit-tests-y := \ 4 4 vkms_config_test.o \ 5 - vkms_format_test.o 5 + vkms_format_test.o \ 6 + vkms_color_test.o 6 7 7 8 obj-$(CONFIG_DRM_VKMS_KUNIT_TEST) += vkms-kunit-tests.o
+129
drivers/gpu/drm/vkms/tests/vkms_color_test.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + 3 + #include <kunit/test.h> 4 + 5 + #include <drm/drm_fixed.h> 6 + #include <drm/drm_mode.h> 7 + #include "../vkms_composer.h" 8 + #include "../vkms_drv.h" 9 + 10 + #define TEST_LUT_SIZE 16 11 + 12 + MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING"); 13 + 14 + static struct drm_color_lut test_linear_array[TEST_LUT_SIZE] = { 15 + { 0x0, 0x0, 0x0, 0 }, 16 + { 0x1111, 0x1111, 0x1111, 0 }, 17 + { 0x2222, 0x2222, 0x2222, 0 }, 18 + { 0x3333, 0x3333, 0x3333, 0 }, 19 + { 0x4444, 0x4444, 0x4444, 0 }, 20 + { 0x5555, 0x5555, 0x5555, 0 }, 21 + { 0x6666, 0x6666, 0x6666, 0 }, 22 + { 0x7777, 0x7777, 0x7777, 0 }, 23 + { 0x8888, 0x8888, 0x8888, 0 }, 24 + { 0x9999, 0x9999, 0x9999, 0 }, 25 + { 0xaaaa, 0xaaaa, 0xaaaa, 0 }, 26 + { 0xbbbb, 0xbbbb, 0xbbbb, 0 }, 27 + { 0xcccc, 0xcccc, 0xcccc, 0 }, 28 + { 0xdddd, 0xdddd, 0xdddd, 0 }, 29 + { 0xeeee, 0xeeee, 0xeeee, 0 }, 30 + { 0xffff, 0xffff, 0xffff, 0 }, 31 + }; 32 + 33 + /* lerp test parameters */ 34 + struct vkms_color_test_lerp_params { 35 + s64 t; 36 + __u16 a; 37 + __u16 b; 38 + __u16 expected; 39 + }; 40 + 41 + /* lerp test cases */ 42 + static const struct vkms_color_test_lerp_params color_test_lerp_cases[] = { 43 + /* Half-way round down */ 44 + { 0x80000000 - 1, 0x0, 0x10, 0x8 }, 45 + { 0x80000000 - 1, 0x1, 0x10, 0x8 }, /* Odd a */ 46 + { 0x80000000 - 1, 0x1, 0xf, 0x8 }, /* Odd b */ 47 + { 0x80000000 - 1, 0x10, 0x10, 0x10 }, /* b = a */ 48 + { 0x80000000 - 1, 0x10, 0x11, 0x10 }, /* b = a + 1*/ 49 + /* Half-way round up */ 50 + { 0x80000000, 0x0, 0x10, 0x8 }, 51 + { 0x80000000, 0x1, 0x10, 0x9 }, /* Odd a */ 52 + { 0x80000000, 0x1, 0xf, 0x8 }, /* Odd b */ 53 + { 0x80000000, 0x10, 0x10, 0x10 }, /* b = a */ 54 + { 0x80000000, 0x10, 0x11, 0x11 }, /* b = a + 1*/ 55 + /* t = 0.0 */ 56 + { 0x0, 0x0, 0x10, 0x0 }, 57 + { 0x0, 0x1, 0x10, 0x1 }, /* Odd a */ 58 + { 0x0, 0x1, 0xf, 0x1 }, /* Odd b */ 59 + { 0x0, 0x10, 0x10, 0x10 }, /* b = a */ 60 + { 0x0, 0x10, 0x11, 0x10 }, /* b = a + 1*/ 61 + /* t = 1.0 */ 62 + { 0x100000000, 0x0, 0x10, 0x10 }, 63 + { 0x100000000, 0x1, 0x10, 0x10 }, /* Odd a */ 64 + { 0x100000000, 0x1, 0xf, 0xf }, /* Odd b */ 65 + { 0x100000000, 0x10, 0x10, 0x10 }, /* b = a */ 66 + { 0x100000000, 0x10, 0x11, 0x11 }, /* b = a + 1*/ 67 + /* t = 0.0 + 1 */ 68 + { 0x0 + 1, 0x0, 0x10, 0x0 }, 69 + { 0x0 + 1, 0x1, 0x10, 0x1 }, /* Odd a */ 70 + { 0x0 + 1, 0x1, 0xf, 0x1 }, /* Odd b */ 71 + { 0x0 + 1, 0x10, 0x10, 0x10 }, /* b = a */ 72 + { 0x0 + 1, 0x10, 0x11, 0x10 }, /* b = a + 1*/ 73 + /* t = 1.0 - 1 */ 74 + { 0x100000000 - 1, 0x0, 0x10, 0x10 }, 75 + { 0x100000000 - 1, 0x1, 0x10, 0x10 }, /* Odd a */ 76 + { 0x100000000 - 1, 0x1, 0xf, 0xf }, /* Odd b */ 77 + { 0x100000000 - 1, 0x10, 0x10, 0x10 }, /* b = a */ 78 + { 0x100000000 - 1, 0x10, 0x11, 0x11 }, /* b = a + 1*/ 79 + /* t chosen to verify the flipping point of result a (or b) to a+1 (or b-1) */ 80 + { 0x80000000 - 1, 0x0, 0x1, 0x0 }, 81 + { 0x80000000, 0x0, 0x1, 0x1 }, 82 + }; 83 + 84 + static const struct vkms_color_lut test_linear_lut = { 85 + .base = test_linear_array, 86 + .lut_length = TEST_LUT_SIZE, 87 + .channel_value2index_ratio = 0xf000fll 88 + }; 89 + 90 + static void vkms_color_test_get_lut_index(struct kunit *test) 91 + { 92 + s64 lut_index; 93 + int i; 94 + 95 + lut_index = get_lut_index(&test_linear_lut, test_linear_array[0].red); 96 + KUNIT_EXPECT_EQ(test, drm_fixp2int(lut_index), 0); 97 + 98 + for (i = 0; i < TEST_LUT_SIZE; i++) { 99 + lut_index = get_lut_index(&test_linear_lut, test_linear_array[i].red); 100 + KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(lut_index), i); 101 + } 102 + } 103 + 104 + static void vkms_color_test_lerp(struct kunit *test) 105 + { 106 + int i; 107 + 108 + for (i = 0; i < ARRAY_SIZE(color_test_lerp_cases); i++) { 109 + const struct vkms_color_test_lerp_params *params = &color_test_lerp_cases[i]; 110 + 111 + KUNIT_EXPECT_EQ(test, lerp_u16(params->a, params->b, params->t), params->expected); 112 + } 113 + } 114 + 115 + static struct kunit_case vkms_color_test_cases[] = { 116 + KUNIT_CASE(vkms_color_test_get_lut_index), 117 + KUNIT_CASE(vkms_color_test_lerp), 118 + {} 119 + }; 120 + 121 + static struct kunit_suite vkms_color_test_suite = { 122 + .name = "vkms-color", 123 + .test_cases = vkms_color_test_cases, 124 + }; 125 + 126 + kunit_test_suite(vkms_color_test_suite); 127 + 128 + MODULE_DESCRIPTION("Kunit test for VKMS LUT handling"); 129 + MODULE_LICENSE("GPL");
+6 -3
drivers/gpu/drm/vkms/vkms_composer.c
··· 11 11 #include <drm/drm_print.h> 12 12 #include <drm/drm_vblank.h> 13 13 #include <linux/minmax.h> 14 + #include <kunit/visibility.h> 14 15 15 - #include "vkms_drv.h" 16 + #include "vkms_composer.h" 16 17 17 18 static u16 pre_mul_blend_channel(u16 src, u16 dst, u16 alpha) 18 19 { ··· 62 61 } 63 62 64 63 // lerp(a, b, t) = a + (b - a) * t 65 - static u16 lerp_u16(u16 a, u16 b, s64 t) 64 + VISIBLE_IF_KUNIT u16 lerp_u16(u16 a, u16 b, s64 t) 66 65 { 67 66 s64 a_fp = drm_int2fixp(a); 68 67 s64 b_fp = drm_int2fixp(b); ··· 71 70 72 71 return drm_fixp2int_round(a_fp + delta); 73 72 } 73 + EXPORT_SYMBOL_IF_KUNIT(lerp_u16); 74 74 75 - static s64 get_lut_index(const struct vkms_color_lut *lut, u16 channel_value) 75 + VISIBLE_IF_KUNIT s64 get_lut_index(const struct vkms_color_lut *lut, u16 channel_value) 76 76 { 77 77 s64 color_channel_fp = drm_int2fixp(channel_value); 78 78 79 79 return drm_fixp_mul(color_channel_fp, lut->channel_value2index_ratio); 80 80 } 81 + EXPORT_SYMBOL_IF_KUNIT(get_lut_index); 81 82 82 83 /* 83 84 * This enum is related to the positions of the variables inside
+14
drivers/gpu/drm/vkms/vkms_composer.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0+ */ 2 + 3 + #ifndef _VKMS_COMPOSER_H_ 4 + #define _VKMS_COMPOSER_H_ 5 + 6 + #include <kunit/visibility.h> 7 + #include "vkms_drv.h" 8 + 9 + #if IS_ENABLED(CONFIG_KUNIT) 10 + u16 lerp_u16(u16 a, u16 b, s64 t); 11 + s64 get_lut_index(const struct vkms_color_lut *lut, u16 channel_value); 12 + #endif 13 + 14 + #endif /* _VKMS_COMPOSER_H_ */