blob: 516e41cf51fd08461e73e8e8654512d79b6667ae [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
4# Test efi API implementation
5
6import pytest
7import u_boot_utils
8
9@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
10def test_efi_selftest(u_boot_console):
Heinrich Schuchardt48161e12018-11-18 17:58:54 +010011 """Test the UEFI implementation
Heinrich Schuchardtd828a052017-09-15 10:06:12 +020012
Heinrich Schuchardt48161e12018-11-18 17:58:54 +010013 :param u_boot_console: U-Boot console
14
15 This function executes all selftests that are not marked as on request.
16 """
Heinrich Schuchardt1dc0a1b2017-10-18 18:13:17 +020017 u_boot_console.run_command(cmd='setenv efi_selftest')
Heinrich Schuchardt1c111f92019-04-20 13:33:55 +020018 u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
Heinrich Schuchardtd828a052017-09-15 10:06:12 +020019 m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])
20 if m != 0:
Heinrich Schuchardt40e99c12018-09-06 20:29:50 +020021 raise Exception('Failures occurred during the EFI selftest')
Heinrich Schuchardtd828a052017-09-15 10:06:12 +020022 u_boot_console.run_command(cmd='', wait_for_echo=False, wait_for_prompt=False);
23 m = u_boot_console.p.expect(['resetting', 'U-Boot'])
24 if m != 0:
25 raise Exception('Reset failed during the EFI selftest')
26 u_boot_console.restart_uboot();
Heinrich Schuchardt1dc0a1b2017-10-18 18:13:17 +020027
28@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
Heinrich Schuchardt43d27992018-03-03 15:29:04 +010029@pytest.mark.buildconfigspec('of_control')
Heinrich Schuchardt1c111f92019-04-20 13:33:55 +020030@pytest.mark.notbuildconfigspec('generate_acpi_table')
Heinrich Schuchardt43d27992018-03-03 15:29:04 +010031def test_efi_selftest_device_tree(u_boot_console):
32 u_boot_console.run_command(cmd='setenv efi_selftest list')
33 output = u_boot_console.run_command('bootefi selftest')
34 assert '\'device tree\'' in output
35 u_boot_console.run_command(cmd='setenv efi_selftest device tree')
36 u_boot_console.run_command(cmd='setenv -f serial# Testing DT')
37 u_boot_console.run_command(cmd='bootefi selftest ${fdtcontroladdr}', wait_for_prompt=False)
38 m = u_boot_console.p.expect(['serial-number: Testing DT', 'U-Boot'])
39 if m != 0:
Heinrich Schuchardte2193d62019-07-05 17:43:13 +020040 raise Exception('serial-number missing in device tree')
Heinrich Schuchardt43d27992018-03-03 15:29:04 +010041 u_boot_console.restart_uboot();
42
43@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
Heinrich Schuchardt1dc0a1b2017-10-18 18:13:17 +020044def test_efi_selftest_watchdog_reboot(u_boot_console):
45 u_boot_console.run_command(cmd='setenv efi_selftest list')
46 output = u_boot_console.run_command('bootefi selftest')
47 assert '\'watchdog reboot\'' in output
48 u_boot_console.run_command(cmd='setenv efi_selftest watchdog reboot')
49 u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
50 m = u_boot_console.p.expect(['resetting', 'U-Boot'])
51 if m != 0:
52 raise Exception('Reset failed in \'watchdog reboot\' test')
53 u_boot_console.restart_uboot();
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +020054
55@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
56def test_efi_selftest_text_input(u_boot_console):
57 """Test the EFI_SIMPLE_TEXT_INPUT_PROTOCOL
58
59 :param u_boot_console: U-Boot console
60
61 This function calls the text input EFI selftest.
62 """
63 u_boot_console.run_command(cmd='setenv efi_selftest text input')
64 output = u_boot_console.run_command(cmd='bootefi selftest',
65 wait_for_prompt=False)
66 m = u_boot_console.p.expect(['To terminate type \'x\''])
67 if m != 0:
68 raise Exception('No prompt for \'text input\' test')
69 u_boot_console.drain_console()
70 u_boot_console.p.timeout = 500
71 # EOT
72 u_boot_console.run_command(cmd=chr(4), wait_for_echo=False,
73 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardtd2cab7f2018-09-11 22:38:07 +020074 m = u_boot_console.p.expect(
75 ['Unicode char 4 \(unknown\), scan code 0 \(Null\)'])
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +020076 if m != 0:
77 raise Exception('EOT failed in \'text input\' test')
78 u_boot_console.drain_console()
79 # BS
80 u_boot_console.run_command(cmd=chr(8), wait_for_echo=False,
81 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardtd2cab7f2018-09-11 22:38:07 +020082 m = u_boot_console.p.expect(
83 ['Unicode char 8 \(BS\), scan code 0 \(Null\)'])
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +020084 if m != 0:
85 raise Exception('BS failed in \'text input\' test')
86 u_boot_console.drain_console()
87 # TAB
88 u_boot_console.run_command(cmd=chr(9), wait_for_echo=False,
89 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardtd2cab7f2018-09-11 22:38:07 +020090 m = u_boot_console.p.expect(
91 ['Unicode char 9 \(TAB\), scan code 0 \(Null\)'])
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +020092 if m != 0:
93 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 Schuchardtd2cab7f2018-09-11 22:38:07 +020098 m = u_boot_console.p.expect(
99 ['Unicode char 97 \(\'a\'\), scan code 0 \(Null\)'])
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +0200100 if m != 0:
101 raise Exception('\'a\' failed in \'text input\' test')
102 u_boot_console.drain_console()
103 # UP escape sequence
104 u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False,
105 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardtd2cab7f2018-09-11 22:38:07 +0200106 m = u_boot_console.p.expect(
107 ['Unicode char 0 \(Null\), scan code 1 \(Up\)'])
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +0200108 if m != 0:
109 raise Exception('UP failed in \'text input\' test')
110 u_boot_console.drain_console()
Heinrich Schuchardt8b2ba082018-09-11 22:38:03 +0200111 # Euro sign
112 u_boot_console.run_command(cmd='\xe2\x82\xac', wait_for_echo=False,
113 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardtd2cab7f2018-09-11 22:38:07 +0200114 m = u_boot_console.p.expect(['Unicode char 8364 \(\''])
Heinrich Schuchardt8b2ba082018-09-11 22:38:03 +0200115 if m != 0:
116 raise Exception('Euro sign failed in \'text input\' test')
117 u_boot_console.drain_console()
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +0200118 u_boot_console.run_command(cmd='x', wait_for_echo=False, send_nl=False,
119 wait_for_prompt=False)
120 m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])
121 if m != 0:
122 raise Exception('Failures occurred during the EFI selftest')
123 u_boot_console.restart_uboot();
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200124
125@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
126def test_efi_selftest_text_input_ex(u_boot_console):
127 """Test the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
128
129 :param u_boot_console: U-Boot console
130
131 This function calls the extended text input EFI selftest.
132 """
133 u_boot_console.run_command(cmd='setenv efi_selftest extended text input')
134 output = u_boot_console.run_command(cmd='bootefi selftest',
135 wait_for_prompt=False)
Heinrich Schuchardta882c4c2018-09-11 22:38:13 +0200136 m = u_boot_console.p.expect(['To terminate type \'CTRL\+x\''])
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200137 if m != 0:
138 raise Exception('No prompt for \'text input\' test')
139 u_boot_console.drain_console()
140 u_boot_console.p.timeout = 500
141 # EOT
142 u_boot_console.run_command(cmd=chr(4), wait_for_echo=False,
143 send_nl=False, wait_for_prompt=False)
144 m = u_boot_console.p.expect(
Heinrich Schuchardt00b00a12019-04-06 20:59:24 +0200145 ['Unicode char 100 \\(\'d\'\\), scan code 0 \\(CTRL\\+Null\\)'])
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200146 if m != 0:
147 raise Exception('EOT failed in \'text input\' test')
148 u_boot_console.drain_console()
149 # BS
150 u_boot_console.run_command(cmd=chr(8), wait_for_echo=False,
151 send_nl=False, wait_for_prompt=False)
152 m = u_boot_console.p.expect(
153 ['Unicode char 8 \(BS\), scan code 0 \(\+Null\)'])
154 if m != 0:
155 raise Exception('BS failed in \'text input\' test')
156 u_boot_console.drain_console()
157 # TAB
158 u_boot_console.run_command(cmd=chr(9), wait_for_echo=False,
159 send_nl=False, wait_for_prompt=False)
160 m = u_boot_console.p.expect(
161 ['Unicode char 9 \(TAB\), scan code 0 \(\+Null\)'])
162 if m != 0:
163 raise Exception('TAB failed in \'text input\' test')
164 u_boot_console.drain_console()
165 # a
166 u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False,
167 wait_for_prompt=False)
168 m = u_boot_console.p.expect(
169 ['Unicode char 97 \(\'a\'\), scan code 0 \(Null\)'])
170 if m != 0:
171 raise Exception('\'a\' failed in \'text input\' test')
172 u_boot_console.drain_console()
173 # UP escape sequence
174 u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False,
175 send_nl=False, wait_for_prompt=False)
176 m = u_boot_console.p.expect(
177 ['Unicode char 0 \(Null\), scan code 1 \(\+Up\)'])
178 if m != 0:
179 raise Exception('UP failed in \'text input\' test')
180 u_boot_console.drain_console()
181 # Euro sign
182 u_boot_console.run_command(cmd='\xe2\x82\xac', wait_for_echo=False,
183 send_nl=False, wait_for_prompt=False)
184 m = u_boot_console.p.expect(['Unicode char 8364 \(\''])
185 if m != 0:
186 raise Exception('Euro sign failed in \'text input\' test')
187 u_boot_console.drain_console()
188 # SHIFT+ALT+FN 5
189 u_boot_console.run_command(cmd='\x1b\x5b\x31\x35\x3b\x34\x7e',
190 wait_for_echo=False, send_nl=False,
191 wait_for_prompt=False)
192 m = u_boot_console.p.expect(
193 ['Unicode char 0 \(Null\), scan code 15 \(SHIFT\+ALT\+FN 5\)'])
194 if m != 0:
195 raise Exception('SHIFT+ALT+FN 5 failed in \'text input\' test')
196 u_boot_console.drain_console()
Heinrich Schuchardta882c4c2018-09-11 22:38:13 +0200197 u_boot_console.run_command(cmd=chr(24), wait_for_echo=False, send_nl=False,
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200198 wait_for_prompt=False)
199 m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])
200 if m != 0:
201 raise Exception('Failures occurred during the EFI selftest')
202 u_boot_console.restart_uboot();