[PATCH 104/108] drm/i915/kunit: setup DP link test context

Imre Deak
2026-04-28T12:56:18Z

Initialize a reusable test context for DP link KUnit tests. Sets up
minimal device, connector, encoder, and DP structures, and seeds the
pseudo-random generator for deterministic test runs.

Signed-off-by: Imre Deak <imre.deak@intel.com>
---
.../i915/display/tests/intel_dp_link_test.c | 47 +++++++++++++++++++
1 file changed, 47 insertions(+)

diff --git a/drivers/gpu/drm/i915/display/tests/intel_dp_link_test.c b/drivers/gpu/drm/i915/display/tests/intel_dp_link_test.c
index 1efcfdc53c936..83f09d8cc4aeb 100644
--- a/drivers/gpu/drm/i915/display/tests/intel_dp_link_test.c
+++ b/drivers/gpu/drm/i915/display/tests/intel_dp_link_test.c
@@ -5,7 +5,32 @@

#include <kunit/test.h>

+#include <linux/compiler.h>
+#include <linux/device.h>
+#include <linux/prandom.h>
+#include <linux/random.h>
+
+#include <drm/display/drm_dp_helper.h>
+
+#include <drm/intel/display_member.h>
+
+#include "intel_connector.h"
+#include "intel_display_core.h"
+#include "intel_display_types.h"
+
struct test_ctx {
+ struct {
+ struct intel_display display;
+ struct device device;
+ struct __intel_generic_device generic_device;
+
+ struct intel_connector connector;
+ struct intel_dp dp;
+
+ struct intel_crtc_state crtc_state;
+ } dev;
+
+ struct rnd_state rnd;
};

static struct kunit_case intel_dp_link_test_cases[] = {
@@ -16,6 +41,26 @@ static struct test_ctx test_ctx;

static int intel_dp_link_test_init(struct kunit *test)
{
+ struct intel_digital_port *dig_port;
+ struct intel_encoder *encoder;
+
+ /* Reset the dev state for each test. */
+ memset(&test_ctx.dev, 0, sizeof(test_ctx.dev));
+
+ test_ctx.dev.generic_device.drm.dev = &test_ctx.dev.device;
+
+ test_ctx.dev.display.drm = &test_ctx.dev.generic_device.drm;
+ test_ctx.dev.generic_device.display = &test_ctx.dev.display;
+
+ encoder = &dp_to_dig_port(&test_ctx.dev.dp)->base;
+ encoder->base.dev = &test_ctx.dev.generic_device.drm;
+
+ dig_port = dp_to_dig_port(&test_ctx.dev.dp);
+ dig_port->base.type = INTEL_OUTPUT_DP;
+
+ test_ctx.dev.connector.encoder = encoder;
+ test_ctx.dev.dp.attached_connector = &test_ctx.dev.connector;
+
test->priv = &test_ctx;

return 0;
@@ -27,6 +72,8 @@ static void intel_dp_link_test_exit(struct kunit *test)

static int intel_dp_link_test_suite_init(struct kunit_suite *test_suite)
{
+ prandom_seed_state(&test_ctx.rnd, 0);
+
return 0;
}

--
2.49.1