]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/amd/display: Add KUnit test for colorop TF bitmasks
authorAlex Hung <alex.hung@amd.com>
Wed, 22 Apr 2026 17:37:19 +0000 (11:37 -0600)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 19 May 2026 15:54:36 +0000 (11:54 -0400)
Add KUnit tests that verify the three supported transfer
function bitmask constants exported by amdgpu_dm_colorop.c:
amdgpu_dm_supported_degam_tfs, amdgpu_dm_supported_shaper_tfs,
and amdgpu_dm_supported_blnd_tfs.

Each bitmask is tested for presence of each expected curve
flag and absence of any unexpected bits.  A cross-check
confirms that degam and blnd bitmasks are identical.

amdgpu_dm_initialize_default_pipeline() is not tested
because it needs a fully initialised drm_plane backed by
an amdgpu_device with DC color caps.

Assisted-by: Copilot:Claude-Opus-4.6
Reviewed-by: Harry Wentland <harry.wentland@amd.com>
Signed-off-by: Alex Hung <alex.hung@amd.com>
Signed-off-by: Ivan Lipski <ivan.lipski@amd.com>
Tested-by: Dan Wheeler <daniel.wheeler@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/amdgpu_dm/tests/Makefile
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_colorop_test.c [new file with mode: 0644]

index 9669ea79a666ac5a5098c168d4d757ebfc557ec8..e300bcf39835756209a7b2691abd0a6f57a88828 100644 (file)
@@ -10,3 +10,4 @@ ccflags-y += -I$(src)/../../dc
 
 obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_crc_test.o
 obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_hdcp_test.o
+obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_colorop_test.o
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_colorop_test.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_colorop_test.c
new file mode 100644 (file)
index 0000000..8bdebca
--- /dev/null
@@ -0,0 +1,161 @@
+// SPDX-License-Identifier: GPL-2.0 OR MIT
+/*
+ * KUnit tests for amdgpu_dm_colorop.c
+ *
+ * Copyright 2026 Advanced Micro Devices, Inc.
+ */
+
+#include <kunit/test.h>
+#include <drm/drm_colorop.h>
+
+#include "amdgpu_dm_colorop.h"
+
+/* Tests for amdgpu_dm_supported_degam_tfs */
+
+static void dm_test_supported_degam_tfs_has_srgb_eotf(struct kunit *test)
+{
+       KUNIT_EXPECT_TRUE(test, amdgpu_dm_supported_degam_tfs &
+                         BIT(DRM_COLOROP_1D_CURVE_SRGB_EOTF));
+}
+
+static void dm_test_supported_degam_tfs_has_pq125_eotf(struct kunit *test)
+{
+       KUNIT_EXPECT_TRUE(test, amdgpu_dm_supported_degam_tfs &
+                         BIT(DRM_COLOROP_1D_CURVE_PQ_125_EOTF));
+}
+
+static void dm_test_supported_degam_tfs_has_bt2020_inv_oetf(struct kunit *test)
+{
+       KUNIT_EXPECT_TRUE(test, amdgpu_dm_supported_degam_tfs &
+                         BIT(DRM_COLOROP_1D_CURVE_BT2020_INV_OETF));
+}
+
+static void dm_test_supported_degam_tfs_has_gamma22_inv(struct kunit *test)
+{
+       KUNIT_EXPECT_TRUE(test, amdgpu_dm_supported_degam_tfs &
+                         BIT(DRM_COLOROP_1D_CURVE_GAMMA22_INV));
+}
+
+static void dm_test_supported_degam_tfs_no_extra_bits(struct kunit *test)
+{
+       u64 expected = BIT(DRM_COLOROP_1D_CURVE_SRGB_EOTF) |
+                      BIT(DRM_COLOROP_1D_CURVE_PQ_125_EOTF) |
+                      BIT(DRM_COLOROP_1D_CURVE_BT2020_INV_OETF) |
+                      BIT(DRM_COLOROP_1D_CURVE_GAMMA22_INV);
+
+       KUNIT_EXPECT_EQ(test, amdgpu_dm_supported_degam_tfs, expected);
+}
+
+/* Tests for amdgpu_dm_supported_shaper_tfs */
+
+static void dm_test_supported_shaper_tfs_has_srgb_inv_eotf(struct kunit *test)
+{
+       KUNIT_EXPECT_TRUE(test, amdgpu_dm_supported_shaper_tfs &
+                         BIT(DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF));
+}
+
+static void dm_test_supported_shaper_tfs_has_pq125_inv_eotf(struct kunit *test)
+{
+       KUNIT_EXPECT_TRUE(test, amdgpu_dm_supported_shaper_tfs &
+                         BIT(DRM_COLOROP_1D_CURVE_PQ_125_INV_EOTF));
+}
+
+static void dm_test_supported_shaper_tfs_has_bt2020_oetf(struct kunit *test)
+{
+       KUNIT_EXPECT_TRUE(test, amdgpu_dm_supported_shaper_tfs &
+                         BIT(DRM_COLOROP_1D_CURVE_BT2020_OETF));
+}
+
+static void dm_test_supported_shaper_tfs_has_gamma22(struct kunit *test)
+{
+       KUNIT_EXPECT_TRUE(test, amdgpu_dm_supported_shaper_tfs &
+                         BIT(DRM_COLOROP_1D_CURVE_GAMMA22));
+}
+
+static void dm_test_supported_degam_tfs_no_extra_bits(struct kunit *test)
+{
+       u64 expected = BIT(DRM_COLOROP_1D_CURVE_SRGB_EOTF) |
+                      BIT(DRM_COLOROP_1D_CURVE_PQ_125_EOTF) |
+                      BIT(DRM_COLOROP_1D_CURVE_BT2020_INV_OETF) |
+                      BIT(DRM_COLOROP_1D_CURVE_GAMMA22_INV);
+
+       KUNIT_EXPECT_EQ(test, amdgpu_dm_supported_shaper_tfs, expected);
+}
+
+/* Tests for amdgpu_dm_supported_blnd_tfs */
+
+static void dm_test_supported_blnd_tfs_has_srgb_eotf(struct kunit *test)
+{
+       KUNIT_EXPECT_TRUE(test, amdgpu_dm_supported_blnd_tfs &
+                         BIT(DRM_COLOROP_1D_CURVE_SRGB_EOTF));
+}
+
+static void dm_test_supported_blnd_tfs_has_pq125_eotf(struct kunit *test)
+{
+       KUNIT_EXPECT_TRUE(test, amdgpu_dm_supported_blnd_tfs &
+                         BIT(DRM_COLOROP_1D_CURVE_PQ_125_EOTF));
+}
+
+static void dm_test_supported_blnd_tfs_has_bt2020_inv_oetf(struct kunit *test)
+{
+       KUNIT_EXPECT_TRUE(test, amdgpu_dm_supported_blnd_tfs &
+                         BIT(DRM_COLOROP_1D_CURVE_BT2020_INV_OETF));
+}
+
+static void dm_test_supported_blnd_tfs_has_gamma22_inv(struct kunit *test)
+{
+       KUNIT_EXPECT_TRUE(test, amdgpu_dm_supported_blnd_tfs &
+                         BIT(DRM_COLOROP_1D_CURVE_GAMMA22_INV));
+}
+
+static void dm_test_supported_blnd_tfs_no_extra_bits(struct kunit *test)
+{
+       u64 expected = BIT(DRM_COLOROP_1D_CURVE_SRGB_EOTF) |
+                      BIT(DRM_COLOROP_1D_CURVE_PQ_125_EOTF) |
+                      BIT(DRM_COLOROP_1D_CURVE_BT2020_INV_OETF) |
+                      BIT(DRM_COLOROP_1D_CURVE_GAMMA22_INV);
+
+       KUNIT_EXPECT_EQ(test, amdgpu_dm_supported_blnd_tfs, expected);
+}
+
+/* degam and blnd should support the same set of EOTF curves */
+static void dm_test_degam_and_blnd_tfs_match(struct kunit *test)
+{
+       KUNIT_EXPECT_EQ(test, amdgpu_dm_supported_degam_tfs,
+                       amdgpu_dm_supported_blnd_tfs);
+}
+
+static struct kunit_case dm_colorop_test_cases[] = {
+       /* degam TFs */
+       KUNIT_CASE(dm_test_supported_degam_tfs_has_srgb_eotf),
+       KUNIT_CASE(dm_test_supported_degam_tfs_has_pq125_eotf),
+       KUNIT_CASE(dm_test_supported_degam_tfs_has_bt2020_inv_oetf),
+       KUNIT_CASE(dm_test_supported_degam_tfs_has_gamma22_inv),
+       KUNIT_CASE(dm_test_supported_degam_tfs_no_extra_bits),
+       /* shaper TFs */
+       KUNIT_CASE(dm_test_supported_shaper_tfs_has_srgb_inv_eotf),
+       KUNIT_CASE(dm_test_supported_shaper_tfs_has_pq125_inv_eotf),
+       KUNIT_CASE(dm_test_supported_shaper_tfs_has_bt2020_oetf),
+       KUNIT_CASE(dm_test_supported_shaper_tfs_has_gamma22),
+       KUNIT_CASE(dm_test_supported_shaper_tfs_no_extra_bits),
+       /* blnd TFs */
+       KUNIT_CASE(dm_test_supported_blnd_tfs_has_srgb_eotf),
+       KUNIT_CASE(dm_test_supported_blnd_tfs_has_pq125_eotf),
+       KUNIT_CASE(dm_test_supported_blnd_tfs_has_bt2020_inv_oetf),
+       KUNIT_CASE(dm_test_supported_blnd_tfs_has_gamma22_inv),
+       KUNIT_CASE(dm_test_supported_blnd_tfs_no_extra_bits),
+       /* cross-check */
+       KUNIT_CASE(dm_test_degam_and_blnd_tfs_match),
+       {}
+};
+
+static struct kunit_suite dm_colorop_test_suite = {
+       .name = "amdgpu_dm_colorop",
+       .test_cases = dm_colorop_test_cases,
+};
+
+kunit_test_suite(dm_colorop_test_suite);
+
+MODULE_LICENSE("Dual MIT/GPL");
+MODULE_DESCRIPTION("KUnit tests for amdgpu_dm_colorop");
+MODULE_AUTHOR("AMD");