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