summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDiego Rondini <diego.rondini@kynetics.com>2022-04-11 13:02:09 +0300
committerTom Rini <trini@konsulko.com>2022-04-20 18:14:39 +0300
commitdd2b8c1155d016800cbbaa1bd70efdd81f9da493 (patch)
tree127dc4d0079353e6f5cb7df708bfc5bc5f348bb5 /test
parent270f7fd25b3d1e825d3364eee652c3ccc9d5aae4 (diff)
downloadu-boot-dd2b8c1155d016800cbbaa1bd70efdd81f9da493.tar.xz
cmd: gpio: Add `gpio read` subcommand
As explained in commit 4af2a33ee5b9 ("cmd: gpio: Make `gpio input` return pin value again") the `gpio input` is used in scripts to obtain the value of a pin, despite the fact that CMD_RET_FAILURE is indistinguishable from a valid pin value. To be able to detect failures and properly use the value of a GPIO in scripts we introduce the `gpio read` command that sets the variable `name` to the value of the pin. Return code of the `gpio read` command can be used to check for CMD_RET_SUCCESS or CMD_RET_FAILURE. CONFIG_CMD_GPIO_READ is used to enable the `gpio read` command. Signed-off-by: Diego Rondini <diego.rondini@kynetics.com>
Diffstat (limited to 'test')
-rw-r--r--test/py/tests/test_gpio.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/py/tests/test_gpio.py b/test/py/tests/test_gpio.py
index 109649e2c7..fa0af5f82b 100644
--- a/test/py/tests/test_gpio.py
+++ b/test/py/tests/test_gpio.py
@@ -46,6 +46,20 @@ def test_gpio_exit_statuses(u_boot_console):
response = u_boot_console.run_command('gpio input 200; echo rc:$?')
assert(expected_response in response)
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('cmd_gpio')
+def test_gpio_read(u_boot_console):
+ """Test that gpio read correctly sets the variable to the value of a gpio pin."""
+
+ response = u_boot_console.run_command('gpio read var 0; echo val:$var,rc:$?')
+ expected_response = 'val:0,rc:0'
+ assert(expected_response in response)
+ response = u_boot_console.run_command('gpio toggle 0; gpio read var 0; echo val:$var,rc:$?')
+ expected_response = 'val:1,rc:0'
+ assert(expected_response in response)
+ response = u_boot_console.run_command('setenv var; gpio read var nonexistent-gpio; echo val:$var,rc:$?')
+ expected_response = 'val:,rc:1'
+ assert(expected_response in response)
"""
Generic Tests for 'gpio' command on sandbox and real hardware.