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