138b1b790SHeinrich Schuchardt# SPDX-License-Identifier: GPL-2.0
283d290c5STom Rini# Copyright (c) 2017, Heinrich Schuchardt <xypron.glpk@gmx.de>
338b1b790SHeinrich Schuchardt
438b1b790SHeinrich Schuchardt# Test efi API implementation
538b1b790SHeinrich Schuchardt
638b1b790SHeinrich Schuchardtimport pytest
738b1b790SHeinrich Schuchardtimport u_boot_utils
838b1b790SHeinrich Schuchardt
938b1b790SHeinrich Schuchardt@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
1038b1b790SHeinrich Schuchardtdef test_efi_selftest(u_boot_console):
11*34c96659SHeinrich Schuchardt	"""Test the UEFI implementation
1238b1b790SHeinrich Schuchardt
13*34c96659SHeinrich Schuchardt	:param u_boot_console: U-Boot console
14*34c96659SHeinrich Schuchardt
15*34c96659SHeinrich Schuchardt	This function executes all selftests that are not marked as on request.
16*34c96659SHeinrich Schuchardt	"""
17df172e11SHeinrich Schuchardt	u_boot_console.run_command(cmd='setenv efi_selftest')
18*34c96659SHeinrich Schuchardt	u_boot_console.run_command(cmd='bootefi selftest ${fdtcontroladdr}', wait_for_prompt=False)
1938b1b790SHeinrich Schuchardt	m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])
2038b1b790SHeinrich Schuchardt	if m != 0:
21da9ea5bbSHeinrich Schuchardt		raise Exception('Failures occurred during the EFI selftest')
2238b1b790SHeinrich Schuchardt	u_boot_console.run_command(cmd='', wait_for_echo=False, wait_for_prompt=False);
2338b1b790SHeinrich Schuchardt	m = u_boot_console.p.expect(['resetting', 'U-Boot'])
2438b1b790SHeinrich Schuchardt	if m != 0:
2538b1b790SHeinrich Schuchardt		raise Exception('Reset failed during the EFI selftest')
2638b1b790SHeinrich Schuchardt	u_boot_console.restart_uboot();
27df172e11SHeinrich Schuchardt
28df172e11SHeinrich Schuchardt@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
2906c3d5b9SHeinrich Schuchardt@pytest.mark.buildconfigspec('of_control')
3006c3d5b9SHeinrich Schuchardtdef test_efi_selftest_device_tree(u_boot_console):
3106c3d5b9SHeinrich Schuchardt	u_boot_console.run_command(cmd='setenv efi_selftest list')
3206c3d5b9SHeinrich Schuchardt	output = u_boot_console.run_command('bootefi selftest')
3306c3d5b9SHeinrich Schuchardt	assert '\'device tree\'' in output
3406c3d5b9SHeinrich Schuchardt	u_boot_console.run_command(cmd='setenv efi_selftest device tree')
3506c3d5b9SHeinrich Schuchardt	u_boot_console.run_command(cmd='setenv -f serial# Testing DT')
3606c3d5b9SHeinrich Schuchardt	u_boot_console.run_command(cmd='bootefi selftest ${fdtcontroladdr}', wait_for_prompt=False)
3706c3d5b9SHeinrich Schuchardt	m = u_boot_console.p.expect(['serial-number: Testing DT', 'U-Boot'])
3806c3d5b9SHeinrich Schuchardt	if m != 0:
3906c3d5b9SHeinrich Schuchardt		raise Exception('Reset failed in \'device tree\' test')
4006c3d5b9SHeinrich Schuchardt	u_boot_console.restart_uboot();
4106c3d5b9SHeinrich Schuchardt
4206c3d5b9SHeinrich Schuchardt@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
43df172e11SHeinrich Schuchardtdef test_efi_selftest_watchdog_reboot(u_boot_console):
44df172e11SHeinrich Schuchardt	u_boot_console.run_command(cmd='setenv efi_selftest list')
45df172e11SHeinrich Schuchardt	output = u_boot_console.run_command('bootefi selftest')
46df172e11SHeinrich Schuchardt	assert '\'watchdog reboot\'' in output
47df172e11SHeinrich Schuchardt	u_boot_console.run_command(cmd='setenv efi_selftest watchdog reboot')
48df172e11SHeinrich Schuchardt	u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
49df172e11SHeinrich Schuchardt	m = u_boot_console.p.expect(['resetting', 'U-Boot'])
50df172e11SHeinrich Schuchardt	if m != 0:
51df172e11SHeinrich Schuchardt		raise Exception('Reset failed in \'watchdog reboot\' test')
52df172e11SHeinrich Schuchardt	u_boot_console.restart_uboot();
53cb03ec06SHeinrich Schuchardt
54cb03ec06SHeinrich Schuchardt@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
55cb03ec06SHeinrich Schuchardtdef test_efi_selftest_text_input(u_boot_console):
56cb03ec06SHeinrich Schuchardt	"""Test the EFI_SIMPLE_TEXT_INPUT_PROTOCOL
57cb03ec06SHeinrich Schuchardt
58cb03ec06SHeinrich Schuchardt	:param u_boot_console: U-Boot console
59cb03ec06SHeinrich Schuchardt
60cb03ec06SHeinrich Schuchardt	This function calls the text input EFI selftest.
61cb03ec06SHeinrich Schuchardt	"""
62cb03ec06SHeinrich Schuchardt	u_boot_console.run_command(cmd='setenv efi_selftest text input')
63cb03ec06SHeinrich Schuchardt	output = u_boot_console.run_command(cmd='bootefi selftest',
64cb03ec06SHeinrich Schuchardt					    wait_for_prompt=False)
65cb03ec06SHeinrich Schuchardt	m = u_boot_console.p.expect(['To terminate type \'x\''])
66cb03ec06SHeinrich Schuchardt	if m != 0:
67cb03ec06SHeinrich Schuchardt		raise Exception('No prompt for \'text input\' test')
68cb03ec06SHeinrich Schuchardt	u_boot_console.drain_console()
69cb03ec06SHeinrich Schuchardt	u_boot_console.p.timeout = 500
70cb03ec06SHeinrich Schuchardt	# EOT
71cb03ec06SHeinrich Schuchardt	u_boot_console.run_command(cmd=chr(4), wait_for_echo=False,
72cb03ec06SHeinrich Schuchardt				   send_nl=False, wait_for_prompt=False)
73ca09f1dfSHeinrich Schuchardt	m = u_boot_console.p.expect(
74ca09f1dfSHeinrich Schuchardt		['Unicode char 4 \(unknown\), scan code 0 \(Null\)'])
75cb03ec06SHeinrich Schuchardt	if m != 0:
76cb03ec06SHeinrich Schuchardt		raise Exception('EOT failed in \'text input\' test')
77cb03ec06SHeinrich Schuchardt	u_boot_console.drain_console()
78cb03ec06SHeinrich Schuchardt	# BS
79cb03ec06SHeinrich Schuchardt	u_boot_console.run_command(cmd=chr(8), wait_for_echo=False,
80cb03ec06SHeinrich Schuchardt				   send_nl=False, wait_for_prompt=False)
81ca09f1dfSHeinrich Schuchardt	m = u_boot_console.p.expect(
82ca09f1dfSHeinrich Schuchardt		['Unicode char 8 \(BS\), scan code 0 \(Null\)'])
83cb03ec06SHeinrich Schuchardt	if m != 0:
84cb03ec06SHeinrich Schuchardt		raise Exception('BS failed in \'text input\' test')
85cb03ec06SHeinrich Schuchardt	u_boot_console.drain_console()
86cb03ec06SHeinrich Schuchardt	# TAB
87cb03ec06SHeinrich Schuchardt	u_boot_console.run_command(cmd=chr(9), wait_for_echo=False,
88cb03ec06SHeinrich Schuchardt				   send_nl=False, wait_for_prompt=False)
89ca09f1dfSHeinrich Schuchardt	m = u_boot_console.p.expect(
90ca09f1dfSHeinrich Schuchardt		['Unicode char 9 \(TAB\), scan code 0 \(Null\)'])
91cb03ec06SHeinrich Schuchardt	if m != 0:
92cb03ec06SHeinrich Schuchardt		raise Exception('BS failed in \'text input\' test')
93cb03ec06SHeinrich Schuchardt	u_boot_console.drain_console()
94cb03ec06SHeinrich Schuchardt	# a
95cb03ec06SHeinrich Schuchardt	u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False,
96cb03ec06SHeinrich Schuchardt				   wait_for_prompt=False)
97ca09f1dfSHeinrich Schuchardt	m = u_boot_console.p.expect(
98ca09f1dfSHeinrich Schuchardt		['Unicode char 97 \(\'a\'\), scan code 0 \(Null\)'])
99cb03ec06SHeinrich Schuchardt	if m != 0:
100cb03ec06SHeinrich Schuchardt		raise Exception('\'a\' failed in \'text input\' test')
101cb03ec06SHeinrich Schuchardt	u_boot_console.drain_console()
102cb03ec06SHeinrich Schuchardt	# UP escape sequence
103cb03ec06SHeinrich Schuchardt	u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False,
104cb03ec06SHeinrich Schuchardt				   send_nl=False, wait_for_prompt=False)
105ca09f1dfSHeinrich Schuchardt	m = u_boot_console.p.expect(
106ca09f1dfSHeinrich Schuchardt		['Unicode char 0 \(Null\), scan code 1 \(Up\)'])
107cb03ec06SHeinrich Schuchardt	if m != 0:
108cb03ec06SHeinrich Schuchardt		raise Exception('UP failed in \'text input\' test')
109cb03ec06SHeinrich Schuchardt	u_boot_console.drain_console()
1107d044886SHeinrich Schuchardt	# Euro sign
1117d044886SHeinrich Schuchardt	u_boot_console.run_command(cmd='\xe2\x82\xac', wait_for_echo=False,
1127d044886SHeinrich Schuchardt				   send_nl=False, wait_for_prompt=False)
113ca09f1dfSHeinrich Schuchardt	m = u_boot_console.p.expect(['Unicode char 8364 \(\''])
1147d044886SHeinrich Schuchardt	if m != 0:
1157d044886SHeinrich Schuchardt		raise Exception('Euro sign failed in \'text input\' test')
1167d044886SHeinrich Schuchardt	u_boot_console.drain_console()
117cb03ec06SHeinrich Schuchardt	u_boot_console.run_command(cmd='x', wait_for_echo=False, send_nl=False,
118cb03ec06SHeinrich Schuchardt				   wait_for_prompt=False)
119cb03ec06SHeinrich Schuchardt	m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])
120cb03ec06SHeinrich Schuchardt	if m != 0:
121cb03ec06SHeinrich Schuchardt		raise Exception('Failures occurred during the EFI selftest')
122cb03ec06SHeinrich Schuchardt	u_boot_console.restart_uboot();
1234f17d8d3SHeinrich Schuchardt
1244f17d8d3SHeinrich Schuchardt@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
1254f17d8d3SHeinrich Schuchardtdef test_efi_selftest_text_input_ex(u_boot_console):
1264f17d8d3SHeinrich Schuchardt	"""Test the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
1274f17d8d3SHeinrich Schuchardt
1284f17d8d3SHeinrich Schuchardt	:param u_boot_console: U-Boot console
1294f17d8d3SHeinrich Schuchardt
1304f17d8d3SHeinrich Schuchardt	This function calls the extended text input EFI selftest.
1314f17d8d3SHeinrich Schuchardt	"""
1324f17d8d3SHeinrich Schuchardt	u_boot_console.run_command(cmd='setenv efi_selftest extended text input')
1334f17d8d3SHeinrich Schuchardt	output = u_boot_console.run_command(cmd='bootefi selftest',
1344f17d8d3SHeinrich Schuchardt					    wait_for_prompt=False)
1356dec8739SHeinrich Schuchardt	m = u_boot_console.p.expect(['To terminate type \'CTRL\+x\''])
1364f17d8d3SHeinrich Schuchardt	if m != 0:
1374f17d8d3SHeinrich Schuchardt		raise Exception('No prompt for \'text input\' test')
1384f17d8d3SHeinrich Schuchardt	u_boot_console.drain_console()
1394f17d8d3SHeinrich Schuchardt	u_boot_console.p.timeout = 500
1404f17d8d3SHeinrich Schuchardt	# EOT
1414f17d8d3SHeinrich Schuchardt	u_boot_console.run_command(cmd=chr(4), wait_for_echo=False,
1424f17d8d3SHeinrich Schuchardt				   send_nl=False, wait_for_prompt=False)
1434f17d8d3SHeinrich Schuchardt	m = u_boot_console.p.expect(
1444f17d8d3SHeinrich Schuchardt		['Unicode char 4 \(unknown\), scan code 0 \(CTRL\+Null\)'])
1454f17d8d3SHeinrich Schuchardt	if m != 0:
1464f17d8d3SHeinrich Schuchardt		raise Exception('EOT failed in \'text input\' test')
1474f17d8d3SHeinrich Schuchardt	u_boot_console.drain_console()
1484f17d8d3SHeinrich Schuchardt	# BS
1494f17d8d3SHeinrich Schuchardt	u_boot_console.run_command(cmd=chr(8), wait_for_echo=False,
1504f17d8d3SHeinrich Schuchardt				   send_nl=False, wait_for_prompt=False)
1514f17d8d3SHeinrich Schuchardt	m = u_boot_console.p.expect(
1524f17d8d3SHeinrich Schuchardt		['Unicode char 8 \(BS\), scan code 0 \(\+Null\)'])
1534f17d8d3SHeinrich Schuchardt	if m != 0:
1544f17d8d3SHeinrich Schuchardt		raise Exception('BS failed in \'text input\' test')
1554f17d8d3SHeinrich Schuchardt	u_boot_console.drain_console()
1564f17d8d3SHeinrich Schuchardt	# TAB
1574f17d8d3SHeinrich Schuchardt	u_boot_console.run_command(cmd=chr(9), wait_for_echo=False,
1584f17d8d3SHeinrich Schuchardt				   send_nl=False, wait_for_prompt=False)
1594f17d8d3SHeinrich Schuchardt	m = u_boot_console.p.expect(
1604f17d8d3SHeinrich Schuchardt		['Unicode char 9 \(TAB\), scan code 0 \(\+Null\)'])
1614f17d8d3SHeinrich Schuchardt	if m != 0:
1624f17d8d3SHeinrich Schuchardt		raise Exception('TAB failed in \'text input\' test')
1634f17d8d3SHeinrich Schuchardt	u_boot_console.drain_console()
1644f17d8d3SHeinrich Schuchardt	# a
1654f17d8d3SHeinrich Schuchardt	u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False,
1664f17d8d3SHeinrich Schuchardt				   wait_for_prompt=False)
1674f17d8d3SHeinrich Schuchardt	m = u_boot_console.p.expect(
1684f17d8d3SHeinrich Schuchardt		['Unicode char 97 \(\'a\'\), scan code 0 \(Null\)'])
1694f17d8d3SHeinrich Schuchardt	if m != 0:
1704f17d8d3SHeinrich Schuchardt		raise Exception('\'a\' failed in \'text input\' test')
1714f17d8d3SHeinrich Schuchardt	u_boot_console.drain_console()
1724f17d8d3SHeinrich Schuchardt	# UP escape sequence
1734f17d8d3SHeinrich Schuchardt	u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False,
1744f17d8d3SHeinrich Schuchardt				   send_nl=False, wait_for_prompt=False)
1754f17d8d3SHeinrich Schuchardt	m = u_boot_console.p.expect(
1764f17d8d3SHeinrich Schuchardt		['Unicode char 0 \(Null\), scan code 1 \(\+Up\)'])
1774f17d8d3SHeinrich Schuchardt	if m != 0:
1784f17d8d3SHeinrich Schuchardt		raise Exception('UP failed in \'text input\' test')
1794f17d8d3SHeinrich Schuchardt	u_boot_console.drain_console()
1804f17d8d3SHeinrich Schuchardt	# Euro sign
1814f17d8d3SHeinrich Schuchardt	u_boot_console.run_command(cmd='\xe2\x82\xac', wait_for_echo=False,
1824f17d8d3SHeinrich Schuchardt				   send_nl=False, wait_for_prompt=False)
1834f17d8d3SHeinrich Schuchardt	m = u_boot_console.p.expect(['Unicode char 8364 \(\''])
1844f17d8d3SHeinrich Schuchardt	if m != 0:
1854f17d8d3SHeinrich Schuchardt		raise Exception('Euro sign failed in \'text input\' test')
1864f17d8d3SHeinrich Schuchardt	u_boot_console.drain_console()
1874f17d8d3SHeinrich Schuchardt	# SHIFT+ALT+FN 5
1884f17d8d3SHeinrich Schuchardt	u_boot_console.run_command(cmd='\x1b\x5b\x31\x35\x3b\x34\x7e',
1894f17d8d3SHeinrich Schuchardt				   wait_for_echo=False, send_nl=False,
1904f17d8d3SHeinrich Schuchardt				   wait_for_prompt=False)
1914f17d8d3SHeinrich Schuchardt	m = u_boot_console.p.expect(
1924f17d8d3SHeinrich Schuchardt		['Unicode char 0 \(Null\), scan code 15 \(SHIFT\+ALT\+FN 5\)'])
1934f17d8d3SHeinrich Schuchardt	if m != 0:
1944f17d8d3SHeinrich Schuchardt		raise Exception('SHIFT+ALT+FN 5 failed in \'text input\' test')
1954f17d8d3SHeinrich Schuchardt	u_boot_console.drain_console()
1966dec8739SHeinrich Schuchardt	u_boot_console.run_command(cmd=chr(24), wait_for_echo=False, send_nl=False,
1974f17d8d3SHeinrich Schuchardt				   wait_for_prompt=False)
1984f17d8d3SHeinrich Schuchardt	m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])
1994f17d8d3SHeinrich Schuchardt	if m != 0:
2004f17d8d3SHeinrich Schuchardt		raise Exception('Failures occurred during the EFI selftest')
2014f17d8d3SHeinrich Schuchardt	u_boot_console.restart_uboot();
202