blob: f3f68169e1480b8462600bfa74fe59be03c0eb4d [file] [log] [blame]
Philippe Reynes1ee26482020-07-24 18:19:51 +02001# SPDX-License-Identifier: GPL-2.0+
2
Tom Rinib1bed972025-05-08 15:34:45 -06003"""Tests for the button command"""
4
Philippe Reynes1ee26482020-07-24 18:19:51 +02005import pytest
6
7@pytest.mark.boardspec('sandbox')
8@pytest.mark.buildconfigspec('cmd_button')
Simon Glassddba5202025-02-09 09:07:14 -07009def test_button_list(ubman):
Heinrich Schuchardtadee5df2020-09-14 12:50:56 +020010 """Test listing buttons"""
Philippe Reynes1ee26482020-07-24 18:19:51 +020011
Simon Glassddba5202025-02-09 09:07:14 -070012 response = ubman.run_command('button list; echo rc:$?')
Heinrich Schuchardtadee5df2020-09-14 12:50:56 +020013 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 Glassddba5202025-02-09 09:07:14 -070020def test_button_return_code(ubman):
Heinrich Schuchardtadee5df2020-09-14 12:50:56 +020021 """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 Glassddba5202025-02-09 09:07:14 -070027 ubman.run_command('gpio set a3; gpio input a3');
28 response = ubman.run_command('button button1; echo rc:$?')
Heinrich Schuchardtadee5df2020-09-14 12:50:56 +020029 assert('on' in response)
30 assert('rc:0' in response)
31
Simon Glassddba5202025-02-09 09:07:14 -070032 ubman.run_command('gpio clear a3; gpio input a3');
33 response = ubman.run_command('button button1; echo rc:$?')
Heinrich Schuchardtadee5df2020-09-14 12:50:56 +020034 assert('off' in response)
35 assert('rc:1' in response)
Philippe Reynes1ee26482020-07-24 18:19:51 +020036
Simon Glassddba5202025-02-09 09:07:14 -070037 response = ubman.run_command('button nonexistent-button; echo rc:$?')
Heinrich Schuchardtadee5df2020-09-14 12:50:56 +020038 assert('not found' in response)
39 assert('rc:1' in response)