blob: f0d85be896d8f6afd744a7dca5938b948fa07aed [file] [log] [blame]
Philippe Reynes1ee26482020-07-24 18:19:51 +02001# SPDX-License-Identifier: GPL-2.0+
2
3import pytest
4
5@pytest.mark.boardspec('sandbox')
6@pytest.mark.buildconfigspec('cmd_button')
Simon Glassddba5202025-02-09 09:07:14 -07007def test_button_list(ubman):
Heinrich Schuchardtadee5df2020-09-14 12:50:56 +02008 """Test listing buttons"""
Philippe Reynes1ee26482020-07-24 18:19:51 +02009
Simon Glassddba5202025-02-09 09:07:14 -070010 response = ubman.run_command('button list; echo rc:$?')
Heinrich Schuchardtadee5df2020-09-14 12:50:56 +020011 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 Glassddba5202025-02-09 09:07:14 -070018def test_button_return_code(ubman):
Heinrich Schuchardtadee5df2020-09-14 12:50:56 +020019 """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 Glassddba5202025-02-09 09:07:14 -070025 ubman.run_command('gpio set a3; gpio input a3');
26 response = ubman.run_command('button button1; echo rc:$?')
Heinrich Schuchardtadee5df2020-09-14 12:50:56 +020027 assert('on' in response)
28 assert('rc:0' in response)
29
Simon Glassddba5202025-02-09 09:07:14 -070030 ubman.run_command('gpio clear a3; gpio input a3');
31 response = ubman.run_command('button button1; echo rc:$?')
Heinrich Schuchardtadee5df2020-09-14 12:50:56 +020032 assert('off' in response)
33 assert('rc:1' in response)
Philippe Reynes1ee26482020-07-24 18:19:51 +020034
Simon Glassddba5202025-02-09 09:07:14 -070035 response = ubman.run_command('button nonexistent-button; echo rc:$?')
Heinrich Schuchardtadee5df2020-09-14 12:50:56 +020036 assert('not found' in response)
37 assert('rc:1' in response)