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