blob: 3b7f148c8fcc48e6e51fed9f8f18674f489c9f74 [file] [log] [blame]
Philippe Reynesa6c6f0f2020-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')
Heinrich Schuchardta6bfd712020-09-14 12:50:56 +02007def test_button_list(u_boot_console):
8 """Test listing buttons"""
Philippe Reynesa6c6f0f2020-07-24 18:19:51 +02009
Philippe Reynesa6c6f0f2020-07-24 18:19:51 +020010 response = u_boot_console.run_command('button list; echo rc:$?')
Heinrich Schuchardta6bfd712020-09-14 12:50:56 +020011 assert('button1' in response)
12 assert('button2' in response)
13 assert('rc:0' in response)
Philippe Reynesa6c6f0f2020-07-24 18:19:51 +020014
Heinrich Schuchardta6bfd712020-09-14 12:50:56 +020015@pytest.mark.boardspec('sandbox')
16@pytest.mark.buildconfigspec('cmd_button')
17@pytest.mark.buildconfigspec('cmd_gpio')
18def 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');
31 response = u_boot_console.run_command('button button1; echo rc:$?')
32 assert('off' in response)
33 assert('rc:1' in response)
34
Philippe Reynesa6c6f0f2020-07-24 18:19:51 +020035 response = u_boot_console.run_command('button nonexistent-button; echo rc:$?')
Heinrich Schuchardta6bfd712020-09-14 12:50:56 +020036 assert('not found' in response)
37 assert('rc:1' in response)