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