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 6/7] tests: harness: support setting invalid lines
Date: Mon, 06 Oct 2025 13:27:51 +0200 [thread overview]
Message-ID: <20251006-gpiosim-valid-lines-v1-6-b399373e90a9@linaro.org> (raw)
In-Reply-To: <20251006-gpiosim-valid-lines-v1-0-b399373e90a9@linaro.org>
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Wrap the new gpiosim_bank_set_line_valid() symbol exported by libgpiosim
in a GLib property and allow libgpiod tests to mark simulated lines as
invalid.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
tests/gpiosim-glib/gpiosim-glib.c | 45 +++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/tests/gpiosim-glib/gpiosim-glib.c b/tests/gpiosim-glib/gpiosim-glib.c
index dd56d91735cb3e78c219addf44ccd6ddba7fd0d2..34073c21fd28b702c89bf30245e684de4bf8d5a2 100644
--- a/tests/gpiosim-glib/gpiosim-glib.c
+++ b/tests/gpiosim-glib/gpiosim-glib.c
@@ -3,6 +3,7 @@
#include <errno.h>
#include <gpiosim.h>
+#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
@@ -18,6 +19,7 @@ struct _GPIOSimChip {
gchar *label;
GVariant *line_names;
GVariant *hogs;
+ GVariant *invalid_lines;
};
enum {
@@ -27,6 +29,7 @@ enum {
G_GPIOSIM_CHIP_PROP_LABEL,
G_GPIOSIM_CHIP_PROP_LINE_NAMES,
G_GPIOSIM_CHIP_PROP_HOGS,
+ G_GPIOSIM_CHIP_PROP_INVALID_LINES,
};
static struct gpiosim_ctx *sim_ctx;
@@ -130,6 +133,31 @@ static gboolean g_gpiosim_chip_apply_hogs(GPIOSimChip *self)
return TRUE;
}
+static gboolean g_gpiosim_chip_apply_invalid_lines(GPIOSimChip *self)
+{
+ g_autoptr(GVariantIter) iter = NULL;
+ gboolean ret;
+ guint offset;
+
+ if (!self->invalid_lines)
+ return TRUE;
+
+ iter = g_variant_iter_new(self->invalid_lines);
+
+ while (g_variant_iter_loop(iter, "u", &offset)) {
+ ret = gpiosim_bank_set_line_valid(self->bank, offset, false);
+ if (ret) {
+ g_set_error(&self->construct_err, G_GPIOSIM_ERROR,
+ G_GPIOSIM_ERR_CHIP_INIT_FAILED,
+ "Unable to set simulated GPIO line as invalid: %s",
+ g_strerror(errno));
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
static gboolean g_gpiosim_chip_apply_properties(GPIOSimChip *self)
{
gboolean err;
@@ -159,6 +187,10 @@ static gboolean g_gpiosim_chip_apply_properties(GPIOSimChip *self)
if (!err)
return FALSE;
+ ret = g_gpiosim_chip_apply_invalid_lines(self);
+ if (!ret)
+ return FALSE;
+
return g_gpiosim_chip_apply_hogs(self);
}
@@ -289,6 +321,9 @@ static void g_gpiosim_chip_set_property(GObject *obj, guint prop_id,
case G_GPIOSIM_CHIP_PROP_HOGS:
set_variant_prop(&self->hogs, val);
break;
+ case G_GPIOSIM_CHIP_PROP_INVALID_LINES:
+ set_variant_prop(&self->invalid_lines, val);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec);
break;
@@ -301,6 +336,7 @@ static void g_gpiosim_chip_dispose(GObject *obj)
g_clear_pointer(&self->line_names, g_variant_unref);
g_clear_pointer(&self->hogs, g_variant_unref);
+ g_clear_pointer(&self->invalid_lines, g_variant_unref);
G_OBJECT_CLASS(g_gpiosim_chip_parent_class)->dispose(obj);
}
@@ -385,6 +421,14 @@ static void g_gpiosim_chip_class_init(GPIOSimChipClass *chip_class)
"List of hogged lines and their directions.",
(GVariantType *)"a(usi)", NULL,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+
+ g_object_class_install_property(
+ class, G_GPIOSIM_CHIP_PROP_INVALID_LINES,
+ g_param_spec_variant(
+ "invalid-lines", "Invalid lines",
+ "List of offsets of lines not valid as GPIOs.",
+ (GVariantType *)"au", NULL,
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}
static void g_gpiosim_chip_init(GPIOSimChip *self)
@@ -394,6 +438,7 @@ static void g_gpiosim_chip_init(GPIOSimChip *self)
self->label = NULL;
self->line_names = NULL;
self->hogs = NULL;
+ self->invalid_lines = NULL;
}
const gchar *g_gpiosim_chip_get_dev_path(GPIOSimChip *self)
--
2.48.1
next prev 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 ` Bartosz Golaszewski [this message]
2025-10-06 11:27 ` [PATCH libgpiod 7/7] tests: add a test case for checking invalid lines Bartosz Golaszewski
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-6-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).