blob: 43f2424558285a7db7629e6624b94605fe3aabfb [file] [log] [blame]
Heinrich Schuchardtd828a052017-09-15 10:06:12 +02001# SPDX-License-Identifier: GPL-2.0
Tom Rini10e47792018-05-06 17:58:06 -04002# Copyright (c) 2017, Heinrich Schuchardt <xypron.glpk@gmx.de>
Heinrich Schuchardtd828a052017-09-15 10:06:12 +02003
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +02004""" Test UEFI API implementation
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +01005"""
Heinrich Schuchardtd828a052017-09-15 10:06:12 +02006
7import pytest
Heinrich Schuchardtd828a052017-09-15 10:06:12 +02008
9@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
Simon Glass945a2592023-04-20 11:38:16 +120010def test_efi_selftest_base(u_boot_console):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010011 """Run UEFI unit tests
Heinrich Schuchardtd828a052017-09-15 10:06:12 +020012
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +020013 u_boot_console -- U-Boot console
Heinrich Schuchardt48161e12018-11-18 17:58:54 +010014
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010015 This function executes all selftests that are not marked as on request.
16 """
17 u_boot_console.run_command(cmd='setenv efi_selftest')
18 u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +020019 if u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010020 raise Exception('Failures occurred during the EFI selftest')
21 u_boot_console.restart_uboot()
Heinrich Schuchardt1dc0a1b2017-10-18 18:13:17 +020022
23@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
Heinrich Schuchardt604c8e72020-08-07 23:11:35 +020024@pytest.mark.buildconfigspec('hush_parser')
Heinrich Schuchardt43d27992018-03-03 15:29:04 +010025@pytest.mark.buildconfigspec('of_control')
Heinrich Schuchardt1c111f92019-04-20 13:33:55 +020026@pytest.mark.notbuildconfigspec('generate_acpi_table')
Heinrich Schuchardt43d27992018-03-03 15:29:04 +010027def test_efi_selftest_device_tree(u_boot_console):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010028 """Test the device tree support in the UEFI sub-system
29
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +020030 u_boot_console -- U-Boot console
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010031
32 This test executes the UEFI unit test by calling 'bootefi selftest'.
33 """
34 u_boot_console.run_command(cmd='setenv efi_selftest list')
35 output = u_boot_console.run_command('bootefi selftest')
36 assert '\'device tree\'' in output
37 u_boot_console.run_command(cmd='setenv efi_selftest device tree')
Heinrich Schuchardt604c8e72020-08-07 23:11:35 +020038 # Set serial# if it is not already set.
39 u_boot_console.run_command(cmd='setenv efi_test "${serial#}x"')
40 u_boot_console.run_command(cmd='test "${efi_test}" = x && setenv serial# 0')
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010041 u_boot_console.run_command(cmd='bootefi selftest ${fdtcontroladdr}', wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +020042 if u_boot_console.p.expect(['serial-number:', 'U-Boot']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010043 raise Exception('serial-number missing in device tree')
44 u_boot_console.restart_uboot()
Heinrich Schuchardt43d27992018-03-03 15:29:04 +010045
46@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
Heinrich Schuchardt1dc0a1b2017-10-18 18:13:17 +020047def test_efi_selftest_watchdog_reboot(u_boot_console):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010048 """Test the watchdog timer
49
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +020050 u_boot_console -- U-Boot console
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010051
52 This function executes the 'watchdog reboot' unit test.
53 """
54 u_boot_console.run_command(cmd='setenv efi_selftest list')
55 output = u_boot_console.run_command('bootefi selftest')
56 assert '\'watchdog reboot\'' in output
57 u_boot_console.run_command(cmd='setenv efi_selftest watchdog reboot')
58 u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +020059 if u_boot_console.p.expect(['resetting', 'U-Boot']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010060 raise Exception('Reset failed in \'watchdog reboot\' test')
61 u_boot_console.restart_uboot()
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +020062
63@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
64def test_efi_selftest_text_input(u_boot_console):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010065 """Test the EFI_SIMPLE_TEXT_INPUT_PROTOCOL
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +020066
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +020067 u_boot_console -- U-Boot console
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +020068
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010069 This function calls the text input EFI selftest.
70 """
71 u_boot_console.run_command(cmd='setenv efi_selftest text input')
Heinrich Schuchardt9460c182021-11-22 08:24:08 +010072 u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +020073 if u_boot_console.p.expect([r'To terminate type \'x\'']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010074 raise Exception('No prompt for \'text input\' test')
75 u_boot_console.drain_console()
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010076 # EOT
77 u_boot_console.run_command(cmd=chr(4), wait_for_echo=False,
78 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +020079 if u_boot_console.p.expect([r'Unicode char 4 \(unknown\), scan code 0 \(Null\)']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010080 raise Exception('EOT failed in \'text input\' test')
81 u_boot_console.drain_console()
82 # BS
83 u_boot_console.run_command(cmd=chr(8), wait_for_echo=False,
84 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +020085 if u_boot_console.p.expect([r'Unicode char 8 \(BS\), scan code 0 \(Null\)']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010086 raise Exception('BS failed in \'text input\' test')
87 u_boot_console.drain_console()
88 # TAB
89 u_boot_console.run_command(cmd=chr(9), wait_for_echo=False,
90 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +020091 if u_boot_console.p.expect([r'Unicode char 9 \(TAB\), scan code 0 \(Null\)']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010092 raise Exception('BS failed in \'text input\' test')
93 u_boot_console.drain_console()
94 # a
95 u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False,
96 wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +020097 if u_boot_console.p.expect([r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010098 raise Exception('\'a\' failed in \'text input\' test')
99 u_boot_console.drain_console()
100 # UP escape sequence
101 u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False,
102 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200103 if u_boot_console.p.expect([r'Unicode char 0 \(Null\), scan code 1 \(Up\)']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100104 raise Exception('UP failed in \'text input\' test')
105 u_boot_console.drain_console()
106 # Euro sign
107 u_boot_console.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False,
108 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200109 if u_boot_console.p.expect([r'Unicode char 8364 \(\'']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100110 raise Exception('Euro sign failed in \'text input\' test')
111 u_boot_console.drain_console()
112 u_boot_console.run_command(cmd='x', wait_for_echo=False, send_nl=False,
113 wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200114 if u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100115 raise Exception('Failures occurred during the EFI selftest')
116 u_boot_console.restart_uboot()
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200117
118@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
119def test_efi_selftest_text_input_ex(u_boot_console):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100120 """Test the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200121
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200122 u_boot_console -- U-Boot console
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200123
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100124 This function calls the extended text input EFI selftest.
125 """
126 u_boot_console.run_command(cmd='setenv efi_selftest extended text input')
Heinrich Schuchardt9460c182021-11-22 08:24:08 +0100127 u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200128 if u_boot_console.p.expect([r'To terminate type \'CTRL\+x\'']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100129 raise Exception('No prompt for \'text input\' test')
130 u_boot_console.drain_console()
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100131 # EOT
132 u_boot_console.run_command(cmd=chr(4), wait_for_echo=False,
133 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200134 if u_boot_console.p.expect([r'Unicode char 100 \(\'d\'\), scan code 0 \(CTRL\+Null\)']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100135 raise Exception('EOT failed in \'text input\' test')
136 u_boot_console.drain_console()
137 # BS
138 u_boot_console.run_command(cmd=chr(8), wait_for_echo=False,
139 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200140 if u_boot_console.p.expect([r'Unicode char 8 \(BS\), scan code 0 \(\+Null\)']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100141 raise Exception('BS failed in \'text input\' test')
142 u_boot_console.drain_console()
143 # TAB
144 u_boot_console.run_command(cmd=chr(9), wait_for_echo=False,
145 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200146 if u_boot_console.p.expect([r'Unicode char 9 \(TAB\), scan code 0 \(\+Null\)']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100147 raise Exception('TAB failed in \'text input\' test')
148 u_boot_console.drain_console()
149 # a
150 u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False,
151 wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200152 if u_boot_console.p.expect([r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100153 raise Exception('\'a\' failed in \'text input\' test')
154 u_boot_console.drain_console()
155 # UP escape sequence
156 u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False,
157 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200158 if u_boot_console.p.expect([r'Unicode char 0 \(Null\), scan code 1 \(\+Up\)']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100159 raise Exception('UP failed in \'text input\' test')
160 u_boot_console.drain_console()
161 # Euro sign
162 u_boot_console.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False,
163 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200164 if u_boot_console.p.expect([r'Unicode char 8364 \(\'']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100165 raise Exception('Euro sign failed in \'text input\' test')
166 u_boot_console.drain_console()
167 # SHIFT+ALT+FN 5
168 u_boot_console.run_command(cmd=b'\x1b\x5b\x31\x35\x3b\x34\x7e'.decode(),
169 wait_for_echo=False, send_nl=False,
170 wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200171 if u_boot_console.p.expect([r'Unicode char 0 \(Null\), scan code 15 \(SHIFT\+ALT\+FN 5\)']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100172 raise Exception('SHIFT+ALT+FN 5 failed in \'text input\' test')
173 u_boot_console.drain_console()
174 u_boot_console.run_command(cmd=chr(24), wait_for_echo=False, send_nl=False,
175 wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200176 if u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100177 raise Exception('Failures occurred during the EFI selftest')
178 u_boot_console.restart_uboot()
Heinrich Schuchardt8226df32021-11-15 18:26:50 +0100179
180@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
181@pytest.mark.buildconfigspec('efi_tcg2_protocol')
182def test_efi_selftest_tcg2(u_boot_console):
183 """Test the EFI_TCG2 PROTOCOL
184
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200185 u_boot_console -- U-Boot console
Heinrich Schuchardt8226df32021-11-15 18:26:50 +0100186
187 This function executes the 'tcg2' unit test.
188 """
189 u_boot_console.restart_uboot()
190 u_boot_console.run_command(cmd='setenv efi_selftest list')
191 output = u_boot_console.run_command('bootefi selftest')
192 assert '\'tcg2\'' in output
193 u_boot_console.run_command(cmd='setenv efi_selftest tcg2')
194 u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200195 if u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']):
Heinrich Schuchardt8226df32021-11-15 18:26:50 +0100196 raise Exception('Failures occurred during the EFI selftest')
197 u_boot_console.restart_uboot()