]> git.baikalelectronics.ru Git - uboot.git/commitdiff
cmd: gpio: Make `gpio input` return pin value again
authorAlex Kiernan <alex.kiernan@gmail.com>
Wed, 11 Mar 2020 08:46:29 +0000 (08:46 +0000)
committerTom Rini <trini@konsulko.com>
Fri, 13 Mar 2020 13:30:30 +0000 (09:30 -0400)
a8f4e9f5cf39 ("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: a8f4e9f5cf39 ("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>
cmd/gpio.c
test/py/tests/test_gpio.py [new file with mode: 0644]

index 16c2cebb3d4bf6a125e452de7b852f718d681acf..408a942455b58627a81107f3145fe08e33fbeb9f 100644 (file)
@@ -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 (file)
index 0000000..8c64f68
--- /dev/null
@@ -0,0 +1,37 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+import pytest
+
+@pytest.mark.boardspec('sandbox')
+@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)
+
+@pytest.mark.boardspec('sandbox')
+@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)