blob: 66f3fb8a1310f96a111e88604af4e1f7995cc9aa [file] [log] [blame]
Heinrich Schuchardtdbb2cf72022-04-30 11:13:55 +02001# SPDX-License-Identifier: GPL-2.0+
2
3"""Test bootmenu"""
4
5import pytest
6
7@pytest.mark.buildconfigspec('cmd_bootmenu')
Simon Glassddba5202025-02-09 09:07:14 -07008def test_bootmenu(ubman):
Heinrich Schuchardtdbb2cf72022-04-30 11:13:55 +02009 """Test bootmenu
10
Simon Glassddba5202025-02-09 09:07:14 -070011 ubman -- U-Boot console
Heinrich Schuchardtdbb2cf72022-04-30 11:13:55 +020012 """
13
Simon Glassddba5202025-02-09 09:07:14 -070014 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)
Heinrich Schuchardtb0a06962022-05-09 21:59:13 +020020 for i in ('U-Boot Boot Menu', 'test 1', 'test 2', 'test 3', 'autoboot'):
Simon Glassddba5202025-02-09 09:07:14 -070021 ubman.p.expect([i])
Heinrich Schuchardtb0a06962022-05-09 21:59:13 +020022 # Press enter key to execute default entry
Simon Glassddba5202025-02-09 09:07:14 -070023 response = ubman.run_command(cmd='\x0d', wait_for_echo=False, send_nl=False)
Heinrich Schuchardtb0a06962022-05-09 21:59:13 +020024 assert 'ok 2' in response
Simon Glassddba5202025-02-09 09:07:14 -070025 ubman.run_command('bootmenu 2', wait_for_prompt=False)
26 ubman.p.expect(['autoboot'])
Heinrich Schuchardtb0a06962022-05-09 21:59:13 +020027 # Press up key to select prior entry followed by the enter key
Simon Glassddba5202025-02-09 09:07:14 -070028 response = ubman.run_command(cmd='\x1b\x5b\x41\x0d', wait_for_echo=False,
Heinrich Schuchardtb0a06962022-05-09 21:59:13 +020029 send_nl=False)
30 assert 'ok 1' in response
Simon Glassddba5202025-02-09 09:07:14 -070031 ubman.run_command('bootmenu 2', wait_for_prompt=False)
32 ubman.p.expect(['autoboot'])
Heinrich Schuchardtb0a06962022-05-09 21:59:13 +020033 # Press down key to select next entry followed by the enter key
Simon Glassddba5202025-02-09 09:07:14 -070034 response = ubman.run_command(cmd='\x1b\x5b\x42\x0d', wait_for_echo=False,
Heinrich Schuchardtb0a06962022-05-09 21:59:13 +020035 send_nl=False)
36 assert 'ok 3' in response
Simon Glassddba5202025-02-09 09:07:14 -070037 ubman.run_command('bootmenu 2; echo rc:$?', wait_for_prompt=False)
38 ubman.p.expect(['autoboot'])
Heinrich Schuchardtb0a06962022-05-09 21:59:13 +020039 # Press the escape key
Simon Glassddba5202025-02-09 09:07:14 -070040 response = ubman.run_command(cmd='\x1b', wait_for_echo=False, send_nl=False)
Heinrich Schuchardtb0a06962022-05-09 21:59:13 +020041 assert 'ok' not in response
42 assert 'rc:0' in response
Simon Glassddba5202025-02-09 09:07:14 -070043 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')