summaryrefslogtreecommitdiff
path: root/test/py
diff options
context:
space:
mode:
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>2022-04-30 12:13:55 +0300
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>2022-05-03 22:39:22 +0300
commitf2c534d354a6f4156f3e476f9bc83a7250206eab (patch)
tree0099a4385d8eb12a7b04f4997484c7b4068eba56 /test/py
parent29a02185cde20c1504b5b7da075591b605140a62 (diff)
downloadu-boot-f2c534d354a6f4156f3e476f9bc83a7250206eab.tar.xz
test: unit test for bootmenu
Provide a unit test for the bootmenu command Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Diffstat (limited to 'test/py')
-rw-r--r--test/py/tests/test_bootmenu.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/py/tests/test_bootmenu.py b/test/py/tests/test_bootmenu.py
new file mode 100644
index 0000000000..fb03fa417b
--- /dev/null
+++ b/test/py/tests/test_bootmenu.py
@@ -0,0 +1,48 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+"""Test bootmenu"""
+
+import pytest
+
+@pytest.mark.buildconfigspec('cmd_bootmenu')
+def test_bootmenu(u_boot_console):
+ """Test bootmenu
+
+ u_boot_console -- U-Boot console
+ """
+
+ u_boot_console.p.timeout = 500
+ u_boot_console.run_command('setenv bootmenu_default 1')
+ u_boot_console.run_command('setenv bootmenu_0 test 1=echo ok 1')
+ u_boot_console.run_command('setenv bootmenu_1 test 2=echo ok 2')
+ u_boot_console.run_command('setenv bootmenu_2 test 3=echo ok 3')
+ u_boot_console.run_command('bootmenu 2', wait_for_prompt=False)
+ for i in ('U-Boot Boot Menu', 'test 1', 'test 2', 'test 3', 'autoboot'):
+ u_boot_console.p.expect([i])
+ # Press enter key to execute default entry
+ response = u_boot_console.run_command(cmd='\x0d', wait_for_echo=False, send_nl=False)
+ assert 'ok 2' in response
+ u_boot_console.run_command('bootmenu 2', wait_for_prompt=False)
+ u_boot_console.p.expect(['autoboot'])
+ # Press up key to select prior entry followed by the enter key
+ response = u_boot_console.run_command(cmd='\x1b\x5b\x41\x0d', wait_for_echo=False,
+ send_nl=False)
+ assert 'ok 1' in response
+ u_boot_console.run_command('bootmenu 2', wait_for_prompt=False)
+ u_boot_console.p.expect(['autoboot'])
+ # Press down key to select next entry followed by the enter key
+ response = u_boot_console.run_command(cmd='\x1b\x5b\x42\x0d', wait_for_echo=False,
+ send_nl=False)
+ assert 'ok 3' in response
+ u_boot_console.run_command('bootmenu 2; echo rc:$?', wait_for_prompt=False)
+ u_boot_console.p.expect(['autoboot'])
+ # Press the escape key
+ response = u_boot_console.run_command(cmd='\x1b', wait_for_echo=False, send_nl=False)
+ assert 'ok' not in response
+ assert 'rc:0' in response
+ u_boot_console.run_command('setenv bootmenu_default')
+ u_boot_console.run_command('setenv bootmenu_0')
+ # Without bootmenu_0 no menu should be shown.
+ u_boot_console.run_command('bootmenu 2')
+ u_boot_console.run_command('setenv bootmenu_1')
+ u_boot_console.run_command('setenv bootmenu_2')