linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Linus Walleij <linus.walleij@linaro.org>,
	 Kent Gibson <warthog618@gmail.com>
Cc: linux-gpio@vger.kernel.org,
	 Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: [PATCH libgpiod 7/7] tests: add a test case for checking invalid lines
Date: Mon, 06 Oct 2025 13:27:52 +0200	[thread overview]
Message-ID: <20251006-gpiosim-valid-lines-v1-7-b399373e90a9@linaro.org> (raw)
In-Reply-To: <20251006-gpiosim-valid-lines-v1-0-b399373e90a9@linaro.org>

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Add a test case for validating kernel's behavior when user-space tries
to request an invalid GPIO line.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 tests/harness/gpiod-test.c |  4 ++--
 tests/tests-kernel-uapi.c  | 29 +++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/tests/harness/gpiod-test.c b/tests/harness/gpiod-test.c
index 4e65ae2d260a0339f881ed7dfe0281b834095588..7fafc030c3712decc3271c72aa8ab789871f764e 100644
--- a/tests/harness/gpiod-test.c
+++ b/tests/harness/gpiod-test.c
@@ -10,8 +10,8 @@
 
 #include "gpiod-test.h"
 
-#define MIN_KERNEL_MAJOR	5
-#define MIN_KERNEL_MINOR	19
+#define MIN_KERNEL_MAJOR	6
+#define MIN_KERNEL_MINOR	17
 #define MIN_KERNEL_RELEASE	0
 #define MIN_KERNEL_VERSION	KERNEL_VERSION(MIN_KERNEL_MAJOR, \
 					       MIN_KERNEL_MINOR, \
diff --git a/tests/tests-kernel-uapi.c b/tests/tests-kernel-uapi.c
index 5955fac59717bb5181e7b6d11ee996b4fb24f588..65f9c50f7e5a0f9186343cec5209c87371ee713d 100644
--- a/tests/tests-kernel-uapi.c
+++ b/tests/tests-kernel-uapi.c
@@ -197,3 +197,32 @@ GPIOD_TEST_CASE(open_source_emulation)
 	g_assert_cmpint(gpiod_line_info_get_drive(info), ==,
 			GPIOD_LINE_DRIVE_OPEN_SOURCE);
 }
+
+GPIOD_TEST_CASE(valid_lines)
+{
+	static const guint invalid_lines[] = { 2, 4 };
+
+	g_autoptr(GPIOSimChip) sim = NULL;
+	g_autoptr(struct_gpiod_chip) chip = NULL;
+	g_autoptr(struct_gpiod_line_info) info0 = NULL;
+	g_autoptr(struct_gpiod_line_info) info1 = NULL;
+	g_autoptr(GVariant) vinval = NULL;
+
+	vinval = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
+					   invalid_lines, 2, sizeof(guint));
+	g_variant_ref_sink(vinval);
+
+	sim = g_gpiosim_chip_new("num-lines", 8,
+				 "invalid-lines", vinval,
+				 NULL);
+
+	chip = gpiod_test_open_chip_or_fail(g_gpiosim_chip_get_dev_path(sim));
+	info0 = gpiod_chip_get_line_info(chip, 0);
+	info1 = gpiod_chip_get_line_info(chip, 2);
+	g_assert_nonnull(info0);
+	g_assert_nonnull(info1);
+	gpiod_test_return_if_failed();
+
+	g_assert_false(gpiod_line_info_is_used(info0));
+	g_assert_true(gpiod_line_info_is_used(info1));
+}

-- 
2.48.1


  parent reply	other threads:[~2025-10-06 11:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-06 11:27 [PATCH libgpiod 0/7] tests: update libgpiosim tests and add a uAPI test case for valid lines Bartosz Golaszewski
2025-10-06 11:27 ` [PATCH libgpiod 1/7] tests: harness: use correct type to capture a boolean retval Bartosz Golaszewski
2025-10-06 11:27 ` [PATCH libgpiod 2/7] tests: gpiosim: don't allow clearing hogs on active devices Bartosz Golaszewski
2025-10-06 11:27 ` [PATCH libgpiod 3/7] tests: gpiosim: selftests: shrink the self-test code Bartosz Golaszewski
2025-10-06 11:27 ` [PATCH libgpiod 4/7] tests: gpiosim: selftests: add more test cases Bartosz Golaszewski
2025-10-06 11:27 ` [PATCH libgpiod 5/7] tests: gpiosim: provide gpiosim_bank_set_line_valid() Bartosz Golaszewski
2025-10-06 11:27 ` [PATCH libgpiod 6/7] tests: harness: support setting invalid lines Bartosz Golaszewski
2025-10-06 11:27 ` Bartosz Golaszewski [this message]
2025-10-09  8:16 ` [PATCH libgpiod 0/7] tests: update libgpiosim tests and add a uAPI test case for valid lines 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=20251006-gpiosim-valid-lines-v1-7-b399373e90a9@linaro.org \
    --to=brgl@bgdev.pl \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=warthog618@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).