blob: ca01542088f163f1c7a5e1d39893dc0ca4340abd [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.restart_uboot();
Heinrich Schuchardt1dc0a1b2017-10-18 18:13:17 +020023
24@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
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):
28 u_boot_console.run_command(cmd='setenv efi_selftest list')
29 output = u_boot_console.run_command('bootefi selftest')
30 assert '\'device tree\'' in output
31 u_boot_console.run_command(cmd='setenv efi_selftest device tree')
32 u_boot_console.run_command(cmd='setenv -f serial# Testing DT')
33 u_boot_console.run_command(cmd='bootefi selftest ${fdtcontroladdr}', wait_for_prompt=False)
34 m = u_boot_console.p.expect(['serial-number: Testing DT', 'U-Boot'])
35 if m != 0:
Heinrich Schuchardte2193d62019-07-05 17:43:13 +020036 raise Exception('serial-number missing in device tree')
Heinrich Schuchardt43d27992018-03-03 15:29:04 +010037 u_boot_console.restart_uboot();
38
39@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
Heinrich Schuchardt1dc0a1b2017-10-18 18:13:17 +020040def test_efi_selftest_watchdog_reboot(u_boot_console):
41 u_boot_console.run_command(cmd='setenv efi_selftest list')
42 output = u_boot_console.run_command('bootefi selftest')
43 assert '\'watchdog reboot\'' in output
44 u_boot_console.run_command(cmd='setenv efi_selftest watchdog reboot')
45 u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
46 m = u_boot_console.p.expect(['resetting', 'U-Boot'])
47 if m != 0:
48 raise Exception('Reset failed in \'watchdog reboot\' test')
49 u_boot_console.restart_uboot();
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +020050
51@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
52def test_efi_selftest_text_input(u_boot_console):
53 """Test the EFI_SIMPLE_TEXT_INPUT_PROTOCOL
54
55 :param u_boot_console: U-Boot console
56
57 This function calls the text input EFI selftest.
58 """
59 u_boot_console.run_command(cmd='setenv efi_selftest text input')
60 output = u_boot_console.run_command(cmd='bootefi selftest',
61 wait_for_prompt=False)
Tom Rinib18abd02019-10-24 11:59:23 -040062 m = u_boot_console.p.expect([r'To terminate type \'x\''])
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +020063 if m != 0:
64 raise Exception('No prompt for \'text input\' test')
65 u_boot_console.drain_console()
66 u_boot_console.p.timeout = 500
67 # EOT
68 u_boot_console.run_command(cmd=chr(4), wait_for_echo=False,
69 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardtd2cab7f2018-09-11 22:38:07 +020070 m = u_boot_console.p.expect(
Tom Rinib18abd02019-10-24 11:59:23 -040071 [r'Unicode char 4 \(unknown\), scan code 0 \(Null\)'])
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +020072 if m != 0:
73 raise Exception('EOT failed in \'text input\' test')
74 u_boot_console.drain_console()
75 # BS
76 u_boot_console.run_command(cmd=chr(8), wait_for_echo=False,
77 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardtd2cab7f2018-09-11 22:38:07 +020078 m = u_boot_console.p.expect(
Tom Rinib18abd02019-10-24 11:59:23 -040079 [r'Unicode char 8 \(BS\), scan code 0 \(Null\)'])
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +020080 if m != 0:
81 raise Exception('BS failed in \'text input\' test')
82 u_boot_console.drain_console()
83 # TAB
84 u_boot_console.run_command(cmd=chr(9), wait_for_echo=False,
85 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardtd2cab7f2018-09-11 22:38:07 +020086 m = u_boot_console.p.expect(
Tom Rinib18abd02019-10-24 11:59:23 -040087 [r'Unicode char 9 \(TAB\), scan code 0 \(Null\)'])
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +020088 if m != 0:
89 raise Exception('BS failed in \'text input\' test')
90 u_boot_console.drain_console()
91 # a
92 u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False,
93 wait_for_prompt=False)
Heinrich Schuchardtd2cab7f2018-09-11 22:38:07 +020094 m = u_boot_console.p.expect(
Tom Rinib18abd02019-10-24 11:59:23 -040095 [r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)'])
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +020096 if m != 0:
97 raise Exception('\'a\' failed in \'text input\' test')
98 u_boot_console.drain_console()
99 # UP escape sequence
100 u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False,
101 send_nl=False, wait_for_prompt=False)
Heinrich Schuchardtd2cab7f2018-09-11 22:38:07 +0200102 m = u_boot_console.p.expect(
Tom Rinib18abd02019-10-24 11:59:23 -0400103 [r'Unicode char 0 \(Null\), scan code 1 \(Up\)'])
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +0200104 if m != 0:
105 raise Exception('UP failed in \'text input\' test')
106 u_boot_console.drain_console()
Heinrich Schuchardt8b2ba082018-09-11 22:38:03 +0200107 # Euro sign
Tom Rinib18abd02019-10-24 11:59:23 -0400108 u_boot_console.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False,
Heinrich Schuchardt8b2ba082018-09-11 22:38:03 +0200109 send_nl=False, wait_for_prompt=False)
Tom Rinib18abd02019-10-24 11:59:23 -0400110 m = u_boot_console.p.expect([r'Unicode char 8364 \(\''])
Heinrich Schuchardt8b2ba082018-09-11 22:38:03 +0200111 if m != 0:
112 raise Exception('Euro sign failed in \'text input\' test')
113 u_boot_console.drain_console()
Heinrich Schuchardt5e450d42018-09-06 20:19:31 +0200114 u_boot_console.run_command(cmd='x', wait_for_echo=False, send_nl=False,
115 wait_for_prompt=False)
116 m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])
117 if m != 0:
118 raise Exception('Failures occurred during the EFI selftest')
119 u_boot_console.restart_uboot();
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200120
121@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
122def test_efi_selftest_text_input_ex(u_boot_console):
123 """Test the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
124
125 :param u_boot_console: U-Boot console
126
127 This function calls the extended text input EFI selftest.
128 """
129 u_boot_console.run_command(cmd='setenv efi_selftest extended text input')
130 output = u_boot_console.run_command(cmd='bootefi selftest',
131 wait_for_prompt=False)
Tom Rinib18abd02019-10-24 11:59:23 -0400132 m = u_boot_console.p.expect([r'To terminate type \'CTRL\+x\''])
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200133 if m != 0:
134 raise Exception('No prompt for \'text input\' test')
135 u_boot_console.drain_console()
136 u_boot_console.p.timeout = 500
137 # EOT
138 u_boot_console.run_command(cmd=chr(4), wait_for_echo=False,
139 send_nl=False, wait_for_prompt=False)
140 m = u_boot_console.p.expect(
Tom Rinib18abd02019-10-24 11:59:23 -0400141 [r'Unicode char 100 \(\'d\'\), scan code 0 \(CTRL\+Null\)'])
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200142 if m != 0:
143 raise Exception('EOT failed in \'text input\' test')
144 u_boot_console.drain_console()
145 # BS
146 u_boot_console.run_command(cmd=chr(8), wait_for_echo=False,
147 send_nl=False, wait_for_prompt=False)
148 m = u_boot_console.p.expect(
Tom Rinib18abd02019-10-24 11:59:23 -0400149 [r'Unicode char 8 \(BS\), scan code 0 \(\+Null\)'])
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200150 if m != 0:
151 raise Exception('BS failed in \'text input\' test')
152 u_boot_console.drain_console()
153 # TAB
154 u_boot_console.run_command(cmd=chr(9), wait_for_echo=False,
155 send_nl=False, wait_for_prompt=False)
156 m = u_boot_console.p.expect(
Tom Rinib18abd02019-10-24 11:59:23 -0400157 [r'Unicode char 9 \(TAB\), scan code 0 \(\+Null\)'])
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200158 if m != 0:
159 raise Exception('TAB failed in \'text input\' test')
160 u_boot_console.drain_console()
161 # a
162 u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False,
163 wait_for_prompt=False)
164 m = u_boot_console.p.expect(
Tom Rinib18abd02019-10-24 11:59:23 -0400165 [r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)'])
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200166 if m != 0:
167 raise Exception('\'a\' failed in \'text input\' test')
168 u_boot_console.drain_console()
169 # UP escape sequence
170 u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False,
171 send_nl=False, wait_for_prompt=False)
172 m = u_boot_console.p.expect(
Tom Rinib18abd02019-10-24 11:59:23 -0400173 [r'Unicode char 0 \(Null\), scan code 1 \(\+Up\)'])
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200174 if m != 0:
175 raise Exception('UP failed in \'text input\' test')
176 u_boot_console.drain_console()
177 # Euro sign
Tom Rinib18abd02019-10-24 11:59:23 -0400178 u_boot_console.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False,
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200179 send_nl=False, wait_for_prompt=False)
Tom Rinib18abd02019-10-24 11:59:23 -0400180 m = u_boot_console.p.expect([r'Unicode char 8364 \(\''])
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200181 if m != 0:
182 raise Exception('Euro sign failed in \'text input\' test')
183 u_boot_console.drain_console()
184 # SHIFT+ALT+FN 5
Tom Rinib18abd02019-10-24 11:59:23 -0400185 u_boot_console.run_command(cmd=b'\x1b\x5b\x31\x35\x3b\x34\x7e'.decode(),
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200186 wait_for_echo=False, send_nl=False,
187 wait_for_prompt=False)
188 m = u_boot_console.p.expect(
Tom Rinib18abd02019-10-24 11:59:23 -0400189 [r'Unicode char 0 \(Null\), scan code 15 \(SHIFT\+ALT\+FN 5\)'])
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200190 if m != 0:
191 raise Exception('SHIFT+ALT+FN 5 failed in \'text input\' test')
192 u_boot_console.drain_console()
Heinrich Schuchardta882c4c2018-09-11 22:38:13 +0200193 u_boot_console.run_command(cmd=chr(24), wait_for_echo=False, send_nl=False,
Heinrich Schuchardt7ecaf972018-09-11 22:38:11 +0200194 wait_for_prompt=False)
195 m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])
196 if m != 0:
197 raise Exception('Failures occurred during the EFI selftest')
198 u_boot_console.restart_uboot();