Merge tag 'dm-pull-29oct19' of git://git.denx.de/u-boot-dm
[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 # Test efi API implementation
5
6 import pytest
7 import u_boot_utils
8
9 @pytest.mark.buildconfigspec('cmd_bootefi_selftest')
10 def test_efi_selftest(u_boot_console):
11         """Test the UEFI implementation
12
13         :param u_boot_console: U-Boot console
14
15         This function executes all selftests that are not marked as on request.
16         """
17         u_boot_console.run_command(cmd='setenv efi_selftest')
18         u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
19         m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])
20         if m != 0:
21                 raise Exception('Failures occurred during the EFI selftest')
22         u_boot_console.restart_uboot();
23
24 @pytest.mark.buildconfigspec('cmd_bootefi_selftest')
25 @pytest.mark.buildconfigspec('of_control')
26 @pytest.mark.notbuildconfigspec('generate_acpi_table')
27 def 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:
36                 raise Exception('serial-number missing in device tree')
37         u_boot_console.restart_uboot();
38
39 @pytest.mark.buildconfigspec('cmd_bootefi_selftest')
40 def 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();
50
51 @pytest.mark.buildconfigspec('cmd_bootefi_selftest')
52 def 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)
62         m = u_boot_console.p.expect([r'To terminate type \'x\''])
63         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)
70         m = u_boot_console.p.expect(
71                 [r'Unicode char 4 \(unknown\), scan code 0 \(Null\)'])
72         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)
78         m = u_boot_console.p.expect(
79                 [r'Unicode char 8 \(BS\), scan code 0 \(Null\)'])
80         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)
86         m = u_boot_console.p.expect(
87                 [r'Unicode char 9 \(TAB\), scan code 0 \(Null\)'])
88         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)
94         m = u_boot_console.p.expect(
95                 [r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)'])
96         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)
102         m = u_boot_console.p.expect(
103                 [r'Unicode char 0 \(Null\), scan code 1 \(Up\)'])
104         if m != 0:
105                 raise Exception('UP failed in \'text input\' test')
106         u_boot_console.drain_console()
107         # Euro sign
108         u_boot_console.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False,
109                                    send_nl=False, wait_for_prompt=False)
110         m = u_boot_console.p.expect([r'Unicode char 8364 \(\''])
111         if m != 0:
112                 raise Exception('Euro sign failed in \'text input\' test')
113         u_boot_console.drain_console()
114         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();
120
121 @pytest.mark.buildconfigspec('cmd_bootefi_selftest')
122 def 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)
132         m = u_boot_console.p.expect([r'To terminate type \'CTRL\+x\''])
133         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(
141                 [r'Unicode char 100 \(\'d\'\), scan code 0 \(CTRL\+Null\)'])
142         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(
149                 [r'Unicode char 8 \(BS\), scan code 0 \(\+Null\)'])
150         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(
157                 [r'Unicode char 9 \(TAB\), scan code 0 \(\+Null\)'])
158         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(
165                 [r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)'])
166         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(
173                 [r'Unicode char 0 \(Null\), scan code 1 \(\+Up\)'])
174         if m != 0:
175                 raise Exception('UP failed in \'text input\' test')
176         u_boot_console.drain_console()
177         # Euro sign
178         u_boot_console.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False,
179                                    send_nl=False, wait_for_prompt=False)
180         m = u_boot_console.p.expect([r'Unicode char 8364 \(\''])
181         if m != 0:
182                 raise Exception('Euro sign failed in \'text input\' test')
183         u_boot_console.drain_console()
184         # SHIFT+ALT+FN 5
185         u_boot_console.run_command(cmd=b'\x1b\x5b\x31\x35\x3b\x34\x7e'.decode(),
186                                    wait_for_echo=False, send_nl=False,
187                                    wait_for_prompt=False)
188         m = u_boot_console.p.expect(
189                 [r'Unicode char 0 \(Null\), scan code 15 \(SHIFT\+ALT\+FN 5\)'])
190         if m != 0:
191                 raise Exception('SHIFT+ALT+FN 5 failed in \'text input\' test')
192         u_boot_console.drain_console()
193         u_boot_console.run_command(cmd=chr(24), wait_for_echo=False, send_nl=False,
194                                    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();