blob: 5257f7a4337ab96100480083af7b8bdda5707ae4 [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')
10def test_efi_selftest(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()
76 u_boot_console.p.timeout = 500
77 # EOT
78 u_boot_console.run_command(cmd=chr(4), wait_for_echo=False,
79 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +020080 if u_boot_console.p.expect([r'Unicode char 4 \(unknown\), scan code 0 \(Null\)']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010081 raise Exception('EOT failed in \'text input\' test')
82 u_boot_console.drain_console()
83 # BS
84 u_boot_console.run_command(cmd=chr(8), wait_for_echo=False,
85 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +020086 if u_boot_console.p.expect([r'Unicode char 8 \(BS\), scan code 0 \(Null\)']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010087 raise Exception('BS failed in \'text input\' test')
88 u_boot_console.drain_console()
89 # TAB
90 u_boot_console.run_command(cmd=chr(9), wait_for_echo=False,
91 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +020092 if u_boot_console.p.expect([r'Unicode char 9 \(TAB\), scan code 0 \(Null\)']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010093 raise Exception('BS failed in \'text input\' test')
94 u_boot_console.drain_console()
95 # a
96 u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False,
97 wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +020098 if u_boot_console.p.expect([r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010099 raise Exception('\'a\' failed in \'text input\' test')
100 u_boot_console.drain_console()
101 # UP escape sequence
102 u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False,
103 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200104 if u_boot_console.p.expect([r'Unicode char 0 \(Null\), scan code 1 \(Up\)']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100105 raise Exception('UP failed in \'text input\' test')
106 u_boot_console.drain_console()
107 # Euro sign
108 u_boot_console.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False,
109 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200110 if u_boot_console.p.expect([r'Unicode char 8364 \(\'']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100111 raise Exception('Euro sign failed in \'text input\' test')
112 u_boot_console.drain_console()
113 u_boot_console.run_command(cmd='x', wait_for_echo=False, send_nl=False,
114 wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200115 if u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100116 raise Exception('Failures occurred during the EFI selftest')
117 u_boot_console.restart_uboot()
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200118
119@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
120def test_efi_selftest_text_input_ex(u_boot_console):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100121 """Test the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200122
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200123 u_boot_console -- U-Boot console
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200124
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100125 This function calls the extended text input EFI selftest.
126 """
127 u_boot_console.run_command(cmd='setenv efi_selftest extended text input')
Heinrich Schuchardt9460c182021-11-22 08:24:08 +0100128 u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200129 if u_boot_console.p.expect([r'To terminate type \'CTRL\+x\'']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100130 raise Exception('No prompt for \'text input\' test')
131 u_boot_console.drain_console()
132 u_boot_console.p.timeout = 500
133 # EOT
134 u_boot_console.run_command(cmd=chr(4), wait_for_echo=False,
135 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200136 if u_boot_console.p.expect([r'Unicode char 100 \(\'d\'\), scan code 0 \(CTRL\+Null\)']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100137 raise Exception('EOT failed in \'text input\' test')
138 u_boot_console.drain_console()
139 # BS
140 u_boot_console.run_command(cmd=chr(8), wait_for_echo=False,
141 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200142 if u_boot_console.p.expect([r'Unicode char 8 \(BS\), scan code 0 \(\+Null\)']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100143 raise Exception('BS failed in \'text input\' test')
144 u_boot_console.drain_console()
145 # TAB
146 u_boot_console.run_command(cmd=chr(9), wait_for_echo=False,
147 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200148 if u_boot_console.p.expect([r'Unicode char 9 \(TAB\), scan code 0 \(\+Null\)']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100149 raise Exception('TAB failed in \'text input\' test')
150 u_boot_console.drain_console()
151 # a
152 u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False,
153 wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200154 if u_boot_console.p.expect([r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100155 raise Exception('\'a\' failed in \'text input\' test')
156 u_boot_console.drain_console()
157 # UP escape sequence
158 u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False,
159 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200160 if u_boot_console.p.expect([r'Unicode char 0 \(Null\), scan code 1 \(\+Up\)']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100161 raise Exception('UP failed in \'text input\' test')
162 u_boot_console.drain_console()
163 # Euro sign
164 u_boot_console.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False,
165 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200166 if u_boot_console.p.expect([r'Unicode char 8364 \(\'']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100167 raise Exception('Euro sign failed in \'text input\' test')
168 u_boot_console.drain_console()
169 # SHIFT+ALT+FN 5
170 u_boot_console.run_command(cmd=b'\x1b\x5b\x31\x35\x3b\x34\x7e'.decode(),
171 wait_for_echo=False, send_nl=False,
172 wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200173 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 +0100174 raise Exception('SHIFT+ALT+FN 5 failed in \'text input\' test')
175 u_boot_console.drain_console()
176 u_boot_console.run_command(cmd=chr(24), wait_for_echo=False, send_nl=False,
177 wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200178 if u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100179 raise Exception('Failures occurred during the EFI selftest')
180 u_boot_console.restart_uboot()
Heinrich Schuchardt8226df32021-11-15 18:26:50 +0100181
182@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
183@pytest.mark.buildconfigspec('efi_tcg2_protocol')
184def test_efi_selftest_tcg2(u_boot_console):
185 """Test the EFI_TCG2 PROTOCOL
186
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200187 u_boot_console -- U-Boot console
Heinrich Schuchardt8226df32021-11-15 18:26:50 +0100188
189 This function executes the 'tcg2' unit test.
190 """
191 u_boot_console.restart_uboot()
192 u_boot_console.run_command(cmd='setenv efi_selftest list')
193 output = u_boot_console.run_command('bootefi selftest')
194 assert '\'tcg2\'' in output
195 u_boot_console.run_command(cmd='setenv efi_selftest tcg2')
196 u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
Heinrich Schuchardt8bf7ffd2022-05-08 10:40:49 +0200197 if u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']):
Heinrich Schuchardt8226df32021-11-15 18:26:50 +0100198 raise Exception('Failures occurred during the EFI selftest')
199 u_boot_console.restart_uboot()