test_button.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # SPDX-License-Identifier: GPL-2.0+
  2. import pytest
  3. @pytest.mark.boardspec('sandbox')
  4. @pytest.mark.buildconfigspec('cmd_button')
  5. def test_button_list(u_boot_console):
  6. """Test listing buttons"""
  7. response = u_boot_console.run_command('button list; echo rc:$?')
  8. assert('button1' in response)
  9. assert('button2' in response)
  10. assert('rc:0' in response)
  11. @pytest.mark.boardspec('sandbox')
  12. @pytest.mark.buildconfigspec('cmd_button')
  13. @pytest.mark.buildconfigspec('cmd_gpio')
  14. def test_button_return_code(u_boot_console):
  15. """Test correct reporting of the button status
  16. The sandbox gpio driver reports the last output value as input value.
  17. We can use this in our test to emulate different input statuses.
  18. """
  19. u_boot_console.run_command('gpio set a3; gpio input a3');
  20. response = u_boot_console.run_command('button button1; echo rc:$?')
  21. assert('on' in response)
  22. assert('rc:0' in response)
  23. u_boot_console.run_command('gpio clear a3; gpio input a3');
  24. response = u_boot_console.run_command('button button1; echo rc:$?')
  25. assert('off' in response)
  26. assert('rc:1' in response)
  27. response = u_boot_console.run_command('button nonexistent-button; echo rc:$?')
  28. assert('not found' in response)
  29. assert('rc:1' in response)