]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/amd/display: Add KUnit tests for amdgpu_dm_colorop
authorAlex Hung <alex.hung@amd.com>
Thu, 21 May 2026 02:10:53 +0000 (20:10 -0600)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 3 Jun 2026 17:41:32 +0000 (13:41 -0400)
[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 <harry.wentland@amd.com>
Signed-off-by: Alex Hung <alex.hung@amd.com>
Signed-off-by: Ray Wu <ray.wu@amd.com>
Tested-by: Daniel Wheeler <daniel.wheeler@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/Kconfig
drivers/gpu/drm/amd/display/amdgpu_dm/tests/.kunitconfig
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_colorop_test.c

index 38323e574c6bb9f9e421cea9582b2188f7239c57..1727d25646cc563a0eb75dcabd2a4d867777c625 100644 (file)
@@ -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.
index a0949d3c4e6f724676a2a0205fd85f6afc61f089..bd1bf8d959f930733ebec16eed05300ad71ca9d9 100644 (file)
@@ -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
index 4245ebd3725b07c0a8fa6a76995ae3789704a262..fa270ff28c6aa0662e6ae1ad1036a526eaf8f090 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <kunit/test.h>
 #include <drm/drm_colorop.h>
+#include <drm/drm_kunit_helpers.h>
 
 #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),
        {}
 };