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