blob: 971c9f6053a311122759875cd5a346f858bbb4f5 [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 Schuchardt43d27992018-03-03 15:29:04 +010026@pytest.mark.buildconfigspec('of_control')
Heinrich Schuchardt1c111f92019-04-20 13:33:55 +020027@pytest.mark.notbuildconfigspec('generate_acpi_table')
Heinrich Schuchardt43d27992018-03-03 15:29:04 +010028def test_efi_selftest_device_tree(u_boot_console):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010029 """Test the device tree support in the UEFI sub-system
30
31 :param u_boot_console: U-Boot console
32
33 This test executes the UEFI unit test by calling 'bootefi selftest'.
34 """
35 u_boot_console.run_command(cmd='setenv efi_selftest list')
36 output = u_boot_console.run_command('bootefi selftest')
37 assert '\'device tree\'' in output
38 u_boot_console.run_command(cmd='setenv efi_selftest device tree')
39 u_boot_console.run_command(cmd='setenv -f serial# Testing DT')
40 u_boot_console.run_command(cmd='bootefi selftest ${fdtcontroladdr}', wait_for_prompt=False)
41 m = u_boot_console.p.expect(['serial-number: Testing DT', 'U-Boot'])
42 if m != 0:
43 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
50 :param u_boot_console: U-Boot console
51
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)
59 m = u_boot_console.p.expect(['resetting', 'U-Boot'])
60 if m != 0:
61 raise Exception('Reset failed in \'watchdog reboot\' test')
62 u_boot_console.restart_uboot()
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +020063
64@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
65def test_efi_selftest_text_input(u_boot_console):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010066 """Test the EFI_SIMPLE_TEXT_INPUT_PROTOCOL
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +020067
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010068 :param u_boot_console: U-Boot console
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +020069
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +010070 This function calls the text input EFI selftest.
71 """
72 u_boot_console.run_command(cmd='setenv efi_selftest text input')
73 output = u_boot_console.run_command(cmd='bootefi selftest',
74 wait_for_prompt=False)
75 m = u_boot_console.p.expect([r'To terminate type \'x\''])
76 if m != 0:
77 raise Exception('No prompt for \'text input\' test')
78 u_boot_console.drain_console()
79 u_boot_console.p.timeout = 500
80 # EOT
81 u_boot_console.run_command(cmd=chr(4), wait_for_echo=False,
82 send_nl=False, wait_for_prompt=False)
83 m = u_boot_console.p.expect(
84 [r'Unicode char 4 \(unknown\), scan code 0 \(Null\)'])
85 if m != 0:
86 raise Exception('EOT failed in \'text input\' test')
87 u_boot_console.drain_console()
88 # BS
89 u_boot_console.run_command(cmd=chr(8), wait_for_echo=False,
90 send_nl=False, wait_for_prompt=False)
91 m = u_boot_console.p.expect(
92 [r'Unicode char 8 \(BS\), scan code 0 \(Null\)'])
93 if m != 0:
94 raise Exception('BS failed in \'text input\' test')
95 u_boot_console.drain_console()
96 # TAB
97 u_boot_console.run_command(cmd=chr(9), wait_for_echo=False,
98 send_nl=False, wait_for_prompt=False)
99 m = u_boot_console.p.expect(
100 [r'Unicode char 9 \(TAB\), scan code 0 \(Null\)'])
101 if m != 0:
102 raise Exception('BS failed in \'text input\' test')
103 u_boot_console.drain_console()
104 # a
105 u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False,
106 wait_for_prompt=False)
107 m = u_boot_console.p.expect(
108 [r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)'])
109 if m != 0:
110 raise Exception('\'a\' failed in \'text input\' test')
111 u_boot_console.drain_console()
112 # UP escape sequence
113 u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False,
114 send_nl=False, wait_for_prompt=False)
115 m = u_boot_console.p.expect(
116 [r'Unicode char 0 \(Null\), scan code 1 \(Up\)'])
117 if m != 0:
118 raise Exception('UP failed in \'text input\' test')
119 u_boot_console.drain_console()
120 # Euro sign
121 u_boot_console.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False,
122 send_nl=False, wait_for_prompt=False)
123 m = u_boot_console.p.expect([r'Unicode char 8364 \(\''])
124 if m != 0:
125 raise Exception('Euro sign failed in \'text input\' test')
126 u_boot_console.drain_console()
127 u_boot_console.run_command(cmd='x', wait_for_echo=False, send_nl=False,
128 wait_for_prompt=False)
129 m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])
130 if m != 0:
131 raise Exception('Failures occurred during the EFI selftest')
132 u_boot_console.restart_uboot()
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200133
134@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
135def test_efi_selftest_text_input_ex(u_boot_console):
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100136 """Test the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200137
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100138 :param u_boot_console: U-Boot console
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200139
Heinrich Schuchardtba41e3e2020-01-25 21:58:56 +0100140 This function calls the extended text input EFI selftest.
141 """
142 u_boot_console.run_command(cmd='setenv efi_selftest extended text input')
143 output = u_boot_console.run_command(cmd='bootefi selftest',
144 wait_for_prompt=False)
145 m = u_boot_console.p.expect([r'To terminate type \'CTRL\+x\''])
146 if m != 0:
147 raise Exception('No prompt for \'text input\' test')
148 u_boot_console.drain_console()
149 u_boot_console.p.timeout = 500
150 # EOT
151 u_boot_console.run_command(cmd=chr(4), wait_for_echo=False,
152 send_nl=False, wait_for_prompt=False)
153 m = u_boot_console.p.expect(
154 [r'Unicode char 100 \(\'d\'\), scan code 0 \(CTRL\+Null\)'])
155 if m != 0:
156 raise Exception('EOT failed in \'text input\' test')
157 u_boot_console.drain_console()
158 # BS
159 u_boot_console.run_command(cmd=chr(8), wait_for_echo=False,
160 send_nl=False, wait_for_prompt=False)
161 m = u_boot_console.p.expect(
162 [r'Unicode char 8 \(BS\), scan code 0 \(\+Null\)'])
163 if m != 0:
164 raise Exception('BS failed in \'text input\' test')
165 u_boot_console.drain_console()
166 # TAB
167 u_boot_console.run_command(cmd=chr(9), wait_for_echo=False,
168 send_nl=False, wait_for_prompt=False)
169 m = u_boot_console.p.expect(
170 [r'Unicode char 9 \(TAB\), scan code 0 \(\+Null\)'])
171 if m != 0:
172 raise Exception('TAB failed in \'text input\' test')
173 u_boot_console.drain_console()
174 # a
175 u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False,
176 wait_for_prompt=False)
177 m = u_boot_console.p.expect(
178 [r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)'])
179 if m != 0:
180 raise Exception('\'a\' failed in \'text input\' test')
181 u_boot_console.drain_console()
182 # UP escape sequence
183 u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False,
184 send_nl=False, wait_for_prompt=False)
185 m = u_boot_console.p.expect(
186 [r'Unicode char 0 \(Null\), scan code 1 \(\+Up\)'])
187 if m != 0:
188 raise Exception('UP failed in \'text input\' test')
189 u_boot_console.drain_console()
190 # Euro sign
191 u_boot_console.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False,
192 send_nl=False, wait_for_prompt=False)
193 m = u_boot_console.p.expect([r'Unicode char 8364 \(\''])
194 if m != 0:
195 raise Exception('Euro sign failed in \'text input\' test')
196 u_boot_console.drain_console()
197 # SHIFT+ALT+FN 5
198 u_boot_console.run_command(cmd=b'\x1b\x5b\x31\x35\x3b\x34\x7e'.decode(),
199 wait_for_echo=False, send_nl=False,
200 wait_for_prompt=False)
201 m = u_boot_console.p.expect(
202 [r'Unicode char 0 \(Null\), scan code 15 \(SHIFT\+ALT\+FN 5\)'])
203 if m != 0:
204 raise Exception('SHIFT+ALT+FN 5 failed in \'text input\' test')
205 u_boot_console.drain_console()
206 u_boot_console.run_command(cmd=chr(24), wait_for_echo=False, send_nl=False,
207 wait_for_prompt=False)
208 m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])
209 if m != 0:
210 raise Exception('Failures occurred during the EFI selftest')
211 u_boot_console.restart_uboot()