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