leds: KUnit registration tests pertaining to init_data
Lee Jones
maintainerv2 cover leds: KUnit registration tests pertaining to init_data
Lots of drivers still register with the LED Class using init_data. Let's provide some additional Kunit infrastructure to exercise the various possibilities.
Change log:
v1 => v2:
- Use devm_* to ensure resources are cleaned-up on exit
Lee Jones (5):
leds: led-test: Move common LED class registration code into helper
function
leds: led-test: Provide test for registration with missing
default_label
leds: led-test: Provide test for registration with missing devicename
leds: led-test: Provide test for registration with a name that is too
long
leds: led-test: Provide test for successful registration using
init_data
drivers/leds/led-test.c | 86 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 80 insertions(+), 6 deletions(-)
Signature · 1 line
2.49.0.1101.gccaa498523-goog
Lee Jones
maintainerPATCH v2 1/5 leds: led-test: Move common LED class registration code into helper function
Since we will always need to register an LED class, it makes sense to avoid duplicating this part over and over.
Returning void and not propagating errors is expected here since the assert will terminate the process early if an error condition is encountered.
--- drivers/leds/led-test.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/leds/led-test.c +14 -6
@@ -22,10 +22,10 @@ static enum led_brightness led_test_brightness_get(struct led_classdev *cdev)return LED_TEST_POST_REG_BRIGHTNESS ; } -static void led_test_class_register (struct kunit *test) +static void led_test_class_register_helper (struct kunit *test) {struct led_test_ddata *ddata = test->priv; -struct led_classdev *cdev_clash, *cdev = &ddata->cdev; +struct led_classdev *cdev = &ddata->cdev;struct device *dev = ddata->dev;int ret;
@@ -36,6 +36,17 @@ static void led_test_class_register(struct kunit *test) ret =devm_led_classdev_register (dev, cdev);KUNIT_ASSERT_EQ (test, ret,0 ); +} + +static void led_test_class_register (struct kunit *test) +{ +struct led_test_ddata *ddata = test->priv; +struct led_classdev *cdev_clash, *cdev = &ddata->cdev; +struct device *dev = ddata->dev; +int ret; + +/* Register initial device - same as always */ +led_test_class_register_helper (test);KUNIT_EXPECT_EQ (test, cdev->max_brightness,LED_FULL );KUNIT_EXPECT_EQ (test, cdev->brightness,LED_TEST_POST_REG_BRIGHTNESS );
@@ -63,12 +74,9 @@ static void led_test_class_add_lookup_and_get(struct kunit *test)struct led_classdev *cdev = &ddata->cdev, *cdev_get;struct device *dev = ddata->dev;struct led_lookup_data lookup; -int ret;/* First, register a LED class device */ - cdev->name ="led-test" ; - ret =devm_led_classdev_register (dev, cdev); -KUNIT_ASSERT_EQ (test, ret,0 ); +led_test_class_register_helper (test);/* Then make the LED available for lookup */ lookup.provider = cdev->name;
Signature · 1 line
2.49.0.1101.gccaa498523-goog
Lee Jones
maintainerPATCH v2 2/5 leds: led-test: Provide test for registration with missing default_label
In reply to Lee JonesInsist on legacy (non-DT) registration and omit the default_label, which should fail with an invalid argument error.
--- drivers/leds/led-test.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/leds/led-test.c +16 -0
@@ -93,9 +93,25 @@ static void led_test_class_add_lookup_and_get(struct kunit *test)led_remove_lookup (&lookup); } +static void led_test_class_init_data_missing_default_label (struct kunit *test) +{ +struct led_test_ddata *ddata = test->priv; +struct led_classdev *cdev = &ddata->cdev; +struct device *dev = ddata->dev; +int ret; + +struct led_init_data init_data = { + .devicename ="led-test-devicename" , + }; + + ret =devm_led_classdev_register_ext (dev, cdev, &init_data); +KUNIT_EXPECT_EQ (test, ret, -EINVAL ); +} +static struct kunit_case led_test_cases[] = {KUNIT_CASE (led_test_class_register),KUNIT_CASE (led_test_class_add_lookup_and_get), +KUNIT_CASE (led_test_class_init_data_missing_default_label), { } };
Signature · 1 line
2.49.0.1101.gccaa498523-goog
Lee Jones
maintainerPATCH v2 3/5 leds: led-test: Provide test for registration with missing devicename
In reply to Lee JonesInsist on legacy (non-DT) registration and omit the devicename, which should fail with an invalid argument error.
--- drivers/leds/led-test.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/leds/led-test.c +16 -0
@@ -108,10 +108,26 @@ static void led_test_class_init_data_missing_default_label(struct kunit *test)KUNIT_EXPECT_EQ (test, ret, -EINVAL ); } +static void led_test_class_init_data_missing_devicename (struct kunit *test) +{ +struct led_test_ddata *ddata = test->priv; +struct led_classdev *cdev = &ddata->cdev; +struct device *dev = ddata->dev; +int ret; + +struct led_init_data init_data = { + .default_label ="led-test-label" , + }; + + ret =devm_led_classdev_register_ext (dev, cdev, &init_data); +KUNIT_EXPECT_EQ (test, ret, -EINVAL ); +} +static struct kunit_case led_test_cases[] = {KUNIT_CASE (led_test_class_register),KUNIT_CASE (led_test_class_add_lookup_and_get),KUNIT_CASE (led_test_class_init_data_missing_default_label), +KUNIT_CASE (led_test_class_init_data_missing_devicename), { } };
Signature · 1 line
2.49.0.1101.gccaa498523-goog
Lee Jones
maintainerPATCH v2 4/5 leds: led-test: Provide test for registration with a name that is too long
In reply to Lee JonesInsist on legacy (non-DT) registration and provide a default_label and devicename that when concatenated together results in a device name that is unacceptably long.
--- drivers/leds/led-test.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/leds/led-test.c +17 -0
@@ -123,11 +123,28 @@ static void led_test_class_init_data_missing_devicename(struct kunit *test)KUNIT_EXPECT_EQ (test, ret, -EINVAL ); } +static void led_test_class_init_data_name_too_long (struct kunit *test) +{ +struct led_test_ddata *ddata = test->priv; +struct led_classdev *cdev = &ddata->cdev; +struct device *dev = ddata->dev; +int ret; + +struct led_init_data init_data = { + .devicename ="led-test-devicename-very-long-names-fail" , + .default_label ="led-test-label-also-very-long-names-fail" , + }; + + ret =devm_led_classdev_register_ext (dev, cdev, &init_data); +KUNIT_EXPECT_EQ (test, ret, -E2BIG ); +} +static struct kunit_case led_test_cases[] = {KUNIT_CASE (led_test_class_register),KUNIT_CASE (led_test_class_add_lookup_and_get),KUNIT_CASE (led_test_class_init_data_missing_default_label),KUNIT_CASE (led_test_class_init_data_missing_devicename), +KUNIT_CASE (led_test_class_init_data_name_too_long), { } };
Signature · 1 line
2.49.0.1101.gccaa498523-goog
Lee Jones
maintainerPATCH v2 5/5 leds: led-test: Provide test for successful registration using init_data
In reply to Lee JonesThis time both the default_label and devicename are provided such that when concatenated together result in a device name that is acceptable. In this case registration should succeed.
--- drivers/leds/led-test.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/leds/led-test.c +17 -0
@@ -139,12 +139,29 @@ static void led_test_class_init_data_name_too_long(struct kunit *test)KUNIT_EXPECT_EQ (test, ret, -E2BIG ); } +static void led_test_class_init_data (struct kunit *test) +{ +struct led_test_ddata *ddata = test->priv; +struct led_classdev *cdev = &ddata->cdev; +struct device *dev = ddata->dev; +int ret; + +struct led_init_data init_data = { + .devicename ="led-test-devicename" , + .default_label ="led-test-label" , + }; + + ret =devm_led_classdev_register_ext (dev, cdev, &init_data); +KUNIT_EXPECT_EQ (test, ret,0 ); +} +static struct kunit_case led_test_cases[] = {KUNIT_CASE (led_test_class_register),KUNIT_CASE (led_test_class_add_lookup_and_get),KUNIT_CASE (led_test_class_init_data_missing_default_label),KUNIT_CASE (led_test_class_init_data_missing_devicename),KUNIT_CASE (led_test_class_init_data_name_too_long), +KUNIT_CASE (led_test_class_init_data), { } };
Signature · 1 line
2.49.0.1101.gccaa498523-goog
Hi Lee,
Quoted 1 line · Lee Jones
Lots of drivers still register with the LED Class using
init_data. Let's
What do you mean by "still"? Actually init_data is the new approach, that turns the LED core DT parser on, and is predestined for use with {devm_}led_classdev_register_ext() API.
Quoted 22 lines
provide some additional Kunit infrastructure to exercise the various possibilities.
Change log:
v1 => v2:
- Use devm_* to ensure resources are cleaned-up on exitLee Jones (5):
leds: led-test: Move common LED class registration code into helper
function
leds: led-test: Provide test for registration with missing
default_label
leds: led-test: Provide test for registration with missing devicename
leds: led-test: Provide test for registration with a name that is too
long
leds: led-test: Provide test for successful registration using
init_datadrivers/leds/led-test.c | 86 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 80 insertions(+), 6 deletions(-)
Signature · 2 lines
Best regards, Jacek Anaszewski
Lee Jones
maintainerQuoted 8 lines · Jacek Anaszewski
Hi Lee,
Quoted 1 line · Lee Jones
Lots of drivers still register with the LED Class using
init_data. Let'sWhat do you mean by "still"? Actually
init_datais the new approach, that turns the LED core DT parser on, and is predestined for use with {devm_}led_classdev_register_ext() API.
Thanks for the information. I'll update the wording.
Signature · 1 line
Lee Jones [李琼斯]
Jacek Anaszewski
Reviewed-byQuoted 4 lines · Lee Jones
Quoted 2 lines · Jacek Anaszewski
Hi Lee,
Quoted 8 lines
Quoted 6 lines · Lee Jones
Quoted 1 line
Lots of drivers still register with the LED Class using
init_data. Let'sWhat do you mean by "still"? Actually
init_datais the new approach, that turns the LED core DT parser on, and is predestined for use with {devm_}led_classdev_register_ext() API.Thanks for the information. I'll update the wording.
Other than that, for the whole series:
Signature · 2 lines
Best regards, Jacek Anaszewski