[PATCH 46/59] drm/amd/display: Test power module init
Alex Hung <[email protected]>
| Newsgroups | org.freedesktop.lists.amd-gfx |
|---|---|
| Message-ID | <[email protected]> |
[WHAT] Add KUnit tests for amdgpu_dm_init_power_module(), covering the skip when no eDP is detected and the backlight parameter setup loop followed by the allocation failure report. [HOW] mod_power_create() rejects a NULL DC, which walks the full parameter setup loop without needing a live display core. Assisted-by: Copilot:Claude-Opus-5 GPT-5.6-Sol Reviewed-by: Bhawanpreet Lakha <[email protected]> Signed-off-by: Alex Hung <[email protected]> --- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 3 +- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h | 1 + .../display/amdgpu_dm/tests/amdgpu_dm_test.c | 40 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c index ffc5cea6b6df..3d2a9e014797 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -407,7 +407,7 @@ STATIC_IFN_KUNIT void mmhub_read_system_context(struct amdgpu_device *adev, } EXPORT_IF_KUNIT(mmhub_read_system_context); -static int amdgpu_dm_init_power_module(struct amdgpu_display_manager *dm) +STATIC_IFN_KUNIT int amdgpu_dm_init_power_module(struct amdgpu_display_manager *dm) { struct mod_power_init_params init_data[MAX_NUM_EDP]; @@ -470,6 +470,7 @@ static int amdgpu_dm_init_power_module(struct amdgpu_display_manager *dm) return 0; } +EXPORT_IF_KUNIT(amdgpu_dm_init_power_module); static int amdgpu_dm_init(struct amdgpu_device *adev) { diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h index a53246040948..5e9d0b203a0f 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h @@ -1252,6 +1252,7 @@ struct dc_phy_addr_space_config; void mmhub_read_system_context(struct amdgpu_device *adev, struct dc_phy_addr_space_config *pa_config); +int amdgpu_dm_init_power_module(struct amdgpu_display_manager *dm); #endif #endif /* __AMDGPU_DM_H__ */ diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c index bb52da037e69..d1a25b3e68c5 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c @@ -3522,6 +3522,43 @@ static void dm_test_mmhub_agp_enabled_renoir(struct kunit *test) KUNIT_EXPECT_EQ(test, pa_config.system_aperture.end_addr, 0x80000000ULL); } +/* Tests for amdgpu_dm_init_power_module() */ + +/** + * dm_test_init_power_module_no_edp - Test no eDP skips the power module + * @test: The KUnit test context + */ +static void dm_test_init_power_module_no_edp(struct kunit *test) +{ + struct amdgpu_device *adev = dm_kunit_alloc_adev(test); + + adev->dm.ddev = &adev->ddev; + adev->dm.num_of_edps = 0; + + KUNIT_EXPECT_EQ(test, amdgpu_dm_init_power_module(&adev->dm), 0); + KUNIT_EXPECT_NULL(test, adev->dm.power_module); +} + +/** + * dm_test_init_power_module_alloc_failure - Test a failed power module create + * @test: The KUnit test context + * + * mod_power_create() rejects a NULL DC, which walks the full parameter setup + * loop and then reports the allocation failure. + */ +static void dm_test_init_power_module_alloc_failure(struct kunit *test) +{ + struct amdgpu_device *adev = dm_kunit_alloc_adev(test); + + adev->dm.ddev = &adev->ddev; + adev->dm.num_of_edps = 1; + adev->dm.backlight_caps[0].min_input_signal = 0x10; + adev->dm.backlight_caps[0].max_input_signal = 0xff; + + KUNIT_EXPECT_EQ(test, amdgpu_dm_init_power_module(&adev->dm), -ENOMEM); + KUNIT_EXPECT_NULL(test, adev->dm.power_module); +} + static struct kunit_case amdgpu_dm_tests[] = { /* Simple DM callbacks */ KUNIT_CASE(dm_test_wait_for_idle), @@ -3699,6 +3736,9 @@ static struct kunit_case amdgpu_dm_tests[] = { KUNIT_CASE(dm_test_mmhub_agp_disabled_raven2), KUNIT_CASE(dm_test_mmhub_agp_enabled), KUNIT_CASE(dm_test_mmhub_agp_enabled_renoir), + /* amdgpu_dm_init_power_module */ + KUNIT_CASE(dm_test_init_power_module_no_edp), + KUNIT_CASE(dm_test_init_power_module_alloc_failure), {} }; -- 2.43.0