drm/amd/display: Add KUnit test for wb jobs

[WHAT]
Add KUnit tests to verify both functions return early when
job->fb is NULL without touching any buffer object.

Assisted-by: Copilot:Claude-Opus-4.6
Reviewed-by: Bhawanpreet Lakha <bhawanpreet.lakha@amd.com>
Signed-off-by: Alex Hung <alex.hung@amd.com>
Signed-off-by: George Zhang <george.zhang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
This commit is contained in:
Alex Hung
2026-06-26 18:18:55 -06:00
committed by Alex Deucher
parent bd9e2b5b04
commit f02b2e4735
3 changed files with 52 additions and 2 deletions

View File

@@ -85,7 +85,7 @@ STATIC_IFN_KUNIT int amdgpu_dm_wb_connector_get_modes(struct drm_connector *conn
}
EXPORT_IF_KUNIT(amdgpu_dm_wb_connector_get_modes);
static int amdgpu_dm_wb_prepare_job(struct drm_writeback_connector *wb_connector,
STATIC_IFN_KUNIT int amdgpu_dm_wb_prepare_job(struct drm_writeback_connector *wb_connector,
struct drm_writeback_job *job)
{
struct amdgpu_framebuffer *afb;
@@ -146,8 +146,9 @@ static int amdgpu_dm_wb_prepare_job(struct drm_writeback_connector *wb_connector
amdgpu_bo_unreserve(rbo);
return r;
}
EXPORT_IF_KUNIT(amdgpu_dm_wb_prepare_job);
static void amdgpu_dm_wb_cleanup_job(struct drm_writeback_connector *connector,
STATIC_IFN_KUNIT void amdgpu_dm_wb_cleanup_job(struct drm_writeback_connector *connector,
struct drm_writeback_job *job)
{
struct amdgpu_bo *rbo;
@@ -167,6 +168,7 @@ static void amdgpu_dm_wb_cleanup_job(struct drm_writeback_connector *connector,
amdgpu_bo_unreserve(rbo);
amdgpu_bo_unref(&rbo);
}
EXPORT_IF_KUNIT(amdgpu_dm_wb_cleanup_job);
static const struct drm_encoder_helper_funcs amdgpu_dm_wb_encoder_helper_funcs = {
.atomic_check = amdgpu_dm_wb_encoder_atomic_check,

View File

@@ -44,6 +44,10 @@ int amdgpu_dm_wb_encoder_atomic_check(struct drm_encoder *encoder,
struct drm_crtc_state *crtc_state,
struct drm_connector_state *conn_state);
int amdgpu_dm_wb_connector_get_modes(struct drm_connector *connector);
int amdgpu_dm_wb_prepare_job(struct drm_writeback_connector *wb_connector,
struct drm_writeback_job *job);
void amdgpu_dm_wb_cleanup_job(struct drm_writeback_connector *connector,
struct drm_writeback_job *job);
#endif
#endif

View File

@@ -364,6 +364,47 @@ static void dm_test_wb_connector_init_success(struct kunit *test)
KUNIT_EXPECT_EQ(test, wbcon->base.encoder.possible_crtcs, 0x1);
}
/* Tests for amdgpu_dm_wb_prepare_job / amdgpu_dm_wb_cleanup_job */
/**
* dm_test_wb_prepare_job_no_fb - Verify prepare_job early return without a framebuffer
* @test: KUnit test context
*
* When job->fb is NULL there is nothing to pin, so amdgpu_dm_wb_prepare_job()
* must return 0 without touching any buffer object.
*/
static void dm_test_wb_prepare_job_no_fb(struct kunit *test)
{
struct drm_writeback_job *job;
int ret;
job = kunit_kzalloc(test, sizeof(*job), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, job);
job->fb = NULL;
ret = amdgpu_dm_wb_prepare_job(NULL, job);
KUNIT_EXPECT_EQ(test, ret, 0);
}
/**
* dm_test_wb_cleanup_job_no_fb - Verify cleanup_job early return without a framebuffer
* @test: KUnit test context
*
* When job->fb is NULL there is nothing to unpin, so amdgpu_dm_wb_cleanup_job()
* must return immediately.
*/
static void dm_test_wb_cleanup_job_no_fb(struct kunit *test)
{
struct drm_writeback_job *job;
job = kunit_kzalloc(test, sizeof(*job), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, job);
job->fb = NULL;
/* Should return without dereferencing any buffer object. */
amdgpu_dm_wb_cleanup_job(NULL, job);
}
static struct kunit_case dm_wb_test_cases[] = {
/* amdgpu_dm_wb_encoder_atomic_check */
KUNIT_CASE(dm_test_wb_atomic_check_no_job),
@@ -378,6 +419,9 @@ static struct kunit_case dm_wb_test_cases[] = {
KUNIT_CASE(dm_test_wb_get_modes_bounded_by_max),
/* amdgpu_dm_wb_connector_init */
KUNIT_CASE(dm_test_wb_connector_init_success),
/* amdgpu_dm_wb_prepare_job / amdgpu_dm_wb_cleanup_job */
KUNIT_CASE(dm_test_wb_prepare_job_no_fb),
KUNIT_CASE(dm_test_wb_cleanup_job_no_fb),
{}
};