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