mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] gpio: kunit: test mixed-polarity multi-line hogs
@ 2026-11-04 12:00 Jinseob Kim
  2026-11-04 14:21 ` Bartosz Golaszewski
  0 siblings, 1 reply; 2+ messages in thread
From: Jinseob Kim @ 2026-11-04 12:00 UTC (permalink / raw)
  To: brgl; +Cc: linusw, linux-gpio, linux-kernel

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.

Signed-off-by: Jinseob Kim <kimjinseob88@gmail.com>
---
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/20261103224339.1180-1-kimjinseob88@gmail.com/
Review: https://lore.kernel.org/linux-gpio/qboynvhfmvltsuopwotpf3sqdwho3qobxmw5qldooedjqodfgy@x4l6hscj5unx/

 drivers/gpio/gpiolib-kunit.c | 61 ++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/drivers/gpio/gpiolib-kunit.c b/drivers/gpio/gpiolib-kunit.c
index 11849aa56..38554280e 100644
--- a/drivers/gpio/gpiolib-kunit.c
+++ b/drivers/gpio/gpiolib-kunit.c
@@ -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

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

* Re: [PATCH] gpio: kunit: test mixed-polarity multi-line hogs
  2026-11-04 12:00 [PATCH] gpio: kunit: test mixed-polarity multi-line hogs Jinseob Kim
@ 2026-11-04 14:21 ` Bartosz Golaszewski
  0 siblings, 0 replies; 2+ messages in thread
From: Bartosz Golaszewski @ 2026-11-04 14:21 UTC (permalink / raw)
  To: Jinseob Kim; +Cc: linusw, linux-gpio, linux-kernel

On Wed, Nov 04, 2026 at 09:00:55PM +0900, Jinseob Kim wrote:
> 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.

> 
> Signed-off-by: Jinseob Kim <kimjinseob88@gmail.com>
> ---
> 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.

> 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/20261103224339.1180-1-kimjinseob88@gmail.com/
> Review: https://lore.kernel.org/linux-gpio/qboynvhfmvltsuopwotpf3sqdwho3qobxmw5qldooedjqodfgy@x4l6hscj5unx/

Ideally this should have been v2 of the series with its proper
Changelog.

Thanks,
Bartosz

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

end of thread, other threads:[~2026-11-04 14:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-04 12:00 [PATCH] gpio: kunit: test mixed-polarity multi-line hogs Jinseob Kim
2026-11-04 14:21 ` Bartosz Golaszewski

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®