1# SPDX-License-Identifier: GPL-2.0 2# Copyright (c) 2017, Heinrich Schuchardt <xypron.glpk@gmx.de> 3 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): 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 ${fdtcontroladdr}', 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') 30def test_efi_selftest_device_tree(u_boot_console): 31 u_boot_console.run_command(cmd='setenv efi_selftest list') 32 output = u_boot_console.run_command('bootefi selftest') 33 assert '\'device tree\'' in output 34 u_boot_console.run_command(cmd='setenv efi_selftest device tree') 35 u_boot_console.run_command(cmd='setenv -f serial# Testing DT') 36 u_boot_console.run_command(cmd='bootefi selftest ${fdtcontroladdr}', wait_for_prompt=False) 37 m = u_boot_console.p.expect(['serial-number: Testing DT', 'U-Boot']) 38 if m != 0: 39 raise Exception('Reset failed in \'device tree\' test') 40 u_boot_console.restart_uboot(); 41 42@pytest.mark.buildconfigspec('cmd_bootefi_selftest') 43def test_efi_selftest_watchdog_reboot(u_boot_console): 44 u_boot_console.run_command(cmd='setenv efi_selftest list') 45 output = u_boot_console.run_command('bootefi selftest') 46 assert '\'watchdog reboot\'' in output 47 u_boot_console.run_command(cmd='setenv efi_selftest watchdog reboot') 48 u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False) 49 m = u_boot_console.p.expect(['resetting', 'U-Boot']) 50 if m != 0: 51 raise Exception('Reset failed in \'watchdog reboot\' test') 52 u_boot_console.restart_uboot(); 53 54@pytest.mark.buildconfigspec('cmd_bootefi_selftest') 55def test_efi_selftest_text_input(u_boot_console): 56 """Test the EFI_SIMPLE_TEXT_INPUT_PROTOCOL 57 58 :param u_boot_console: U-Boot console 59 60 This function calls the text input EFI selftest. 61 """ 62 u_boot_console.run_command(cmd='setenv efi_selftest text input') 63 output = u_boot_console.run_command(cmd='bootefi selftest', 64 wait_for_prompt=False) 65 m = u_boot_console.p.expect(['To terminate type \'x\'']) 66 if m != 0: 67 raise Exception('No prompt for \'text input\' test') 68 u_boot_console.drain_console() 69 u_boot_console.p.timeout = 500 70 # EOT 71 u_boot_console.run_command(cmd=chr(4), wait_for_echo=False, 72 send_nl=False, wait_for_prompt=False) 73 m = u_boot_console.p.expect( 74 ['Unicode char 4 \(unknown\), scan code 0 \(Null\)']) 75 if m != 0: 76 raise Exception('EOT failed in \'text input\' test') 77 u_boot_console.drain_console() 78 # BS 79 u_boot_console.run_command(cmd=chr(8), wait_for_echo=False, 80 send_nl=False, wait_for_prompt=False) 81 m = u_boot_console.p.expect( 82 ['Unicode char 8 \(BS\), scan code 0 \(Null\)']) 83 if m != 0: 84 raise Exception('BS failed in \'text input\' test') 85 u_boot_console.drain_console() 86 # TAB 87 u_boot_console.run_command(cmd=chr(9), wait_for_echo=False, 88 send_nl=False, wait_for_prompt=False) 89 m = u_boot_console.p.expect( 90 ['Unicode char 9 \(TAB\), scan code 0 \(Null\)']) 91 if m != 0: 92 raise Exception('BS failed in \'text input\' test') 93 u_boot_console.drain_console() 94 # a 95 u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False, 96 wait_for_prompt=False) 97 m = u_boot_console.p.expect( 98 ['Unicode char 97 \(\'a\'\), scan code 0 \(Null\)']) 99 if m != 0: 100 raise Exception('\'a\' failed in \'text input\' test') 101 u_boot_console.drain_console() 102 # UP escape sequence 103 u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False, 104 send_nl=False, wait_for_prompt=False) 105 m = u_boot_console.p.expect( 106 ['Unicode char 0 \(Null\), scan code 1 \(Up\)']) 107 if m != 0: 108 raise Exception('UP failed in \'text input\' test') 109 u_boot_console.drain_console() 110 # Euro sign 111 u_boot_console.run_command(cmd='\xe2\x82\xac', wait_for_echo=False, 112 send_nl=False, wait_for_prompt=False) 113 m = u_boot_console.p.expect(['Unicode char 8364 \(\'']) 114 if m != 0: 115 raise Exception('Euro sign failed in \'text input\' test') 116 u_boot_console.drain_console() 117 u_boot_console.run_command(cmd='x', wait_for_echo=False, send_nl=False, 118 wait_for_prompt=False) 119 m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']) 120 if m != 0: 121 raise Exception('Failures occurred during the EFI selftest') 122 u_boot_console.restart_uboot(); 123 124@pytest.mark.buildconfigspec('cmd_bootefi_selftest') 125def test_efi_selftest_text_input_ex(u_boot_console): 126 """Test the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL 127 128 :param u_boot_console: U-Boot console 129 130 This function calls the extended text input EFI selftest. 131 """ 132 u_boot_console.run_command(cmd='setenv efi_selftest extended text input') 133 output = u_boot_console.run_command(cmd='bootefi selftest', 134 wait_for_prompt=False) 135 m = u_boot_console.p.expect(['To terminate type \'CTRL\+x\'']) 136 if m != 0: 137 raise Exception('No prompt for \'text input\' test') 138 u_boot_console.drain_console() 139 u_boot_console.p.timeout = 500 140 # EOT 141 u_boot_console.run_command(cmd=chr(4), wait_for_echo=False, 142 send_nl=False, wait_for_prompt=False) 143 m = u_boot_console.p.expect( 144 ['Unicode char 4 \(unknown\), scan code 0 \(CTRL\+Null\)']) 145 if m != 0: 146 raise Exception('EOT failed in \'text input\' test') 147 u_boot_console.drain_console() 148 # BS 149 u_boot_console.run_command(cmd=chr(8), wait_for_echo=False, 150 send_nl=False, wait_for_prompt=False) 151 m = u_boot_console.p.expect( 152 ['Unicode char 8 \(BS\), scan code 0 \(\+Null\)']) 153 if m != 0: 154 raise Exception('BS failed in \'text input\' test') 155 u_boot_console.drain_console() 156 # TAB 157 u_boot_console.run_command(cmd=chr(9), wait_for_echo=False, 158 send_nl=False, wait_for_prompt=False) 159 m = u_boot_console.p.expect( 160 ['Unicode char 9 \(TAB\), scan code 0 \(\+Null\)']) 161 if m != 0: 162 raise Exception('TAB failed in \'text input\' test') 163 u_boot_console.drain_console() 164 # a 165 u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False, 166 wait_for_prompt=False) 167 m = u_boot_console.p.expect( 168 ['Unicode char 97 \(\'a\'\), scan code 0 \(Null\)']) 169 if m != 0: 170 raise Exception('\'a\' failed in \'text input\' test') 171 u_boot_console.drain_console() 172 # UP escape sequence 173 u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False, 174 send_nl=False, wait_for_prompt=False) 175 m = u_boot_console.p.expect( 176 ['Unicode char 0 \(Null\), scan code 1 \(\+Up\)']) 177 if m != 0: 178 raise Exception('UP failed in \'text input\' test') 179 u_boot_console.drain_console() 180 # Euro sign 181 u_boot_console.run_command(cmd='\xe2\x82\xac', wait_for_echo=False, 182 send_nl=False, wait_for_prompt=False) 183 m = u_boot_console.p.expect(['Unicode char 8364 \(\'']) 184 if m != 0: 185 raise Exception('Euro sign failed in \'text input\' test') 186 u_boot_console.drain_console() 187 # SHIFT+ALT+FN 5 188 u_boot_console.run_command(cmd='\x1b\x5b\x31\x35\x3b\x34\x7e', 189 wait_for_echo=False, send_nl=False, 190 wait_for_prompt=False) 191 m = u_boot_console.p.expect( 192 ['Unicode char 0 \(Null\), scan code 15 \(SHIFT\+ALT\+FN 5\)']) 193 if m != 0: 194 raise Exception('SHIFT+ALT+FN 5 failed in \'text input\' test') 195 u_boot_console.drain_console() 196 u_boot_console.run_command(cmd=chr(24), wait_for_echo=False, send_nl=False, 197 wait_for_prompt=False) 198 m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']) 199 if m != 0: 200 raise Exception('Failures occurred during the EFI selftest') 201 u_boot_console.restart_uboot(); 202