blob: 27cdd73fd49c740be458e2b70f4f2c754c52947d [file] [log] [blame]
Stephen Warren1a218552016-01-21 16:05:31 -07001# SPDX-License-Identifier: GPL-2.0
Tom Rini10e47792018-05-06 17:58:06 -04002# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
Stephen Warren1a218552016-01-21 16:05:31 -07003
4# Test various network-related functionality, such as the dhcp, ping, and
5# tftpboot commands.
6
Stephen Warren75e731e2016-01-26 13:41:30 -07007"""
Stephen Warren1a218552016-01-21 16:05:31 -07008Note: This test relies on boardenv_* containing configuration values to define
Ehsan Mohandesi3eb50532023-04-21 17:08:22 -07009which network environment is available for testing. Without this, this test
Stephen Warren1a218552016-01-21 16:05:31 -070010will be automatically skipped.
11
12For example:
13
Tom Riniff8edfc2025-05-07 17:23:00 -060014.. code-block:: python
Stephen Warren8d57b922016-01-26 11:10:14 -070015
Tom Riniff8edfc2025-05-07 17:23:00 -060016 # 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 Warren1a218552016-01-21 16:05:31 -070020
Tom Riniff8edfc2025-05-07 17:23:00 -060021 # 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 Warren1a218552016-01-21 16:05:31 -070025
Tom Riniff8edfc2025-05-07 17:23:00 -060026 # 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 Kumar4578d152024-01-30 13:37:01 +053030
Tom Riniff8edfc2025-05-07 17:23:00 -060031 # 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 Edmondd407acf2023-04-11 10:48:48 -070036
Tom Riniff8edfc2025-05-07 17:23:00 -060037 # 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 Warren1a218552016-01-21 16:05:31 -070041
Tom Riniff8edfc2025-05-07 17:23:00 -060042 # 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 GARDET1b0102d2016-09-14 10:29:12 +020050
Tom Riniff8edfc2025-05-07 17:23:00 -060051 # 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 Mohandesi3eb50532023-04-21 17:08:22 -070061
Tom Riniff8edfc2025-05-07 17:23:00 -060062 # 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 Kumar55ef4532023-10-03 18:42:46 +053070
Tom Riniff8edfc2025-05-07 17:23:00 -060071 # 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 Warren75e731e2016-01-26 13:41:30 -070085"""
Stephen Warren1a218552016-01-21 16:05:31 -070086
Tom Riniff8edfc2025-05-07 17:23:00 -060087import pytest
88import utils
89import uuid
90import datetime
91import re
92
Stephen Warren1a218552016-01-21 16:05:31 -070093net_set_up = False
Sean Edmondd407acf2023-04-11 10:48:48 -070094net6_set_up = False
Stephen Warren1a218552016-01-21 16:05:31 -070095
Simon Glass86bf4ef2025-02-09 09:07:19 -070096
97@pytest.mark.buildconfigspec('cmd_net')
Simon Glassddba5202025-02-09 09:07:14 -070098def test_net_pre_commands(ubman):
Stephen Warren75e731e2016-01-26 13:41:30 -070099 """Execute any commands required to enable network hardware.
Stephen Warren1a218552016-01-21 16:05:31 -0700100
101 These commands are provided by the boardenv_* file; see the comment at the
102 beginning of this file.
Stephen Warren75e731e2016-01-26 13:41:30 -0700103 """
Stephen Warren1a218552016-01-21 16:05:31 -0700104
Simon Glassddba5202025-02-09 09:07:14 -0700105 init_usb = ubman.config.env.get('env__net_uses_usb', False)
Stephen Warren8d57b922016-01-26 11:10:14 -0700106 if init_usb:
Simon Glassddba5202025-02-09 09:07:14 -0700107 ubman.run_command('usb start')
Stephen Warren1a218552016-01-21 16:05:31 -0700108
Simon Glassddba5202025-02-09 09:07:14 -0700109 init_pci = ubman.config.env.get('env__net_uses_pci', False)
Stephen Warren8d57b922016-01-26 11:10:14 -0700110 if init_pci:
Simon Glassddba5202025-02-09 09:07:14 -0700111 ubman.run_command('pci enum')
Stephen Warren1a218552016-01-21 16:05:31 -0700112
Simon Glassddba5202025-02-09 09:07:14 -0700113 ubman.run_command('net list')
Maxim Uvarovb5977fc2023-12-26 21:46:12 +0600114
Stephen Warren1a218552016-01-21 16:05:31 -0700115@pytest.mark.buildconfigspec('cmd_dhcp')
Simon Glassddba5202025-02-09 09:07:14 -0700116def test_net_dhcp(ubman):
Stephen Warren75e731e2016-01-26 13:41:30 -0700117 """Test the dhcp command.
Stephen Warren1a218552016-01-21 16:05:31 -0700118
119 The boardenv_* file may be used to enable/disable this test; see the
120 comment at the beginning of this file.
Stephen Warren75e731e2016-01-26 13:41:30 -0700121 """
Stephen Warren1a218552016-01-21 16:05:31 -0700122
Simon Glassddba5202025-02-09 09:07:14 -0700123 test_dhcp = ubman.config.env.get('env__net_dhcp_server', False)
Stephen Warren1a218552016-01-21 16:05:31 -0700124 if not test_dhcp:
125 pytest.skip('No DHCP server available')
126
Simon Glassddba5202025-02-09 09:07:14 -0700127 ubman.run_command('setenv autoload no')
128 output = ubman.run_command('dhcp')
Stephen Warren1a218552016-01-21 16:05:31 -0700129 assert 'DHCP client bound to address ' in output
130
131 global net_set_up
132 net_set_up = True
133
Love Kumar4578d152024-01-30 13:37:01 +0530134@pytest.mark.buildconfigspec('cmd_dhcp')
135@pytest.mark.buildconfigspec('cmd_mii')
Simon Glassddba5202025-02-09 09:07:14 -0700136def test_net_dhcp_abort(ubman):
Love Kumar4578d152024-01-30 13:37:01 +0530137 """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 Glassddba5202025-02-09 09:07:14 -0700143 test_dhcp = ubman.config.env.get('env__net_dhcp_server', False)
Love Kumar4578d152024-01-30 13:37:01 +0530144 if not test_dhcp:
145 pytest.skip('No DHCP server available')
146
Simon Glassddba5202025-02-09 09:07:14 -0700147 if ubman.config.env.get('env__dhcp_abort_test_skip', True):
Love Kumar4578d152024-01-30 13:37:01 +0530148 pytest.skip('DHCP abort test is not enabled!')
149
Simon Glassddba5202025-02-09 09:07:14 -0700150 ubman.run_command('setenv autoload no')
Love Kumar4578d152024-01-30 13:37:01 +0530151
152 # Phy reset before running dhcp command
Simon Glassddba5202025-02-09 09:07:14 -0700153 output = ubman.run_command('mii device')
Love Kumar4578d152024-01-30 13:37:01 +0530154 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 Glassddba5202025-02-09 09:07:14 -0700157 ubman.run_command(f'mii device {eth_num}')
158 output = ubman.run_command('mii info')
Love Kumar4578d152024-01-30 13:37:01 +0530159 eth_addr = hex(int(re.search(r'PHY (.+?):', output).groups()[0], 16))
Simon Glassddba5202025-02-09 09:07:14 -0700160 ubman.run_command(f'mii modify {eth_addr} 0 0x8000 0x8000')
Love Kumar4578d152024-01-30 13:37:01 +0530161
Simon Glassddba5202025-02-09 09:07:14 -0700162 ubman.run_command('dhcp', wait_for_prompt=False)
Love Kumar4578d152024-01-30 13:37:01 +0530163 try:
Simon Glassddba5202025-02-09 09:07:14 -0700164 ubman.wait_for('Waiting for PHY auto negotiation to complete')
Love Kumar4578d152024-01-30 13:37:01 +0530165 except:
166 pytest.skip('Timeout waiting for PHY auto negotiation to complete')
167
Simon Glassddba5202025-02-09 09:07:14 -0700168 ubman.wait_for('done')
Love Kumar4578d152024-01-30 13:37:01 +0530169
170 try:
171 # Sending Ctrl-C
Simon Glassddba5202025-02-09 09:07:14 -0700172 output = ubman.run_command(
Love Kumar4578d152024-01-30 13:37:01 +0530173 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 Glassddba5202025-02-09 09:07:14 -0700181 ubman.run_command('sleep 1')
Love Kumar4578d152024-01-30 13:37:01 +0530182 # Run the dhcp test to setup the network configuration
Simon Glassddba5202025-02-09 09:07:14 -0700183 test_net_dhcp(ubman)
Love Kumar4578d152024-01-30 13:37:01 +0530184
Sean Edmondd407acf2023-04-11 10:48:48 -0700185@pytest.mark.buildconfigspec('cmd_dhcp6')
Simon Glassddba5202025-02-09 09:07:14 -0700186def test_net_dhcp6(ubman):
Sean Edmondd407acf2023-04-11 10:48:48 -0700187 """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 Glassddba5202025-02-09 09:07:14 -0700193 test_dhcp6 = ubman.config.env.get('env__net_dhcp6_server', False)
Sean Edmondd407acf2023-04-11 10:48:48 -0700194 if not test_dhcp6:
195 pytest.skip('No DHCP6 server available')
196
Simon Glassddba5202025-02-09 09:07:14 -0700197 ubman.run_command('setenv autoload no')
198 output = ubman.run_command('dhcp6')
Sean Edmondd407acf2023-04-11 10:48:48 -0700199 assert 'DHCP6 client bound to ' in output
200
201 global net6_set_up
202 net6_set_up = True
203
Stephen Warren1a218552016-01-21 16:05:31 -0700204@pytest.mark.buildconfigspec('net')
Simon Glassddba5202025-02-09 09:07:14 -0700205def test_net_setup_static(ubman):
Stephen Warren75e731e2016-01-26 13:41:30 -0700206 """Set up a static IP configuration.
Stephen Warren1a218552016-01-21 16:05:31 -0700207
208 The configuration is provided by the boardenv_* file; see the comment at
209 the beginning of this file.
Stephen Warren75e731e2016-01-26 13:41:30 -0700210 """
Stephen Warren1a218552016-01-21 16:05:31 -0700211
Simon Glassddba5202025-02-09 09:07:14 -0700212 env_vars = ubman.config.env.get('env__net_static_env_vars', None)
Stephen Warren1a218552016-01-21 16:05:31 -0700213 if not env_vars:
214 pytest.skip('No static network configuration is defined')
215
216 for (var, val) in env_vars:
Simon Glassddba5202025-02-09 09:07:14 -0700217 ubman.run_command('setenv %s %s' % (var, val))
Stephen Warren1a218552016-01-21 16:05:31 -0700218
219 global net_set_up
220 net_set_up = True
221
222@pytest.mark.buildconfigspec('cmd_ping')
Simon Glassddba5202025-02-09 09:07:14 -0700223def test_net_ping(ubman):
Stephen Warren75e731e2016-01-26 13:41:30 -0700224 """Test the ping command.
Stephen Warren1a218552016-01-21 16:05:31 -0700225
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 Warren75e731e2016-01-26 13:41:30 -0700229 """
Stephen Warren1a218552016-01-21 16:05:31 -0700230
231 if not net_set_up:
Stephen Warren3deb8962016-01-26 13:41:31 -0700232 pytest.skip('Network not initialized')
Stephen Warren1a218552016-01-21 16:05:31 -0700233
Simon Glassddba5202025-02-09 09:07:14 -0700234 output = ubman.run_command('ping $serverip')
Stephen Warren1a218552016-01-21 16:05:31 -0700235 assert 'is alive' in output
236
Ehsan Mohandesi3eb50532023-04-21 17:08:22 -0700237@pytest.mark.buildconfigspec('IPV6_ROUTER_DISCOVERY')
Simon Glassddba5202025-02-09 09:07:14 -0700238def test_net_network_discovery(ubman):
Ehsan Mohandesi3eb50532023-04-21 17:08:22 -0700239 """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 Glassddba5202025-02-09 09:07:14 -0700251 router_on_net = ubman.config.env.get('env__router_on_net', False)
Ehsan Mohandesi3eb50532023-04-21 17:08:22 -0700252 if not router_on_net:
253 pytest.skip('No router on network')
254
255 fake_host_ip = 'fe80::215:5dff:fef6:2ec6'
Simon Glassddba5202025-02-09 09:07:14 -0700256 output = ubman.run_command('ping6 ' + fake_host_ip)
Ehsan Mohandesi3eb50532023-04-21 17:08:22 -0700257 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 Rini5568cc32024-06-18 14:23:43 -0600261@pytest.mark.buildconfigspec('cmd_tftpboot')
Simon Glassddba5202025-02-09 09:07:14 -0700262def test_net_tftpboot(ubman):
Stephen Warren75e731e2016-01-26 13:41:30 -0700263 """Test the tftpboot command.
Stephen Warren1a218552016-01-21 16:05:31 -0700264
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 Warren75e731e2016-01-26 13:41:30 -0700270 """
Stephen Warren1a218552016-01-21 16:05:31 -0700271
272 if not net_set_up:
Stephen Warren3deb8962016-01-26 13:41:31 -0700273 pytest.skip('Network not initialized')
Stephen Warren1a218552016-01-21 16:05:31 -0700274
Simon Glassddba5202025-02-09 09:07:14 -0700275 f = ubman.config.env.get('env__net_tftp_readable_file', None)
Stephen Warren1a218552016-01-21 16:05:31 -0700276 if not f:
277 pytest.skip('No TFTP readable file to read')
278
Michal Simek6596e032016-04-04 20:06:14 +0200279 addr = f.get('addr', None)
Michal Simek6596e032016-04-04 20:06:14 +0200280
Stephen Warren1a218552016-01-21 16:05:31 -0700281 fn = f['fn']
Heinrich Schuchardt23287c82019-01-26 15:25:12 +0100282 if not addr:
Simon Glassddba5202025-02-09 09:07:14 -0700283 output = ubman.run_command('tftpboot %s' % (fn))
Heinrich Schuchardt23287c82019-01-26 15:25:12 +0100284 else:
Simon Glassddba5202025-02-09 09:07:14 -0700285 output = ubman.run_command('tftpboot %x %s' % (addr, fn))
Stephen Warren1a218552016-01-21 16:05:31 -0700286 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 Glassddba5202025-02-09 09:07:14 -0700296 if ubman.config.buildconfig.get('config_cmd_crc32', 'n') != 'y':
Stephen Warren1a218552016-01-21 16:05:31 -0700297 return
298
Simon Glassddba5202025-02-09 09:07:14 -0700299 output = ubman.run_command('crc32 $fileaddr $filesize')
Stephen Warren1a218552016-01-21 16:05:31 -0700300 assert expected_crc in output
Guillaume GARDET1b0102d2016-09-14 10:29:12 +0200301
302@pytest.mark.buildconfigspec('cmd_nfs')
Simon Glassddba5202025-02-09 09:07:14 -0700303def test_net_nfs(ubman):
Guillaume GARDET1b0102d2016-09-14 10:29:12 +0200304 """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 Glassddba5202025-02-09 09:07:14 -0700316 f = ubman.config.env.get('env__net_nfs_readable_file', None)
Guillaume GARDET1b0102d2016-09-14 10:29:12 +0200317 if not f:
318 pytest.skip('No NFS readable file to read')
319
320 addr = f.get('addr', None)
321 if not addr:
Simon Glassfb916372025-02-09 09:07:15 -0700322 addr = utils.find_ram_base(ubman)
Guillaume GARDET1b0102d2016-09-14 10:29:12 +0200323
324 fn = f['fn']
Simon Glassddba5202025-02-09 09:07:14 -0700325 output = ubman.run_command('nfs %x %s' % (addr, fn))
Guillaume GARDET1b0102d2016-09-14 10:29:12 +0200326 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 Glassddba5202025-02-09 09:07:14 -0700336 if ubman.config.buildconfig.get('config_cmd_crc32', 'n') != 'y':
Guillaume GARDET1b0102d2016-09-14 10:29:12 +0200337 return
338
Simon Glassddba5202025-02-09 09:07:14 -0700339 output = ubman.run_command('crc32 %x $filesize' % addr)
Guillaume GARDET1b0102d2016-09-14 10:29:12 +0200340 assert expected_crc in output
Love Kumar55ef4532023-10-03 18:42:46 +0530341
Love Kumar55ef4532023-10-03 18:42:46 +0530342@pytest.mark.buildconfigspec("cmd_pxe")
Simon Glassddba5202025-02-09 09:07:14 -0700343def test_net_pxe_get(ubman):
Love Kumar55ef4532023-10-03 18:42:46 +0530344 """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 Glassddba5202025-02-09 09:07:14 -0700356 test_net_setup_static(ubman)
Love Kumar55ef4532023-10-03 18:42:46 +0530357
Simon Glassddba5202025-02-09 09:07:14 -0700358 f = ubman.config.env.get("env__net_pxe_readable_file", None)
Love Kumar55ef4532023-10-03 18:42:46 +0530359 if not f:
360 pytest.skip("No PXE readable file to read")
361
362 addr = f.get("addr", None)
Simon Glassddba5202025-02-09 09:07:14 -0700363 timeout = f.get("timeout", ubman.p.timeout)
Love Kumar55ef4532023-10-03 18:42:46 +0530364
365 pxeuuid = uuid.uuid1()
Simon Glassddba5202025-02-09 09:07:14 -0700366 ubman.run_command(f"setenv pxeuuid {pxeuuid}")
Love Kumar55ef4532023-10-03 18:42:46 +0530367 expected_text_uuid = f"Retrieving file: pxelinux.cfg/{pxeuuid}"
368
Simon Glassddba5202025-02-09 09:07:14 -0700369 ethaddr = ubman.run_command("echo $ethaddr")
Love Kumar55ef4532023-10-03 18:42:46 +0530370 ethaddr = ethaddr.replace(':', '-')
371 expected_text_ethaddr = f"Retrieving file: pxelinux.cfg/01-{ethaddr}"
372
Simon Glassddba5202025-02-09 09:07:14 -0700373 ip = ubman.run_command("echo $ipaddr")
Love Kumar55ef4532023-10-03 18:42:46 +0530374 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 Glassddba5202025-02-09 09:07:14 -0700379 with ubman.temporary_timeout(timeout):
380 output = ubman.run_command("pxe get")
Love Kumar55ef4532023-10-03 18:42:46 +0530381
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 Kumar49f87492023-11-08 12:40:31 +0530395
396@pytest.mark.buildconfigspec("cmd_crc32")
Tom Rini5568cc32024-06-18 14:23:43 -0600397@pytest.mark.buildconfigspec("cmd_tftpboot")
Love Kumar49f87492023-11-08 12:40:31 +0530398@pytest.mark.buildconfigspec("cmd_tftpput")
Simon Glassddba5202025-02-09 09:07:14 -0700399def test_net_tftpput(ubman):
Love Kumar49f87492023-11-08 12:40:31 +0530400 """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 Glassddba5202025-02-09 09:07:14 -0700412 f = ubman.config.env.get("env__net_tftp_readable_file", None)
Love Kumar49f87492023-11-08 12:40:31 +0530413 if not f:
414 pytest.skip("No TFTP readable file to read")
415
416 addr = f.get("addr", None)
417 if not addr:
Simon Glassfb916372025-02-09 09:07:15 -0700418 addr = utils.find_ram_base(ubman)
Love Kumar49f87492023-11-08 12:40:31 +0530419
420 sz = f.get("size", None)
Simon Glassddba5202025-02-09 09:07:14 -0700421 timeout = f.get("timeout", ubman.p.timeout)
Love Kumar49f87492023-11-08 12:40:31 +0530422 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 Glassddba5202025-02-09 09:07:14 -0700428 with ubman.temporary_timeout(timeout):
429 output = ubman.run_command("tftpboot %x %s" % (addr, fn))
Love Kumar49f87492023-11-08 12:40:31 +0530430
431 assert "TIMEOUT" not in output
432 assert expected_text in output
433
434 expected_tftpb_crc = f.get("crc32", None)
435
Simon Glassddba5202025-02-09 09:07:14 -0700436 output = ubman.run_command("crc32 $fileaddr $filesize")
Love Kumar49f87492023-11-08 12:40:31 +0530437 assert expected_tftpb_crc in output
438
Simon Glassddba5202025-02-09 09:07:14 -0700439 with ubman.temporary_timeout(timeout):
440 output = ubman.run_command(
Love Kumar49f87492023-11-08 12:40:31 +0530441 "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 Glassddba5202025-02-09 09:07:14 -0700452 with ubman.temporary_timeout(timeout):
453 output = ubman.run_command("tftpboot %x %s" % (addr, fnu))
Love Kumar49f87492023-11-08 12:40:31 +0530454
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 Glassddba5202025-02-09 09:07:14 -0700461 output = ubman.run_command("crc32 $fileaddr $filesize")
Love Kumar49f87492023-11-08 12:40:31 +0530462 assert expected_tftpb_crc in output