Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 2 | # Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 3 | |
| 4 | # Test various network-related functionality, such as the dhcp, ping, and |
| 5 | # tftpboot commands. |
| 6 | |
| 7 | import pytest |
Simon Glass | fb91637 | 2025-02-09 09:07:15 -0700 | [diff] [blame] | 8 | import utils |
Love Kumar | 55ef453 | 2023-10-03 18:42:46 +0530 | [diff] [blame] | 9 | import uuid |
Love Kumar | 49f8749 | 2023-11-08 12:40:31 +0530 | [diff] [blame] | 10 | import datetime |
Love Kumar | 4578d15 | 2024-01-30 13:37:01 +0530 | [diff] [blame] | 11 | import re |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 12 | |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 13 | """ |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 14 | Note: This test relies on boardenv_* containing configuration values to define |
Ehsan Mohandesi | 3eb5053 | 2023-04-21 17:08:22 -0700 | [diff] [blame] | 15 | which network environment is available for testing. Without this, this test |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 16 | will be automatically skipped. |
| 17 | |
| 18 | For example: |
| 19 | |
Stephen Warren | 8d57b92 | 2016-01-26 11:10:14 -0700 | [diff] [blame] | 20 | # Boolean indicating whether the Ethernet device is attached to USB, and hence |
| 21 | # USB enumeration needs to be performed prior to network tests. |
| 22 | # This variable may be omitted if its value is False. |
| 23 | env__net_uses_usb = False |
| 24 | |
| 25 | # Boolean indicating whether the Ethernet device is attached to PCI, and hence |
| 26 | # PCI enumeration needs to be performed prior to network tests. |
| 27 | # This variable may be omitted if its value is False. |
| 28 | env__net_uses_pci = True |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 29 | |
| 30 | # True if a DHCP server is attached to the network, and should be tested. |
| 31 | # If DHCP testing is not possible or desired, this variable may be omitted or |
| 32 | # set to False. |
| 33 | env__net_dhcp_server = True |
| 34 | |
Love Kumar | 4578d15 | 2024-01-30 13:37:01 +0530 | [diff] [blame] | 35 | # False or omitted if a DHCP server is attached to the network, and dhcp abort |
| 36 | # case should be tested. |
| 37 | # If DHCP abort testing is not possible or desired, set this variable to True. |
| 38 | # For example: On some setup, dhcp is too fast and this case may not work. |
| 39 | env__dhcp_abort_test_skip = True |
| 40 | |
Sean Edmond | d407acf | 2023-04-11 10:48:48 -0700 | [diff] [blame] | 41 | # True if a DHCPv6 server is attached to the network, and should be tested. |
| 42 | # If DHCPv6 testing is not possible or desired, this variable may be omitted or |
| 43 | # set to False. |
| 44 | env__net_dhcp6_server = True |
| 45 | |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 46 | # A list of environment variables that should be set in order to configure a |
| 47 | # static IP. If solely relying on DHCP, this variable may be omitted or set to |
| 48 | # an empty list. |
| 49 | env__net_static_env_vars = [ |
Simon Glass | e9f4d87 | 2018-12-27 08:11:13 -0700 | [diff] [blame] | 50 | ('ipaddr', '10.0.0.100'), |
| 51 | ('netmask', '255.255.255.0'), |
| 52 | ('serverip', '10.0.0.1'), |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 53 | ] |
| 54 | |
| 55 | # Details regarding a file that may be read from a TFTP server. This variable |
| 56 | # may be omitted or set to None if TFTP testing is not possible or desired. |
| 57 | env__net_tftp_readable_file = { |
Simon Glass | e9f4d87 | 2018-12-27 08:11:13 -0700 | [diff] [blame] | 58 | 'fn': 'ubtest-readable.bin', |
| 59 | 'addr': 0x10000000, |
| 60 | 'size': 5058624, |
| 61 | 'crc32': 'c2244b26', |
Love Kumar | 49f8749 | 2023-11-08 12:40:31 +0530 | [diff] [blame] | 62 | 'timeout': 50000, |
| 63 | 'fnu': 'ubtest-upload.bin', |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 64 | } |
Guillaume GARDET | 1b0102d | 2016-09-14 10:29:12 +0200 | [diff] [blame] | 65 | |
| 66 | # Details regarding a file that may be read from a NFS server. This variable |
| 67 | # may be omitted or set to None if NFS testing is not possible or desired. |
| 68 | env__net_nfs_readable_file = { |
Simon Glass | e9f4d87 | 2018-12-27 08:11:13 -0700 | [diff] [blame] | 69 | 'fn': 'ubtest-readable.bin', |
| 70 | 'addr': 0x10000000, |
| 71 | 'size': 5058624, |
| 72 | 'crc32': 'c2244b26', |
Guillaume GARDET | 1b0102d | 2016-09-14 10:29:12 +0200 | [diff] [blame] | 73 | } |
Ehsan Mohandesi | 3eb5053 | 2023-04-21 17:08:22 -0700 | [diff] [blame] | 74 | |
Love Kumar | 55ef453 | 2023-10-03 18:42:46 +0530 | [diff] [blame] | 75 | # Details regarding a file that may be read from a TFTP server. This variable |
| 76 | # may be omitted or set to None if PXE testing is not possible or desired. |
| 77 | env__net_pxe_readable_file = { |
| 78 | 'fn': 'default', |
| 79 | 'addr': 0x2000000, |
| 80 | 'size': 74, |
| 81 | 'timeout': 50000, |
| 82 | 'pattern': 'Linux', |
| 83 | } |
| 84 | |
Ehsan Mohandesi | 3eb5053 | 2023-04-21 17:08:22 -0700 | [diff] [blame] | 85 | # True if a router advertisement service is connected to the network, and should |
| 86 | # be tested. If router advertisement testing is not possible or desired, this |
| 87 | variable may be omitted or set to False. |
| 88 | env__router_on_net = True |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 89 | """ |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 90 | |
| 91 | net_set_up = False |
Sean Edmond | d407acf | 2023-04-11 10:48:48 -0700 | [diff] [blame] | 92 | net6_set_up = False |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 93 | |
Simon Glass | 86bf4ef | 2025-02-09 09:07:19 -0700 | [diff] [blame] | 94 | |
| 95 | @pytest.mark.buildconfigspec('cmd_net') |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 96 | def test_net_pre_commands(ubman): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 97 | """Execute any commands required to enable network hardware. |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 98 | |
| 99 | These commands are provided by the boardenv_* file; see the comment at the |
| 100 | beginning of this file. |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 101 | """ |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 102 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 103 | init_usb = ubman.config.env.get('env__net_uses_usb', False) |
Stephen Warren | 8d57b92 | 2016-01-26 11:10:14 -0700 | [diff] [blame] | 104 | if init_usb: |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 105 | ubman.run_command('usb start') |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 106 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 107 | init_pci = ubman.config.env.get('env__net_uses_pci', False) |
Stephen Warren | 8d57b92 | 2016-01-26 11:10:14 -0700 | [diff] [blame] | 108 | if init_pci: |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 109 | ubman.run_command('pci enum') |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 110 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 111 | ubman.run_command('net list') |
Maxim Uvarov | b5977fc | 2023-12-26 21:46:12 +0600 | [diff] [blame] | 112 | |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 113 | @pytest.mark.buildconfigspec('cmd_dhcp') |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 114 | def test_net_dhcp(ubman): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 115 | """Test the dhcp command. |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 116 | |
| 117 | The boardenv_* file may be used to enable/disable this test; see the |
| 118 | comment at the beginning of this file. |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 119 | """ |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 120 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 121 | test_dhcp = ubman.config.env.get('env__net_dhcp_server', False) |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 122 | if not test_dhcp: |
| 123 | pytest.skip('No DHCP server available') |
| 124 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 125 | ubman.run_command('setenv autoload no') |
| 126 | output = ubman.run_command('dhcp') |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 127 | assert 'DHCP client bound to address ' in output |
| 128 | |
| 129 | global net_set_up |
| 130 | net_set_up = True |
| 131 | |
Love Kumar | 4578d15 | 2024-01-30 13:37:01 +0530 | [diff] [blame] | 132 | @pytest.mark.buildconfigspec('cmd_dhcp') |
| 133 | @pytest.mark.buildconfigspec('cmd_mii') |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 134 | def test_net_dhcp_abort(ubman): |
Love Kumar | 4578d15 | 2024-01-30 13:37:01 +0530 | [diff] [blame] | 135 | """Test the dhcp command by pressing ctrl+c in the middle of dhcp request |
| 136 | |
| 137 | The boardenv_* file may be used to enable/disable this test; see the |
| 138 | comment at the beginning of this file. |
| 139 | """ |
| 140 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 141 | test_dhcp = ubman.config.env.get('env__net_dhcp_server', False) |
Love Kumar | 4578d15 | 2024-01-30 13:37:01 +0530 | [diff] [blame] | 142 | if not test_dhcp: |
| 143 | pytest.skip('No DHCP server available') |
| 144 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 145 | if ubman.config.env.get('env__dhcp_abort_test_skip', True): |
Love Kumar | 4578d15 | 2024-01-30 13:37:01 +0530 | [diff] [blame] | 146 | pytest.skip('DHCP abort test is not enabled!') |
| 147 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 148 | ubman.run_command('setenv autoload no') |
Love Kumar | 4578d15 | 2024-01-30 13:37:01 +0530 | [diff] [blame] | 149 | |
| 150 | # Phy reset before running dhcp command |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 151 | output = ubman.run_command('mii device') |
Love Kumar | 4578d15 | 2024-01-30 13:37:01 +0530 | [diff] [blame] | 152 | if not re.search(r"Current device: '(.+?)'", output): |
| 153 | pytest.skip('PHY device does not exist!') |
| 154 | eth_num = re.search(r"Current device: '(.+?)'", output).groups()[0] |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 155 | ubman.run_command(f'mii device {eth_num}') |
| 156 | output = ubman.run_command('mii info') |
Love Kumar | 4578d15 | 2024-01-30 13:37:01 +0530 | [diff] [blame] | 157 | eth_addr = hex(int(re.search(r'PHY (.+?):', output).groups()[0], 16)) |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 158 | ubman.run_command(f'mii modify {eth_addr} 0 0x8000 0x8000') |
Love Kumar | 4578d15 | 2024-01-30 13:37:01 +0530 | [diff] [blame] | 159 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 160 | ubman.run_command('dhcp', wait_for_prompt=False) |
Love Kumar | 4578d15 | 2024-01-30 13:37:01 +0530 | [diff] [blame] | 161 | try: |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 162 | ubman.wait_for('Waiting for PHY auto negotiation to complete') |
Love Kumar | 4578d15 | 2024-01-30 13:37:01 +0530 | [diff] [blame] | 163 | except: |
| 164 | pytest.skip('Timeout waiting for PHY auto negotiation to complete') |
| 165 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 166 | ubman.wait_for('done') |
Love Kumar | 4578d15 | 2024-01-30 13:37:01 +0530 | [diff] [blame] | 167 | |
| 168 | try: |
| 169 | # Sending Ctrl-C |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 170 | output = ubman.run_command( |
Love Kumar | 4578d15 | 2024-01-30 13:37:01 +0530 | [diff] [blame] | 171 | chr(3), wait_for_echo=False, send_nl=False |
| 172 | ) |
| 173 | assert 'TIMEOUT' not in output |
| 174 | assert 'DHCP client bound to address ' not in output |
| 175 | assert 'Abort' in output |
| 176 | finally: |
| 177 | # Provide a time to recover from Abort - if it is not performed |
| 178 | # There is message like: ethernet@ff0e0000: No link. |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 179 | ubman.run_command('sleep 1') |
Love Kumar | 4578d15 | 2024-01-30 13:37:01 +0530 | [diff] [blame] | 180 | # Run the dhcp test to setup the network configuration |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 181 | test_net_dhcp(ubman) |
Love Kumar | 4578d15 | 2024-01-30 13:37:01 +0530 | [diff] [blame] | 182 | |
Sean Edmond | d407acf | 2023-04-11 10:48:48 -0700 | [diff] [blame] | 183 | @pytest.mark.buildconfigspec('cmd_dhcp6') |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 184 | def test_net_dhcp6(ubman): |
Sean Edmond | d407acf | 2023-04-11 10:48:48 -0700 | [diff] [blame] | 185 | """Test the dhcp6 command. |
| 186 | |
| 187 | The boardenv_* file may be used to enable/disable this test; see the |
| 188 | comment at the beginning of this file. |
| 189 | """ |
| 190 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 191 | test_dhcp6 = ubman.config.env.get('env__net_dhcp6_server', False) |
Sean Edmond | d407acf | 2023-04-11 10:48:48 -0700 | [diff] [blame] | 192 | if not test_dhcp6: |
| 193 | pytest.skip('No DHCP6 server available') |
| 194 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 195 | ubman.run_command('setenv autoload no') |
| 196 | output = ubman.run_command('dhcp6') |
Sean Edmond | d407acf | 2023-04-11 10:48:48 -0700 | [diff] [blame] | 197 | assert 'DHCP6 client bound to ' in output |
| 198 | |
| 199 | global net6_set_up |
| 200 | net6_set_up = True |
| 201 | |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 202 | @pytest.mark.buildconfigspec('net') |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 203 | def test_net_setup_static(ubman): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 204 | """Set up a static IP configuration. |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 205 | |
| 206 | The configuration is provided by the boardenv_* file; see the comment at |
| 207 | the beginning of this file. |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 208 | """ |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 209 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 210 | env_vars = ubman.config.env.get('env__net_static_env_vars', None) |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 211 | if not env_vars: |
| 212 | pytest.skip('No static network configuration is defined') |
| 213 | |
| 214 | for (var, val) in env_vars: |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 215 | ubman.run_command('setenv %s %s' % (var, val)) |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 216 | |
| 217 | global net_set_up |
| 218 | net_set_up = True |
| 219 | |
| 220 | @pytest.mark.buildconfigspec('cmd_ping') |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 221 | def test_net_ping(ubman): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 222 | """Test the ping command. |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 223 | |
| 224 | The $serverip (as set up by either test_net_dhcp or test_net_setup_static) |
| 225 | is pinged. The test validates that the host is alive, as reported by the |
| 226 | ping command's output. |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 227 | """ |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 228 | |
| 229 | if not net_set_up: |
Stephen Warren | 3deb896 | 2016-01-26 13:41:31 -0700 | [diff] [blame] | 230 | pytest.skip('Network not initialized') |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 231 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 232 | output = ubman.run_command('ping $serverip') |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 233 | assert 'is alive' in output |
| 234 | |
Ehsan Mohandesi | 3eb5053 | 2023-04-21 17:08:22 -0700 | [diff] [blame] | 235 | @pytest.mark.buildconfigspec('IPV6_ROUTER_DISCOVERY') |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 236 | def test_net_network_discovery(ubman): |
Ehsan Mohandesi | 3eb5053 | 2023-04-21 17:08:22 -0700 | [diff] [blame] | 237 | """Test the network discovery feature of IPv6. |
| 238 | |
| 239 | An IPv6 network command (ping6 in this case) is run to make U-Boot send a |
| 240 | router solicitation packet, receive a router advertisement message, and |
| 241 | parse it. |
| 242 | A router advertisement service needs to be running for this test to succeed. |
| 243 | U-Boot receives the RA, processes it, and if successful, assigns the gateway |
| 244 | IP and prefix length. |
| 245 | The configuration is provided by the boardenv_* file; see the comment at |
| 246 | the beginning of this file. |
| 247 | """ |
| 248 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 249 | router_on_net = ubman.config.env.get('env__router_on_net', False) |
Ehsan Mohandesi | 3eb5053 | 2023-04-21 17:08:22 -0700 | [diff] [blame] | 250 | if not router_on_net: |
| 251 | pytest.skip('No router on network') |
| 252 | |
| 253 | fake_host_ip = 'fe80::215:5dff:fef6:2ec6' |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 254 | output = ubman.run_command('ping6 ' + fake_host_ip) |
Ehsan Mohandesi | 3eb5053 | 2023-04-21 17:08:22 -0700 | [diff] [blame] | 255 | assert 'ROUTER SOLICITATION 1' in output |
| 256 | assert 'Set gatewayip6:' in output |
| 257 | assert '0000:0000:0000:0000:0000:0000:0000:0000' not in output |
| 258 | |
Tom Rini | 5568cc3 | 2024-06-18 14:23:43 -0600 | [diff] [blame] | 259 | @pytest.mark.buildconfigspec('cmd_tftpboot') |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 260 | def test_net_tftpboot(ubman): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 261 | """Test the tftpboot command. |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 262 | |
| 263 | A file is downloaded from the TFTP server, its size and optionally its |
| 264 | CRC32 are validated. |
| 265 | |
| 266 | The details of the file to download are provided by the boardenv_* file; |
| 267 | see the comment at the beginning of this file. |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 268 | """ |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 269 | |
| 270 | if not net_set_up: |
Stephen Warren | 3deb896 | 2016-01-26 13:41:31 -0700 | [diff] [blame] | 271 | pytest.skip('Network not initialized') |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 272 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 273 | f = ubman.config.env.get('env__net_tftp_readable_file', None) |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 274 | if not f: |
| 275 | pytest.skip('No TFTP readable file to read') |
| 276 | |
Michal Simek | 6596e03 | 2016-04-04 20:06:14 +0200 | [diff] [blame] | 277 | addr = f.get('addr', None) |
Michal Simek | 6596e03 | 2016-04-04 20:06:14 +0200 | [diff] [blame] | 278 | |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 279 | fn = f['fn'] |
Heinrich Schuchardt | 23287c8 | 2019-01-26 15:25:12 +0100 | [diff] [blame] | 280 | if not addr: |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 281 | output = ubman.run_command('tftpboot %s' % (fn)) |
Heinrich Schuchardt | 23287c8 | 2019-01-26 15:25:12 +0100 | [diff] [blame] | 282 | else: |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 283 | output = ubman.run_command('tftpboot %x %s' % (addr, fn)) |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 284 | expected_text = 'Bytes transferred = ' |
| 285 | sz = f.get('size', None) |
| 286 | if sz: |
| 287 | expected_text += '%d' % sz |
| 288 | assert expected_text in output |
| 289 | |
| 290 | expected_crc = f.get('crc32', None) |
| 291 | if not expected_crc: |
| 292 | return |
| 293 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 294 | if ubman.config.buildconfig.get('config_cmd_crc32', 'n') != 'y': |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 295 | return |
| 296 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 297 | output = ubman.run_command('crc32 $fileaddr $filesize') |
Stephen Warren | 1a21855 | 2016-01-21 16:05:31 -0700 | [diff] [blame] | 298 | assert expected_crc in output |
Guillaume GARDET | 1b0102d | 2016-09-14 10:29:12 +0200 | [diff] [blame] | 299 | |
| 300 | @pytest.mark.buildconfigspec('cmd_nfs') |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 301 | def test_net_nfs(ubman): |
Guillaume GARDET | 1b0102d | 2016-09-14 10:29:12 +0200 | [diff] [blame] | 302 | """Test the nfs command. |
| 303 | |
| 304 | A file is downloaded from the NFS server, its size and optionally its |
| 305 | CRC32 are validated. |
| 306 | |
| 307 | The details of the file to download are provided by the boardenv_* file; |
| 308 | see the comment at the beginning of this file. |
| 309 | """ |
| 310 | |
| 311 | if not net_set_up: |
| 312 | pytest.skip('Network not initialized') |
| 313 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 314 | f = ubman.config.env.get('env__net_nfs_readable_file', None) |
Guillaume GARDET | 1b0102d | 2016-09-14 10:29:12 +0200 | [diff] [blame] | 315 | if not f: |
| 316 | pytest.skip('No NFS readable file to read') |
| 317 | |
| 318 | addr = f.get('addr', None) |
| 319 | if not addr: |
Simon Glass | fb91637 | 2025-02-09 09:07:15 -0700 | [diff] [blame] | 320 | addr = utils.find_ram_base(ubman) |
Guillaume GARDET | 1b0102d | 2016-09-14 10:29:12 +0200 | [diff] [blame] | 321 | |
| 322 | fn = f['fn'] |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 323 | output = ubman.run_command('nfs %x %s' % (addr, fn)) |
Guillaume GARDET | 1b0102d | 2016-09-14 10:29:12 +0200 | [diff] [blame] | 324 | expected_text = 'Bytes transferred = ' |
| 325 | sz = f.get('size', None) |
| 326 | if sz: |
| 327 | expected_text += '%d' % sz |
| 328 | assert expected_text in output |
| 329 | |
| 330 | expected_crc = f.get('crc32', None) |
| 331 | if not expected_crc: |
| 332 | return |
| 333 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 334 | if ubman.config.buildconfig.get('config_cmd_crc32', 'n') != 'y': |
Guillaume GARDET | 1b0102d | 2016-09-14 10:29:12 +0200 | [diff] [blame] | 335 | return |
| 336 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 337 | output = ubman.run_command('crc32 %x $filesize' % addr) |
Guillaume GARDET | 1b0102d | 2016-09-14 10:29:12 +0200 | [diff] [blame] | 338 | assert expected_crc in output |
Love Kumar | 55ef453 | 2023-10-03 18:42:46 +0530 | [diff] [blame] | 339 | |
Love Kumar | 55ef453 | 2023-10-03 18:42:46 +0530 | [diff] [blame] | 340 | @pytest.mark.buildconfigspec("cmd_pxe") |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 341 | def test_net_pxe_get(ubman): |
Love Kumar | 55ef453 | 2023-10-03 18:42:46 +0530 | [diff] [blame] | 342 | """Test the pxe get command. |
| 343 | |
| 344 | A pxe configuration file is downloaded from the TFTP server and interpreted |
| 345 | to boot the images mentioned in pxe configuration file. |
| 346 | |
| 347 | The details of the file to download are provided by the boardenv_* file; |
| 348 | see the comment at the beginning of this file. |
| 349 | """ |
| 350 | |
| 351 | if not net_set_up: |
| 352 | pytest.skip("Network not initialized") |
| 353 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 354 | test_net_setup_static(ubman) |
Love Kumar | 55ef453 | 2023-10-03 18:42:46 +0530 | [diff] [blame] | 355 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 356 | f = ubman.config.env.get("env__net_pxe_readable_file", None) |
Love Kumar | 55ef453 | 2023-10-03 18:42:46 +0530 | [diff] [blame] | 357 | if not f: |
| 358 | pytest.skip("No PXE readable file to read") |
| 359 | |
| 360 | addr = f.get("addr", None) |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 361 | timeout = f.get("timeout", ubman.p.timeout) |
Love Kumar | 55ef453 | 2023-10-03 18:42:46 +0530 | [diff] [blame] | 362 | |
| 363 | pxeuuid = uuid.uuid1() |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 364 | ubman.run_command(f"setenv pxeuuid {pxeuuid}") |
Love Kumar | 55ef453 | 2023-10-03 18:42:46 +0530 | [diff] [blame] | 365 | expected_text_uuid = f"Retrieving file: pxelinux.cfg/{pxeuuid}" |
| 366 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 367 | ethaddr = ubman.run_command("echo $ethaddr") |
Love Kumar | 55ef453 | 2023-10-03 18:42:46 +0530 | [diff] [blame] | 368 | ethaddr = ethaddr.replace(':', '-') |
| 369 | expected_text_ethaddr = f"Retrieving file: pxelinux.cfg/01-{ethaddr}" |
| 370 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 371 | ip = ubman.run_command("echo $ipaddr") |
Love Kumar | 55ef453 | 2023-10-03 18:42:46 +0530 | [diff] [blame] | 372 | ip = ip.split('.') |
| 373 | ipaddr_file = "".join(['%02x' % int(x) for x in ip]).upper() |
| 374 | expected_text_ipaddr = f"Retrieving file: pxelinux.cfg/{ipaddr_file}" |
| 375 | expected_text_default = f"Retrieving file: pxelinux.cfg/default" |
| 376 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 377 | with ubman.temporary_timeout(timeout): |
| 378 | output = ubman.run_command("pxe get") |
Love Kumar | 55ef453 | 2023-10-03 18:42:46 +0530 | [diff] [blame] | 379 | |
| 380 | assert "TIMEOUT" not in output |
| 381 | assert expected_text_uuid in output |
| 382 | assert expected_text_ethaddr in output |
| 383 | assert expected_text_ipaddr in output |
| 384 | |
| 385 | i = 1 |
| 386 | for i in range(0, len(ipaddr_file) - 1): |
| 387 | expected_text_ip = f"Retrieving file: pxelinux.cfg/{ipaddr_file[:-i]}" |
| 388 | assert expected_text_ip in output |
| 389 | i += 1 |
| 390 | |
| 391 | assert expected_text_default in output |
| 392 | assert "Config file 'default.boot' found" in output |
Love Kumar | 49f8749 | 2023-11-08 12:40:31 +0530 | [diff] [blame] | 393 | |
| 394 | @pytest.mark.buildconfigspec("cmd_crc32") |
Tom Rini | 5568cc3 | 2024-06-18 14:23:43 -0600 | [diff] [blame] | 395 | @pytest.mark.buildconfigspec("cmd_tftpboot") |
Love Kumar | 49f8749 | 2023-11-08 12:40:31 +0530 | [diff] [blame] | 396 | @pytest.mark.buildconfigspec("cmd_tftpput") |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 397 | def test_net_tftpput(ubman): |
Love Kumar | 49f8749 | 2023-11-08 12:40:31 +0530 | [diff] [blame] | 398 | """Test the tftpput command. |
| 399 | |
| 400 | A file is downloaded from the TFTP server and then uploaded to the TFTP |
| 401 | server, its size and its CRC32 are validated. |
| 402 | |
| 403 | The details of the file to download are provided by the boardenv_* file; |
| 404 | see the comment at the beginning of this file. |
| 405 | """ |
| 406 | |
| 407 | if not net_set_up: |
| 408 | pytest.skip("Network not initialized") |
| 409 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 410 | f = ubman.config.env.get("env__net_tftp_readable_file", None) |
Love Kumar | 49f8749 | 2023-11-08 12:40:31 +0530 | [diff] [blame] | 411 | if not f: |
| 412 | pytest.skip("No TFTP readable file to read") |
| 413 | |
| 414 | addr = f.get("addr", None) |
| 415 | if not addr: |
Simon Glass | fb91637 | 2025-02-09 09:07:15 -0700 | [diff] [blame] | 416 | addr = utils.find_ram_base(ubman) |
Love Kumar | 49f8749 | 2023-11-08 12:40:31 +0530 | [diff] [blame] | 417 | |
| 418 | sz = f.get("size", None) |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 419 | timeout = f.get("timeout", ubman.p.timeout) |
Love Kumar | 49f8749 | 2023-11-08 12:40:31 +0530 | [diff] [blame] | 420 | fn = f["fn"] |
| 421 | fnu = f.get("fnu", "_".join([datetime.datetime.now().strftime("%y%m%d%H%M%S"), fn])) |
| 422 | expected_text = "Bytes transferred = " |
| 423 | if sz: |
| 424 | expected_text += "%d" % sz |
| 425 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 426 | with ubman.temporary_timeout(timeout): |
| 427 | output = ubman.run_command("tftpboot %x %s" % (addr, fn)) |
Love Kumar | 49f8749 | 2023-11-08 12:40:31 +0530 | [diff] [blame] | 428 | |
| 429 | assert "TIMEOUT" not in output |
| 430 | assert expected_text in output |
| 431 | |
| 432 | expected_tftpb_crc = f.get("crc32", None) |
| 433 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 434 | output = ubman.run_command("crc32 $fileaddr $filesize") |
Love Kumar | 49f8749 | 2023-11-08 12:40:31 +0530 | [diff] [blame] | 435 | assert expected_tftpb_crc in output |
| 436 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 437 | with ubman.temporary_timeout(timeout): |
| 438 | output = ubman.run_command( |
Love Kumar | 49f8749 | 2023-11-08 12:40:31 +0530 | [diff] [blame] | 439 | "tftpput $fileaddr $filesize $serverip:%s" % (fnu) |
| 440 | ) |
| 441 | |
| 442 | expected_text = "Bytes transferred = " |
| 443 | if sz: |
| 444 | expected_text += "%d" % sz |
| 445 | addr = addr + sz |
| 446 | assert "TIMEOUT" not in output |
| 447 | assert "Access violation" not in output |
| 448 | assert expected_text in output |
| 449 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 450 | with ubman.temporary_timeout(timeout): |
| 451 | output = ubman.run_command("tftpboot %x %s" % (addr, fnu)) |
Love Kumar | 49f8749 | 2023-11-08 12:40:31 +0530 | [diff] [blame] | 452 | |
| 453 | expected_text = "Bytes transferred = " |
| 454 | if sz: |
| 455 | expected_text += "%d" % sz |
| 456 | assert "TIMEOUT" not in output |
| 457 | assert expected_text in output |
| 458 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 459 | output = ubman.run_command("crc32 $fileaddr $filesize") |
Love Kumar | 49f8749 | 2023-11-08 12:40:31 +0530 | [diff] [blame] | 460 | assert expected_tftpb_crc in output |