]> git.hungrycats.org Git - linux/commitdiff
drm/amd/display: Add KUnit tests for amdgpu_dm_quirks
authorAlex Hung <alex.hung@amd.com>
Thu, 7 May 2026 16:56:40 +0000 (10:56 -0600)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 17 Jun 2026 20:16:43 +0000 (16:16 -0400)
Add KUnit test file amdgpu_dm_quirks_test.c covering retrieve_dmi_info().

Three test cases are provided:
- Verify aux_hpd_discon_quirk is reset to false even when previously true
- Verify edp0_on_dp1_quirk is reset to false even when previously true
- Verify both quirks remain false on a zero-initialised dm when no
  DMI match is found (expected in UML/KUnit environment)

Register the new test object in the tests/Makefile under
CONFIG_DRM_AMD_DC_KUNIT_TEST.

Assisted-by: Copilot:Claude-Sonnet-4.6
Reviewed-by: Bhawanpreet Lakha <bhawanpreet.lakha@amd.com>
Signed-off-by: Alex Hung <alex.hung@amd.com>
Signed-off-by: Chenyu Chen <chen-yu.chen@amd.com>
Tested-by: Daniel Wheeler <daniel.wheeler@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_quirks.c
drivers/gpu/drm/amd/display/amdgpu_dm/tests/Makefile
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_quirks_test.c [new file with mode: 0644]

index 1da07ebf9217c09bb9bfc906d19b5d55d0921347..cf28d50c3b5ee9dbdb4d4cd43e90568f73230448 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "amdgpu.h"
 #include "amdgpu_dm.h"
+#include "amdgpu_dm_kunit_helpers.h"
 
 struct amdgpu_dm_quirks {
        bool aux_hpd_discon;
@@ -176,3 +177,4 @@ void retrieve_dmi_info(struct amdgpu_display_manager *dm)
                drm_info(dev, "support_edp0_on_dp1 attached\n");
        }
 }
+EXPORT_IF_KUNIT(retrieve_dmi_info);
index a067332f9f413e37a9290c2b70fb501b102eef37..168ad064e7cb59acaa4a6716d5c5df3604f18263 100644 (file)
@@ -30,3 +30,4 @@ obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_test.o
 obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_crtc_test.o
 obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_services_test.o
 obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_helpers_test.o
+obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_quirks_test.o
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_quirks_test.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_quirks_test.c
new file mode 100644 (file)
index 0000000..a09f31e
--- /dev/null
@@ -0,0 +1,103 @@
+// SPDX-License-Identifier: GPL-2.0 OR MIT
+/*
+ * KUnit tests for amdgpu_dm_quirks.c
+ *
+ * Copyright 2026 Advanced Micro Devices, Inc.
+ */
+
+#include <kunit/test.h>
+
+#include "dc.h"
+#include "amdgpu_mode.h"
+#include "amdgpu_dm.h"
+
+/* Tests for retrieve_dmi_info() */
+
+/*
+ * Verify that retrieve_dmi_info() always initialises aux_hpd_discon_quirk to
+ * false, even when the caller had previously set it to true.
+ */
+/**
+ * dm_test_quirks_aux_hpd_discon_reset - Test Quirks aux hpd discon reset
+ * @test: The KUnit test context
+ */
+static void dm_test_quirks_aux_hpd_discon_reset(struct kunit *test)
+{
+       struct amdgpu_display_manager *dm;
+
+       dm = kunit_kzalloc(test, sizeof(*dm), GFP_KERNEL);
+       KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dm);
+
+       dm->aux_hpd_discon_quirk = true;
+
+       retrieve_dmi_info(dm);
+
+       /*
+        * In a KUnit / UML environment no real DMI table is present, so
+        * dmi_check_system() returns 0 and retrieve_dmi_info() leaves the
+        * quirk at its initialised-to-false value.
+        */
+       KUNIT_EXPECT_FALSE(test, dm->aux_hpd_discon_quirk);
+}
+
+/*
+ * Verify that retrieve_dmi_info() always initialises edp0_on_dp1_quirk to
+ * false, even when the caller had previously set it to true.
+ */
+/**
+ * dm_test_quirks_edp0_on_dp1_reset - Test Quirks edp0 on dp1 reset
+ * @test: The KUnit test context
+ */
+static void dm_test_quirks_edp0_on_dp1_reset(struct kunit *test)
+{
+       struct amdgpu_display_manager *dm;
+
+       dm = kunit_kzalloc(test, sizeof(*dm), GFP_KERNEL);
+       KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dm);
+
+       dm->edp0_on_dp1_quirk = true;
+
+       retrieve_dmi_info(dm);
+
+       KUNIT_EXPECT_FALSE(test, dm->edp0_on_dp1_quirk);
+}
+
+/*
+ * Verify that when no DMI match is found both quirks remain false after a
+ * fresh (zero-initialised) dm is passed to retrieve_dmi_info().
+ */
+/**
+ * dm_test_quirks_no_dmi_match_both_false - Test Quirks no dmi match both false
+ * @test: The KUnit test context
+ */
+static void dm_test_quirks_no_dmi_match_both_false(struct kunit *test)
+{
+       struct amdgpu_display_manager *dm;
+
+       dm = kunit_kzalloc(test, sizeof(*dm), GFP_KERNEL);
+       KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dm);
+
+       retrieve_dmi_info(dm);
+
+       KUNIT_EXPECT_FALSE(test, dm->aux_hpd_discon_quirk);
+       KUNIT_EXPECT_FALSE(test, dm->edp0_on_dp1_quirk);
+}
+
+static struct kunit_case amdgpu_dm_quirks_tests[] = {
+       /* retrieve_dmi_info */
+       KUNIT_CASE(dm_test_quirks_aux_hpd_discon_reset),
+       KUNIT_CASE(dm_test_quirks_edp0_on_dp1_reset),
+       KUNIT_CASE(dm_test_quirks_no_dmi_match_both_false),
+       {}
+};
+
+static struct kunit_suite amdgpu_dm_quirks_test_suite = {
+       .name = "amdgpu_dm_quirks",
+       .test_cases = amdgpu_dm_quirks_tests,
+};
+
+kunit_test_suite(amdgpu_dm_quirks_test_suite);
+
+MODULE_AUTHOR("AMD");
+MODULE_DESCRIPTION("KUnit tests for amdgpu_dm_quirks");
+MODULE_LICENSE("Dual MIT/GPL");