linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH libgpiod 0/2] tools: don't implicity unquote unnamed lines in gpioinfo
@ 2025-03-21 11:05 Bartosz Golaszewski
  2025-03-21 11:05 ` [PATCH libgpiod 1/2] tools: gpioinfo: don't implicity unquote unnamed lines Bartosz Golaszewski
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2025-03-21 11:05 UTC (permalink / raw)
  To: Kent Gibson, Linus Walleij; +Cc: Bartosz Golaszewski, linux-gpio

Fix inconsistent output of gpioinfo for named and unnamed lines and add
a relevant test-case.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
Bartosz Golaszewski (2):
      tools: gpioinfo: don't implicity unquote unnamed lines
      tools: tests: add a test case for gpioinfo output consistency

 tools/gpio-tools-test.bash | 18 ++++++++++++++++++
 tools/gpioinfo.c           |  5 +++--
 2 files changed, 21 insertions(+), 2 deletions(-)
---
base-commit: 2cd1efbc5783f5daa47598c76bede5ea7e47993f
change-id: 20250320-gpioinfo-unnamed-quotes-4d74db6e48dd

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>


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

* [PATCH libgpiod 1/2] tools: gpioinfo: don't implicity unquote unnamed lines
  2025-03-21 11:05 [PATCH libgpiod 0/2] tools: don't implicity unquote unnamed lines in gpioinfo Bartosz Golaszewski
@ 2025-03-21 11:05 ` Bartosz Golaszewski
  2025-03-21 11:44   ` Kent Gibson
  2025-03-21 11:05 ` [PATCH libgpiod 2/2] tools: tests: add a test case for gpioinfo output consistency Bartosz Golaszewski
  2025-03-24  9:42 ` [PATCH libgpiod 0/2] tools: don't implicity unquote unnamed lines in gpioinfo Bartosz Golaszewski
  2 siblings, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2025-03-21 11:05 UTC (permalink / raw)
  To: Kent Gibson, Linus Walleij; +Cc: Bartosz Golaszewski, linux-gpio

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

Consider the following output of `gpioinfo`:

gpiochip1 - 2 lines:
        line   0:       "foo"                   output
        line   1:       unnamed                 output

Now let's run:

    gpioset --chip=gpiochip1 0=active 1=active

The output of `gpioinfo --unquoted` is correct:

gpiochip1 - 2 lines:
        line   0:       foo                     output consumer=gpioset
        line   1:       unnamed                 output consumer=gpioset

However, without the `unquoted` switch, it's inconsistent:

gpiochip1 - 2 lines:
        line   0:       "foo"                   output consumer="gpioset"
        line   1:       unnamed                 output consumer=gpioset

This is because gpioinfo drops the quotes for all subsequent attribute
strings when it encounters an unnamed line. We should instead keep a
separate instance of the `unquoted` flag just for the line name and pass
the original value of `unquoted_strings` down to
print_line_attributes().

Fixes: 8ffb6489286f ("tools: line name focussed rework")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 tools/gpioinfo.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/gpioinfo.c b/tools/gpioinfo.c
index d5e4751..4619ca7 100644
--- a/tools/gpioinfo.c
+++ b/tools/gpioinfo.c
@@ -137,6 +137,7 @@ static bool resolve_line(struct line_resolver *resolver,
 
 static void print_line_info(struct gpiod_line_info *info, bool unquoted_strings)
 {
+	bool unquoted_name = unquoted_strings;
 	char quoted_name[17];
 	const char *name;
 	int len;
@@ -144,10 +145,10 @@ static void print_line_info(struct gpiod_line_info *info, bool unquoted_strings)
 	name = gpiod_line_info_get_name(info);
 	if (!name) {
 		name = "unnamed";
-		unquoted_strings = true;
+		unquoted_name = true;
 	}
 
-	if (unquoted_strings) {
+	if (unquoted_name) {
 		printf("%-16s\t", name);
 	} else {
 		len = strlen(name);

-- 
2.45.2


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

* [PATCH libgpiod 2/2] tools: tests: add a test case for gpioinfo output consistency
  2025-03-21 11:05 [PATCH libgpiod 0/2] tools: don't implicity unquote unnamed lines in gpioinfo Bartosz Golaszewski
  2025-03-21 11:05 ` [PATCH libgpiod 1/2] tools: gpioinfo: don't implicity unquote unnamed lines Bartosz Golaszewski
@ 2025-03-21 11:05 ` Bartosz Golaszewski
  2025-03-24  9:42 ` [PATCH libgpiod 0/2] tools: don't implicity unquote unnamed lines in gpioinfo Bartosz Golaszewski
  2 siblings, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2025-03-21 11:05 UTC (permalink / raw)
  To: Kent Gibson, Linus Walleij; +Cc: Bartosz Golaszewski, linux-gpio

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

Add a test case making sure that without the `--unquoted` switch, the
consumer name is still quoted both for named and unnamed lines.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 tools/gpio-tools-test.bash | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/tools/gpio-tools-test.bash b/tools/gpio-tools-test.bash
index 359960a..898b348 100755
--- a/tools/gpio-tools-test.bash
+++ b/tools/gpio-tools-test.bash
@@ -478,6 +478,24 @@ test_gpioinfo_with_offset_out_of_range() {
 	status_is 1
 }
 
+test_gpioinfo_quoted_output_consistency() {
+	gpiosim_chip sim0 num_lines=2 line_name=0:foo
+
+	local sim0=${GPIOSIM_CHIP_NAME[sim0]}
+
+	dut_run gpioset --chip=$sim0 0=active 1=active
+
+	run_prog gpioinfo --chip=$sim0
+
+	status_is 0
+	num_lines_is 3
+	output_regex_match "line\\s+0:\\s+\"foo\"\\s+output\\s+consumer=\"gpioset\""
+	output_regex_match "line\\s+1:\\s+unnamed\\s+output\\s+consumer=\"gpioset\""
+
+	dut_kill
+	dut_wait
+}
+
 #
 # gpioget test cases
 #

-- 
2.45.2


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

* Re: [PATCH libgpiod 1/2] tools: gpioinfo: don't implicity unquote unnamed lines
  2025-03-21 11:05 ` [PATCH libgpiod 1/2] tools: gpioinfo: don't implicity unquote unnamed lines Bartosz Golaszewski
@ 2025-03-21 11:44   ` Kent Gibson
  0 siblings, 0 replies; 5+ messages in thread
From: Kent Gibson @ 2025-03-21 11:44 UTC (permalink / raw)
  To: Bartosz Golaszewski; +Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio

On Fri, Mar 21, 2025 at 12:05:24PM +0100, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> Consider the following output of `gpioinfo`:
>
> gpiochip1 - 2 lines:
>         line   0:       "foo"                   output
>         line   1:       unnamed                 output
>
> Now let's run:
>
>     gpioset --chip=gpiochip1 0=active 1=active
>
> The output of `gpioinfo --unquoted` is correct:
>
> gpiochip1 - 2 lines:
>         line   0:       foo                     output consumer=gpioset
>         line   1:       unnamed                 output consumer=gpioset
>
> However, without the `unquoted` switch, it's inconsistent:
>
> gpiochip1 - 2 lines:
>         line   0:       "foo"                   output consumer="gpioset"
>         line   1:       unnamed                 output consumer=gpioset
>
> This is because gpioinfo drops the quotes for all subsequent attribute
> strings when it encounters an unnamed line. We should instead keep a
> separate instance of the `unquoted` flag just for the line name and pass
> the original value of `unquoted_strings` down to
> print_line_attributes().
>

Oh nuts, originally the consumer was a separate field, so the line name
was the only string in the info.
I didn't consider that when making the consumer an attribute :(.

The fix and test look good to me.

Reviewed-by: Kent Gibson <warthog618@gmail.com>

Cheers,
Kent.

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

* Re: [PATCH libgpiod 0/2] tools: don't implicity unquote unnamed lines in gpioinfo
  2025-03-21 11:05 [PATCH libgpiod 0/2] tools: don't implicity unquote unnamed lines in gpioinfo Bartosz Golaszewski
  2025-03-21 11:05 ` [PATCH libgpiod 1/2] tools: gpioinfo: don't implicity unquote unnamed lines Bartosz Golaszewski
  2025-03-21 11:05 ` [PATCH libgpiod 2/2] tools: tests: add a test case for gpioinfo output consistency Bartosz Golaszewski
@ 2025-03-24  9:42 ` Bartosz Golaszewski
  2 siblings, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2025-03-24  9:42 UTC (permalink / raw)
  To: Kent Gibson, Linus Walleij, Bartosz Golaszewski
  Cc: Bartosz Golaszewski, linux-gpio

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


On Fri, 21 Mar 2025 12:05:23 +0100, Bartosz Golaszewski wrote:
> Fix inconsistent output of gpioinfo for named and unnamed lines and add
> a relevant test-case.
> 
> 

Applied, thanks!

[1/2] tools: gpioinfo: don't implicity unquote unnamed lines
      commit: c152accf916b609a2b856b480e7360f7e97127ed
[2/2] tools: tests: add a test case for gpioinfo output consistency
      commit: 0182cb5cddc48a0db1641c7310dda2e3eed44cb4

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

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

end of thread, other threads:[~2025-03-24  9:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-21 11:05 [PATCH libgpiod 0/2] tools: don't implicity unquote unnamed lines in gpioinfo Bartosz Golaszewski
2025-03-21 11:05 ` [PATCH libgpiod 1/2] tools: gpioinfo: don't implicity unquote unnamed lines Bartosz Golaszewski
2025-03-21 11:44   ` Kent Gibson
2025-03-21 11:05 ` [PATCH libgpiod 2/2] tools: tests: add a test case for gpioinfo output consistency Bartosz Golaszewski
2025-03-24  9:42 ` [PATCH libgpiod 0/2] tools: don't implicity unquote unnamed lines in gpioinfo Bartosz Golaszewski

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).