Philippe Reynes | 1ee2648 | 2020-07-24 18:19:51 +0200 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
| 2 | |
| 3 | import pytest |
| 4 | |
| 5 | @pytest.mark.boardspec('sandbox') |
| 6 | @pytest.mark.buildconfigspec('cmd_button') |
Heinrich Schuchardt | adee5df | 2020-09-14 12:50:56 +0200 | [diff] [blame] | 7 | def test_button_list(u_boot_console): |
| 8 | """Test listing buttons""" |
Philippe Reynes | 1ee2648 | 2020-07-24 18:19:51 +0200 | [diff] [blame] | 9 | |
Philippe Reynes | 1ee2648 | 2020-07-24 18:19:51 +0200 | [diff] [blame] | 10 | response = u_boot_console.run_command('button list; echo rc:$?') |
Heinrich Schuchardt | adee5df | 2020-09-14 12:50:56 +0200 | [diff] [blame] | 11 | assert('button1' in response) |
| 12 | assert('button2' in response) |
| 13 | assert('rc:0' in response) |
| 14 | |
| 15 | @pytest.mark.boardspec('sandbox') |
| 16 | @pytest.mark.buildconfigspec('cmd_button') |
| 17 | @pytest.mark.buildconfigspec('cmd_gpio') |
| 18 | def test_button_return_code(u_boot_console): |
| 19 | """Test correct reporting of the button status |
| 20 | |
| 21 | The sandbox gpio driver reports the last output value as input value. |
| 22 | We can use this in our test to emulate different input statuses. |
| 23 | """ |
| 24 | |
| 25 | u_boot_console.run_command('gpio set a3; gpio input a3'); |
| 26 | response = u_boot_console.run_command('button button1; echo rc:$?') |
| 27 | assert('on' in response) |
| 28 | assert('rc:0' in response) |
| 29 | |
| 30 | u_boot_console.run_command('gpio clear a3; gpio input a3'); |
Heinrich Schuchardt | 57c2fc6 | 2020-09-14 12:50:54 +0200 | [diff] [blame] | 31 | response = u_boot_console.run_command('button button1; echo rc:$?') |
Heinrich Schuchardt | adee5df | 2020-09-14 12:50:56 +0200 | [diff] [blame] | 32 | assert('off' in response) |
| 33 | assert('rc:1' in response) |
Philippe Reynes | 1ee2648 | 2020-07-24 18:19:51 +0200 | [diff] [blame] | 34 | |
Philippe Reynes | 1ee2648 | 2020-07-24 18:19:51 +0200 | [diff] [blame] | 35 | response = u_boot_console.run_command('button nonexistent-button; echo rc:$?') |
Heinrich Schuchardt | adee5df | 2020-09-14 12:50:56 +0200 | [diff] [blame] | 36 | assert('not found' in response) |
| 37 | assert('rc:1' in response) |