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') |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame^] | 7 | def test_button_list(ubman): |
Heinrich Schuchardt | adee5df | 2020-09-14 12:50:56 +0200 | [diff] [blame] | 8 | """Test listing buttons""" |
Philippe Reynes | 1ee2648 | 2020-07-24 18:19:51 +0200 | [diff] [blame] | 9 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame^] | 10 | response = ubman.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') |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame^] | 18 | def test_button_return_code(ubman): |
Heinrich Schuchardt | adee5df | 2020-09-14 12:50:56 +0200 | [diff] [blame] | 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 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame^] | 25 | ubman.run_command('gpio set a3; gpio input a3'); |
| 26 | response = ubman.run_command('button button1; echo rc:$?') |
Heinrich Schuchardt | adee5df | 2020-09-14 12:50:56 +0200 | [diff] [blame] | 27 | assert('on' in response) |
| 28 | assert('rc:0' in response) |
| 29 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame^] | 30 | ubman.run_command('gpio clear a3; gpio input a3'); |
| 31 | response = ubman.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 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame^] | 35 | response = ubman.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) |