drm/tests: Add KUnit tests for drm_mode_create_dvi_i_properties()
Subsystems (2)
PATCH v2 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.
--- drivers/gpu/drm/tests/drm_connector_test.c | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+)
drivers/gpu/drm/tests/drm_connector_test.c +38 -0
@@ -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 <[email protected]>" );MODULE_LICENSE ("GPL" );
Signature · 1 line
2.34.1
Dipam Turkar <[email protected]> writes:
Hello Dipam,
Quoted 8 lines
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 <[email protected]>--- 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.
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Maxime Ripard
maintainerHi,
Quoted 37 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.Signed-off-by Dipam Turkar <[email protected]>--- drivers/gpu/drm/tests/drm_connector_test.c | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+)drivers/gpu/drm/tests/drm_connector_test.c +14
-0@@ -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);
drivers/gpu/drm/tests/drm_connector_test.c static void drm_test_get_tv_mode_from_name_truncated(struct kunit *test) · line 84
Quoted 10 lines
drivers/gpu/drm/tests/drm_connector_test.c +10
-0+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
drivers/gpu/drm/tests/drm_connector_test.c static void drm_test_get_tv_mode_from_name_truncated(struct kunit *test) · line 85
Quoted 1 line
drivers/gpu/drm/tests/drm_connector_test.c +1
-0+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.
drivers/gpu/drm/tests/drm_connector_test.c static struct kunit_suite drm_get_tv_mode_from_name_test_suite = { · line 98
Quoted 8 lines
drivers/gpu/drm/tests/drm_connector_test.c +2
-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, };
The test should be next to the test suite definition
drivers/gpu/drm/tests/drm_connector_test.c static struct kunit_suite drm_get_tv_mode_from_name_test_suite = { · line 106
Quoted 7 lines
drivers/gpu/drm/tests/drm_connector_test.c +7
-0+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.
drivers/gpu/drm/tests/drm_connector_test.c static struct kunit_suite drm_get_tv_mode_from_name_test_suite = { · line 111
Quoted 5 lines
drivers/gpu/drm/tests/drm_connector_test.c +4
-0+ .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
Will work on that.
Dipam Turkar
Quoted 98 lines · Maxime Ripard
Hi,
Quoted 1 line · Dipam Turkar
Introduce unit tests for the
drm_mode_create_dvi_i_properties()functionto ensure
Review
Quoted 8 lines
the proper creation of DVI-I specific connector properties.
Signed-off-by Dipam Turkar <[email protected]>--- drivers/gpu/drm/tests/drm_connector_test.c | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+)(quoted diff) +0
-0
b/drivers/gpu/drm/tests/drm_connector_test.cdrivers/gpu/drm/tests/drm_connector_test.c static void
Quoted 14 lines
index
c66aa2dc8d9d..9ac1fd32c579100644drivers/gpu/drm/tests/drm_connector_test.c +3
-0@@ -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)Quoted 7 lines
drivers/gpu/drm/tests/drm_connector_test.c +4
-0KUNIT_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. drivers/gpu/drm/tests/drm_connector_test.c static void drm_test_get_tv_mode_from_name_truncated(struct kunit *test)
Quoted 10 lines
drivers/gpu/drm/tests/drm_connector_test.c +10
-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);drivers/gpu/drm/tests/drm_connector_test.c static void drm_test_get_tv_mode_from_name_truncated(struct kunit *test)
Quoted 4 lines
drivers/gpu/drm/tests/drm_connector_test.c +4
-0+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);drivers/gpu/drm/tests/drm_connector_test.c static void · line 82
Quoted 1 line
drivers/gpu/drm/tests/drm_connector_test.c +1
-0+ KUNIT_EXPECT_NOT_ERR_OR_NULL(test,
drm->mode_config.dvi_i_subconnector_property);drivers/gpu/drm/tests/drm_connector_test.c static void · line 84
Quoted 2 lines
drivers/gpu/drm/tests/drm_connector_test.c +2
-0+ +// Expect the function to return 0 if called twice. This is not the proper comment format
drivers/gpu/drm/tests/drm_connector_test.c static void · line 85
Quoted 1 line
drivers/gpu/drm/tests/drm_connector_test.c +1
-0+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.
drivers/gpu/drm/tests/drm_connector_test.c static struct kunit_suite
Quoted 6 lines
drivers/gpu/drm/tests/drm_connector_test.c +2
-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= {drivers/gpu/drm/tests/drm_connector_test.c static struct kunit_suite drm_get_tv_mode_from_name_test_suite = { · line 98
Quoted 2 lines
drivers/gpu/drm/tests/drm_connector_test.c +0
-0.test_cases = drm_get_tv_mode_from_name_tests, };The test should be next to the test suite definition
drivers/gpu/drm/tests/drm_connector_test.c static struct kunit_suite drm_get_tv_mode_from_name_test_suite = { · line 106
Quoted 7 lines
drivers/gpu/drm/tests/drm_connector_test.c +7
-0+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(), notdrm_connectorin general.drivers/gpu/drm/tests/drm_connector_test.c static struct kunit_suite drm_get_tv_mode_from_name_test_suite = { · line 111
Quoted 5 lines
drivers/gpu/drm/tests/drm_connector_test.c +4
-0+ .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_suitesMaxime
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?
Thanks and regards
Dipam Turkar
Quoted 98 lines · Maxime Ripard
Hi,
Quoted 1 line · Dipam Turkar
Introduce unit tests for the
drm_mode_create_dvi_i_properties()functionto ensure
Review
Quoted 8 lines
the proper creation of DVI-I specific connector properties.
Signed-off-by Dipam Turkar <[email protected]>--- drivers/gpu/drm/tests/drm_connector_test.c | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+)(quoted diff) +0
-0
b/drivers/gpu/drm/tests/drm_connector_test.cdrivers/gpu/drm/tests/drm_connector_test.c static void
Quoted 14 lines
index
c66aa2dc8d9d..9ac1fd32c579100644drivers/gpu/drm/tests/drm_connector_test.c +3
-0@@ -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)Quoted 7 lines
drivers/gpu/drm/tests/drm_connector_test.c +4
-0KUNIT_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. drivers/gpu/drm/tests/drm_connector_test.c static void drm_test_get_tv_mode_from_name_truncated(struct kunit *test)
Quoted 10 lines
drivers/gpu/drm/tests/drm_connector_test.c +10
-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);drivers/gpu/drm/tests/drm_connector_test.c static void drm_test_get_tv_mode_from_name_truncated(struct kunit *test)
Quoted 4 lines
drivers/gpu/drm/tests/drm_connector_test.c +4
-0+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);drivers/gpu/drm/tests/drm_connector_test.c static void · line 82
Quoted 1 line
drivers/gpu/drm/tests/drm_connector_test.c +1
-0+ KUNIT_EXPECT_NOT_ERR_OR_NULL(test,
drm->mode_config.dvi_i_subconnector_property);drivers/gpu/drm/tests/drm_connector_test.c static void · line 84
Quoted 2 lines
drivers/gpu/drm/tests/drm_connector_test.c +2
-0+ +// Expect the function to return 0 if called twice. This is not the proper comment format
drivers/gpu/drm/tests/drm_connector_test.c static void · line 85
Quoted 1 line
drivers/gpu/drm/tests/drm_connector_test.c +1
-0+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.
drivers/gpu/drm/tests/drm_connector_test.c static struct kunit_suite
Quoted 6 lines
drivers/gpu/drm/tests/drm_connector_test.c +2
-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= {drivers/gpu/drm/tests/drm_connector_test.c static struct kunit_suite drm_get_tv_mode_from_name_test_suite = { · line 98
Quoted 2 lines
drivers/gpu/drm/tests/drm_connector_test.c +0
-0.test_cases = drm_get_tv_mode_from_name_tests, };The test should be next to the test suite definition
drivers/gpu/drm/tests/drm_connector_test.c static struct kunit_suite drm_get_tv_mode_from_name_test_suite = { · line 106
Quoted 7 lines
drivers/gpu/drm/tests/drm_connector_test.c +7
-0+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(), notdrm_connectorin general.drivers/gpu/drm/tests/drm_connector_test.c static struct kunit_suite drm_get_tv_mode_from_name_test_suite = { · line 111
Quoted 5 lines
drivers/gpu/drm/tests/drm_connector_test.c +4
-0+ .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_suitesMaxime
PATCH v3 1/1 drm/tests: Add KUnit tests for drm_mode_create_dvi_i_properties()
--- drivers/gpu/drm/tests/drm_connector_test.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/gpu/drm/tests/drm_connector_test.c +20 -0
@@ -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), { } };
Signature · 1 line
2.34.1
Maxime Ripard
maintainerQuoted 3 lines · Dipam Turkar
--- 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.
Quoted 29 lines
drivers/gpu/drm/tests/drm_connector_test.c +14
-0@@ -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); +
drivers/gpu/drm/tests/drm_connector_test.c static void drm_test_get_tv_mode_from_name_truncated(struct kunit *test) · line 84
Quoted 10 lines
drivers/gpu/drm/tests/drm_connector_test.c +6
-0+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
Maxime Ripard
maintainerQuoted 5 lines · Dipam Turkar
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