Merge tag 'u-boot-imx-20190426' of git://git.denx.de/u-boot-imx
[platform/kernel/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.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();
27
28 @pytest.mark.buildconfigspec('cmd_bootefi_selftest')
29 @pytest.mark.buildconfigspec('of_control')
30 @pytest.mark.notbuildconfigspec('generate_acpi_table')
31 def 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:
40                 raise Exception('Reset failed in \'device tree\' test')
41         u_boot_console.restart_uboot();
42
43 @pytest.mark.buildconfigspec('cmd_bootefi_selftest')
44 def 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();
54
55 @pytest.mark.buildconfigspec('cmd_bootefi_selftest')
56 def 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)
74         m = u_boot_console.p.expect(
75                 ['Unicode char 4 \(unknown\), scan code 0 \(Null\)'])
76         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)
82         m = u_boot_console.p.expect(
83                 ['Unicode char 8 \(BS\), scan code 0 \(Null\)'])
84         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)
90         m = u_boot_console.p.expect(
91                 ['Unicode char 9 \(TAB\), scan code 0 \(Null\)'])
92         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)
98         m = u_boot_console.p.expect(
99                 ['Unicode char 97 \(\'a\'\), scan code 0 \(Null\)'])
100         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)
106         m = u_boot_console.p.expect(
107                 ['Unicode char 0 \(Null\), scan code 1 \(Up\)'])
108         if m != 0:
109                 raise Exception('UP failed in \'text input\' test')
110         u_boot_console.drain_console()
111         # Euro sign
112         u_boot_console.run_command(cmd='\xe2\x82\xac', wait_for_echo=False,
113                                    send_nl=False, wait_for_prompt=False)
114         m = u_boot_console.p.expect(['Unicode char 8364 \(\''])
115         if m != 0:
116                 raise Exception('Euro sign failed in \'text input\' test')
117         u_boot_console.drain_console()
118         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();
124
125 @pytest.mark.buildconfigspec('cmd_bootefi_selftest')
126 def 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)
136         m = u_boot_console.p.expect(['To terminate type \'CTRL\+x\''])
137         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(
145                 ['Unicode char 100 \\(\'d\'\\), scan code 0 \\(CTRL\\+Null\\)'])
146         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()
197         u_boot_console.run_command(cmd=chr(24), wait_for_echo=False, send_nl=False,
198                                    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();