From: Alex Hung Date: Fri, 15 May 2026 22:09:48 +0000 (-0600) Subject: drm/amd/display: Add KUnit tests for amdgpu_dm_psr_set_event X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=34f281489976fb20fe8be12f084055b5560a3190;p=thirdparty%2Flinux.git drm/amd/display: Add KUnit tests for amdgpu_dm_psr_set_event [Why & How] Add three KUnit tests covering the early-exit validation guard in amdgpu_dm_psr_set_event(): - NULL stream argument returns false immediately - Valid stream with NULL link returns false - Valid stream/link with psr_feature_enabled == false returns false Assisted-by: Copilot:Claude-Sonnet-4.6 Reviewed-by: Ray Wu 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/amdgpu_dm/amdgpu_dm_psr.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_psr.c index 4b823bba43921..dd26de9a57e5d 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_psr.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_psr.c @@ -25,6 +25,7 @@ */ #include "amdgpu_dm_psr.h" +#include "amdgpu.h" #include "dc_dmub_srv.h" #include "dc.h" #include "amdgpu_dm.h" diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_psr.h b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_psr.h index 9f3e22520ca02..40a09b5dc606f 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_psr.h +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_psr.h @@ -27,10 +27,12 @@ #ifndef AMDGPU_DM_AMDGPU_DM_PSR_H_ #define AMDGPU_DM_AMDGPU_DM_PSR_H_ -#include "amdgpu.h" #include "dc.h" #include "modules/inc/mod_power.h" +struct amdgpu_display_manager; +struct amdgpu_dm_connector; + /* the number of pageflips before enabling psr */ #define AMDGPU_DM_PSR_ENTRY_DELAY 5 diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_psr_test.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_psr_test.c index 61a4167898cbd..09084f70a4052 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_psr_test.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_psr_test.c @@ -7,11 +7,7 @@ #include -#include "dc.h" - -/* Extern declaration for the function under test */ -extern void amdgpu_dm_psr_fill_caps(struct dc_link *link, - struct psr_caps *caps); +#include "amdgpu_dm_psr.h" /* * Helper: allocate and zero-initialise a dc_link sufficient for @@ -227,6 +223,43 @@ static void dm_test_psr_fill_caps_power_opts_z10_always_set(struct kunit *test) } /* End of tests for amdgpu_dm_psr_fill_caps() */ +/* Tests for amdgpu_dm_psr_set_event() — early-exit validation guards */ + +static void dm_test_psr_set_event_null_stream(struct kunit *test) +{ + /* NULL stream → immediate false, dm is not accessed */ + KUNIT_EXPECT_FALSE(test, amdgpu_dm_psr_set_event(NULL, NULL, true, psr_event_vsync, false)); +} + +static void dm_test_psr_set_event_null_link(struct kunit *test) +{ + struct dc_stream_state *stream; + + stream = kunit_kzalloc(test, sizeof(*stream), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, stream); + /* stream->link remains NULL from kzalloc */ + + KUNIT_EXPECT_FALSE(test, amdgpu_dm_psr_set_event(NULL, stream, true, psr_event_vsync, false)); +} + +static void dm_test_psr_set_event_psr_not_enabled(struct kunit *test) +{ + struct dc_stream_state *stream; + struct dc_link *link; + + stream = kunit_kzalloc(test, sizeof(*stream), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, stream); + + link = kunit_kzalloc(test, sizeof(*link), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, link); + + stream->link = link; + /* link->psr_settings.psr_feature_enabled remains false from kzalloc */ + + KUNIT_EXPECT_FALSE(test, amdgpu_dm_psr_set_event(NULL, stream, true, psr_event_vsync, false)); +} +/* End of tests for amdgpu_dm_psr_set_event() */ + static struct kunit_case dm_psr_test_cases[] = { KUNIT_CASE(dm_test_psr_fill_caps_version_1), KUNIT_CASE(dm_test_psr_fill_caps_version_su1), @@ -240,6 +273,9 @@ static struct kunit_case dm_psr_test_cases[] = { KUNIT_CASE(dm_test_psr_fill_caps_dpcd_fields_unset), KUNIT_CASE(dm_test_psr_fill_caps_rate_control_always_zero), KUNIT_CASE(dm_test_psr_fill_caps_power_opts_z10_always_set), + KUNIT_CASE(dm_test_psr_set_event_null_stream), + KUNIT_CASE(dm_test_psr_set_event_null_link), + KUNIT_CASE(dm_test_psr_set_event_psr_not_enabled), {} };