Heinrich Schuchardt | d828a05 | 2017-09-15 10:06:12 +0200 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 2 | # Copyright (c) 2017, Heinrich Schuchardt <xypron.glpk@gmx.de> |
Heinrich Schuchardt | d828a05 | 2017-09-15 10:06:12 +0200 | [diff] [blame] | 3 | |
Heinrich Schuchardt | ba41e3e | 2020-01-25 21:58:56 +0100 | [diff] [blame] | 4 | """ |
| 5 | Test UEFI API implementation |
| 6 | """ |
Heinrich Schuchardt | d828a05 | 2017-09-15 10:06:12 +0200 | [diff] [blame] | 7 | |
| 8 | import pytest |
Heinrich Schuchardt | d828a05 | 2017-09-15 10:06:12 +0200 | [diff] [blame] | 9 | |
| 10 | @pytest.mark.buildconfigspec('cmd_bootefi_selftest') |
| 11 | def test_efi_selftest(u_boot_console): |
Heinrich Schuchardt | ba41e3e | 2020-01-25 21:58:56 +0100 | [diff] [blame] | 12 | """Run UEFI unit tests |
Heinrich Schuchardt | d828a05 | 2017-09-15 10:06:12 +0200 | [diff] [blame] | 13 | |
Heinrich Schuchardt | ba41e3e | 2020-01-25 21:58:56 +0100 | [diff] [blame] | 14 | :param u_boot_console: U-Boot console |
Heinrich Schuchardt | 48161e1 | 2018-11-18 17:58:54 +0100 | [diff] [blame] | 15 | |
Heinrich Schuchardt | ba41e3e | 2020-01-25 21:58:56 +0100 | [diff] [blame] | 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() |
Heinrich Schuchardt | 1dc0a1b | 2017-10-18 18:13:17 +0200 | [diff] [blame] | 24 | |
| 25 | @pytest.mark.buildconfigspec('cmd_bootefi_selftest') |
Heinrich Schuchardt | 604c8e7 | 2020-08-07 23:11:35 +0200 | [diff] [blame] | 26 | @pytest.mark.buildconfigspec('hush_parser') |
Heinrich Schuchardt | 43d2799 | 2018-03-03 15:29:04 +0100 | [diff] [blame] | 27 | @pytest.mark.buildconfigspec('of_control') |
Heinrich Schuchardt | 1c111f9 | 2019-04-20 13:33:55 +0200 | [diff] [blame] | 28 | @pytest.mark.notbuildconfigspec('generate_acpi_table') |
Heinrich Schuchardt | 43d2799 | 2018-03-03 15:29:04 +0100 | [diff] [blame] | 29 | def test_efi_selftest_device_tree(u_boot_console): |
Heinrich Schuchardt | ba41e3e | 2020-01-25 21:58:56 +0100 | [diff] [blame] | 30 | """Test the device tree support in the UEFI sub-system |
| 31 | |
| 32 | :param u_boot_console: U-Boot console |
| 33 | |
| 34 | This test executes the UEFI unit test by calling 'bootefi selftest'. |
| 35 | """ |
| 36 | u_boot_console.run_command(cmd='setenv efi_selftest list') |
| 37 | output = u_boot_console.run_command('bootefi selftest') |
| 38 | assert '\'device tree\'' in output |
| 39 | u_boot_console.run_command(cmd='setenv efi_selftest device tree') |
Heinrich Schuchardt | 604c8e7 | 2020-08-07 23:11:35 +0200 | [diff] [blame] | 40 | # Set serial# if it is not already set. |
| 41 | u_boot_console.run_command(cmd='setenv efi_test "${serial#}x"') |
| 42 | u_boot_console.run_command(cmd='test "${efi_test}" = x && setenv serial# 0') |
Heinrich Schuchardt | ba41e3e | 2020-01-25 21:58:56 +0100 | [diff] [blame] | 43 | u_boot_console.run_command(cmd='bootefi selftest ${fdtcontroladdr}', wait_for_prompt=False) |
Heinrich Schuchardt | 604c8e7 | 2020-08-07 23:11:35 +0200 | [diff] [blame] | 44 | m = u_boot_console.p.expect(['serial-number:', 'U-Boot']) |
Heinrich Schuchardt | ba41e3e | 2020-01-25 21:58:56 +0100 | [diff] [blame] | 45 | if m != 0: |
| 46 | raise Exception('serial-number missing in device tree') |
| 47 | u_boot_console.restart_uboot() |
Heinrich Schuchardt | 43d2799 | 2018-03-03 15:29:04 +0100 | [diff] [blame] | 48 | |
| 49 | @pytest.mark.buildconfigspec('cmd_bootefi_selftest') |
Heinrich Schuchardt | 1dc0a1b | 2017-10-18 18:13:17 +0200 | [diff] [blame] | 50 | def test_efi_selftest_watchdog_reboot(u_boot_console): |
Heinrich Schuchardt | ba41e3e | 2020-01-25 21:58:56 +0100 | [diff] [blame] | 51 | """Test the watchdog timer |
| 52 | |
| 53 | :param u_boot_console: U-Boot console |
| 54 | |
| 55 | This function executes the 'watchdog reboot' unit test. |
| 56 | """ |
| 57 | u_boot_console.run_command(cmd='setenv efi_selftest list') |
| 58 | output = u_boot_console.run_command('bootefi selftest') |
| 59 | assert '\'watchdog reboot\'' in output |
| 60 | u_boot_console.run_command(cmd='setenv efi_selftest watchdog reboot') |
| 61 | u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False) |
| 62 | m = u_boot_console.p.expect(['resetting', 'U-Boot']) |
| 63 | if m != 0: |
| 64 | raise Exception('Reset failed in \'watchdog reboot\' test') |
| 65 | u_boot_console.restart_uboot() |
Heinrich Schuchardt | 5e450d4 | 2018-09-06 20:19:31 +0200 | [diff] [blame] | 66 | |
| 67 | @pytest.mark.buildconfigspec('cmd_bootefi_selftest') |
| 68 | def test_efi_selftest_text_input(u_boot_console): |
Heinrich Schuchardt | ba41e3e | 2020-01-25 21:58:56 +0100 | [diff] [blame] | 69 | """Test the EFI_SIMPLE_TEXT_INPUT_PROTOCOL |
Heinrich Schuchardt | 5e450d4 | 2018-09-06 20:19:31 +0200 | [diff] [blame] | 70 | |
Heinrich Schuchardt | ba41e3e | 2020-01-25 21:58:56 +0100 | [diff] [blame] | 71 | :param u_boot_console: U-Boot console |
Heinrich Schuchardt | 5e450d4 | 2018-09-06 20:19:31 +0200 | [diff] [blame] | 72 | |
Heinrich Schuchardt | ba41e3e | 2020-01-25 21:58:56 +0100 | [diff] [blame] | 73 | This function calls the text input EFI selftest. |
| 74 | """ |
| 75 | u_boot_console.run_command(cmd='setenv efi_selftest text input') |
Heinrich Schuchardt | 9460c18 | 2021-11-22 08:24:08 +0100 | [diff] [blame] | 76 | u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False) |
Heinrich Schuchardt | ba41e3e | 2020-01-25 21:58:56 +0100 | [diff] [blame] | 77 | m = u_boot_console.p.expect([r'To terminate type \'x\'']) |
| 78 | if m != 0: |
| 79 | raise Exception('No prompt for \'text input\' test') |
| 80 | u_boot_console.drain_console() |
| 81 | u_boot_console.p.timeout = 500 |
| 82 | # EOT |
| 83 | u_boot_console.run_command(cmd=chr(4), wait_for_echo=False, |
| 84 | send_nl=False, wait_for_prompt=False) |
| 85 | m = u_boot_console.p.expect( |
| 86 | [r'Unicode char 4 \(unknown\), scan code 0 \(Null\)']) |
| 87 | if m != 0: |
| 88 | raise Exception('EOT failed in \'text input\' test') |
| 89 | u_boot_console.drain_console() |
| 90 | # BS |
| 91 | u_boot_console.run_command(cmd=chr(8), wait_for_echo=False, |
| 92 | send_nl=False, wait_for_prompt=False) |
| 93 | m = u_boot_console.p.expect( |
| 94 | [r'Unicode char 8 \(BS\), scan code 0 \(Null\)']) |
| 95 | if m != 0: |
| 96 | raise Exception('BS failed in \'text input\' test') |
| 97 | u_boot_console.drain_console() |
| 98 | # TAB |
| 99 | u_boot_console.run_command(cmd=chr(9), wait_for_echo=False, |
| 100 | send_nl=False, wait_for_prompt=False) |
| 101 | m = u_boot_console.p.expect( |
| 102 | [r'Unicode char 9 \(TAB\), scan code 0 \(Null\)']) |
| 103 | if m != 0: |
| 104 | raise Exception('BS failed in \'text input\' test') |
| 105 | u_boot_console.drain_console() |
| 106 | # a |
| 107 | u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False, |
| 108 | wait_for_prompt=False) |
| 109 | m = u_boot_console.p.expect( |
| 110 | [r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)']) |
| 111 | if m != 0: |
| 112 | raise Exception('\'a\' failed in \'text input\' test') |
| 113 | u_boot_console.drain_console() |
| 114 | # UP escape sequence |
| 115 | u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False, |
| 116 | send_nl=False, wait_for_prompt=False) |
| 117 | m = u_boot_console.p.expect( |
| 118 | [r'Unicode char 0 \(Null\), scan code 1 \(Up\)']) |
| 119 | if m != 0: |
| 120 | raise Exception('UP failed in \'text input\' test') |
| 121 | u_boot_console.drain_console() |
| 122 | # Euro sign |
| 123 | u_boot_console.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False, |
| 124 | send_nl=False, wait_for_prompt=False) |
| 125 | m = u_boot_console.p.expect([r'Unicode char 8364 \(\'']) |
| 126 | if m != 0: |
| 127 | raise Exception('Euro sign failed in \'text input\' test') |
| 128 | u_boot_console.drain_console() |
| 129 | u_boot_console.run_command(cmd='x', wait_for_echo=False, send_nl=False, |
| 130 | wait_for_prompt=False) |
| 131 | m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']) |
| 132 | if m != 0: |
| 133 | raise Exception('Failures occurred during the EFI selftest') |
| 134 | u_boot_console.restart_uboot() |
Heinrich Schuchardt | 7ecaf97 | 2018-09-11 22:38:11 +0200 | [diff] [blame] | 135 | |
| 136 | @pytest.mark.buildconfigspec('cmd_bootefi_selftest') |
| 137 | def test_efi_selftest_text_input_ex(u_boot_console): |
Heinrich Schuchardt | ba41e3e | 2020-01-25 21:58:56 +0100 | [diff] [blame] | 138 | """Test the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL |
Heinrich Schuchardt | 7ecaf97 | 2018-09-11 22:38:11 +0200 | [diff] [blame] | 139 | |
Heinrich Schuchardt | ba41e3e | 2020-01-25 21:58:56 +0100 | [diff] [blame] | 140 | :param u_boot_console: U-Boot console |
Heinrich Schuchardt | 7ecaf97 | 2018-09-11 22:38:11 +0200 | [diff] [blame] | 141 | |
Heinrich Schuchardt | ba41e3e | 2020-01-25 21:58:56 +0100 | [diff] [blame] | 142 | This function calls the extended text input EFI selftest. |
| 143 | """ |
| 144 | u_boot_console.run_command(cmd='setenv efi_selftest extended text input') |
Heinrich Schuchardt | 9460c18 | 2021-11-22 08:24:08 +0100 | [diff] [blame] | 145 | u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False) |
Heinrich Schuchardt | ba41e3e | 2020-01-25 21:58:56 +0100 | [diff] [blame] | 146 | m = u_boot_console.p.expect([r'To terminate type \'CTRL\+x\'']) |
| 147 | if m != 0: |
| 148 | raise Exception('No prompt for \'text input\' test') |
| 149 | u_boot_console.drain_console() |
| 150 | u_boot_console.p.timeout = 500 |
| 151 | # EOT |
| 152 | u_boot_console.run_command(cmd=chr(4), wait_for_echo=False, |
| 153 | send_nl=False, wait_for_prompt=False) |
| 154 | m = u_boot_console.p.expect( |
| 155 | [r'Unicode char 100 \(\'d\'\), scan code 0 \(CTRL\+Null\)']) |
| 156 | if m != 0: |
| 157 | raise Exception('EOT failed in \'text input\' test') |
| 158 | u_boot_console.drain_console() |
| 159 | # BS |
| 160 | u_boot_console.run_command(cmd=chr(8), wait_for_echo=False, |
| 161 | send_nl=False, wait_for_prompt=False) |
| 162 | m = u_boot_console.p.expect( |
| 163 | [r'Unicode char 8 \(BS\), scan code 0 \(\+Null\)']) |
| 164 | if m != 0: |
| 165 | raise Exception('BS failed in \'text input\' test') |
| 166 | u_boot_console.drain_console() |
| 167 | # TAB |
| 168 | u_boot_console.run_command(cmd=chr(9), wait_for_echo=False, |
| 169 | send_nl=False, wait_for_prompt=False) |
| 170 | m = u_boot_console.p.expect( |
| 171 | [r'Unicode char 9 \(TAB\), scan code 0 \(\+Null\)']) |
| 172 | if m != 0: |
| 173 | raise Exception('TAB failed in \'text input\' test') |
| 174 | u_boot_console.drain_console() |
| 175 | # a |
| 176 | u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False, |
| 177 | wait_for_prompt=False) |
| 178 | m = u_boot_console.p.expect( |
| 179 | [r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)']) |
| 180 | if m != 0: |
| 181 | raise Exception('\'a\' failed in \'text input\' test') |
| 182 | u_boot_console.drain_console() |
| 183 | # UP escape sequence |
| 184 | u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False, |
| 185 | send_nl=False, wait_for_prompt=False) |
| 186 | m = u_boot_console.p.expect( |
| 187 | [r'Unicode char 0 \(Null\), scan code 1 \(\+Up\)']) |
| 188 | if m != 0: |
| 189 | raise Exception('UP failed in \'text input\' test') |
| 190 | u_boot_console.drain_console() |
| 191 | # Euro sign |
| 192 | u_boot_console.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False, |
| 193 | send_nl=False, wait_for_prompt=False) |
| 194 | m = u_boot_console.p.expect([r'Unicode char 8364 \(\'']) |
| 195 | if m != 0: |
| 196 | raise Exception('Euro sign failed in \'text input\' test') |
| 197 | u_boot_console.drain_console() |
| 198 | # SHIFT+ALT+FN 5 |
| 199 | u_boot_console.run_command(cmd=b'\x1b\x5b\x31\x35\x3b\x34\x7e'.decode(), |
| 200 | wait_for_echo=False, send_nl=False, |
| 201 | wait_for_prompt=False) |
| 202 | m = u_boot_console.p.expect( |
| 203 | [r'Unicode char 0 \(Null\), scan code 15 \(SHIFT\+ALT\+FN 5\)']) |
| 204 | if m != 0: |
| 205 | raise Exception('SHIFT+ALT+FN 5 failed in \'text input\' test') |
| 206 | u_boot_console.drain_console() |
| 207 | u_boot_console.run_command(cmd=chr(24), wait_for_echo=False, send_nl=False, |
| 208 | wait_for_prompt=False) |
| 209 | m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']) |
| 210 | if m != 0: |
| 211 | raise Exception('Failures occurred during the EFI selftest') |
| 212 | u_boot_console.restart_uboot() |
Heinrich Schuchardt | 8226df3 | 2021-11-15 18:26:50 +0100 | [diff] [blame] | 213 | |
| 214 | @pytest.mark.buildconfigspec('cmd_bootefi_selftest') |
| 215 | @pytest.mark.buildconfigspec('efi_tcg2_protocol') |
| 216 | def test_efi_selftest_tcg2(u_boot_console): |
| 217 | """Test the EFI_TCG2 PROTOCOL |
| 218 | |
| 219 | :param u_boot_console: U-Boot console |
| 220 | |
| 221 | This function executes the 'tcg2' unit test. |
| 222 | """ |
| 223 | u_boot_console.restart_uboot() |
| 224 | u_boot_console.run_command(cmd='setenv efi_selftest list') |
| 225 | output = u_boot_console.run_command('bootefi selftest') |
| 226 | assert '\'tcg2\'' in output |
| 227 | u_boot_console.run_command(cmd='setenv efi_selftest tcg2') |
| 228 | u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False) |
| 229 | m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']) |
| 230 | if m != 0: |
| 231 | raise Exception('Failures occurred during the EFI selftest') |
| 232 | u_boot_console.restart_uboot() |