gpio: kunit: test mixed-polarity multi-line hogs
PATCH 1/1 gpio: kunit: test mixed-polarity multi-line hogs
A single software-node GPIO hog can describe several lines with different polarities. Add a case with alternating active-low and active-high lines to verify that lookup flags do not carry over between GPIO specifiers. Check both descriptor polarity and the raw output level for a logical output-high value.
Register the additional provider and hog nodes in the existing hog node group and add the case to gpio_swnode_hog_tests. Reuse the existing suite lifecycle and test-managed GPIO device reference cleanup.
Codex assisted with the regression test and commit message.
---
Test split from the combined v1 patch, for v7.5:
- Add the case to the existing gpio-swnode-hog suite and node group.
- Drop the duplicate suite lifecycle and keep managed reference cleanup.
- Adapt to gpio/for-next's provider label and existing test helpers.
Target: brgl/linux gpio/for-next at d66b6b86d5a6278ca930112c634d03725beb7d9a.
Dependency: apply the fix-only v2, "gpiolib: reset lookup flags for each hogged line", before this test. Without that prerequisite the new test is expected to fail. The test itself changes no GPIO implementation. The maintainer requested this test for v7.5, separately from the fix.
Testing on this target: actual UML/KUnit, before 10 pass / 1 fail; after 11 pass / 0 fail, with the same config and test source. GCC W=1 and Clang W=1/private Sparse C=2 builds completed. The mixed-polarity case also passes alone and within the hog suite. No physical GPIO or runtime OF hardware validation was performed.
Previous version: https://lore.kernel.org/linux-gpio/[email protected]/
Review: https://lore.kernel.org/linux-gpio/qboynvhfmvltsuopwotpf3sqdwho3qobxmw5qldooedjqodfgy@x4l6hscj5unx/
drivers/gpio/gpiolib-kunit.c | 61 ++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)
drivers/gpio/gpiolib-kunit.c +61 -0
@@ -713,11 +713,36 @@ static const struct software_node gpio_hog_input_swnode =SOFTWARE_NODE ("hog-input" , gpio_hog_input_properties, &gpio_test_provider_swnode); +/* A single non-OF hog may describe lines with different polarities. */ +static const struct software_node gpio_mixed_hog_provider_swnode = { + .name ="gpio-mixed-hog-provider" , +}; + +static const u32 gpio_mixed_hog_gpios[] = { +0 ,GPIO_ACTIVE_LOW , +1 ,GPIO_ACTIVE_HIGH , +2 ,GPIO_ACTIVE_LOW , +3 ,GPIO_ACTIVE_HIGH , +}; + +static const struct property_entry gpio_mixed_hog_properties[] = { +PROPERTY_ENTRY_U32_ARRAY ("gpios" , gpio_mixed_hog_gpios), +PROPERTY_ENTRY_BOOL ("output-high" ), +PROPERTY_ENTRY_BOOL ("gpio-hog" ), + { } +}; + +static const struct software_node gpio_mixed_hog_swnode = +SOFTWARE_NODE ("mixed-hog" , gpio_mixed_hog_properties, + &gpio_mixed_hog_provider_swnode); +static const struct software_node *const gpio_hog_swnodes[] = { &gpio_test_provider_swnode, &gpio_hog_output_high_swnode, &gpio_hog_output_low_swnode, &gpio_hog_input_swnode, + &gpio_mixed_hog_provider_swnode, + &gpio_mixed_hog_swnode,NULL };
@@ -809,6 +834,41 @@ static void gpio_hog_input(struct kunit *test)gpio_hog_assert (test,GPIO_HOG_INPUT_OFFSET ,GPIO_LINE_DIRECTION_IN ); } +static void gpio_hog_mixed_polarities (struct kunit *test) +{ +struct platform_device_info pdevinfo = { + .name =GPIO_TEST_PROVIDER , + .id =PLATFORM_DEVID_NONE , + .fwnode =software_node_fwnode (&gpio_mixed_hog_provider_swnode), + }; +struct platform_device *pdev; +struct gpio_device *gdev; +struct gpio_desc *desc; +bool active_low; +int ret; + + pdev =kunit_platform_device_register_full (test, &pdevinfo); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, pdev); + +wait_for_device_probe (); + + gdev =gpio_device_find_by_label (GPIO_TEST_PROVIDER ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, gdev); + + ret =kunit_add_action_or_reset (test, gpio_device_put_wrapper, gdev); +KUNIT_ASSERT_EQ (test, ret,0 ); + +for (unsigned int i =0 ; i <GPIO_TEST_PROVIDER_NGPIO ; i++) { + desc =gpio_device_get_desc (gdev, i); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, desc); + + active_low = gpio_mixed_hog_gpios[i *2 +1 ] ==GPIO_ACTIVE_LOW ; +KUNIT_EXPECT_EQ (test,gpiod_is_active_low (desc), active_low); +/* A logical high must drive the inverse level on active-low lines. */ +KUNIT_EXPECT_EQ (test,gpiod_get_raw_value_cansleep (desc), !active_low); + } +} +static int gpio_hog_suite_init (struct kunit_suite *suite) {return software_node_register_node_group (gpio_hog_swnodes);
@@ -823,6 +883,7 @@ static struct kunit_case gpio_swnode_hog_tests[] = {KUNIT_CASE (gpio_hog_output_high),KUNIT_CASE (gpio_hog_output_low),KUNIT_CASE (gpio_hog_input), + KUNIT_CASE(gpio_hog_mixed_polarities), { } };
base-commit: d66b6b86d5a6278ca930112c634d03725beb7d9a
prerequisite-patch-id: 3aa172b6fbd4d7ead61ff22c62c2be020339b988
Bartosz Golaszewski
maintainerQuoted 11 lines · Jinseob Kim
A single software-node GPIO hog can describe several lines with different polarities. Add a case with alternating active-low and active-high lines to verify that lookup flags do not carry over between GPIO specifiers. Check both descriptor polarity and the raw output level for a logical output-high value.
Register the additional provider and hog nodes in the existing hog node group and add the case to
gpio_swnode_hog_tests. Reuse the existing suite lifecycle and test-managed GPIO device reference cleanup.Codex assisted with the regression test and commit message.
Don't put that in commit message, that can go under the '---' or in the cover letter.
Quoted 8 lines
Signed-off-by Jinseob Kim <[email protected]>---
Test split from the combined v1 patch, for v7.5:
- Add the case to the existing gpio-swnode-hog suite and node group.
- Drop the duplicate suite lifecycle and keep managed reference cleanup.
- Adapt to gpio/for-next's provider label and existing test helpers.
Maybe I didn't make myself clear enough: this should have been part of the same series as the fix, just a separate commit in that series. No worries, don't resend unless there's another reason, I'll keep track of it.
Quoted 6 lines
Target: brgl/linux gpio/for-next at
d66b6b86d5a6278ca930112c634d03725beb7d9a.
Dependency: apply the fix-only v2, "gpiolib: reset lookup flags for each hogged line", before this test. Without that prerequisite the new test is expected to fail. The test itself changes no GPIO implementation. The maintainer requested this test for v7.5, separately from the fix.
Quoted 8 lines
Testing on this target: actual UML/KUnit, before 10 pass / 1 fail; after 11 pass / 0 fail, with the same config and test source. GCC W=1 and Clang W=1/private Sparse C=2 builds completed. The mixed-polarity case also passes alone and within the hog suite. No physical GPIO or runtime OF hardware validation was performed.
Previous version: https://lore.kernel.org/linux-gpio/[email protected]/
Review: https://lore.kernel.org/linux-gpio/qboynvhfmvltsuopwotpf3sqdwho3qobxmw5qldooedjqodfgy@x4l6hscj5unx/
Ideally this should have been v2 of the series with its proper Changelog.
Thanks,
Bartosz
Bartosz Golaszewski
AppliedQuoted 11 lines · Jinseob Kim
A single software-node GPIO hog can describe several lines with different polarities. Add a case with alternating active-low and active-high lines to verify that lookup flags do not carry over between GPIO specifiers. Check both descriptor polarity and the raw output level for a logical output-high value.
Register the additional provider and hog nodes in the existing hog node group and add the case to
gpio_swnode_hog_tests. Reuse the existing suite lifecycle and test-managed GPIO device reference cleanup.[...]
Applied, thanks!
[1/1] gpio: kunit: test mixed-polarity multi-line hogs
https://git.kernel.org/brgl/c/e60a08613402e1fcf6e3d4df0bc80969140f7fa1
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>