From: Alex Hung Date: Thu, 21 May 2026 02:10:53 +0000 (-0600) Subject: drm/amd/display: Add KUnit tests for amdgpu_dm_colorop X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2da6b0b28f87c16305771d5d4b5d1699c3c6a799;p=thirdparty%2Fkernel%2Flinux.git drm/amd/display: Add KUnit tests for amdgpu_dm_colorop [Why & How] Add a KUnit pipeline test for amdgpu_dm_build_default_pipeline(). The pipeline test uses a mock drm_device (via DRM KUnit helpers), calls amdgpu_dm_build_default_pipeline() with hw_3d_lut=true, then walks the returned colorop chain asserting the correct type sequence (degam_tf, mult, ctm, shaper_tf, shaper_lut, 3dlut, blnd_tf, blnd_lut), that every op carries bypass_property, and that the chain length is exactly eight. A kunit cleanup action calls drm_colorop_pipeline_destroy() before the device is torn down. Assisted-by: Copilot:Claude-Sonnet-4.6 Reviewed-by: Harry Wentland Signed-off-by: Alex Hung Signed-off-by: Ray Wu Tested-by: Daniel Wheeler Signed-off-by: Alex Deucher --- diff --git a/drivers/gpu/drm/amd/display/Kconfig b/drivers/gpu/drm/amd/display/Kconfig index 38323e574c6bb..1727d25646cc5 100644 --- a/drivers/gpu/drm/amd/display/Kconfig +++ b/drivers/gpu/drm/amd/display/Kconfig @@ -58,7 +58,7 @@ config DRM_AMD_SECURE_DISPLAY config DRM_AMD_DC_KUNIT_TEST tristate "KUnit tests for the AMD DC display driver" if !KUNIT_ALL_TESTS - depends on DRM_AMD_DC && KUNIT && DEBUG_FS + depends on DRM_AMD_DC && KUNIT && DEBUG_FS && DRM_KUNIT_TEST_HELPERS default KUNIT_ALL_TESTS help This option enables KUnit tests for the AMD Display Core driver. diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/.kunitconfig b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/.kunitconfig index a0949d3c4e6f7..bd1bf8d959f93 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/.kunitconfig +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/.kunitconfig @@ -6,6 +6,8 @@ CONFIG_DRM_AMD_DC=y CONFIG_DEBUG_FS=y CONFIG_DRM_AMD_DC_KUNIT_TEST=y CONFIG_FW_LOADER=y +CONFIG_DRM_KUNIT_TEST=y +CONFIG_DRM_KUNIT_TEST_HELPERS=y CONFIG_DRM_KMS_HELPER=y CONFIG_DRM_TTM=y CONFIG_HWMON=y 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 index 4245ebd3725b0..fa270ff28c6aa 100644 --- 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 @@ -7,6 +7,7 @@ #include #include +#include #include "amdgpu_dm_colorop.h" @@ -125,6 +126,81 @@ static void dm_test_degam_and_blnd_tfs_match(struct kunit *test) amdgpu_dm_supported_blnd_tfs); } +/* Tests for amdgpu_dm_initialize_default_pipeline */ + +static void kunit_colorop_pipeline_destroy(void *drm) +{ + drm_colorop_pipeline_destroy((struct drm_device *)drm); +} + +/** + * dm_test_initialize_default_pipeline() - Verify amdgpu_dm_build_default_pipeline() + * produces the expected colorop chain with all ops bypassable. + * @test: KUnit test context. + */ +static void dm_test_initialize_default_pipeline(struct kunit *test) +{ + static const enum drm_colorop_type expected[] = { + DRM_COLOROP_1D_CURVE, /* degam TF */ + DRM_COLOROP_MULTIPLIER, + DRM_COLOROP_CTM_3X4, + DRM_COLOROP_1D_CURVE, /* shaper TF */ + DRM_COLOROP_1D_LUT, /* shaper LUT */ + DRM_COLOROP_3D_LUT, + DRM_COLOROP_1D_CURVE, /* blnd TF */ + DRM_COLOROP_1D_LUT, /* blnd LUT */ + }; + struct device *dev; + struct drm_device *drm; + struct drm_plane *plane; + struct drm_prop_enum_list list = {}; + struct drm_colorop *op, *first = NULL; + int i = 0; + int ret; + + dev = drm_kunit_helper_alloc_device(test); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev); + + /* + * Allocate a plain drm_device (not an amdgpu_device) — sufficient + * because amdgpu_dm_build_default_pipeline() only needs the DRM + * mode-config infrastructure, not the amdgpu device wrapper. + */ + drm = __drm_kunit_helper_alloc_drm_device(test, dev, + sizeof(*drm), 0, 0); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm); + + plane = drm_kunit_helper_create_primary_plane(test, drm, + NULL, NULL, NULL, 0, NULL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, plane); + + /* + * Destroy the pipeline before the DRM device is cleaned up so + * that the colorop objects (kzalloc'd inside the function) are + * freed while the device is still valid. + */ + kunit_add_action(test, kunit_colorop_pipeline_destroy, drm); + + ret = amdgpu_dm_build_default_pipeline(drm, plane, true, &list); + KUNIT_ASSERT_EQ(test, ret, 0); + kfree(list.name); + + drm_for_each_colorop(op, drm) { + if (op->base.id == (uint32_t)list.type) { + first = op; + break; + } + } + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, first); + + for (op = first; op; op = op->next, i++) { + KUNIT_ASSERT_LT(test, i, (int)ARRAY_SIZE(expected)); + KUNIT_EXPECT_EQ(test, op->type, expected[i]); + KUNIT_EXPECT_NOT_NULL(test, op->bypass_property); + } + KUNIT_EXPECT_EQ(test, i, (int)ARRAY_SIZE(expected)); +} + static struct kunit_case dm_colorop_test_cases[] = { /* degam TFs */ KUNIT_CASE(dm_test_supported_degam_tfs_has_srgb_eotf), @@ -146,6 +222,8 @@ static struct kunit_case dm_colorop_test_cases[] = { KUNIT_CASE(dm_test_supported_blnd_tfs_no_extra_bits), /* cross-check */ KUNIT_CASE(dm_test_degam_and_blnd_tfs_match), + /* amdgpu_dm_initialize_default_pipeline */ + KUNIT_CASE(dm_test_initialize_default_pipeline), {} };