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 <[email protected]> --- drivers/gpu/drm/vkms/tests/vkms_color_test.c | 32 +++++++++++++++----- 1 file changed, 24 insertions(+), 8 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..c031718b0a41 100644 --- a/drivers/gpu/drm/vkms/tests/vkms_color_test.c +++ b/drivers/gpu/drm/vkms/tests/vkms_color_test.c @@ -120,20 +120,36 @@ 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; - u32 x; + u32 sum = 0; + u16 count = 0; for (u32 i = 0; i <= 4095; i++) { + u16 tmp, final; + u32 x; + 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); - KUNIT_EXPECT_LE(test, final, (int)x + tolerance); + KUNIT_EXPECT_GE(test, final, (int)x - tolerance_max); + KUNIT_EXPECT_LE(test, final, (int)x + tolerance_max); + + 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
