test_gpio.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # SPDX-License-Identifier: GPL-2.0+
  2. import pytest
  3. @pytest.mark.boardspec('sandbox')
  4. @pytest.mark.buildconfigspec('cmd_gpio')
  5. def test_gpio_input(u_boot_console):
  6. """Test that gpio input correctly returns the value of a gpio pin."""
  7. response = u_boot_console.run_command('gpio input 0; echo rc:$?')
  8. expected_response = 'rc:0'
  9. assert(expected_response in response)
  10. response = u_boot_console.run_command('gpio toggle 0; gpio input 0; echo rc:$?')
  11. expected_response = 'rc:1'
  12. assert(expected_response in response)
  13. @pytest.mark.boardspec('sandbox')
  14. @pytest.mark.buildconfigspec('cmd_gpio')
  15. def test_gpio_exit_statuses(u_boot_console):
  16. """Test that non-input gpio commands correctly return the command
  17. success/failure status."""
  18. expected_response = 'rc:0'
  19. response = u_boot_console.run_command('gpio clear 0; echo rc:$?')
  20. assert(expected_response in response)
  21. response = u_boot_console.run_command('gpio set 0; echo rc:$?')
  22. assert(expected_response in response)
  23. response = u_boot_console.run_command('gpio toggle 0; echo rc:$?')
  24. assert(expected_response in response)
  25. response = u_boot_console.run_command('gpio status -a; echo rc:$?')
  26. assert(expected_response in response)
  27. expected_response = 'rc:1'
  28. response = u_boot_console.run_command('gpio nonexistent-command; echo rc:$?')
  29. assert(expected_response in response)
  30. response = u_boot_console.run_command('gpio input 200; echo rc:$?')
  31. assert(expected_response in response)