Skip to contentSkip to conversation

drm/tests: Add KUnit tests for drm_mode_create_dvi_i_properties()

PATCH In review Dipam Turkar 2 participants 2 messages Jan 14, 2024 – Jan 17, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 drm/tests: Add KUnit tests for drm_mode_create_dvi_i_properties()

Introduce unit tests for the drm_mode_create_dvi_i_properties() function to ensure the proper creation of DVI-I specific connector properties and success if called multiple times.

---
 drivers/gpu/drm/tests/drm_connector_test.c | 58 ++++++++++++++++++++++
 1 file changed, 58 insertions(+)
drivers/gpu/drm/tests/drm_connector_test.c +58 -0
index c66aa2dc8d9d..217c0988171e 100644
@@ -4,6 +4,9 @@
  */
 
 #include <drm/drm_connector.h>
+#include <drm/drm_device.h>
+#include <drm/drm_drv.h>
+#include <drm/drm_kunit_helpers.h>
 
 #include <kunit/test.h>
 
@@ -70,7 +73,62 @@ static struct kunit_suite drm_get_tv_mode_from_name_test_suite = {
 	.test_cases = drm_get_tv_mode_from_name_tests,
 };
 
+/*
+ * Test that drm_mode_create_dvi_i_properties() succeeds and
+ * DVI-I subconnector and select subconectors properties have
+ * been created.
+ */
+static void drm_test_mode_create_dvi_i_properties(struct kunit *test)
+{
+	struct drm_device *drm;
+	struct device *dev;
+
+	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(*drm), 0, DRIVER_MODESET);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm);
+
+	KUNIT_EXPECT_EQ(test, drm_mode_create_dvi_i_properties(drm), 0);
+	KUNIT_EXPECT_NOT_ERR_OR_NULL(test, drm->mode_config.dvi_i_select_subconnector_property);
+	KUNIT_EXPECT_NOT_ERR_OR_NULL(test, drm->mode_config.dvi_i_subconnector_property);
+}
+
+/*
+ * Test that drm_mode_create_dvi_i_properties() doesn't fail if called twice.
+ */
+static void drm_test_mode_create_dvi_i_properties_repeated(struct kunit *test)
+{
+	struct drm_device *drm;
+	struct device *dev;
+
+	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(*drm), 0, DRIVER_MODESET);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm);
+
+	KUNIT_EXPECT_EQ(test, drm_mode_create_dvi_i_properties(drm), 0);
+	KUNIT_EXPECT_NOT_ERR_OR_NULL(test, drm->mode_config.dvi_i_select_subconnector_property);
+	KUNIT_EXPECT_NOT_ERR_OR_NULL(test, drm->mode_config.dvi_i_subconnector_property);
+
+	/* Expect the function to return 0 if called twice. */
+	KUNIT_EXPECT_EQ(test, drm_mode_create_dvi_i_properties(drm), 0);
+}
+
+static struct kunit_case drm_mode_create_dvi_i_properties_tests[] = {
+	KUNIT_CASE(drm_test_mode_create_dvi_i_properties),
+	KUNIT_CASE(drm_test_mode_create_dvi_i_properties_repeated),
+	{ }
+};
+
+static struct kunit_suite drm_mode_create_dvi_i_properties_test_suite = {
+	.name = "drm_mode_create_dvi_i_properties",
+	.test_cases = drm_mode_create_dvi_i_properties_tests,
+};
+
 kunit_test_suite(drm_get_tv_mode_from_name_test_suite);
+kunit_test_suite(drm_mode_create_dvi_i_properties_test_suite);
 
 MODULE_AUTHOR("Maxime Ripard <[email protected]>");
 MODULE_LICENSE("GPL");
Signature · 1 line
2.34.1
maintainer
#1 lore raw

Hi,

Quoted 73 lines · Dipam Turkar

Introduce unit tests for the drm_mode_create_dvi_i_properties() function to ensure the proper creation of DVI-I specific connector properties and success if called multiple times.

---
 drivers/gpu/drm/tests/drm_connector_test.c | 58 ++++++++++++++++++++++
 1 file changed, 58 insertions(+)
drivers/gpu/drm/tests/drm_connector_test.c +49 -0
index c66aa2dc8d9d..217c0988171e 100644
@@ -4,6 +4,9 @@
  */
 
 #include <drm/drm_connector.h>
+#include <drm/drm_device.h>
+#include <drm/drm_drv.h>
+#include <drm/drm_kunit_helpers.h>
 
 #include <kunit/test.h>
 
@@ -70,7 +73,62 @@ static struct kunit_suite drm_get_tv_mode_from_name_test_suite = {
 	.test_cases = drm_get_tv_mode_from_name_tests,
 };
 
+/*
+ * Test that drm_mode_create_dvi_i_properties() succeeds and
+ * DVI-I subconnector and select subconectors properties have
+ * been created.
+ */
+static void drm_test_mode_create_dvi_i_properties(struct kunit *test)
+{
+	struct drm_device *drm;
+	struct device *dev;
+
+	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(*drm), 0, DRIVER_MODESET);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm);
+
+	KUNIT_EXPECT_EQ(test, drm_mode_create_dvi_i_properties(drm), 0);
+	KUNIT_EXPECT_NOT_ERR_OR_NULL(test, drm->mode_config.dvi_i_select_subconnector_property);
+	KUNIT_EXPECT_NOT_ERR_OR_NULL(test, drm->mode_config.dvi_i_subconnector_property);
+}
+
+/*
+ * Test that drm_mode_create_dvi_i_properties() doesn't fail if called twice.
+ */
+static void drm_test_mode_create_dvi_i_properties_repeated(struct kunit *test)
+{
+	struct drm_device *drm;
+	struct device *dev;
+
+	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(*drm), 0, DRIVER_MODESET);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm);
+
+	KUNIT_EXPECT_EQ(test, drm_mode_create_dvi_i_properties(drm), 0);
+	KUNIT_EXPECT_NOT_ERR_OR_NULL(test, drm->mode_config.dvi_i_select_subconnector_property);
+	KUNIT_EXPECT_NOT_ERR_OR_NULL(test, drm->mode_config.dvi_i_subconnector_property);
+
+	/* Expect the function to return 0 if called twice. */
+	KUNIT_EXPECT_EQ(test, drm_mode_create_dvi_i_properties(drm), 0);
+}
+
+static struct kunit_case drm_mode_create_dvi_i_properties_tests[] = {
+	KUNIT_CASE(drm_test_mode_create_dvi_i_properties),
+	KUNIT_CASE(drm_test_mode_create_dvi_i_properties_repeated),

drivers/gpu/drm/tests/drm_connector_test.c static struct kunit_suite drm_get_tv_mode_from_name_test_suite = { · line 131

Quoted 10 lines
drivers/gpu/drm/tests/drm_connector_test.c +9 -0
+	{ }
+};
+
+static struct kunit_suite drm_mode_create_dvi_i_properties_test_suite = {
+	.name = "drm_mode_create_dvi_i_properties",
+	.test_cases = drm_mode_create_dvi_i_properties_tests,
+};
+
 kunit_test_suite(drm_get_tv_mode_from_name_test_suite);
+kunit_test_suite(drm_mode_create_dvi_i_properties_test_suite);

You should use kunit_test_suites here

Maxime