mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jinseob Kim <kimjinseob88@gmail.com>
To: brgl@kernel.org
Cc: linusw@kernel.org, linux-gpio@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] gpio: kunit: test mixed-polarity multi-line hogs
Date: Wed,  4 Nov 2026 21:00:55 +0900	[thread overview]
Message-ID: <20261104120055.256-1-kimjinseob88@gmail.com> (raw)

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

             reply	other threads:[~2026-11-04 12:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 12:00 Jinseob Kim [this message]
2026-11-04 14:21 ` Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261104120055.256-1-kimjinseob88@gmail.com \
    --to=kimjinseob88@gmail.com \
    --cc=brgl@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®