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 <[email protected]>
---
 .../i915/display/tests/intel_dp_link_test.c   | 50 +++++++++++++++++++
 1 file changed, 50 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 62e1844605ac5..aa5358c94839f 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_digital_port dig_port;
+
+               struct intel_crtc_state crtc_state;
+       } dev;
+
+       struct rnd_state rnd;
 };
 
 static struct kunit_case intel_dp_link_test_cases[] = {
@@ -16,6 +41,29 @@ 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;
+       struct intel_dp *intel_dp;
+
+       /* 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 = &test_ctx.dev.dig_port.base;
+       encoder->base.dev = &test_ctx.dev.generic_device.drm;
+
+       dig_port = &test_ctx.dev.dig_port;
+       dig_port->base.type = INTEL_OUTPUT_DP;
+
+       test_ctx.dev.connector.encoder = encoder;
+
+       intel_dp = &dig_port->dp;
+       intel_dp->attached_connector = &test_ctx.dev.connector;
+
        test->priv = &test_ctx;
 
        return 0;
@@ -27,6 +75,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

Reply via email to