Alex Kiernan | 1073c23 | 2020-03-11 08:46:29 +0000 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
| 2 | |
| 3 | import pytest |
| 4 | |
| 5 | @pytest.mark.boardspec('sandbox') |
| 6 | @pytest.mark.buildconfigspec('cmd_gpio') |
| 7 | def test_gpio_input(u_boot_console): |
| 8 | """Test that gpio input correctly returns the value of a gpio pin.""" |
| 9 | |
| 10 | response = u_boot_console.run_command('gpio input 0; echo rc:$?') |
| 11 | expected_response = 'rc:0' |
| 12 | assert(expected_response in response) |
| 13 | response = u_boot_console.run_command('gpio toggle 0; gpio input 0; echo rc:$?') |
| 14 | expected_response = 'rc:1' |
| 15 | assert(expected_response in response) |
| 16 | |
| 17 | @pytest.mark.boardspec('sandbox') |
| 18 | @pytest.mark.buildconfigspec('cmd_gpio') |
| 19 | def test_gpio_exit_statuses(u_boot_console): |
| 20 | """Test that non-input gpio commands correctly return the command |
| 21 | success/failure status.""" |
| 22 | |
| 23 | expected_response = 'rc:0' |
| 24 | response = u_boot_console.run_command('gpio clear 0; echo rc:$?') |
| 25 | assert(expected_response in response) |
| 26 | response = u_boot_console.run_command('gpio set 0; echo rc:$?') |
| 27 | assert(expected_response in response) |
| 28 | response = u_boot_console.run_command('gpio toggle 0; echo rc:$?') |
| 29 | assert(expected_response in response) |
| 30 | response = u_boot_console.run_command('gpio status -a; echo rc:$?') |
| 31 | assert(expected_response in response) |
| 32 | |
| 33 | expected_response = 'rc:1' |
| 34 | response = u_boot_console.run_command('gpio nonexistent-command; echo rc:$?') |
| 35 | assert(expected_response in response) |
| 36 | response = u_boot_console.run_command('gpio input 200; echo rc:$?') |
| 37 | assert(expected_response in response) |