blob: 63218efbc269c414de534220ce83eb96d4d68254 [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 Schuchardtba41e3e2020-01-25 21:58:56 +01004"""
5Test UEFI API implementation
6"""
Heinrich Schuchardtd828a052017-09-15 10:06:12 +02007
8import pytest
Heinrich Schuchardtd828a052017-09-15 10:06:12 +02009
10@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
11def test_efi_selftest(u_boot_console):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010012 """Run UEFI unit tests
Heinrich Schuchardtd828a052017-09-15 10:06:12 +020013
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010014 :param u_boot_console: U-Boot console
Heinrich Schuchardt48161e12018-11-18 17:58:54 +010015
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010016 This function executes all selftests that are not marked as on request.
17 """
18 u_boot_console.run_command(cmd='setenv efi_selftest')
19 u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
20 m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])
21 if m != 0:
22 raise Exception('Failures occurred during the EFI selftest')
23 u_boot_console.restart_uboot()
Heinrich Schuchardt1dc0a1b2017-10-18 18:13:17 +020024
25@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
Heinrich Schuchardt604c8e72020-08-07 23:11:35 +020026@pytest.mark.buildconfigspec('hush_parser')
Heinrich Schuchardt43d27992018-03-03 15:29:04 +010027@pytest.mark.buildconfigspec('of_control')
Heinrich Schuchardt1c111f92019-04-20 13:33:55 +020028@pytest.mark.notbuildconfigspec('generate_acpi_table')
Heinrich Schuchardt43d27992018-03-03 15:29:04 +010029def test_efi_selftest_device_tree(u_boot_console):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010030 """Test the device tree support in the UEFI sub-system
31
32 :param u_boot_console: U-Boot console
33
34 This test executes the UEFI unit test by calling 'bootefi selftest'.
35 """
36 u_boot_console.run_command(cmd='setenv efi_selftest list')
37 output = u_boot_console.run_command('bootefi selftest')
38 assert '\'device tree\'' in output
39 u_boot_console.run_command(cmd='setenv efi_selftest device tree')
Heinrich Schuchardt604c8e72020-08-07 23:11:35 +020040 # Set serial# if it is not already set.
41 u_boot_console.run_command(cmd='setenv efi_test "${serial#}x"')
42 u_boot_console.run_command(cmd='test "${efi_test}" = x && setenv serial# 0')
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010043 u_boot_console.run_command(cmd='bootefi selftest ${fdtcontroladdr}', wait_for_prompt=False)
Heinrich Schuchardt604c8e72020-08-07 23:11:35 +020044 m = u_boot_console.p.expect(['serial-number:', 'U-Boot'])
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010045 if m != 0:
46 raise Exception('serial-number missing in device tree')
47 u_boot_console.restart_uboot()
Heinrich Schuchardt43d27992018-03-03 15:29:04 +010048
49@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
Heinrich Schuchardt1dc0a1b2017-10-18 18:13:17 +020050def test_efi_selftest_watchdog_reboot(u_boot_console):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010051 """Test the watchdog timer
52
53 :param u_boot_console: U-Boot console
54
55 This function executes the 'watchdog reboot' unit test.
56 """
57 u_boot_console.run_command(cmd='setenv efi_selftest list')
58 output = u_boot_console.run_command('bootefi selftest')
59 assert '\'watchdog reboot\'' in output
60 u_boot_console.run_command(cmd='setenv efi_selftest watchdog reboot')
61 u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
62 m = u_boot_console.p.expect(['resetting', 'U-Boot'])
63 if m != 0:
64 raise Exception('Reset failed in \'watchdog reboot\' test')
65 u_boot_console.restart_uboot()
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +020066
67@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
68def test_efi_selftest_text_input(u_boot_console):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010069 """Test the EFI_SIMPLE_TEXT_INPUT_PROTOCOL
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +020070
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010071 :param u_boot_console: U-Boot console
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +020072
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010073 This function calls the text input EFI selftest.
74 """
75 u_boot_console.run_command(cmd='setenv efi_selftest text input')
76 output = u_boot_console.run_command(cmd='bootefi selftest',
77 wait_for_prompt=False)
78 m = u_boot_console.p.expect([r'To terminate type \'x\''])
79 if m != 0:
80 raise Exception('No prompt for \'text input\' test')
81 u_boot_console.drain_console()
82 u_boot_console.p.timeout = 500
83 # EOT
84 u_boot_console.run_command(cmd=chr(4), wait_for_echo=False,
85 send_nl=False, wait_for_prompt=False)
86 m = u_boot_console.p.expect(
87 [r'Unicode char 4 \(unknown\), scan code 0 \(Null\)'])
88 if m != 0:
89 raise Exception('EOT failed in \'text input\' test')
90 u_boot_console.drain_console()
91 # BS
92 u_boot_console.run_command(cmd=chr(8), wait_for_echo=False,
93 send_nl=False, wait_for_prompt=False)
94 m = u_boot_console.p.expect(
95 [r'Unicode char 8 \(BS\), scan code 0 \(Null\)'])
96 if m != 0:
97 raise Exception('BS failed in \'text input\' test')
98 u_boot_console.drain_console()
99 # TAB
100 u_boot_console.run_command(cmd=chr(9), wait_for_echo=False,
101 send_nl=False, wait_for_prompt=False)
102 m = u_boot_console.p.expect(
103 [r'Unicode char 9 \(TAB\), scan code 0 \(Null\)'])
104 if m != 0:
105 raise Exception('BS failed in \'text input\' test')
106 u_boot_console.drain_console()
107 # a
108 u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False,
109 wait_for_prompt=False)
110 m = u_boot_console.p.expect(
111 [r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)'])
112 if m != 0:
113 raise Exception('\'a\' failed in \'text input\' test')
114 u_boot_console.drain_console()
115 # UP escape sequence
116 u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False,
117 send_nl=False, wait_for_prompt=False)
118 m = u_boot_console.p.expect(
119 [r'Unicode char 0 \(Null\), scan code 1 \(Up\)'])
120 if m != 0:
121 raise Exception('UP failed in \'text input\' test')
122 u_boot_console.drain_console()
123 # Euro sign
124 u_boot_console.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False,
125 send_nl=False, wait_for_prompt=False)
126 m = u_boot_console.p.expect([r'Unicode char 8364 \(\''])
127 if m != 0:
128 raise Exception('Euro sign failed in \'text input\' test')
129 u_boot_console.drain_console()
130 u_boot_console.run_command(cmd='x', wait_for_echo=False, send_nl=False,
131 wait_for_prompt=False)
132 m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])
133 if m != 0:
134 raise Exception('Failures occurred during the EFI selftest')
135 u_boot_console.restart_uboot()
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200136
137@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
138def test_efi_selftest_text_input_ex(u_boot_console):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100139 """Test the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200140
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100141 :param u_boot_console: U-Boot console
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200142
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100143 This function calls the extended text input EFI selftest.
144 """
145 u_boot_console.run_command(cmd='setenv efi_selftest extended text input')
146 output = u_boot_console.run_command(cmd='bootefi selftest',
147 wait_for_prompt=False)
148 m = u_boot_console.p.expect([r'To terminate type \'CTRL\+x\''])
149 if m != 0:
150 raise Exception('No prompt for \'text input\' test')
151 u_boot_console.drain_console()
152 u_boot_console.p.timeout = 500
153 # EOT
154 u_boot_console.run_command(cmd=chr(4), wait_for_echo=False,
155 send_nl=False, wait_for_prompt=False)
156 m = u_boot_console.p.expect(
157 [r'Unicode char 100 \(\'d\'\), scan code 0 \(CTRL\+Null\)'])
158 if m != 0:
159 raise Exception('EOT failed in \'text input\' test')
160 u_boot_console.drain_console()
161 # BS
162 u_boot_console.run_command(cmd=chr(8), wait_for_echo=False,
163 send_nl=False, wait_for_prompt=False)
164 m = u_boot_console.p.expect(
165 [r'Unicode char 8 \(BS\), scan code 0 \(\+Null\)'])
166 if m != 0:
167 raise Exception('BS failed in \'text input\' test')
168 u_boot_console.drain_console()
169 # TAB
170 u_boot_console.run_command(cmd=chr(9), wait_for_echo=False,
171 send_nl=False, wait_for_prompt=False)
172 m = u_boot_console.p.expect(
173 [r'Unicode char 9 \(TAB\), scan code 0 \(\+Null\)'])
174 if m != 0:
175 raise Exception('TAB failed in \'text input\' test')
176 u_boot_console.drain_console()
177 # a
178 u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False,
179 wait_for_prompt=False)
180 m = u_boot_console.p.expect(
181 [r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)'])
182 if m != 0:
183 raise Exception('\'a\' failed in \'text input\' test')
184 u_boot_console.drain_console()
185 # UP escape sequence
186 u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False,
187 send_nl=False, wait_for_prompt=False)
188 m = u_boot_console.p.expect(
189 [r'Unicode char 0 \(Null\), scan code 1 \(\+Up\)'])
190 if m != 0:
191 raise Exception('UP failed in \'text input\' test')
192 u_boot_console.drain_console()
193 # Euro sign
194 u_boot_console.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False,
195 send_nl=False, wait_for_prompt=False)
196 m = u_boot_console.p.expect([r'Unicode char 8364 \(\''])
197 if m != 0:
198 raise Exception('Euro sign failed in \'text input\' test')
199 u_boot_console.drain_console()
200 # SHIFT+ALT+FN 5
201 u_boot_console.run_command(cmd=b'\x1b\x5b\x31\x35\x3b\x34\x7e'.decode(),
202 wait_for_echo=False, send_nl=False,
203 wait_for_prompt=False)
204 m = u_boot_console.p.expect(
205 [r'Unicode char 0 \(Null\), scan code 15 \(SHIFT\+ALT\+FN 5\)'])
206 if m != 0:
207 raise Exception('SHIFT+ALT+FN 5 failed in \'text input\' test')
208 u_boot_console.drain_console()
209 u_boot_console.run_command(cmd=chr(24), wait_for_echo=False, send_nl=False,
210 wait_for_prompt=False)
211 m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])
212 if m != 0:
213 raise Exception('Failures occurred during the EFI selftest')
214 u_boot_console.restart_uboot()