test_bootmenu.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # SPDX-License-Identifier: GPL-2.0+
  2. """Test bootmenu"""
  3. import pytest
  4. @pytest.mark.buildconfigspec('cmd_bootmenu')
  5. def test_bootmenu(u_boot_console):
  6. """Test bootmenu
  7. u_boot_console -- U-Boot console
  8. """
  9. with u_boot_console.temporary_timeout(500):
  10. u_boot_console.run_command('setenv bootmenu_default 1')
  11. u_boot_console.run_command('setenv bootmenu_0 test 1=echo ok 1')
  12. u_boot_console.run_command('setenv bootmenu_1 test 2=echo ok 2')
  13. u_boot_console.run_command('setenv bootmenu_2 test 3=echo ok 3')
  14. u_boot_console.run_command('bootmenu 2', wait_for_prompt=False)
  15. for i in ('U-Boot Boot Menu', 'test 1', 'test 2', 'test 3', 'autoboot'):
  16. u_boot_console.p.expect([i])
  17. # Press enter key to execute default entry
  18. response = u_boot_console.run_command(cmd='\x0d', wait_for_echo=False, send_nl=False)
  19. assert 'ok 2' in response
  20. u_boot_console.run_command('bootmenu 2', wait_for_prompt=False)
  21. u_boot_console.p.expect(['autoboot'])
  22. # Press up key to select prior entry followed by the enter key
  23. response = u_boot_console.run_command(cmd='\x1b\x5b\x41\x0d', wait_for_echo=False,
  24. send_nl=False)
  25. assert 'ok 1' in response
  26. u_boot_console.run_command('bootmenu 2', wait_for_prompt=False)
  27. u_boot_console.p.expect(['autoboot'])
  28. # Press down key to select next entry followed by the enter key
  29. response = u_boot_console.run_command(cmd='\x1b\x5b\x42\x0d', wait_for_echo=False,
  30. send_nl=False)
  31. assert 'ok 3' in response
  32. u_boot_console.run_command('bootmenu 2; echo rc:$?', wait_for_prompt=False)
  33. u_boot_console.p.expect(['autoboot'])
  34. # Press the escape key
  35. response = u_boot_console.run_command(cmd='\x1b', wait_for_echo=False, send_nl=False)
  36. assert 'ok' not in response
  37. assert 'rc:0' in response
  38. u_boot_console.run_command('setenv bootmenu_default')
  39. u_boot_console.run_command('setenv bootmenu_0')
  40. u_boot_console.run_command('setenv bootmenu_1')
  41. u_boot_console.run_command('setenv bootmenu_2')