mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] drm/tests: Add KUnit tests for drm_mode_create_dvi_i_properties()
@ 2023-11-10 19:24 Dipam Turkar
  2023-11-28 12:05 ` Javier Martinez Canillas
  2023-11-28 15:09 ` Maxime Ripard
  0 siblings, 2 replies; 6+ messages in thread
From: Dipam Turkar @ 2023-11-10 19:24 UTC (permalink / raw)
  To: maarten.lankhorst
  Cc: mripard, tzimmermann, airlied, daniel, mairacanal, javierm,
	arthurgrillo, dri-devel, linux-kernel, 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.

Signed-off-by: Dipam Turkar <dipamt1729@gmail.com>
---
 drivers/gpu/drm/tests/drm_connector_test.c | 38 ++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/drivers/gpu/drm/tests/drm_connector_test.c b/drivers/gpu/drm/tests/drm_connector_test.c
index c66aa2dc8d9d..9ac1fd32c579 100644
--- a/drivers/gpu/drm/tests/drm_connector_test.c
+++ b/drivers/gpu/drm/tests/drm_connector_test.c
@@ -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>
 
@@ -58,6 +61,30 @@ static void drm_test_get_tv_mode_from_name_truncated(struct kunit *test)
 	KUNIT_EXPECT_LT(test, ret, 0);
 };
 
+/*
+ * 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);
+
+	// 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_get_tv_mode_from_name_tests[] = {
 	KUNIT_CASE_PARAM(drm_test_get_tv_mode_from_name_valid,
 			 drm_get_tv_mode_from_name_valid_gen_params),
@@ -70,7 +97,18 @@ static struct kunit_suite drm_get_tv_mode_from_name_test_suite = {
 	.test_cases = drm_get_tv_mode_from_name_tests,
 };
 
+static struct kunit_case drm_connector_tests[] = {
+	KUNIT_CASE(drm_test_mode_create_dvi_i_properties),
+	{ }
+};
+
+static struct kunit_suite drm_connector_test_suite = {
+	.name = "drm_connector",
+	.test_cases = drm_connector_tests,
+};
+
 kunit_test_suite(drm_get_tv_mode_from_name_test_suite);
+kunit_test_suite(drm_connector_test_suite);
 
 MODULE_AUTHOR("Maxime Ripard <maxime@cerno.tech>");
 MODULE_LICENSE("GPL");
-- 
2.34.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] drm/tests: Add KUnit tests for drm_mode_create_dvi_i_properties()
  2023-11-10 19:24 [PATCH v2] drm/tests: Add KUnit tests for drm_mode_create_dvi_i_properties() Dipam Turkar
@ 2023-11-28 12:05 ` Javier Martinez Canillas
  2023-11-28 15:09 ` Maxime Ripard
  1 sibling, 0 replies; 6+ messages in thread
From: Javier Martinez Canillas @ 2023-11-28 12:05 UTC (permalink / raw)
  To: Dipam Turkar, maarten.lankhorst
  Cc: mripard, tzimmermann, airlied, daniel, mairacanal, arthurgrillo,
	dri-devel, linux-kernel, Dipam Turkar

Dipam Turkar <dipamt1729@gmail.com> writes:

Hello Dipam,

> Introduce unit tests for the drm_mode_create_dvi_i_properties() function to ensure
> the proper creation of DVI-I specific connector properties.
>
> Signed-off-by: Dipam Turkar <dipamt1729@gmail.com>
> ---
>  drivers/gpu/drm/tests/drm_connector_test.c | 38 ++++++++++++++++++++++
>  1 file changed, 38 insertions(+)
>

The test looks good to me but I would like Maxime to review before is merged.

Acked-by: Javier Martinez Canillas <javierm@redhat.com>

-- 
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] drm/tests: Add KUnit tests for drm_mode_create_dvi_i_properties()
  2023-11-10 19:24 [PATCH v2] drm/tests: Add KUnit tests for drm_mode_create_dvi_i_properties() Dipam Turkar
  2023-11-28 12:05 ` Javier Martinez Canillas
@ 2023-11-28 15:09 ` Maxime Ripard
       [not found]   ` <CALHmwspWRT=pj+mPDhf8YTwSpTz6LiNjq18wbUk7wCW3ijKU4A@mail.gmail.com>
  1 sibling, 1 reply; 6+ messages in thread
From: Maxime Ripard @ 2023-11-28 15:09 UTC (permalink / raw)
  To: Dipam Turkar
  Cc: maarten.lankhorst, tzimmermann, airlied, daniel, mairacanal,
	javierm, arthurgrillo, dri-devel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 3095 bytes --]

Hi,

On Sat, Nov 11, 2023 at 12:54:53AM +0530, Dipam Turkar wrote:
> Introduce unit tests for the drm_mode_create_dvi_i_properties() function to ensure
> the proper creation of DVI-I specific connector properties.
> 
> Signed-off-by: Dipam Turkar <dipamt1729@gmail.com>
> ---
>  drivers/gpu/drm/tests/drm_connector_test.c | 38 ++++++++++++++++++++++
>  1 file changed, 38 insertions(+)
> 
> diff --git a/drivers/gpu/drm/tests/drm_connector_test.c b/drivers/gpu/drm/tests/drm_connector_test.c
> index c66aa2dc8d9d..9ac1fd32c579 100644
> --- a/drivers/gpu/drm/tests/drm_connector_test.c
> +++ b/drivers/gpu/drm/tests/drm_connector_test.c
> @@ -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>
>  
> @@ -58,6 +61,30 @@ static void drm_test_get_tv_mode_from_name_truncated(struct kunit *test)
>  	KUNIT_EXPECT_LT(test, ret, 0);
>  };
>  
> +/*
> + * 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);
> +
> +	// Expect the function to return 0 if called twice.

This is not the proper comment format

> +	KUNIT_EXPECT_EQ(test, drm_mode_create_dvi_i_properties(drm), 0);

This should be in a separate test, with a separate description. We want
to test two things: that the function works well, and that the function
still works if we call it a second time.

> +}
> +
>  static struct kunit_case drm_get_tv_mode_from_name_tests[] = {
>  	KUNIT_CASE_PARAM(drm_test_get_tv_mode_from_name_valid,
>  			 drm_get_tv_mode_from_name_valid_gen_params),
> @@ -70,7 +97,18 @@ static struct kunit_suite drm_get_tv_mode_from_name_test_suite = {
>  	.test_cases = drm_get_tv_mode_from_name_tests,
>  };

The test should be next to the test suite definition

> +static struct kunit_case drm_connector_tests[] = {
> +	KUNIT_CASE(drm_test_mode_create_dvi_i_properties),
> +	{ }
> +};
> +
> +static struct kunit_suite drm_connector_test_suite = {
> +	.name = "drm_connector",

That's too generic, the test suite is only about
drm_mode_create_dvi_i_properties(), not drm_connector in general.

> +	.test_cases = drm_connector_tests,
> +};
> +
>  kunit_test_suite(drm_get_tv_mode_from_name_test_suite);
> +kunit_test_suite(drm_connector_test_suite);

kunit_test_suites

Maxime

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3 1/1] drm/tests: Add KUnit tests for drm_mode_create_dvi_i_properties()
       [not found]   ` <CALHmwspWRT=pj+mPDhf8YTwSpTz6LiNjq18wbUk7wCW3ijKU4A@mail.gmail.com>
@ 2024-01-06 14:01     ` Dipam Turkar
  2024-01-08 10:50       ` Maxime Ripard
  2024-01-08 10:49     ` [PATCH v2] " Maxime Ripard
  1 sibling, 1 reply; 6+ messages in thread
From: Dipam Turkar @ 2024-01-06 14:01 UTC (permalink / raw)
  To: maarten.lankhorst
  Cc: mripard, tzimmermann, airlied, daniel, dri-devel, linux-kernel,
	Dipam Turkar

---
 drivers/gpu/drm/tests/drm_connector_test.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/gpu/drm/tests/drm_connector_test.c b/drivers/gpu/drm/tests/drm_connector_test.c
index c66aa2dc8d9d..aad63839b5e5 100644
--- a/drivers/gpu/drm/tests/drm_connector_test.c
+++ b/drivers/gpu/drm/tests/drm_connector_test.c
@@ -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>
 
@@ -58,10 +61,27 @@ static void drm_test_get_tv_mode_from_name_truncated(struct kunit *test)
 	KUNIT_EXPECT_LT(test, ret, 0);
 };
 
+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_ASSERT_NOT_ERR_OR_NULL(test, drm->mode_config.dvi_i_select_subconnector_property);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm->mode_config.dvi_i_subconnector_property);
+}
+
 static struct kunit_case drm_get_tv_mode_from_name_tests[] = {
 	KUNIT_CASE_PARAM(drm_test_get_tv_mode_from_name_valid,
 			 drm_get_tv_mode_from_name_valid_gen_params),
 	KUNIT_CASE(drm_test_get_tv_mode_from_name_truncated),
+	KUNIT_CASE(drm_test_mode_create_dvi_i_properties),
 	{ }
 };
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] drm/tests: Add KUnit tests for drm_mode_create_dvi_i_properties()
       [not found]   ` <CALHmwspWRT=pj+mPDhf8YTwSpTz6LiNjq18wbUk7wCW3ijKU4A@mail.gmail.com>
  2024-01-06 14:01     ` [PATCH v3 1/1] " Dipam Turkar
@ 2024-01-08 10:49     ` Maxime Ripard
  1 sibling, 0 replies; 6+ messages in thread
From: Maxime Ripard @ 2024-01-08 10:49 UTC (permalink / raw)
  To: Dipam Turkar
  Cc: maarten.lankhorst, tzimmermann, airlied, daniel, mairacanal,
	javierm, arthurgrillo, dri-devel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 548 bytes --]

On Sat, Dec 23, 2023 at 03:59:33PM +0530, Dipam Turkar wrote:
> I needed some help regarding introducing a separate test for testing if the
> function still works if called a second time as suggested. Wouldn't we need
> to call it on the same object we called in the first time. So, that will
> bring redundancy in the two functions. Is this correct? Or am I
> understanding this wrong?

There will be redundancy indeed, but you're also not testing the same
thing so it's fine.

A test should be there to test one thing and one thing only.

Maxime

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 1/1] drm/tests: Add KUnit tests for drm_mode_create_dvi_i_properties()
  2024-01-06 14:01     ` [PATCH v3 1/1] " Dipam Turkar
@ 2024-01-08 10:50       ` Maxime Ripard
  0 siblings, 0 replies; 6+ messages in thread
From: Maxime Ripard @ 2024-01-08 10:50 UTC (permalink / raw)
  To: Dipam Turkar
  Cc: maarten.lankhorst, tzimmermann, airlied, daniel, dri-devel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1868 bytes --]

On Sat, Jan 06, 2024 at 07:31:18PM +0530, Dipam Turkar wrote:
> ---
>  drivers/gpu/drm/tests/drm_connector_test.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)

You're missing your commit message, Signed-off-by and version changes here.

> diff --git a/drivers/gpu/drm/tests/drm_connector_test.c b/drivers/gpu/drm/tests/drm_connector_test.c
> index c66aa2dc8d9d..aad63839b5e5 100644
> --- a/drivers/gpu/drm/tests/drm_connector_test.c
> +++ b/drivers/gpu/drm/tests/drm_connector_test.c
> @@ -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>
>  
> @@ -58,10 +61,27 @@ static void drm_test_get_tv_mode_from_name_truncated(struct kunit *test)
>  	KUNIT_EXPECT_LT(test, ret, 0);
>  };
>  
> +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_ASSERT_NOT_ERR_OR_NULL(test, drm->mode_config.dvi_i_select_subconnector_property);
> +	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm->mode_config.dvi_i_subconnector_property);
> +}
> +
>  static struct kunit_case drm_get_tv_mode_from_name_tests[] = {
>  	KUNIT_CASE_PARAM(drm_test_get_tv_mode_from_name_valid,
>  			 drm_get_tv_mode_from_name_valid_gen_params),
>  	KUNIT_CASE(drm_test_get_tv_mode_from_name_truncated),
> +	KUNIT_CASE(drm_test_mode_create_dvi_i_properties),

And you still don't have the other test we talked about

Maxime

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-01-08 10:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-10 19:24 [PATCH v2] drm/tests: Add KUnit tests for drm_mode_create_dvi_i_properties() Dipam Turkar
2023-11-28 12:05 ` Javier Martinez Canillas
2023-11-28 15:09 ` Maxime Ripard
     [not found]   ` <CALHmwspWRT=pj+mPDhf8YTwSpTz6LiNjq18wbUk7wCW3ijKU4A@mail.gmail.com>
2024-01-06 14:01     ` [PATCH v3 1/1] " Dipam Turkar
2024-01-08 10:50       ` Maxime Ripard
2024-01-08 10:49     ` [PATCH v2] " Maxime Ripard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®