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):
1138b1b790SHeinrich Schuchardt	"""
1238b1b790SHeinrich Schuchardt	Run bootefi selftest
1338b1b790SHeinrich Schuchardt	"""
1438b1b790SHeinrich Schuchardt
15df172e11SHeinrich Schuchardt	u_boot_console.run_command(cmd='setenv efi_selftest')
1638b1b790SHeinrich Schuchardt	u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
1738b1b790SHeinrich Schuchardt	m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])
1838b1b790SHeinrich Schuchardt	if m != 0:
19*da9ea5bbSHeinrich Schuchardt		raise Exception('Failures occurred during the EFI selftest')
2038b1b790SHeinrich Schuchardt	u_boot_console.run_command(cmd='', wait_for_echo=False, wait_for_prompt=False);
2138b1b790SHeinrich Schuchardt	m = u_boot_console.p.expect(['resetting', 'U-Boot'])
2238b1b790SHeinrich Schuchardt	if m != 0:
2338b1b790SHeinrich Schuchardt		raise Exception('Reset failed during the EFI selftest')
2438b1b790SHeinrich Schuchardt	u_boot_console.restart_uboot();
25df172e11SHeinrich Schuchardt
26df172e11SHeinrich Schuchardt@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
2706c3d5b9SHeinrich Schuchardt@pytest.mark.buildconfigspec('of_control')
2806c3d5b9SHeinrich Schuchardtdef test_efi_selftest_device_tree(u_boot_console):
2906c3d5b9SHeinrich Schuchardt	u_boot_console.run_command(cmd='setenv efi_selftest list')
3006c3d5b9SHeinrich Schuchardt	output = u_boot_console.run_command('bootefi selftest')
3106c3d5b9SHeinrich Schuchardt	assert '\'device tree\'' in output
3206c3d5b9SHeinrich Schuchardt	u_boot_console.run_command(cmd='setenv efi_selftest device tree')
3306c3d5b9SHeinrich Schuchardt	u_boot_console.run_command(cmd='setenv -f serial# Testing DT')
3406c3d5b9SHeinrich Schuchardt	u_boot_console.run_command(cmd='bootefi selftest ${fdtcontroladdr}', wait_for_prompt=False)
3506c3d5b9SHeinrich Schuchardt	m = u_boot_console.p.expect(['serial-number: Testing DT', 'U-Boot'])
3606c3d5b9SHeinrich Schuchardt	if m != 0:
3706c3d5b9SHeinrich Schuchardt		raise Exception('Reset failed in \'device tree\' test')
3806c3d5b9SHeinrich Schuchardt	u_boot_console.restart_uboot();
3906c3d5b9SHeinrich Schuchardt
4006c3d5b9SHeinrich Schuchardt@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
41df172e11SHeinrich Schuchardtdef test_efi_selftest_watchdog_reboot(u_boot_console):
42df172e11SHeinrich Schuchardt	u_boot_console.run_command(cmd='setenv efi_selftest list')
43df172e11SHeinrich Schuchardt	output = u_boot_console.run_command('bootefi selftest')
44df172e11SHeinrich Schuchardt	assert '\'watchdog reboot\'' in output
45df172e11SHeinrich Schuchardt	u_boot_console.run_command(cmd='setenv efi_selftest watchdog reboot')
46df172e11SHeinrich Schuchardt	u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
47df172e11SHeinrich Schuchardt	m = u_boot_console.p.expect(['resetting', 'U-Boot'])
48df172e11SHeinrich Schuchardt	if m != 0:
49df172e11SHeinrich Schuchardt		raise Exception('Reset failed in \'watchdog reboot\' test')
50df172e11SHeinrich Schuchardt	u_boot_console.restart_uboot();
51cb03ec06SHeinrich Schuchardt
52cb03ec06SHeinrich Schuchardt@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
53cb03ec06SHeinrich Schuchardtdef test_efi_selftest_text_input(u_boot_console):
54cb03ec06SHeinrich Schuchardt	"""Test the EFI_SIMPLE_TEXT_INPUT_PROTOCOL
55cb03ec06SHeinrich Schuchardt
56cb03ec06SHeinrich Schuchardt	:param u_boot_console: U-Boot console
57cb03ec06SHeinrich Schuchardt
58cb03ec06SHeinrich Schuchardt	This function calls the text input EFI selftest.
59cb03ec06SHeinrich Schuchardt	"""
60cb03ec06SHeinrich Schuchardt	u_boot_console.run_command(cmd='setenv efi_selftest text input')
61cb03ec06SHeinrich Schuchardt	output = u_boot_console.run_command(cmd='bootefi selftest',
62cb03ec06SHeinrich Schuchardt					    wait_for_prompt=False)
63cb03ec06SHeinrich Schuchardt	m = u_boot_console.p.expect(['To terminate type \'x\''])
64cb03ec06SHeinrich Schuchardt	if m != 0:
65cb03ec06SHeinrich Schuchardt		raise Exception('No prompt for \'text input\' test')
66cb03ec06SHeinrich Schuchardt	u_boot_console.drain_console()
67cb03ec06SHeinrich Schuchardt	u_boot_console.p.timeout = 500
68cb03ec06SHeinrich Schuchardt	# EOT
69cb03ec06SHeinrich Schuchardt	u_boot_console.run_command(cmd=chr(4), wait_for_echo=False,
70cb03ec06SHeinrich Schuchardt				   send_nl=False, wait_for_prompt=False)
71cb03ec06SHeinrich Schuchardt	m = u_boot_console.p.expect(['Unicode char 4'])
72cb03ec06SHeinrich Schuchardt	if m != 0:
73cb03ec06SHeinrich Schuchardt		raise Exception('EOT failed in \'text input\' test')
74cb03ec06SHeinrich Schuchardt	u_boot_console.drain_console()
75cb03ec06SHeinrich Schuchardt	# BS
76cb03ec06SHeinrich Schuchardt	u_boot_console.run_command(cmd=chr(8), wait_for_echo=False,
77cb03ec06SHeinrich Schuchardt				   send_nl=False, wait_for_prompt=False)
78cb03ec06SHeinrich Schuchardt	m = u_boot_console.p.expect(['(BS)'])
79cb03ec06SHeinrich Schuchardt	if m != 0:
80cb03ec06SHeinrich Schuchardt		raise Exception('BS failed in \'text input\' test')
81cb03ec06SHeinrich Schuchardt	u_boot_console.drain_console()
82cb03ec06SHeinrich Schuchardt	# TAB
83cb03ec06SHeinrich Schuchardt	u_boot_console.run_command(cmd=chr(9), wait_for_echo=False,
84cb03ec06SHeinrich Schuchardt				   send_nl=False, wait_for_prompt=False)
85cb03ec06SHeinrich Schuchardt	m = u_boot_console.p.expect(['(TAB)'])
86cb03ec06SHeinrich Schuchardt	if m != 0:
87cb03ec06SHeinrich Schuchardt		raise Exception('BS failed in \'text input\' test')
88cb03ec06SHeinrich Schuchardt	u_boot_console.drain_console()
89cb03ec06SHeinrich Schuchardt	# a
90cb03ec06SHeinrich Schuchardt	u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False,
91cb03ec06SHeinrich Schuchardt				   wait_for_prompt=False)
92cb03ec06SHeinrich Schuchardt	m = u_boot_console.p.expect(['(\'a\')'])
93cb03ec06SHeinrich Schuchardt	if m != 0:
94cb03ec06SHeinrich Schuchardt		raise Exception('\'a\' failed in \'text input\' test')
95cb03ec06SHeinrich Schuchardt	u_boot_console.drain_console()
96cb03ec06SHeinrich Schuchardt	# UP escape sequence
97cb03ec06SHeinrich Schuchardt	u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False,
98cb03ec06SHeinrich Schuchardt				   send_nl=False, wait_for_prompt=False)
99cb03ec06SHeinrich Schuchardt	m = u_boot_console.p.expect(['(Up)'])
100cb03ec06SHeinrich Schuchardt	if m != 0:
101cb03ec06SHeinrich Schuchardt		raise Exception('UP failed in \'text input\' test')
102cb03ec06SHeinrich Schuchardt	u_boot_console.drain_console()
103cb03ec06SHeinrich Schuchardt	u_boot_console.run_command(cmd='x', wait_for_echo=False, send_nl=False,
104cb03ec06SHeinrich Schuchardt				   wait_for_prompt=False)
105cb03ec06SHeinrich Schuchardt	m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])
106cb03ec06SHeinrich Schuchardt	if m != 0:
107cb03ec06SHeinrich Schuchardt		raise Exception('Failures occurred during the EFI selftest')
108cb03ec06SHeinrich Schuchardt	u_boot_console.restart_uboot();
109