From: Bhawanpreet Lakha <[email protected]>
Add a KUnit test that initializes a TMDS encoder on a DRM device embedded
in an amdgpu_device and verifies the derived possible_crtcs mask, the
encoder id set from the link index, and the attached helper funcs.
Assisted-by: Copilot:Claude-Opus-4.8
Reviewed-by: Alex Hung <[email protected]>
Signed-off-by: Bhawanpreet Lakha <[email protected]>
Signed-off-by: Ivan Lipski <[email protected]>
---
.../display/amdgpu_dm/amdgpu_dm_connector.c | 2 +
.../tests/amdgpu_dm_connector_test.c | 38 +++++++++++++++++++
2 files changed, 40 insertions(+)
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
index 2cc3734c992bd..ed16e01987726 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
@@ -171,6 +171,7 @@ const struct drm_encoder_helper_funcs amdgpu_dm_encoder_helper_funcs = {
.disable = dm_encoder_helper_disable,
.atomic_check = dm_encoder_helper_atomic_check
};
+EXPORT_IF_KUNIT(amdgpu_dm_encoder_helper_funcs);
int amdgpu_dm_get_encoder_crtc_mask(struct amdgpu_device *adev)
{
@@ -215,6 +216,7 @@ int amdgpu_dm_encoder_init(struct drm_device *dev,
return res;
}
+EXPORT_IF_KUNIT(amdgpu_dm_encoder_init);
STATIC_IFN_KUNIT enum drm_mode_subconnector get_subconnector_type(struct dc_link *link)
{
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c
index d209e26b684eb..b51aba8c07c3c 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c
@@ -4289,6 +4289,43 @@ static void dm_test_encoder_disable_noop(struct kunit *test)
* connector and connector-state are stacked in their containers and wired
* together through conn_state->connector.
*/
+/* Tests for amdgpu_dm_encoder_init() */
+
+/**
+ * dm_test_encoder_init_success - Test encoder init wires id, crtc mask and helpers
+ * @test: The KUnit test context
+ *
+ * On a DRM device embedded in an amdgpu_device, amdgpu_dm_encoder_init()
+ * registers a TMDS encoder, derives possible_crtcs from mode_info.num_crtc,
+ * records the link index as the encoder id and attaches the helper funcs.
+ */
+static void dm_test_encoder_init_success(struct kunit *test)
+{
+ struct device *dev;
+ struct drm_device *drm;
+ struct amdgpu_device *adev;
+ struct amdgpu_encoder *aencoder;
+
+ dev = drm_kunit_helper_alloc_device(test);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
+ drm = __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*adev),
+ offsetof(struct amdgpu_device, ddev),
+ DRIVER_MODESET);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm);
+ adev = drm_to_adev(drm);
+ adev->mode_info.num_crtc = 4;
+
+ /* Plain kzalloc: amdgpu_dm_encoder_destroy() kfree()s it on teardown. */
+ aencoder = kzalloc_obj(*aencoder);
+ KUNIT_ASSERT_NOT_NULL(test, aencoder);
+
+ KUNIT_EXPECT_EQ(test, amdgpu_dm_encoder_init(drm, aencoder, 2), 0);
+ KUNIT_EXPECT_EQ(test, aencoder->encoder_id, 2);
+ KUNIT_EXPECT_EQ(test, (int)aencoder->base.possible_crtcs, 0xf);
+ KUNIT_EXPECT_PTR_EQ(test, (const void *)aencoder->base.helper_private,
+ (const void *)&amdgpu_dm_encoder_helper_funcs);
+}
+
struct dm_test_atomic_check_ctx {
struct drm_device *drm;
struct amdgpu_encoder *aenc;
@@ -5863,6 +5900,7 @@ static struct kunit_case amdgpu_dm_connector_tests[] = {
KUNIT_CASE(dm_test_atomic_check_mst_duplicated_skips_pbn),
KUNIT_CASE(dm_test_atomic_check_mst_topology_err_propagates),
KUNIT_CASE(dm_test_atomic_check_mst_vcpi_error_propagates),
+ KUNIT_CASE(dm_test_encoder_init_success),
/* hdmi_cec_unset_edid */
KUNIT_CASE(dm_test_hdmi_cec_unset_edid_no_notifier),
/* create_eml_sink */
--
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.