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') |
| 10 | def test_efi_selftest(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() |
| 76 | u_boot_console.p.timeout = 500 |
| 77 | # EOT |
| 78 | u_boot_console.run_command(cmd=chr(4), wait_for_echo=False, |
| 79 | send_nl=False, wait_for_prompt=False) |
Heinrich Schuchardt | 8bf7ffd | 2022-05-08 10:40:49 +0200 | [diff] [blame^] | 80 | 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] | 81 | raise Exception('EOT failed in \'text input\' test') |
| 82 | u_boot_console.drain_console() |
| 83 | # BS |
| 84 | u_boot_console.run_command(cmd=chr(8), wait_for_echo=False, |
| 85 | send_nl=False, wait_for_prompt=False) |
Heinrich Schuchardt | 8bf7ffd | 2022-05-08 10:40:49 +0200 | [diff] [blame^] | 86 | 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] | 87 | raise Exception('BS failed in \'text input\' test') |
| 88 | u_boot_console.drain_console() |
| 89 | # TAB |
| 90 | u_boot_console.run_command(cmd=chr(9), wait_for_echo=False, |
| 91 | send_nl=False, wait_for_prompt=False) |
Heinrich Schuchardt | 8bf7ffd | 2022-05-08 10:40:49 +0200 | [diff] [blame^] | 92 | 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] | 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) |
Heinrich Schuchardt | 8bf7ffd | 2022-05-08 10:40:49 +0200 | [diff] [blame^] | 98 | 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] | 99 | raise Exception('\'a\' failed in \'text input\' test') |
| 100 | u_boot_console.drain_console() |
| 101 | # UP escape sequence |
| 102 | u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False, |
| 103 | send_nl=False, wait_for_prompt=False) |
Heinrich Schuchardt | 8bf7ffd | 2022-05-08 10:40:49 +0200 | [diff] [blame^] | 104 | 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] | 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) |
Heinrich Schuchardt | 8bf7ffd | 2022-05-08 10:40:49 +0200 | [diff] [blame^] | 110 | if u_boot_console.p.expect([r'Unicode char 8364 \(\'']): |
Heinrich Schuchardt | ba41e3e | 2020-01-25 21:58:56 +0100 | [diff] [blame] | 111 | raise Exception('Euro sign failed in \'text input\' test') |
| 112 | u_boot_console.drain_console() |
| 113 | u_boot_console.run_command(cmd='x', wait_for_echo=False, send_nl=False, |
| 114 | wait_for_prompt=False) |
Heinrich Schuchardt | 8bf7ffd | 2022-05-08 10:40:49 +0200 | [diff] [blame^] | 115 | if u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']): |
Heinrich Schuchardt | ba41e3e | 2020-01-25 21:58:56 +0100 | [diff] [blame] | 116 | raise Exception('Failures occurred during the EFI selftest') |
| 117 | u_boot_console.restart_uboot() |
Heinrich Schuchardt | 7ecaf97 | 2018-09-11 22:38:11 +0200 | [diff] [blame] | 118 | |
| 119 | @pytest.mark.buildconfigspec('cmd_bootefi_selftest') |
| 120 | def test_efi_selftest_text_input_ex(u_boot_console): |
Heinrich Schuchardt | ba41e3e | 2020-01-25 21:58:56 +0100 | [diff] [blame] | 121 | """Test the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL |
Heinrich Schuchardt | 7ecaf97 | 2018-09-11 22:38:11 +0200 | [diff] [blame] | 122 | |
Heinrich Schuchardt | 8bf7ffd | 2022-05-08 10:40:49 +0200 | [diff] [blame^] | 123 | u_boot_console -- U-Boot console |
Heinrich Schuchardt | 7ecaf97 | 2018-09-11 22:38:11 +0200 | [diff] [blame] | 124 | |
Heinrich Schuchardt | ba41e3e | 2020-01-25 21:58:56 +0100 | [diff] [blame] | 125 | This function calls the extended text input EFI selftest. |
| 126 | """ |
| 127 | u_boot_console.run_command(cmd='setenv efi_selftest extended text input') |
Heinrich Schuchardt | 9460c18 | 2021-11-22 08:24:08 +0100 | [diff] [blame] | 128 | u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False) |
Heinrich Schuchardt | 8bf7ffd | 2022-05-08 10:40:49 +0200 | [diff] [blame^] | 129 | if u_boot_console.p.expect([r'To terminate type \'CTRL\+x\'']): |
Heinrich Schuchardt | ba41e3e | 2020-01-25 21:58:56 +0100 | [diff] [blame] | 130 | raise Exception('No prompt for \'text input\' test') |
| 131 | u_boot_console.drain_console() |
| 132 | u_boot_console.p.timeout = 500 |
| 133 | # EOT |
| 134 | u_boot_console.run_command(cmd=chr(4), wait_for_echo=False, |
| 135 | send_nl=False, wait_for_prompt=False) |
Heinrich Schuchardt | 8bf7ffd | 2022-05-08 10:40:49 +0200 | [diff] [blame^] | 136 | 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] | 137 | raise Exception('EOT failed in \'text input\' test') |
| 138 | u_boot_console.drain_console() |
| 139 | # BS |
| 140 | u_boot_console.run_command(cmd=chr(8), wait_for_echo=False, |
| 141 | send_nl=False, wait_for_prompt=False) |
Heinrich Schuchardt | 8bf7ffd | 2022-05-08 10:40:49 +0200 | [diff] [blame^] | 142 | 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] | 143 | raise Exception('BS failed in \'text input\' test') |
| 144 | u_boot_console.drain_console() |
| 145 | # TAB |
| 146 | u_boot_console.run_command(cmd=chr(9), wait_for_echo=False, |
| 147 | send_nl=False, wait_for_prompt=False) |
Heinrich Schuchardt | 8bf7ffd | 2022-05-08 10:40:49 +0200 | [diff] [blame^] | 148 | 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] | 149 | raise Exception('TAB failed in \'text input\' test') |
| 150 | u_boot_console.drain_console() |
| 151 | # a |
| 152 | u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False, |
| 153 | wait_for_prompt=False) |
Heinrich Schuchardt | 8bf7ffd | 2022-05-08 10:40:49 +0200 | [diff] [blame^] | 154 | 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] | 155 | raise Exception('\'a\' failed in \'text input\' test') |
| 156 | u_boot_console.drain_console() |
| 157 | # UP escape sequence |
| 158 | u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False, |
| 159 | send_nl=False, wait_for_prompt=False) |
Heinrich Schuchardt | 8bf7ffd | 2022-05-08 10:40:49 +0200 | [diff] [blame^] | 160 | 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] | 161 | raise Exception('UP failed in \'text input\' test') |
| 162 | u_boot_console.drain_console() |
| 163 | # Euro sign |
| 164 | u_boot_console.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False, |
| 165 | send_nl=False, wait_for_prompt=False) |
Heinrich Schuchardt | 8bf7ffd | 2022-05-08 10:40:49 +0200 | [diff] [blame^] | 166 | if u_boot_console.p.expect([r'Unicode char 8364 \(\'']): |
Heinrich Schuchardt | ba41e3e | 2020-01-25 21:58:56 +0100 | [diff] [blame] | 167 | raise Exception('Euro sign failed in \'text input\' test') |
| 168 | u_boot_console.drain_console() |
| 169 | # SHIFT+ALT+FN 5 |
| 170 | u_boot_console.run_command(cmd=b'\x1b\x5b\x31\x35\x3b\x34\x7e'.decode(), |
| 171 | wait_for_echo=False, send_nl=False, |
| 172 | wait_for_prompt=False) |
Heinrich Schuchardt | 8bf7ffd | 2022-05-08 10:40:49 +0200 | [diff] [blame^] | 173 | 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] | 174 | raise Exception('SHIFT+ALT+FN 5 failed in \'text input\' test') |
| 175 | u_boot_console.drain_console() |
| 176 | u_boot_console.run_command(cmd=chr(24), wait_for_echo=False, send_nl=False, |
| 177 | wait_for_prompt=False) |
Heinrich Schuchardt | 8bf7ffd | 2022-05-08 10:40:49 +0200 | [diff] [blame^] | 178 | if u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']): |
Heinrich Schuchardt | ba41e3e | 2020-01-25 21:58:56 +0100 | [diff] [blame] | 179 | raise Exception('Failures occurred during the EFI selftest') |
| 180 | u_boot_console.restart_uboot() |
Heinrich Schuchardt | 8226df3 | 2021-11-15 18:26:50 +0100 | [diff] [blame] | 181 | |
| 182 | @pytest.mark.buildconfigspec('cmd_bootefi_selftest') |
| 183 | @pytest.mark.buildconfigspec('efi_tcg2_protocol') |
| 184 | def test_efi_selftest_tcg2(u_boot_console): |
| 185 | """Test the EFI_TCG2 PROTOCOL |
| 186 | |
Heinrich Schuchardt | 8bf7ffd | 2022-05-08 10:40:49 +0200 | [diff] [blame^] | 187 | u_boot_console -- U-Boot console |
Heinrich Schuchardt | 8226df3 | 2021-11-15 18:26:50 +0100 | [diff] [blame] | 188 | |
| 189 | This function executes the 'tcg2' unit test. |
| 190 | """ |
| 191 | u_boot_console.restart_uboot() |
| 192 | u_boot_console.run_command(cmd='setenv efi_selftest list') |
| 193 | output = u_boot_console.run_command('bootefi selftest') |
| 194 | assert '\'tcg2\'' in output |
| 195 | u_boot_console.run_command(cmd='setenv efi_selftest tcg2') |
| 196 | u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False) |
Heinrich Schuchardt | 8bf7ffd | 2022-05-08 10:40:49 +0200 | [diff] [blame^] | 197 | if u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']): |
Heinrich Schuchardt | 8226df3 | 2021-11-15 18:26:50 +0100 | [diff] [blame] | 198 | raise Exception('Failures occurred during the EFI selftest') |
| 199 | u_boot_console.restart_uboot() |