* [PATCH v3 1/4] gpio: kunit: fix the label of the dummy GPIO chip
2026-10-13 13:02 [PATCH v3 0/4] gpio: kunit: add test cases for platform lookup tables Bartosz Golaszewski
@ 2026-10-13 13:03 ` Bartosz Golaszewski
2026-10-13 13:14 ` sashiko-bot
2026-10-13 13:03 ` [PATCH v3 2/4] gpio: kunit: factor out common code for waiting for device probe Bartosz Golaszewski
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ messages in thread
From: Bartosz Golaszewski @ 2026-10-13 13:03 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski
Cc: linux-gpio, linux-kernel, Bartosz Golaszewski
The label of the test GPIO provider is currently set to the consumer
name. Use the provider name instead.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
drivers/gpio/gpiolib-kunit.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/gpio/gpiolib-kunit.c b/drivers/gpio/gpiolib-kunit.c
index 90b7e77ef0b51f5115d8a3afe53060a8f33992d2..66095c7a3d4277c6cf6c5a39ba292b67ecc990e3 100644
--- a/drivers/gpio/gpiolib-kunit.c
+++ b/drivers/gpio/gpiolib-kunit.c
@@ -24,7 +24,6 @@
#define GPIO_PROBE_ORDER_TEST_CONSUMER "gpio-probe-order-test-consumer"
#define GPIO_PROBE_DEFER_TEST_CONSUMER "gpio-probe-defer-test-consumer"
#define GPIO_UNBIND_TEST_CONSUMER "gpio-unbind-test-consumer"
-#define GPIO_CONSUMER_NAME "gpio-swnode-consumer-test-device"
#define GPIO_TEST_PROVIDER_NGPIO 4
@@ -101,7 +100,7 @@ static int gpio_test_provider_probe(struct platform_device *pdev)
gc->base = -1;
gc->ngpio = GPIO_TEST_PROVIDER_NGPIO;
- gc->label = GPIO_CONSUMER_NAME;
+ gc->label = GPIO_TEST_PROVIDER;
gc->parent = dev;
gc->owner = THIS_MODULE;
@@ -780,7 +779,7 @@ static void gpio_hog_assert(struct kunit *test, unsigned int offset,
/* The hog must have configured the line with the expected direction. */
struct gpio_device *gdev __free(gpio_device_put) =
- gpio_device_find_by_label(GPIO_CONSUMER_NAME);
+ gpio_device_find_by_label(GPIO_TEST_PROVIDER);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, gdev);
desc = gpio_device_get_desc(gdev, offset);
--
2.47.3
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v3 1/4] gpio: kunit: fix the label of the dummy GPIO chip
2026-10-13 13:03 ` [PATCH v3 1/4] gpio: kunit: fix the label of the dummy GPIO chip Bartosz Golaszewski
@ 2026-10-13 13:14 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-10-13 13:14 UTC (permalink / raw)
To: Bartosz Golaszewski; +Cc: linux-gpio
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] gpio: resource leak of gdev on KUnit test assertion failure
--
commit b7e40967a53cb1589f5bac90dea8c80d8d27bce0
Author: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
gpio: kunit: fix the label of the dummy GPIO chip
The label of the test GPIO provider is currently set to the consumer
name. Use the provider name instead.
> diff --git a/drivers/gpio/gpiolib-kunit.c b/drivers/gpio/gpiolib-kunit.c
> --- a/drivers/gpio/gpiolib-kunit.c
> +++ b/drivers/gpio/gpiolib-kunit.c
[ ... ]
> @@ -780,7 +779,7 @@ static void gpio_hog_assert(struct kunit *test, unsigned int offset,
>
> /* The hog must have configured the line with the expected direction. */
> struct gpio_device *gdev __free(gpio_device_put) =
> - gpio_device_find_by_label(GPIO_CONSUMER_NAME);
> + gpio_device_find_by_label(GPIO_TEST_PROVIDER);
> KUNIT_ASSERT_NOT_ERR_OR_NULL(test, gdev);
>
> desc = gpio_device_get_desc(gdev, offset);
> KUNIT_ASSERT_NOT_ERR_OR_NULL(test, desc);
>
> ret = gpiod_get_direction(desc);
> KUNIT_ASSERT_EQ(test, ret, expected_direction);
[Severity: Medium]
Does this code leak the gdev reference when KUnit assertions fail?
If KUNIT_ASSERT_NOT_ERR_OR_NULL(test, desc) or the subsequent KUNIT_ASSERT_EQ()
fails in gpio_hog_assert(), KUnit aborts the test thread immediately using
kthread_exit().
Because kthread_exit() bypasses normal C scope exit, compiler-generated
cleanup handlers like __free(gpio_device_put) are skipped, causing a reference
count leak of the gpio_device.
This leaked reference could prevent the dummy device from being properly freed,
which might wedge subsequent test runs or module unloads.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261013-gpio-kunit-plat-lookup-v3-0-3907f913e964@oss.qualcomm.com?part=1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 2/4] gpio: kunit: factor out common code for waiting for device probe
2026-10-13 13:02 [PATCH v3 0/4] gpio: kunit: add test cases for platform lookup tables Bartosz Golaszewski
2026-10-13 13:03 ` [PATCH v3 1/4] gpio: kunit: fix the label of the dummy GPIO chip Bartosz Golaszewski
@ 2026-10-13 13:03 ` Bartosz Golaszewski
2026-10-13 13:03 ` [PATCH v3 3/4] gpio: kunit: rename the swnode consumer to a more generic test consumer Bartosz Golaszewski
2026-10-13 13:03 ` [PATCH v3 4/4] gpio: kunit: add a test case for platform lookup tables Bartosz Golaszewski
3 siblings, 0 replies; 6+ messages in thread
From: Bartosz Golaszewski @ 2026-10-13 13:03 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski
Cc: linux-gpio, linux-kernel, Bartosz Golaszewski
We repeat the same sequence of function calls when waiting synchronously
for a device to probe. Put them into a dedicated helper function and
shrink the test-case code in the process.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
drivers/gpio/gpiolib-kunit.c | 80 ++++++++++++++------------------------------
1 file changed, 26 insertions(+), 54 deletions(-)
diff --git a/drivers/gpio/gpiolib-kunit.c b/drivers/gpio/gpiolib-kunit.c
index 66095c7a3d4277c6cf6c5a39ba292b67ecc990e3..f5f1e3627bf0084dc87f4a4dad8ac7e003c3945c 100644
--- a/drivers/gpio/gpiolib-kunit.c
+++ b/drivers/gpio/gpiolib-kunit.c
@@ -4,6 +4,7 @@
*/
#include <linux/cleanup.h>
+#include <linux/device.h>
#include <linux/err.h>
#include <linux/fwnode.h>
#include <linux/gpio/consumer.h>
@@ -27,6 +28,21 @@
#define GPIO_TEST_PROVIDER_NGPIO 4
+static void gpio_test_device_check_bound(struct kunit *test,
+ struct device *dev, bool expected)
+{
+ bool bound = false;
+
+ wait_for_device_probe();
+ scoped_guard(device, dev)
+ bound = device_is_bound(dev);
+
+ if (expected)
+ KUNIT_ASSERT_TRUE(test, bound);
+ else
+ KUNIT_ASSERT_FALSE(test, bound);
+}
+
/*
* The test provider tracks per-line direction and value so that lines can be
* driven as both inputs and outputs - this is needed to exercise input as well
@@ -177,7 +193,6 @@ static void gpio_swnode_lookup_by_primary(struct kunit *test)
struct platform_device_info pdevinfo;
struct property_entry properties[2];
struct platform_device *pdev;
- bool bound = false;
pdevinfo = (struct platform_device_info){
.name = GPIO_TEST_PROVIDER,
@@ -204,11 +219,7 @@ static void gpio_swnode_lookup_by_primary(struct kunit *test)
pdev = kunit_platform_device_register_full(test, &pdevinfo);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev);
- wait_for_device_probe();
- scoped_guard(device, &pdev->dev)
- bound = device_is_bound(&pdev->dev);
-
- KUNIT_ASSERT_TRUE(test, bound);
+ gpio_test_device_check_bound(test, &pdev->dev, true);
pdata = dev_get_platdata(&pdev->dev);
KUNIT_ASSERT_TRUE(test, pdata->gpio_ok);
@@ -221,7 +232,6 @@ static void gpio_swnode_lookup_by_secondary(struct kunit *test)
struct property_entry properties[2];
struct fwnode_handle *primary;
struct platform_device *pdev;
- bool bound = false;
/*
* Can't live on the stack as it will still get referenced in cleanup
@@ -258,11 +268,7 @@ static void gpio_swnode_lookup_by_secondary(struct kunit *test)
pdev = kunit_platform_device_register_full(test, &pdevinfo);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev);
- wait_for_device_probe();
- scoped_guard(device, &pdev->dev)
- bound = device_is_bound(&pdev->dev);
-
- KUNIT_ASSERT_TRUE(test, bound);
+ gpio_test_device_check_bound(test, &pdev->dev, true);
pdata = dev_get_platdata(&pdev->dev);
KUNIT_ASSERT_TRUE(test, pdata->gpio_ok);
@@ -332,7 +338,6 @@ static void gpio_swnode_probe_order(struct kunit *test)
struct gpio_probe_order_pdata *pdata;
struct platform_device_info pdevinfo;
struct platform_device *prvd, *cons;
- bool bound = false;
int ret;
ret = kunit_platform_driver_register(test, &gpio_test_provider_driver);
@@ -363,11 +368,7 @@ static void gpio_swnode_probe_order(struct kunit *test)
cons = kunit_platform_device_register_full(test, &pdevinfo);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cons);
- wait_for_device_probe();
- scoped_guard(device, &cons->dev)
- bound = device_is_bound(&cons->dev);
-
- KUNIT_ASSERT_FALSE(test, bound);
+ gpio_test_device_check_bound(test, &cons->dev, false);
pdata = dev_get_platdata(&cons->dev);
KUNIT_ASSERT_EQ(test, pdata->probe_count, 0);
@@ -382,15 +383,8 @@ static void gpio_swnode_probe_order(struct kunit *test)
prvd = kunit_platform_device_register_full(test, &pdevinfo);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, prvd);
- wait_for_device_probe();
-
- scoped_guard(device, &prvd->dev)
- bound = device_is_bound(&prvd->dev);
- KUNIT_ASSERT_TRUE(test, bound);
-
- scoped_guard(device, &cons->dev)
- bound = device_is_bound(&cons->dev);
- KUNIT_ASSERT_TRUE(test, bound);
+ gpio_test_device_check_bound(test, &prvd->dev, true);
+ gpio_test_device_check_bound(test, &cons->dev, true);
pdata = dev_get_platdata(&cons->dev);
KUNIT_ASSERT_EQ(test, pdata->probe_count, 1);
@@ -452,7 +446,6 @@ static void gpio_swnode_probe_defer_on_unregistered(struct kunit *test)
struct platform_device_info pdevinfo;
struct platform_device *prvd, *cons;
struct fwnode_handle *fwnode;
- bool bound = false;
int ret;
ret = kunit_platform_driver_register(test, &gpio_test_provider_driver);
@@ -476,11 +469,7 @@ static void gpio_swnode_probe_defer_on_unregistered(struct kunit *test)
cons = kunit_platform_device_register_full(test, &pdevinfo);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cons);
- wait_for_device_probe();
- scoped_guard(device, &cons->dev)
- bound = device_is_bound(&cons->dev);
-
- KUNIT_ASSERT_FALSE(test, bound);
+ gpio_test_device_check_bound(test, &cons->dev, false);
pdata = dev_get_platdata(&cons->dev);
KUNIT_ASSERT_GT(test, pdata->probe_count, 0);
@@ -498,15 +487,8 @@ static void gpio_swnode_probe_defer_on_unregistered(struct kunit *test)
prvd = kunit_platform_device_register_full(test, &pdevinfo);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, prvd);
- wait_for_device_probe();
-
- scoped_guard(device, &prvd->dev)
- bound = device_is_bound(&prvd->dev);
- KUNIT_ASSERT_TRUE(test, bound);
-
- scoped_guard(device, &cons->dev)
- bound = device_is_bound(&cons->dev);
- KUNIT_ASSERT_TRUE(test, bound);
+ gpio_test_device_check_bound(test, &cons->dev, true);
+ gpio_test_device_check_bound(test, &prvd->dev, true);
pdata = dev_get_platdata(&cons->dev);
KUNIT_ASSERT_EQ(test, pdata->gpio_err, 0);
@@ -603,7 +585,6 @@ static void gpio_unbind_with_consumers(struct kunit *test)
struct platform_device_info pdevinfo;
struct property_entry properties[2];
struct platform_device *prvd, *cons;
- bool bound = false;
int ret;
ret = kunit_platform_driver_register(test, &gpio_test_provider_driver);
@@ -644,11 +625,7 @@ static void gpio_unbind_with_consumers(struct kunit *test)
ret = kunit_platform_device_add(test, cons);
KUNIT_ASSERT_EQ(test, ret, 0);
- wait_for_device_probe();
- scoped_guard(device, &cons->dev)
- bound = device_is_bound(&cons->dev);
-
- KUNIT_ASSERT_TRUE(test, bound);
+ gpio_test_device_check_bound(test, &cons->dev, true);
kunit_platform_device_unregister(test, prvd);
@@ -760,7 +737,6 @@ static void gpio_hog_assert(struct kunit *test, unsigned int offset,
struct platform_device *pdev;
struct fwnode_handle *fwnode;
struct gpio_desc *desc;
- bool bound = true;
int ret;
fwnode = software_node_fwnode(&gpio_test_provider_swnode);
@@ -805,11 +781,7 @@ static void gpio_hog_assert(struct kunit *test, unsigned int offset,
pdev = kunit_platform_device_register_full(test, &pdevinfo);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev);
- wait_for_device_probe();
- scoped_guard(device, &pdev->dev)
- bound = device_is_bound(&pdev->dev);
-
- KUNIT_ASSERT_FALSE(test, bound);
+ gpio_test_device_check_bound(test, &pdev->dev, false);
pdata = dev_get_platdata(&pdev->dev);
KUNIT_ASSERT_FALSE(test, pdata->gpio_ok);
--
2.47.3
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v3 3/4] gpio: kunit: rename the swnode consumer to a more generic test consumer
2026-10-13 13:02 [PATCH v3 0/4] gpio: kunit: add test cases for platform lookup tables Bartosz Golaszewski
2026-10-13 13:03 ` [PATCH v3 1/4] gpio: kunit: fix the label of the dummy GPIO chip Bartosz Golaszewski
2026-10-13 13:03 ` [PATCH v3 2/4] gpio: kunit: factor out common code for waiting for device probe Bartosz Golaszewski
@ 2026-10-13 13:03 ` Bartosz Golaszewski
2026-10-13 13:03 ` [PATCH v3 4/4] gpio: kunit: add a test case for platform lookup tables Bartosz Golaszewski
3 siblings, 0 replies; 6+ messages in thread
From: Bartosz Golaszewski @ 2026-10-13 13:03 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski
Cc: linux-gpio, linux-kernel, Bartosz Golaszewski
Ahead of reusing the existing code in machine lookup test cases, rename
the swnode consumer variables and functions to a more generic "test
consumer".
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
drivers/gpio/gpiolib-kunit.c | 48 ++++++++++++++++++++++----------------------
1 file changed, 24 insertions(+), 24 deletions(-)
diff --git a/drivers/gpio/gpiolib-kunit.c b/drivers/gpio/gpiolib-kunit.c
index f5f1e3627bf0084dc87f4a4dad8ac7e003c3945c..b662be88a08711380f938852d84809f36a8d62d0 100644
--- a/drivers/gpio/gpiolib-kunit.c
+++ b/drivers/gpio/gpiolib-kunit.c
@@ -21,7 +21,7 @@
#include <kunit/test.h>
#define GPIO_TEST_PROVIDER "gpio-test-provider"
-#define GPIO_SWNODE_TEST_CONSUMER "gpio-swnode-test-consumer"
+#define GPIO_BASE_TEST_CONSUMER "gpio-base-test-consumer"
#define GPIO_PROBE_ORDER_TEST_CONSUMER "gpio-probe-order-test-consumer"
#define GPIO_PROBE_DEFER_TEST_CONSUMER "gpio-probe-defer-test-consumer"
#define GPIO_UNBIND_TEST_CONSUMER "gpio-unbind-test-consumer"
@@ -140,20 +140,20 @@ static const struct software_node gpio_test_provider_swnode = {
.name = "gpio-test-provider-primary",
};
-struct gpio_swnode_consumer_pdata {
+struct gpio_test_consumer_pdata {
bool gpio_ok;
int errno;
};
-static const struct gpio_swnode_consumer_pdata gpio_swnode_pdata_template = {
+static const struct gpio_test_consumer_pdata gpio_test_pdata_template = {
.gpio_ok = false,
.errno = 0,
};
-static int gpio_swnode_consumer_probe(struct platform_device *pdev)
+static int gpio_test_consumer_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- struct gpio_swnode_consumer_pdata *pdata = dev_get_platdata(dev);
+ struct gpio_test_consumer_pdata *pdata = dev_get_platdata(dev);
struct gpio_desc *desc;
desc = devm_gpiod_get(dev, "foo", GPIOD_OUT_HIGH);
@@ -167,21 +167,21 @@ static int gpio_swnode_consumer_probe(struct platform_device *pdev)
return 0;
}
-static struct platform_driver gpio_swnode_consumer_driver = {
- .probe = gpio_swnode_consumer_probe,
+static struct platform_driver gpio_test_consumer_driver = {
+ .probe = gpio_test_consumer_probe,
.driver = {
- .name = GPIO_SWNODE_TEST_CONSUMER,
+ .name = GPIO_BASE_TEST_CONSUMER,
},
};
-static int gpio_swnode_register_drivers(struct kunit *test)
+static int gpio_test_register_drivers(struct kunit *test)
{
int ret;
ret = kunit_platform_driver_register(test, &gpio_test_provider_driver);
KUNIT_ASSERT_EQ(test, ret, 0);
- ret = kunit_platform_driver_register(test, &gpio_swnode_consumer_driver);
+ ret = kunit_platform_driver_register(test, &gpio_test_consumer_driver);
KUNIT_ASSERT_EQ(test, ret, 0);
return 0;
@@ -189,7 +189,7 @@ static int gpio_swnode_register_drivers(struct kunit *test)
static void gpio_swnode_lookup_by_primary(struct kunit *test)
{
- struct gpio_swnode_consumer_pdata *pdata;
+ struct gpio_test_consumer_pdata *pdata;
struct platform_device_info pdevinfo;
struct property_entry properties[2];
struct platform_device *pdev;
@@ -209,10 +209,10 @@ static void gpio_swnode_lookup_by_primary(struct kunit *test)
properties[1] = (struct property_entry){ };
pdevinfo = (struct platform_device_info){
- .name = GPIO_SWNODE_TEST_CONSUMER,
+ .name = GPIO_BASE_TEST_CONSUMER,
.id = PLATFORM_DEVID_NONE,
- .data = &gpio_swnode_pdata_template,
- .size_data = sizeof(gpio_swnode_pdata_template),
+ .data = &gpio_test_pdata_template,
+ .size_data = sizeof(gpio_test_pdata_template),
.properties = properties,
};
@@ -227,7 +227,7 @@ static void gpio_swnode_lookup_by_primary(struct kunit *test)
static void gpio_swnode_lookup_by_secondary(struct kunit *test)
{
- struct gpio_swnode_consumer_pdata *pdata;
+ struct gpio_test_consumer_pdata *pdata;
struct platform_device_info pdevinfo;
struct property_entry properties[2];
struct fwnode_handle *primary;
@@ -258,10 +258,10 @@ static void gpio_swnode_lookup_by_secondary(struct kunit *test)
properties[1] = (struct property_entry){ };
pdevinfo = (struct platform_device_info){
- .name = GPIO_SWNODE_TEST_CONSUMER,
+ .name = GPIO_BASE_TEST_CONSUMER,
.id = PLATFORM_DEVID_NONE,
- .data = &gpio_swnode_pdata_template,
- .size_data = sizeof(gpio_swnode_pdata_template),
+ .data = &gpio_test_pdata_template,
+ .size_data = sizeof(gpio_test_pdata_template),
.properties = properties,
};
@@ -283,7 +283,7 @@ static struct kunit_case gpio_swnode_lookup_tests[] = {
static struct kunit_suite gpio_swnode_lookup_test_suite = {
.name = "gpio-swnode-lookup",
.test_cases = gpio_swnode_lookup_tests,
- .init = gpio_swnode_register_drivers,
+ .init = gpio_test_register_drivers,
};
static void gpio_swnode_unregister_swnode(void *data)
@@ -731,7 +731,7 @@ static const struct software_node *const gpio_hog_swnodes[] = {
static void gpio_hog_assert(struct kunit *test, unsigned int offset,
int expected_direction)
{
- struct gpio_swnode_consumer_pdata *pdata;
+ struct gpio_test_consumer_pdata *pdata;
struct platform_device_info pdevinfo;
struct property_entry properties[2];
struct platform_device *pdev;
@@ -771,10 +771,10 @@ static void gpio_hog_assert(struct kunit *test, unsigned int offset,
properties[1] = (struct property_entry){ };
pdevinfo = (struct platform_device_info){
- .name = GPIO_SWNODE_TEST_CONSUMER,
+ .name = GPIO_BASE_TEST_CONSUMER,
.id = PLATFORM_DEVID_NONE,
- .data = &gpio_swnode_pdata_template,
- .size_data = sizeof(gpio_swnode_pdata_template),
+ .data = &gpio_test_pdata_template,
+ .size_data = sizeof(gpio_test_pdata_template),
.properties = properties,
};
@@ -825,7 +825,7 @@ static struct kunit_suite gpio_swnode_hog_test_suite = {
.test_cases = gpio_swnode_hog_tests,
.suite_init = gpio_hog_suite_init,
.suite_exit = gpio_hog_suite_exit,
- .init = gpio_swnode_register_drivers,
+ .init = gpio_test_register_drivers,
};
kunit_test_suites(
--
2.47.3
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v3 4/4] gpio: kunit: add a test case for platform lookup tables
2026-10-13 13:02 [PATCH v3 0/4] gpio: kunit: add test cases for platform lookup tables Bartosz Golaszewski
` (2 preceding siblings ...)
2026-10-13 13:03 ` [PATCH v3 3/4] gpio: kunit: rename the swnode consumer to a more generic test consumer Bartosz Golaszewski
@ 2026-10-13 13:03 ` Bartosz Golaszewski
3 siblings, 0 replies; 6+ messages in thread
From: Bartosz Golaszewski @ 2026-10-13 13:03 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski
Cc: linux-gpio, linux-kernel, Bartosz Golaszewski
Add a kunit test-case for retrieving GPIOs using platform lookup tables.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
drivers/gpio/gpiolib-kunit.c | 102 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 102 insertions(+)
diff --git a/drivers/gpio/gpiolib-kunit.c b/drivers/gpio/gpiolib-kunit.c
index b662be88a08711380f938852d84809f36a8d62d0..c5d4637ea2c587622af8fd7c6173c88ac122e23f 100644
--- a/drivers/gpio/gpiolib-kunit.c
+++ b/drivers/gpio/gpiolib-kunit.c
@@ -18,6 +18,7 @@
#include <kunit/fwnode.h>
#include <kunit/platform_device.h>
+#include <kunit/resource.h>
#include <kunit/test.h>
#define GPIO_TEST_PROVIDER "gpio-test-provider"
@@ -828,11 +829,112 @@ static struct kunit_suite gpio_swnode_hog_test_suite = {
.init = gpio_test_register_drivers,
};
+KUNIT_DEFINE_ACTION_WRAPPER(gpiod_remove_lookup_table_wrapper,
+ gpiod_remove_lookup_table,
+ struct gpiod_lookup_table *);
+
+static int kunit_gpiod_add_lookup_table(struct kunit *test,
+ struct gpiod_lookup_table *table)
+{
+ gpiod_add_lookup_table(table);
+
+ return kunit_add_action_or_reset(test, gpiod_remove_lookup_table_wrapper, table);
+}
+
+static struct gpiod_lookup_table gpio_test_lookup_table_by_device = {
+ .dev_id = GPIO_BASE_TEST_CONSUMER,
+ .table = {
+ GPIO_LOOKUP(GPIO_TEST_PROVIDER, 0, "foo", GPIO_ACTIVE_HIGH),
+ { }
+ },
+};
+
+static void gpio_lookup_table_by_device(struct kunit *test)
+{
+ struct gpio_test_consumer_pdata *pdata;
+ struct platform_device_info pdevinfo;
+ struct platform_device *pdev;
+ int ret;
+
+ ret = kunit_gpiod_add_lookup_table(test, &gpio_test_lookup_table_by_device);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+
+ pdevinfo = (struct platform_device_info){
+ .name = GPIO_TEST_PROVIDER,
+ .id = PLATFORM_DEVID_NONE,
+ };
+
+ pdev = kunit_platform_device_register_full(test, &pdevinfo);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev);
+
+ pdevinfo = (struct platform_device_info){
+ .name = GPIO_BASE_TEST_CONSUMER,
+ .id = PLATFORM_DEVID_NONE,
+ .data = &gpio_test_pdata_template,
+ .size_data = sizeof(gpio_test_pdata_template),
+ };
+
+ pdev = kunit_platform_device_register_full(test, &pdevinfo);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev);
+
+ gpio_test_device_check_bound(test, &pdev->dev, true);
+
+ pdata = dev_get_platdata(&pdev->dev);
+ KUNIT_ASSERT_TRUE(test, pdata->gpio_ok);
+}
+
+static struct gpiod_lookup_table gpio_test_lookup_table_global = {
+ .dev_id = NULL,
+ .table = {
+ GPIO_LOOKUP(GPIO_TEST_PROVIDER, 0, "foo", GPIO_ACTIVE_HIGH),
+ { }
+ },
+};
+
+static void gpio_lookup_table_global(struct kunit *test)
+{
+ struct platform_device_info pdevinfo;
+ struct platform_device *pdev;
+ struct gpio_desc *desc;
+ int ret;
+
+ ret = kunit_gpiod_add_lookup_table(test, &gpio_test_lookup_table_global);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+
+ pdevinfo = (struct platform_device_info){
+ .name = GPIO_TEST_PROVIDER,
+ .id = PLATFORM_DEVID_NONE,
+ };
+
+ pdev = kunit_platform_device_register_full(test, &pdevinfo);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev);
+
+ gpio_test_device_check_bound(test, &pdev->dev, true);
+
+ desc = gpiod_get_index(NULL, "foo", 0, GPIOD_OUT_HIGH);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, desc);
+
+ gpiod_put(desc);
+}
+
+static struct kunit_case gpio_lookup_table_tests[] = {
+ KUNIT_CASE(gpio_lookup_table_by_device),
+ KUNIT_CASE(gpio_lookup_table_global),
+ { }
+};
+
+static struct kunit_suite gpio_lookup_tables_suite = {
+ .name = "gpio-lookup-tables",
+ .test_cases = gpio_lookup_table_tests,
+ .init = gpio_test_register_drivers,
+};
+
kunit_test_suites(
&gpio_swnode_lookup_test_suite,
&gpio_swnode_probe_order_test_suite,
&gpio_unbind_with_consumers_test_suite,
&gpio_swnode_hog_test_suite,
+ &gpio_lookup_tables_suite,
);
MODULE_DESCRIPTION("Test module for the GPIO subsystem");
--
2.47.3
^ permalink raw reply related [flat|nested] 6+ messages in thread