* [PATCH v2] cmd: gpio: Make `gpio input` return pin value again
@ 2020-03-11 8:46 Alex Kiernan
2020-03-13 17:25 ` Tom Rini
0 siblings, 1 reply; 2+ messages in thread
From: Alex Kiernan @ 2020-03-11 8:46 UTC (permalink / raw)
To: u-boot
4dbc107f4683 ("cmd: gpio: Correct do_gpio() return value") correctly
changed the behaviour of the gpio command to return CMD_RET_SUCCESS or
CMD_RET_FAILURE, but any existing script which expects the return value
to be the pin value is broken by this change.
Reinstate the legacy behaviour for `gpio input` only.
Fixes: 4dbc107f4683 ("cmd: gpio: Correct do_gpio() return value")
Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Kiernan <alex.kiernan@hivehome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
Changes in v2:
- add test
cmd/gpio.c | 7 ++++++-
test/py/tests/test_gpio.py | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 1 deletion(-)
create mode 100644 test/py/tests/test_gpio.py
diff --git a/cmd/gpio.c b/cmd/gpio.c
index 16c2cebb3d4b..408a942455b5 100644
--- a/cmd/gpio.c
+++ b/cmd/gpio.c
@@ -248,7 +248,12 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
if (ret != -EBUSY)
gpio_free(gpio);
- return CMD_RET_SUCCESS;
+ /*
+ * Whilst wrong, the legacy gpio input command returns the pin
+ * value, or CMD_RET_FAILURE (which is indistinguishable from a
+ * valid pin value).
+ */
+ return (sub_cmd == GPIOC_INPUT) ? value : CMD_RET_SUCCESS;
err:
if (ret != -EBUSY)
diff --git a/test/py/tests/test_gpio.py b/test/py/tests/test_gpio.py
new file mode 100644
index 000000000000..8c64f686b0ba
--- /dev/null
+++ b/test/py/tests/test_gpio.py
@@ -0,0 +1,37 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+import pytest
+
+ at pytest.mark.boardspec('sandbox')
+ at pytest.mark.buildconfigspec('cmd_gpio')
+def test_gpio_input(u_boot_console):
+ """Test that gpio input correctly returns the value of a gpio pin."""
+
+ response = u_boot_console.run_command('gpio input 0; echo rc:$?')
+ expected_response = 'rc:0'
+ assert(expected_response in response)
+ response = u_boot_console.run_command('gpio toggle 0; gpio input 0; echo rc:$?')
+ expected_response = 'rc:1'
+ assert(expected_response in response)
+
+ at pytest.mark.boardspec('sandbox')
+ at pytest.mark.buildconfigspec('cmd_gpio')
+def test_gpio_exit_statuses(u_boot_console):
+ """Test that non-input gpio commands correctly return the command
+ success/failure status."""
+
+ expected_response = 'rc:0'
+ response = u_boot_console.run_command('gpio clear 0; echo rc:$?')
+ assert(expected_response in response)
+ response = u_boot_console.run_command('gpio set 0; echo rc:$?')
+ assert(expected_response in response)
+ response = u_boot_console.run_command('gpio toggle 0; echo rc:$?')
+ assert(expected_response in response)
+ response = u_boot_console.run_command('gpio status -a; echo rc:$?')
+ assert(expected_response in response)
+
+ expected_response = 'rc:1'
+ response = u_boot_console.run_command('gpio nonexistent-command; echo rc:$?')
+ assert(expected_response in response)
+ response = u_boot_console.run_command('gpio input 200; echo rc:$?')
+ assert(expected_response in response)
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH v2] cmd: gpio: Make `gpio input` return pin value again
2020-03-11 8:46 [PATCH v2] cmd: gpio: Make `gpio input` return pin value again Alex Kiernan
@ 2020-03-13 17:25 ` Tom Rini
0 siblings, 0 replies; 2+ messages in thread
From: Tom Rini @ 2020-03-13 17:25 UTC (permalink / raw)
To: u-boot
On Wed, Mar 11, 2020 at 08:46:29AM +0000, Alex Kiernan wrote:
> 4dbc107f4683 ("cmd: gpio: Correct do_gpio() return value") correctly
> changed the behaviour of the gpio command to return CMD_RET_SUCCESS or
> CMD_RET_FAILURE, but any existing script which expects the return value
> to be the pin value is broken by this change.
>
> Reinstate the legacy behaviour for `gpio input` only.
>
> Fixes: 4dbc107f4683 ("cmd: gpio: Correct do_gpio() return value")
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
> Signed-off-by: Alex Kiernan <alex.kiernan@hivehome.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>
Applied to u-boot/master, thanks!
--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200313/330f5dfe/attachment.sig>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-03-13 17:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-11 8:46 [PATCH v2] cmd: gpio: Make `gpio input` return pin value again Alex Kiernan
2020-03-13 17:25 ` Tom Rini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.