Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
| 2 | # (C) Copyright 2023, Advanced Micro Devices, Inc. |
| 3 | |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 4 | """ |
| 5 | Note: This test relies on boardenv_* containing configuration values to define |
| 6 | which the network environment available for testing. Without this, this test |
| 7 | will be automatically skipped. |
| 8 | |
| 9 | For example: |
| 10 | |
Tom Rini | 562f265 | 2025-05-07 16:08:19 -0600 | [diff] [blame^] | 11 | .. code-block:: python |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 12 | |
Tom Rini | 562f265 | 2025-05-07 16:08:19 -0600 | [diff] [blame^] | 13 | # Details regarding a boot image file that may be read from a TFTP server. This |
| 14 | # variable may be omitted or set to None if TFTP boot testing is not possible |
| 15 | # or desired. |
| 16 | env__net_tftp_bootable_file = { |
| 17 | 'fn': 'image.ub', |
| 18 | 'addr': 0x10000000, |
| 19 | 'size': 5058624, |
| 20 | 'crc32': 'c2244b26', |
| 21 | 'pattern': 'Linux', |
| 22 | 'config': 'config@2', |
| 23 | 'timeout': 50000, |
| 24 | 'check_type': 'boot_error', |
| 25 | 'check_pattern': 'ERROR', |
| 26 | } |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 27 | |
Tom Rini | 562f265 | 2025-05-07 16:08:19 -0600 | [diff] [blame^] | 28 | # False or omitted if a TFTP boot test should be tested. |
| 29 | # If TFTP boot testing is not possible or desired, set this variable to True. |
| 30 | # For example: If FIT image is not proper to boot |
| 31 | env__tftp_boot_test_skip = False |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 32 | |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 33 | |
Tom Rini | 562f265 | 2025-05-07 16:08:19 -0600 | [diff] [blame^] | 34 | Here is the example of FIT image configurations: |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 35 | |
Tom Rini | 562f265 | 2025-05-07 16:08:19 -0600 | [diff] [blame^] | 36 | .. code-block:: devicetree |
| 37 | |
| 38 | configurations { |
| 39 | default = "config@1"; |
| 40 | config@1 { |
| 41 | description = "Boot Linux kernel with config@1"; |
| 42 | kernel = "kernel@0"; |
| 43 | fdt = "fdt@0"; |
| 44 | ramdisk = "ramdisk@0"; |
| 45 | hash@1 { |
| 46 | algo = "sha1"; |
| 47 | }; |
| 48 | }; |
| 49 | config@2 { |
| 50 | description = "Boot Linux kernel with config@2"; |
| 51 | kernel = "kernel@1"; |
| 52 | fdt = "fdt@1"; |
| 53 | ramdisk = "ramdisk@1"; |
| 54 | hash@1 { |
| 55 | algo = "sha1"; |
| 56 | }; |
| 57 | }; |
| 58 | }; |
| 59 | |
| 60 | .. code-block:: python |
| 61 | |
| 62 | # Details regarding a file that may be read from a TFTP server. This variable |
| 63 | # may be omitted or set to None if PXE testing is not possible or desired. |
| 64 | env__net_pxe_bootable_file = { |
| 65 | 'fn': 'default', |
| 66 | 'addr': 0x10000000, |
| 67 | 'size': 74, |
| 68 | 'timeout': 50000, |
| 69 | 'pattern': 'Linux', |
| 70 | 'valid_label': '1', |
| 71 | 'invalid_label': '2', |
| 72 | 'exp_str_invalid': 'Skipping install for failure retrieving', |
| 73 | 'local_label': '3', |
| 74 | 'exp_str_local': 'missing environment variable: localcmd', |
| 75 | 'empty_label': '4', |
| 76 | 'exp_str_empty': 'No kernel given, skipping boot', |
| 77 | 'check_type': 'boot_error', |
| 78 | 'check_pattern': 'ERROR', |
| 79 | } |
| 80 | |
| 81 | # False if a PXE boot test should be tested. |
| 82 | # If PXE boot testing is not possible or desired, set this variable to True. |
| 83 | # For example: If pxe configuration file is not proper to boot |
| 84 | env__pxe_boot_test_skip = False |
| 85 | |
| 86 | Here is the example of pxe configuration file ordered based on the execution |
| 87 | flow: |
| 88 | |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 89 | 1) /tftpboot/pxelinux.cfg/default-arm-zynqmp |
| 90 | |
Tom Rini | 562f265 | 2025-05-07 16:08:19 -0600 | [diff] [blame^] | 91 | .. code-block:: |
| 92 | |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 93 | menu include pxelinux.cfg/default-arm |
| 94 | timeout 50 |
| 95 | |
| 96 | default Linux |
| 97 | |
| 98 | 2) /tftpboot/pxelinux.cfg/default-arm |
| 99 | |
Tom Rini | 562f265 | 2025-05-07 16:08:19 -0600 | [diff] [blame^] | 100 | .. code-block:: |
| 101 | |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 102 | menu title Linux boot selections |
| 103 | menu include pxelinux.cfg/default |
| 104 | |
| 105 | label install |
| 106 | menu label Invalid boot |
| 107 | kernel kernels/install.bin |
| 108 | append console=ttyAMA0,38400 debug earlyprintk |
| 109 | initrd initrds/uzInitrdDebInstall |
| 110 | |
| 111 | label local |
| 112 | menu label Local boot |
| 113 | append root=/dev/sdb1 |
| 114 | localboot 1 |
| 115 | |
| 116 | label boot |
| 117 | menu label Empty boot |
| 118 | |
| 119 | 3) /tftpboot/pxelinux.cfg/default |
| 120 | |
Tom Rini | 562f265 | 2025-05-07 16:08:19 -0600 | [diff] [blame^] | 121 | .. code-block:: |
| 122 | |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 123 | label Linux |
| 124 | menu label Boot kernel |
| 125 | kernel Image |
| 126 | fdt system.dtb |
| 127 | initrd rootfs.cpio.gz.u-boot |
| 128 | """ |
| 129 | |
Tom Rini | 562f265 | 2025-05-07 16:08:19 -0600 | [diff] [blame^] | 130 | import pytest |
| 131 | import utils |
| 132 | import test_net |
| 133 | import re |
| 134 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 135 | def setup_networking(ubman): |
| 136 | test_net.test_net_dhcp(ubman) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 137 | if not test_net.net_set_up: |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 138 | test_net.test_net_setup_static(ubman) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 139 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 140 | def setup_tftpboot_boot(ubman): |
| 141 | f = ubman.config.env.get('env__net_tftp_bootable_file', None) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 142 | if not f: |
| 143 | pytest.skip('No TFTP bootable file to read') |
| 144 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 145 | setup_networking(ubman) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 146 | addr = f.get('addr', None) |
| 147 | if not addr: |
Simon Glass | fb91637 | 2025-02-09 09:07:15 -0700 | [diff] [blame] | 148 | addr = utils.find_ram_base(ubman) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 149 | |
| 150 | fn = f['fn'] |
| 151 | timeout = f.get('timeout', 50000) |
| 152 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 153 | with ubman.temporary_timeout(timeout): |
| 154 | output = ubman.run_command('tftpboot %x %s' % (addr, fn)) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 155 | |
| 156 | expected_text = 'Bytes transferred = ' |
| 157 | sz = f.get('size', None) |
| 158 | if sz: |
| 159 | expected_text += '%d' % sz |
| 160 | assert expected_text in output |
| 161 | |
| 162 | expected_crc = f.get('crc32', None) |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 163 | output = ubman.run_command('crc32 %x $filesize' % addr) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 164 | if expected_crc: |
| 165 | assert expected_crc in output |
| 166 | |
| 167 | pattern = f.get('pattern') |
| 168 | chk_type = f.get('check_type', 'boot_error') |
| 169 | chk_pattern = re.compile(f.get('check_pattern', 'ERROR')) |
| 170 | config = f.get('config', None) |
| 171 | |
| 172 | return addr, timeout, pattern, chk_type, chk_pattern, config |
| 173 | |
Tom Rini | 5568cc3 | 2024-06-18 14:23:43 -0600 | [diff] [blame] | 174 | @pytest.mark.buildconfigspec('cmd_tftpboot') |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 175 | def test_net_tftpboot_boot(ubman): |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 176 | """Boot the loaded image |
| 177 | |
| 178 | A boot file (fit image) is downloaded from the TFTP server and booted using |
| 179 | bootm command with the default fit configuration, its boot log pattern are |
| 180 | validated. |
| 181 | |
| 182 | The details of the file to download are provided by the boardenv_* file; |
| 183 | see the comment at the beginning of this file. |
| 184 | """ |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 185 | if ubman.config.env.get('env__tftp_boot_test_skip', True): |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 186 | pytest.skip('TFTP boot test is not enabled!') |
| 187 | |
| 188 | addr, timeout, pattern, chk_type, chk_pattern, imcfg = setup_tftpboot_boot( |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 189 | ubman |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 190 | ) |
| 191 | |
| 192 | if imcfg: |
| 193 | bootcmd = 'bootm %x#%s' % (addr, imcfg) |
| 194 | else: |
| 195 | bootcmd = 'bootm %x' % addr |
| 196 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 197 | with ubman.enable_check( |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 198 | chk_type, chk_pattern |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 199 | ), ubman.temporary_timeout(timeout): |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 200 | try: |
| 201 | # wait_for_prompt=False makes the core code not wait for the U-Boot |
| 202 | # prompt code to be seen, since it won't be on a successful kernel |
| 203 | # boot |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 204 | ubman.run_command(bootcmd, wait_for_prompt=False) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 205 | |
| 206 | # Wait for boot log pattern |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 207 | ubman.wait_for(pattern) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 208 | finally: |
| 209 | # This forces the console object to be shutdown, so any subsequent |
| 210 | # test will reset the board back into U-Boot. We want to force this |
| 211 | # no matter whether the kernel boot passed or failed. |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 212 | ubman.drain_console() |
| 213 | ubman.cleanup_spawn() |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 214 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 215 | def setup_pxe_boot(ubman): |
| 216 | f = ubman.config.env.get('env__net_pxe_bootable_file', None) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 217 | if not f: |
| 218 | pytest.skip('No PXE bootable file to read') |
| 219 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 220 | setup_networking(ubman) |
| 221 | bootfile = ubman.run_command('echo $bootfile') |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 222 | if not bootfile: |
| 223 | bootfile = '<NULL>' |
| 224 | |
| 225 | return f, bootfile |
| 226 | |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 227 | @pytest.mark.buildconfigspec('cmd_pxe') |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 228 | def test_net_pxe_boot(ubman): |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 229 | """Test the pxe boot command. |
| 230 | |
| 231 | A pxe configuration file is downloaded from the TFTP server and interpreted |
| 232 | to boot the images mentioned in pxe configuration file. |
| 233 | |
| 234 | The details of the file to download are provided by the boardenv_* file; |
| 235 | see the comment at the beginning of this file. |
| 236 | """ |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 237 | if ubman.config.env.get('env__pxe_boot_test_skip', True): |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 238 | pytest.skip('PXE boot test is not enabled!') |
| 239 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 240 | f, bootfile = setup_pxe_boot(ubman) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 241 | addr = f.get('addr', None) |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 242 | timeout = f.get('timeout', ubman.p.timeout) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 243 | fn = f['fn'] |
| 244 | |
| 245 | if addr: |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 246 | ubman.run_command('setenv pxefile_addr_r %x' % addr) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 247 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 248 | with ubman.temporary_timeout(timeout): |
| 249 | output = ubman.run_command('pxe get') |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 250 | |
| 251 | expected_text = 'Bytes transferred = ' |
| 252 | sz = f.get('size', None) |
| 253 | if sz: |
| 254 | expected_text += '%d' % sz |
| 255 | assert 'TIMEOUT' not in output |
| 256 | assert expected_text in output |
| 257 | assert f"Config file '{bootfile}' found" in output |
| 258 | |
| 259 | pattern = f.get('pattern') |
| 260 | chk_type = f.get('check_type', 'boot_error') |
| 261 | chk_pattern = re.compile(f.get('check_pattern', 'ERROR')) |
| 262 | |
| 263 | if not addr: |
| 264 | pxe_boot_cmd = 'pxe boot' |
| 265 | else: |
| 266 | pxe_boot_cmd = 'pxe boot %x' % addr |
| 267 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 268 | with ubman.enable_check( |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 269 | chk_type, chk_pattern |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 270 | ), ubman.temporary_timeout(timeout): |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 271 | try: |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 272 | ubman.run_command(pxe_boot_cmd, wait_for_prompt=False) |
| 273 | ubman.wait_for(pattern) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 274 | finally: |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 275 | ubman.drain_console() |
| 276 | ubman.cleanup_spawn() |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 277 | |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 278 | @pytest.mark.buildconfigspec('cmd_pxe') |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 279 | def test_net_pxe_boot_config(ubman): |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 280 | """Test the pxe boot command by selecting different combination of labels |
| 281 | |
| 282 | A pxe configuration file is downloaded from the TFTP server and interpreted |
| 283 | to boot the images mentioned in pxe configuration file. |
| 284 | |
| 285 | The details of the file to download are provided by the boardenv_* file; |
| 286 | see the comment at the beginning of this file. |
| 287 | """ |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 288 | if ubman.config.env.get('env__pxe_boot_test_skip', True): |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 289 | pytest.skip('PXE boot test is not enabled!') |
| 290 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 291 | f, bootfile = setup_pxe_boot(ubman) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 292 | addr = f.get('addr', None) |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 293 | timeout = f.get('timeout', ubman.p.timeout) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 294 | fn = f['fn'] |
| 295 | local_label = f['local_label'] |
| 296 | empty_label = f['empty_label'] |
| 297 | exp_str_local = f['exp_str_local'] |
| 298 | exp_str_empty = f['exp_str_empty'] |
| 299 | |
| 300 | if addr: |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 301 | ubman.run_command('setenv pxefile_addr_r %x' % addr) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 302 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 303 | with ubman.temporary_timeout(timeout): |
| 304 | output = ubman.run_command('pxe get') |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 305 | |
| 306 | expected_text = 'Bytes transferred = ' |
| 307 | sz = f.get('size', None) |
| 308 | if sz: |
| 309 | expected_text += '%d' % sz |
| 310 | assert 'TIMEOUT' not in output |
| 311 | assert expected_text in output |
| 312 | assert f"Config file '{bootfile}' found" in output |
| 313 | |
| 314 | pattern = f.get('pattern') |
| 315 | chk_type = f.get('check_type', 'boot_error') |
| 316 | chk_pattern = re.compile(f.get('check_pattern', 'ERROR')) |
| 317 | |
| 318 | if not addr: |
| 319 | pxe_boot_cmd = 'pxe boot' |
| 320 | else: |
| 321 | pxe_boot_cmd = 'pxe boot %x' % addr |
| 322 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 323 | with ubman.enable_check( |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 324 | chk_type, chk_pattern |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 325 | ), ubman.temporary_timeout(timeout): |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 326 | try: |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 327 | ubman.run_command(pxe_boot_cmd, wait_for_prompt=False) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 328 | |
| 329 | # pxe config is loaded where multiple labels are there and need to |
| 330 | # select particular label to boot and check for expected string |
| 331 | # In this case, local label is selected and it should look for |
| 332 | # localcmd env variable and if that variable is not defined it |
| 333 | # should not boot it and come out to u-boot prompt |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 334 | ubman.wait_for('Enter choice:') |
| 335 | ubman.run_command(local_label, wait_for_prompt=False) |
| 336 | expected_str = ubman.p.expect([exp_str_local]) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 337 | assert ( |
| 338 | expected_str == 0 |
| 339 | ), f'Expected string: {exp_str_local} did not match!' |
| 340 | |
| 341 | # In this case, empty label is selected and it should look for |
| 342 | # kernel image path and if it is not set it should fail it and load |
| 343 | # default label to boot |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 344 | ubman.run_command(pxe_boot_cmd, wait_for_prompt=False) |
| 345 | ubman.wait_for('Enter choice:') |
| 346 | ubman.run_command(empty_label, wait_for_prompt=False) |
| 347 | expected_str = ubman.p.expect([exp_str_empty]) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 348 | assert ( |
| 349 | expected_str == 0 |
| 350 | ), f'Expected string: {exp_str_empty} did not match!' |
| 351 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 352 | ubman.wait_for(pattern) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 353 | finally: |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 354 | ubman.drain_console() |
| 355 | ubman.cleanup_spawn() |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 356 | |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 357 | @pytest.mark.buildconfigspec('cmd_pxe') |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 358 | def test_net_pxe_boot_config_invalid(ubman): |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 359 | """Test the pxe boot command by selecting invalid label |
| 360 | |
| 361 | A pxe configuration file is downloaded from the TFTP server and interpreted |
| 362 | to boot the images mentioned in pxe configuration file. |
| 363 | |
| 364 | The details of the file to download are provided by the boardenv_* file; |
| 365 | see the comment at the beginning of this file. |
| 366 | """ |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 367 | if ubman.config.env.get('env__pxe_boot_test_skip', True): |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 368 | pytest.skip('PXE boot test is not enabled!') |
| 369 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 370 | f, bootfile = setup_pxe_boot(ubman) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 371 | addr = f.get('addr', None) |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 372 | timeout = f.get('timeout', ubman.p.timeout) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 373 | fn = f['fn'] |
| 374 | invalid_label = f['invalid_label'] |
| 375 | exp_str_invalid = f['exp_str_invalid'] |
| 376 | |
| 377 | if addr: |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 378 | ubman.run_command('setenv pxefile_addr_r %x' % addr) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 379 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 380 | with ubman.temporary_timeout(timeout): |
| 381 | output = ubman.run_command('pxe get') |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 382 | |
| 383 | expected_text = 'Bytes transferred = ' |
| 384 | sz = f.get('size', None) |
| 385 | if sz: |
| 386 | expected_text += '%d' % sz |
| 387 | assert 'TIMEOUT' not in output |
| 388 | assert expected_text in output |
| 389 | assert f"Config file '{bootfile}' found" in output |
| 390 | |
| 391 | pattern = f.get('pattern') |
| 392 | if not addr: |
| 393 | pxe_boot_cmd = 'pxe boot' |
| 394 | else: |
| 395 | pxe_boot_cmd = 'pxe boot %x' % addr |
| 396 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 397 | with ubman.temporary_timeout(timeout): |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 398 | try: |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 399 | ubman.run_command(pxe_boot_cmd, wait_for_prompt=False) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 400 | |
| 401 | # pxe config is loaded where multiple labels are there and need to |
| 402 | # select particular label to boot and check for expected string |
| 403 | # In this case invalid label is selected, it should load invalid |
| 404 | # label and if it fails it should load the default label to boot |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 405 | ubman.wait_for('Enter choice:') |
| 406 | ubman.run_command(invalid_label, wait_for_prompt=False) |
| 407 | expected_str = ubman.p.expect([exp_str_invalid]) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 408 | assert ( |
| 409 | expected_str == 0 |
| 410 | ), f'Expected string: {exp_str_invalid} did not match!' |
| 411 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 412 | ubman.wait_for(pattern) |
Love Kumar | b2835c5 | 2024-06-05 15:19:35 +0530 | [diff] [blame] | 413 | finally: |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 414 | ubman.drain_console() |
| 415 | ubman.cleanup_spawn() |