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