common: Drop linux/delay.h from common header
[oweals/u-boot.git] / test / py / tests / test_efi_selftest.py
1 # SPDX-License-Identifier: GPL-2.0
2 # Copyright (c) 2017, Heinrich Schuchardt <xypron.glpk@gmx.de>
3
4 """
5 Test UEFI API implementation
6 """
7
8 import pytest
9
10 @pytest.mark.buildconfigspec('cmd_bootefi_selftest')
11 def test_efi_selftest(u_boot_console):
12     """Run UEFI unit tests
13
14     :param u_boot_console: U-Boot console
15
16     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()
24
25 @pytest.mark.buildconfigspec('cmd_bootefi_selftest')
26 @pytest.mark.buildconfigspec('of_control')
27 @pytest.mark.notbuildconfigspec('generate_acpi_table')
28 def test_efi_selftest_device_tree(u_boot_console):
29     """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()
45
46 @pytest.mark.buildconfigspec('cmd_bootefi_selftest')
47 def test_efi_selftest_watchdog_reboot(u_boot_console):
48     """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()
63
64 @pytest.mark.buildconfigspec('cmd_bootefi_selftest')
65 def test_efi_selftest_text_input(u_boot_console):
66     """Test the EFI_SIMPLE_TEXT_INPUT_PROTOCOL
67
68     :param u_boot_console: U-Boot console
69
70     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()
133
134 @pytest.mark.buildconfigspec('cmd_bootefi_selftest')
135 def test_efi_selftest_text_input_ex(u_boot_console):
136     """Test the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
137
138     :param u_boot_console: U-Boot console
139
140     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()