]> git.hungrycats.org Git - linux/commitdiff
drm/amd/display: Add FBC init tests for connector
authorBhawanpreet Lakha <bhawanpreet.lakha@amd.com>
Tue, 23 Jun 2026 18:41:01 +0000 (14:41 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 15 Jul 2026 13:15:38 +0000 (09:15 -0400)
Add KUnit coverage for amdgpu_dm_fbc_init() on the
amdgpu_dm_connector tests:

- No FBC present
- Non-eDP link
- Buffer already allocated

Assisted-by: Copilot:Claude-Opus-4.8
Reviewed-by: Alex Hung <alex.hung@amd.com>
Signed-off-by: Bhawanpreet Lakha <bhawanpreet.lakha@amd.com>
Signed-off-by: George Zhang <george.zhang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.h
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c

index b24a4afb915375a7fe73fcb62b5fb60f35321c39..82eb8b0bcc4bfb50fce2c53e0a356aa6a7141104 100644 (file)
@@ -255,7 +255,7 @@ EXPORT_IF_KUNIT(update_subconnector_property);
 
 static int amdgpu_dm_connector_get_modes(struct drm_connector *connector);
 
-static void amdgpu_dm_fbc_init(struct drm_connector *connector)
+STATIC_IFN_KUNIT void amdgpu_dm_fbc_init(struct drm_connector *connector)
 {
        struct amdgpu_device *adev = drm_to_adev(connector->dev);
        struct dm_compressor_info *compressor = &adev->dm.compressor;
@@ -293,6 +293,7 @@ static void amdgpu_dm_fbc_init(struct drm_connector *connector)
        }
 
 }
+EXPORT_IF_KUNIT(amdgpu_dm_fbc_init);
 
 
 int amdgpu_dm_detect_mst_link_for_all_connectors(struct drm_device *dev)
index ecf23d0fb72e6c954998756da4d0d9887e99c558..7d351587c42a45e786c84bd4c96d588eae62ff8c 100644 (file)
@@ -148,6 +148,7 @@ int amdgpu_dm_encoder_init(struct drm_device *dev,
 #if IS_ENABLED(CONFIG_DRM_AMD_DC_KUNIT_TEST)
 enum drm_mode_subconnector get_subconnector_type(struct dc_link *link);
 void update_subconnector_property(struct amdgpu_dm_connector *aconnector);
+void amdgpu_dm_fbc_init(struct drm_connector *connector);
 enum display_content_type
 get_output_content_type(const struct drm_connector_state *connector_state);
 bool adjust_colour_depth_from_display_info(struct dc_crtc_timing *timing_out,
index 782a22e4f0748f87ce9f980306aeddf114c8f2e0..aa274f5e4b8482856cafeec06c453cfb8d41f025 100644 (file)
@@ -2665,6 +2665,113 @@ static void dm_test_update_subconnector_non_dp_noop(struct kunit *test)
        KUNIT_EXPECT_EQ(test, (int)val, (int)DRM_MODE_SUBCONNECTOR_VGA);
 }
 
+/* Tests for amdgpu_dm_fbc_init() */
+
+/*
+ * Build an amdgpu_dm_connector wired to a kunit-allocated amdgpu_device so
+ * that drm_to_adev() and to_amdgpu_dm_connector() resolve correctly, with a
+ * dc, dc_link and an empty modes list ready for amdgpu_dm_fbc_init().
+ */
+struct dm_test_fbc_ctx {
+       struct amdgpu_device *adev;
+       struct amdgpu_dm_connector *aconnector;
+       struct dc *dc;
+       struct dc_link *link;
+};
+
+static struct dm_test_fbc_ctx *dm_test_fbc_ctx_alloc(struct kunit *test)
+{
+       struct dm_test_fbc_ctx *ctx;
+
+       ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
+       KUNIT_ASSERT_NOT_NULL(test, ctx);
+
+       ctx->adev = kunit_kzalloc(test, sizeof(*ctx->adev), GFP_KERNEL);
+       KUNIT_ASSERT_NOT_NULL(test, ctx->adev);
+       ctx->aconnector = kunit_kzalloc(test, sizeof(*ctx->aconnector), GFP_KERNEL);
+       KUNIT_ASSERT_NOT_NULL(test, ctx->aconnector);
+       ctx->dc = kunit_kzalloc(test, sizeof(*ctx->dc), GFP_KERNEL);
+       KUNIT_ASSERT_NOT_NULL(test, ctx->dc);
+       ctx->link = kunit_kzalloc(test, sizeof(*ctx->link), GFP_KERNEL);
+       KUNIT_ASSERT_NOT_NULL(test, ctx->link);
+
+       ctx->aconnector->base.dev = &ctx->adev->ddev;
+       INIT_LIST_HEAD(&ctx->aconnector->base.modes);
+       ctx->adev->dm.dc = ctx->dc;
+       ctx->aconnector->dc_link = ctx->link;
+
+       /* Default to the fully-enabled path so each test only flips one knob */
+       ctx->link->connector_signal = SIGNAL_TYPE_EDP;
+       ctx->dc->fbc_compressor =
+               (struct compressor *)kunit_kzalloc(test, sizeof(void *), GFP_KERNEL);
+       KUNIT_ASSERT_NOT_NULL(test, ctx->dc->fbc_compressor);
+
+       return ctx;
+}
+
+/**
+ * dm_test_fbc_init_no_compressor - Test fbc_init is a no-op without a compressor
+ * @test: The KUnit test context
+ */
+static void dm_test_fbc_init_no_compressor(struct kunit *test)
+{
+       struct dm_test_fbc_ctx *ctx = dm_test_fbc_ctx_alloc(test);
+
+       ctx->dc->fbc_compressor = NULL;
+
+       amdgpu_dm_fbc_init(&ctx->aconnector->base);
+
+       KUNIT_EXPECT_NULL(test, ctx->adev->dm.compressor.bo_ptr);
+}
+
+/**
+ * dm_test_fbc_init_non_edp - Test fbc_init is a no-op for non-eDP links
+ * @test: The KUnit test context
+ */
+static void dm_test_fbc_init_non_edp(struct kunit *test)
+{
+       struct dm_test_fbc_ctx *ctx = dm_test_fbc_ctx_alloc(test);
+
+       ctx->link->connector_signal = SIGNAL_TYPE_DISPLAY_PORT;
+
+       amdgpu_dm_fbc_init(&ctx->aconnector->base);
+
+       KUNIT_EXPECT_NULL(test, ctx->adev->dm.compressor.bo_ptr);
+}
+
+/**
+ * dm_test_fbc_init_already_allocated - Test fbc_init keeps an existing buffer
+ * @test: The KUnit test context
+ */
+static void dm_test_fbc_init_already_allocated(struct kunit *test)
+{
+       struct dm_test_fbc_ctx *ctx = dm_test_fbc_ctx_alloc(test);
+       struct amdgpu_bo *existing;
+
+       existing = kunit_kzalloc(test, sizeof(void *), GFP_KERNEL);
+       KUNIT_ASSERT_NOT_NULL(test, existing);
+       ctx->adev->dm.compressor.bo_ptr = existing;
+
+       amdgpu_dm_fbc_init(&ctx->aconnector->base);
+
+       /* Buffer already present → left untouched, no reallocation */
+       KUNIT_EXPECT_PTR_EQ(test, ctx->adev->dm.compressor.bo_ptr, existing);
+}
+
+/**
+ * dm_test_fbc_init_no_modes - Test fbc_init skips allocation with no modes
+ * @test: The KUnit test context
+ */
+static void dm_test_fbc_init_no_modes(struct kunit *test)
+{
+       struct dm_test_fbc_ctx *ctx = dm_test_fbc_ctx_alloc(test);
+
+       /* All prerequisites met but the modes list is empty → max_size 0 */
+       amdgpu_dm_fbc_init(&ctx->aconnector->base);
+
+       KUNIT_EXPECT_NULL(test, ctx->adev->dm.compressor.bo_ptr);
+}
+
 static struct kunit_case amdgpu_dm_connector_tests[] = {
        /* get_subconnector_type */
        KUNIT_CASE(dm_test_subconnector_type_none),
@@ -2822,6 +2929,11 @@ static struct kunit_case amdgpu_dm_connector_tests[] = {
        KUNIT_CASE(dm_test_set_panel_type_did_lcd),
        KUNIT_CASE(dm_test_set_panel_type_vendor_lum_heuristic),
        KUNIT_CASE(dm_test_set_panel_type_defaults_to_lcd),
+       /* amdgpu_dm_fbc_init */
+       KUNIT_CASE(dm_test_fbc_init_no_compressor),
+       KUNIT_CASE(dm_test_fbc_init_non_edp),
+       KUNIT_CASE(dm_test_fbc_init_already_allocated),
+       KUNIT_CASE(dm_test_fbc_init_no_modes),
        {}
 };