blob: 52ecf93d41dfbfbb7425c30c84a707c9b85e93e9 [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
7import pytest
8import u_boot_utils
Love Kumar55ef4532023-10-03 18:42:46 +05309import uuid
Love Kumar49f87492023-11-08 12:40:31 +053010import datetime
Love Kumar4578d152024-01-30 13:37:01 +053011import re
Stephen Warren1a218552016-01-21 16:05:31 -070012
Stephen Warren75e731e2016-01-26 13:41:30 -070013"""
Stephen Warren1a218552016-01-21 16:05:31 -070014Note: This test relies on boardenv_* containing configuration values to define
Ehsan Mohandesi3eb50532023-04-21 17:08:22 -070015which network environment is available for testing. Without this, this test
Stephen Warren1a218552016-01-21 16:05:31 -070016will be automatically skipped.
17
18For example:
19
Stephen Warren8d57b922016-01-26 11:10:14 -070020# 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.
23env__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.
28env__net_uses_pci = True
Stephen Warren1a218552016-01-21 16:05:31 -070029
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.
33env__net_dhcp_server = True
34
Love Kumar4578d152024-01-30 13:37:01 +053035# 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.
39env__dhcp_abort_test_skip = True
40
Sean Edmondd407acf2023-04-11 10:48:48 -070041# 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.
44env__net_dhcp6_server = True
45
Stephen Warren1a218552016-01-21 16:05:31 -070046# 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.
49env__net_static_env_vars = [
Simon Glasse9f4d872018-12-27 08:11:13 -070050 ('ipaddr', '10.0.0.100'),
51 ('netmask', '255.255.255.0'),
52 ('serverip', '10.0.0.1'),
Stephen Warren1a218552016-01-21 16:05:31 -070053]
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.
57env__net_tftp_readable_file = {
Simon Glasse9f4d872018-12-27 08:11:13 -070058 'fn': 'ubtest-readable.bin',
59 'addr': 0x10000000,
60 'size': 5058624,
61 'crc32': 'c2244b26',
Love Kumar49f87492023-11-08 12:40:31 +053062 'timeout': 50000,
63 'fnu': 'ubtest-upload.bin',
Stephen Warren1a218552016-01-21 16:05:31 -070064}
Guillaume GARDET1b0102d2016-09-14 10:29:12 +020065
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.
68env__net_nfs_readable_file = {
Simon Glasse9f4d872018-12-27 08:11:13 -070069 'fn': 'ubtest-readable.bin',
70 'addr': 0x10000000,
71 'size': 5058624,
72 'crc32': 'c2244b26',
Guillaume GARDET1b0102d2016-09-14 10:29:12 +020073}
Ehsan Mohandesi3eb50532023-04-21 17:08:22 -070074
Love Kumar55ef4532023-10-03 18:42:46 +053075# 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.
77env__net_pxe_readable_file = {
78 'fn': 'default',
79 'addr': 0x2000000,
80 'size': 74,
81 'timeout': 50000,
82 'pattern': 'Linux',
83}
84
Ehsan Mohandesi3eb50532023-04-21 17:08:22 -070085# 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
87variable may be omitted or set to False.
88env__router_on_net = True
Stephen Warren75e731e2016-01-26 13:41:30 -070089"""
Stephen Warren1a218552016-01-21 16:05:31 -070090
91net_set_up = False
Sean Edmondd407acf2023-04-11 10:48:48 -070092net6_set_up = False
Stephen Warren1a218552016-01-21 16:05:31 -070093
Simon Glassddba5202025-02-09 09:07:14 -070094def test_net_pre_commands(ubman):
Stephen Warren75e731e2016-01-26 13:41:30 -070095 """Execute any commands required to enable network hardware.
Stephen Warren1a218552016-01-21 16:05:31 -070096
97 These commands are provided by the boardenv_* file; see the comment at the
98 beginning of this file.
Stephen Warren75e731e2016-01-26 13:41:30 -070099 """
Stephen Warren1a218552016-01-21 16:05:31 -0700100
Simon Glassddba5202025-02-09 09:07:14 -0700101 init_usb = ubman.config.env.get('env__net_uses_usb', False)
Stephen Warren8d57b922016-01-26 11:10:14 -0700102 if init_usb:
Simon Glassddba5202025-02-09 09:07:14 -0700103 ubman.run_command('usb start')
Stephen Warren1a218552016-01-21 16:05:31 -0700104
Simon Glassddba5202025-02-09 09:07:14 -0700105 init_pci = ubman.config.env.get('env__net_uses_pci', False)
Stephen Warren8d57b922016-01-26 11:10:14 -0700106 if init_pci:
Simon Glassddba5202025-02-09 09:07:14 -0700107 ubman.run_command('pci enum')
Stephen Warren1a218552016-01-21 16:05:31 -0700108
Simon Glassddba5202025-02-09 09:07:14 -0700109 ubman.run_command('net list')
Maxim Uvarovb5977fc2023-12-26 21:46:12 +0600110
Stephen Warren1a218552016-01-21 16:05:31 -0700111@pytest.mark.buildconfigspec('cmd_dhcp')
Simon Glassddba5202025-02-09 09:07:14 -0700112def test_net_dhcp(ubman):
Stephen Warren75e731e2016-01-26 13:41:30 -0700113 """Test the dhcp command.
Stephen Warren1a218552016-01-21 16:05:31 -0700114
115 The boardenv_* file may be used to enable/disable this test; see the
116 comment at the beginning of this file.
Stephen Warren75e731e2016-01-26 13:41:30 -0700117 """
Stephen Warren1a218552016-01-21 16:05:31 -0700118
Simon Glassddba5202025-02-09 09:07:14 -0700119 test_dhcp = ubman.config.env.get('env__net_dhcp_server', False)
Stephen Warren1a218552016-01-21 16:05:31 -0700120 if not test_dhcp:
121 pytest.skip('No DHCP server available')
122
Simon Glassddba5202025-02-09 09:07:14 -0700123 ubman.run_command('setenv autoload no')
124 output = ubman.run_command('dhcp')
Stephen Warren1a218552016-01-21 16:05:31 -0700125 assert 'DHCP client bound to address ' in output
126
127 global net_set_up
128 net_set_up = True
129
Love Kumar4578d152024-01-30 13:37:01 +0530130@pytest.mark.buildconfigspec('cmd_dhcp')
131@pytest.mark.buildconfigspec('cmd_mii')
Simon Glassddba5202025-02-09 09:07:14 -0700132def test_net_dhcp_abort(ubman):
Love Kumar4578d152024-01-30 13:37:01 +0530133 """Test the dhcp command by pressing ctrl+c in the middle of dhcp request
134
135 The boardenv_* file may be used to enable/disable this test; see the
136 comment at the beginning of this file.
137 """
138
Simon Glassddba5202025-02-09 09:07:14 -0700139 test_dhcp = ubman.config.env.get('env__net_dhcp_server', False)
Love Kumar4578d152024-01-30 13:37:01 +0530140 if not test_dhcp:
141 pytest.skip('No DHCP server available')
142
Simon Glassddba5202025-02-09 09:07:14 -0700143 if ubman.config.env.get('env__dhcp_abort_test_skip', True):
Love Kumar4578d152024-01-30 13:37:01 +0530144 pytest.skip('DHCP abort test is not enabled!')
145
Simon Glassddba5202025-02-09 09:07:14 -0700146 ubman.run_command('setenv autoload no')
Love Kumar4578d152024-01-30 13:37:01 +0530147
148 # Phy reset before running dhcp command
Simon Glassddba5202025-02-09 09:07:14 -0700149 output = ubman.run_command('mii device')
Love Kumar4578d152024-01-30 13:37:01 +0530150 if not re.search(r"Current device: '(.+?)'", output):
151 pytest.skip('PHY device does not exist!')
152 eth_num = re.search(r"Current device: '(.+?)'", output).groups()[0]
Simon Glassddba5202025-02-09 09:07:14 -0700153 ubman.run_command(f'mii device {eth_num}')
154 output = ubman.run_command('mii info')
Love Kumar4578d152024-01-30 13:37:01 +0530155 eth_addr = hex(int(re.search(r'PHY (.+?):', output).groups()[0], 16))
Simon Glassddba5202025-02-09 09:07:14 -0700156 ubman.run_command(f'mii modify {eth_addr} 0 0x8000 0x8000')
Love Kumar4578d152024-01-30 13:37:01 +0530157
Simon Glassddba5202025-02-09 09:07:14 -0700158 ubman.run_command('dhcp', wait_for_prompt=False)
Love Kumar4578d152024-01-30 13:37:01 +0530159 try:
Simon Glassddba5202025-02-09 09:07:14 -0700160 ubman.wait_for('Waiting for PHY auto negotiation to complete')
Love Kumar4578d152024-01-30 13:37:01 +0530161 except:
162 pytest.skip('Timeout waiting for PHY auto negotiation to complete')
163
Simon Glassddba5202025-02-09 09:07:14 -0700164 ubman.wait_for('done')
Love Kumar4578d152024-01-30 13:37:01 +0530165
166 try:
167 # Sending Ctrl-C
Simon Glassddba5202025-02-09 09:07:14 -0700168 output = ubman.run_command(
Love Kumar4578d152024-01-30 13:37:01 +0530169 chr(3), wait_for_echo=False, send_nl=False
170 )
171 assert 'TIMEOUT' not in output
172 assert 'DHCP client bound to address ' not in output
173 assert 'Abort' in output
174 finally:
175 # Provide a time to recover from Abort - if it is not performed
176 # There is message like: ethernet@ff0e0000: No link.
Simon Glassddba5202025-02-09 09:07:14 -0700177 ubman.run_command('sleep 1')
Love Kumar4578d152024-01-30 13:37:01 +0530178 # Run the dhcp test to setup the network configuration
Simon Glassddba5202025-02-09 09:07:14 -0700179 test_net_dhcp(ubman)
Love Kumar4578d152024-01-30 13:37:01 +0530180
Sean Edmondd407acf2023-04-11 10:48:48 -0700181@pytest.mark.buildconfigspec('cmd_dhcp6')
Simon Glassddba5202025-02-09 09:07:14 -0700182def test_net_dhcp6(ubman):
Sean Edmondd407acf2023-04-11 10:48:48 -0700183 """Test the dhcp6 command.
184
185 The boardenv_* file may be used to enable/disable this test; see the
186 comment at the beginning of this file.
187 """
188
Simon Glassddba5202025-02-09 09:07:14 -0700189 test_dhcp6 = ubman.config.env.get('env__net_dhcp6_server', False)
Sean Edmondd407acf2023-04-11 10:48:48 -0700190 if not test_dhcp6:
191 pytest.skip('No DHCP6 server available')
192
Simon Glassddba5202025-02-09 09:07:14 -0700193 ubman.run_command('setenv autoload no')
194 output = ubman.run_command('dhcp6')
Sean Edmondd407acf2023-04-11 10:48:48 -0700195 assert 'DHCP6 client bound to ' in output
196
197 global net6_set_up
198 net6_set_up = True
199
Stephen Warren1a218552016-01-21 16:05:31 -0700200@pytest.mark.buildconfigspec('net')
Simon Glassddba5202025-02-09 09:07:14 -0700201def test_net_setup_static(ubman):
Stephen Warren75e731e2016-01-26 13:41:30 -0700202 """Set up a static IP configuration.
Stephen Warren1a218552016-01-21 16:05:31 -0700203
204 The configuration is provided by the boardenv_* file; see the comment at
205 the beginning of this file.
Stephen Warren75e731e2016-01-26 13:41:30 -0700206 """
Stephen Warren1a218552016-01-21 16:05:31 -0700207
Simon Glassddba5202025-02-09 09:07:14 -0700208 env_vars = ubman.config.env.get('env__net_static_env_vars', None)
Stephen Warren1a218552016-01-21 16:05:31 -0700209 if not env_vars:
210 pytest.skip('No static network configuration is defined')
211
212 for (var, val) in env_vars:
Simon Glassddba5202025-02-09 09:07:14 -0700213 ubman.run_command('setenv %s %s' % (var, val))
Stephen Warren1a218552016-01-21 16:05:31 -0700214
215 global net_set_up
216 net_set_up = True
217
218@pytest.mark.buildconfigspec('cmd_ping')
Simon Glassddba5202025-02-09 09:07:14 -0700219def test_net_ping(ubman):
Stephen Warren75e731e2016-01-26 13:41:30 -0700220 """Test the ping command.
Stephen Warren1a218552016-01-21 16:05:31 -0700221
222 The $serverip (as set up by either test_net_dhcp or test_net_setup_static)
223 is pinged. The test validates that the host is alive, as reported by the
224 ping command's output.
Stephen Warren75e731e2016-01-26 13:41:30 -0700225 """
Stephen Warren1a218552016-01-21 16:05:31 -0700226
227 if not net_set_up:
Stephen Warren3deb8962016-01-26 13:41:31 -0700228 pytest.skip('Network not initialized')
Stephen Warren1a218552016-01-21 16:05:31 -0700229
Simon Glassddba5202025-02-09 09:07:14 -0700230 output = ubman.run_command('ping $serverip')
Stephen Warren1a218552016-01-21 16:05:31 -0700231 assert 'is alive' in output
232
Ehsan Mohandesi3eb50532023-04-21 17:08:22 -0700233@pytest.mark.buildconfigspec('IPV6_ROUTER_DISCOVERY')
Simon Glassddba5202025-02-09 09:07:14 -0700234def test_net_network_discovery(ubman):
Ehsan Mohandesi3eb50532023-04-21 17:08:22 -0700235 """Test the network discovery feature of IPv6.
236
237 An IPv6 network command (ping6 in this case) is run to make U-Boot send a
238 router solicitation packet, receive a router advertisement message, and
239 parse it.
240 A router advertisement service needs to be running for this test to succeed.
241 U-Boot receives the RA, processes it, and if successful, assigns the gateway
242 IP and prefix length.
243 The configuration is provided by the boardenv_* file; see the comment at
244 the beginning of this file.
245 """
246
Simon Glassddba5202025-02-09 09:07:14 -0700247 router_on_net = ubman.config.env.get('env__router_on_net', False)
Ehsan Mohandesi3eb50532023-04-21 17:08:22 -0700248 if not router_on_net:
249 pytest.skip('No router on network')
250
251 fake_host_ip = 'fe80::215:5dff:fef6:2ec6'
Simon Glassddba5202025-02-09 09:07:14 -0700252 output = ubman.run_command('ping6 ' + fake_host_ip)
Ehsan Mohandesi3eb50532023-04-21 17:08:22 -0700253 assert 'ROUTER SOLICITATION 1' in output
254 assert 'Set gatewayip6:' in output
255 assert '0000:0000:0000:0000:0000:0000:0000:0000' not in output
256
Tom Rini5568cc32024-06-18 14:23:43 -0600257@pytest.mark.buildconfigspec('cmd_tftpboot')
Simon Glassddba5202025-02-09 09:07:14 -0700258def test_net_tftpboot(ubman):
Stephen Warren75e731e2016-01-26 13:41:30 -0700259 """Test the tftpboot command.
Stephen Warren1a218552016-01-21 16:05:31 -0700260
261 A file is downloaded from the TFTP server, its size and optionally its
262 CRC32 are validated.
263
264 The details of the file to download are provided by the boardenv_* file;
265 see the comment at the beginning of this file.
Stephen Warren75e731e2016-01-26 13:41:30 -0700266 """
Stephen Warren1a218552016-01-21 16:05:31 -0700267
268 if not net_set_up:
Stephen Warren3deb8962016-01-26 13:41:31 -0700269 pytest.skip('Network not initialized')
Stephen Warren1a218552016-01-21 16:05:31 -0700270
Simon Glassddba5202025-02-09 09:07:14 -0700271 f = ubman.config.env.get('env__net_tftp_readable_file', None)
Stephen Warren1a218552016-01-21 16:05:31 -0700272 if not f:
273 pytest.skip('No TFTP readable file to read')
274
Michal Simek6596e032016-04-04 20:06:14 +0200275 addr = f.get('addr', None)
Michal Simek6596e032016-04-04 20:06:14 +0200276
Stephen Warren1a218552016-01-21 16:05:31 -0700277 fn = f['fn']
Heinrich Schuchardt23287c82019-01-26 15:25:12 +0100278 if not addr:
Simon Glassddba5202025-02-09 09:07:14 -0700279 output = ubman.run_command('tftpboot %s' % (fn))
Heinrich Schuchardt23287c82019-01-26 15:25:12 +0100280 else:
Simon Glassddba5202025-02-09 09:07:14 -0700281 output = ubman.run_command('tftpboot %x %s' % (addr, fn))
Stephen Warren1a218552016-01-21 16:05:31 -0700282 expected_text = 'Bytes transferred = '
283 sz = f.get('size', None)
284 if sz:
285 expected_text += '%d' % sz
286 assert expected_text in output
287
288 expected_crc = f.get('crc32', None)
289 if not expected_crc:
290 return
291
Simon Glassddba5202025-02-09 09:07:14 -0700292 if ubman.config.buildconfig.get('config_cmd_crc32', 'n') != 'y':
Stephen Warren1a218552016-01-21 16:05:31 -0700293 return
294
Simon Glassddba5202025-02-09 09:07:14 -0700295 output = ubman.run_command('crc32 $fileaddr $filesize')
Stephen Warren1a218552016-01-21 16:05:31 -0700296 assert expected_crc in output
Guillaume GARDET1b0102d2016-09-14 10:29:12 +0200297
298@pytest.mark.buildconfigspec('cmd_nfs')
Simon Glassddba5202025-02-09 09:07:14 -0700299def test_net_nfs(ubman):
Guillaume GARDET1b0102d2016-09-14 10:29:12 +0200300 """Test the nfs command.
301
302 A file is downloaded from the NFS server, its size and optionally its
303 CRC32 are validated.
304
305 The details of the file to download are provided by the boardenv_* file;
306 see the comment at the beginning of this file.
307 """
308
309 if not net_set_up:
310 pytest.skip('Network not initialized')
311
Simon Glassddba5202025-02-09 09:07:14 -0700312 f = ubman.config.env.get('env__net_nfs_readable_file', None)
Guillaume GARDET1b0102d2016-09-14 10:29:12 +0200313 if not f:
314 pytest.skip('No NFS readable file to read')
315
316 addr = f.get('addr', None)
317 if not addr:
Simon Glassddba5202025-02-09 09:07:14 -0700318 addr = u_boot_utils.find_ram_base(ubman)
Guillaume GARDET1b0102d2016-09-14 10:29:12 +0200319
320 fn = f['fn']
Simon Glassddba5202025-02-09 09:07:14 -0700321 output = ubman.run_command('nfs %x %s' % (addr, fn))
Guillaume GARDET1b0102d2016-09-14 10:29:12 +0200322 expected_text = 'Bytes transferred = '
323 sz = f.get('size', None)
324 if sz:
325 expected_text += '%d' % sz
326 assert expected_text in output
327
328 expected_crc = f.get('crc32', None)
329 if not expected_crc:
330 return
331
Simon Glassddba5202025-02-09 09:07:14 -0700332 if ubman.config.buildconfig.get('config_cmd_crc32', 'n') != 'y':
Guillaume GARDET1b0102d2016-09-14 10:29:12 +0200333 return
334
Simon Glassddba5202025-02-09 09:07:14 -0700335 output = ubman.run_command('crc32 %x $filesize' % addr)
Guillaume GARDET1b0102d2016-09-14 10:29:12 +0200336 assert expected_crc in output
Love Kumar55ef4532023-10-03 18:42:46 +0530337
Love Kumar55ef4532023-10-03 18:42:46 +0530338@pytest.mark.buildconfigspec("cmd_pxe")
Simon Glassddba5202025-02-09 09:07:14 -0700339def test_net_pxe_get(ubman):
Love Kumar55ef4532023-10-03 18:42:46 +0530340 """Test the pxe get command.
341
342 A pxe configuration file is downloaded from the TFTP server and interpreted
343 to boot the images mentioned in pxe configuration file.
344
345 The details of the file to download are provided by the boardenv_* file;
346 see the comment at the beginning of this file.
347 """
348
349 if not net_set_up:
350 pytest.skip("Network not initialized")
351
Simon Glassddba5202025-02-09 09:07:14 -0700352 test_net_setup_static(ubman)
Love Kumar55ef4532023-10-03 18:42:46 +0530353
Simon Glassddba5202025-02-09 09:07:14 -0700354 f = ubman.config.env.get("env__net_pxe_readable_file", None)
Love Kumar55ef4532023-10-03 18:42:46 +0530355 if not f:
356 pytest.skip("No PXE readable file to read")
357
358 addr = f.get("addr", None)
Simon Glassddba5202025-02-09 09:07:14 -0700359 timeout = f.get("timeout", ubman.p.timeout)
Love Kumar55ef4532023-10-03 18:42:46 +0530360
361 pxeuuid = uuid.uuid1()
Simon Glassddba5202025-02-09 09:07:14 -0700362 ubman.run_command(f"setenv pxeuuid {pxeuuid}")
Love Kumar55ef4532023-10-03 18:42:46 +0530363 expected_text_uuid = f"Retrieving file: pxelinux.cfg/{pxeuuid}"
364
Simon Glassddba5202025-02-09 09:07:14 -0700365 ethaddr = ubman.run_command("echo $ethaddr")
Love Kumar55ef4532023-10-03 18:42:46 +0530366 ethaddr = ethaddr.replace(':', '-')
367 expected_text_ethaddr = f"Retrieving file: pxelinux.cfg/01-{ethaddr}"
368
Simon Glassddba5202025-02-09 09:07:14 -0700369 ip = ubman.run_command("echo $ipaddr")
Love Kumar55ef4532023-10-03 18:42:46 +0530370 ip = ip.split('.')
371 ipaddr_file = "".join(['%02x' % int(x) for x in ip]).upper()
372 expected_text_ipaddr = f"Retrieving file: pxelinux.cfg/{ipaddr_file}"
373 expected_text_default = f"Retrieving file: pxelinux.cfg/default"
374
Simon Glassddba5202025-02-09 09:07:14 -0700375 with ubman.temporary_timeout(timeout):
376 output = ubman.run_command("pxe get")
Love Kumar55ef4532023-10-03 18:42:46 +0530377
378 assert "TIMEOUT" not in output
379 assert expected_text_uuid in output
380 assert expected_text_ethaddr in output
381 assert expected_text_ipaddr in output
382
383 i = 1
384 for i in range(0, len(ipaddr_file) - 1):
385 expected_text_ip = f"Retrieving file: pxelinux.cfg/{ipaddr_file[:-i]}"
386 assert expected_text_ip in output
387 i += 1
388
389 assert expected_text_default in output
390 assert "Config file 'default.boot' found" in output
Love Kumar49f87492023-11-08 12:40:31 +0530391
392@pytest.mark.buildconfigspec("cmd_crc32")
Tom Rini5568cc32024-06-18 14:23:43 -0600393@pytest.mark.buildconfigspec("cmd_tftpboot")
Love Kumar49f87492023-11-08 12:40:31 +0530394@pytest.mark.buildconfigspec("cmd_tftpput")
Simon Glassddba5202025-02-09 09:07:14 -0700395def test_net_tftpput(ubman):
Love Kumar49f87492023-11-08 12:40:31 +0530396 """Test the tftpput command.
397
398 A file is downloaded from the TFTP server and then uploaded to the TFTP
399 server, its size and its CRC32 are validated.
400
401 The details of the file to download are provided by the boardenv_* file;
402 see the comment at the beginning of this file.
403 """
404
405 if not net_set_up:
406 pytest.skip("Network not initialized")
407
Simon Glassddba5202025-02-09 09:07:14 -0700408 f = ubman.config.env.get("env__net_tftp_readable_file", None)
Love Kumar49f87492023-11-08 12:40:31 +0530409 if not f:
410 pytest.skip("No TFTP readable file to read")
411
412 addr = f.get("addr", None)
413 if not addr:
Simon Glassddba5202025-02-09 09:07:14 -0700414 addr = u_boot_utils.find_ram_base(ubman)
Love Kumar49f87492023-11-08 12:40:31 +0530415
416 sz = f.get("size", None)
Simon Glassddba5202025-02-09 09:07:14 -0700417 timeout = f.get("timeout", ubman.p.timeout)
Love Kumar49f87492023-11-08 12:40:31 +0530418 fn = f["fn"]
419 fnu = f.get("fnu", "_".join([datetime.datetime.now().strftime("%y%m%d%H%M%S"), fn]))
420 expected_text = "Bytes transferred = "
421 if sz:
422 expected_text += "%d" % sz
423
Simon Glassddba5202025-02-09 09:07:14 -0700424 with ubman.temporary_timeout(timeout):
425 output = ubman.run_command("tftpboot %x %s" % (addr, fn))
Love Kumar49f87492023-11-08 12:40:31 +0530426
427 assert "TIMEOUT" not in output
428 assert expected_text in output
429
430 expected_tftpb_crc = f.get("crc32", None)
431
Simon Glassddba5202025-02-09 09:07:14 -0700432 output = ubman.run_command("crc32 $fileaddr $filesize")
Love Kumar49f87492023-11-08 12:40:31 +0530433 assert expected_tftpb_crc in output
434
Simon Glassddba5202025-02-09 09:07:14 -0700435 with ubman.temporary_timeout(timeout):
436 output = ubman.run_command(
Love Kumar49f87492023-11-08 12:40:31 +0530437 "tftpput $fileaddr $filesize $serverip:%s" % (fnu)
438 )
439
440 expected_text = "Bytes transferred = "
441 if sz:
442 expected_text += "%d" % sz
443 addr = addr + sz
444 assert "TIMEOUT" not in output
445 assert "Access violation" not in output
446 assert expected_text in output
447
Simon Glassddba5202025-02-09 09:07:14 -0700448 with ubman.temporary_timeout(timeout):
449 output = ubman.run_command("tftpboot %x %s" % (addr, fnu))
Love Kumar49f87492023-11-08 12:40:31 +0530450
451 expected_text = "Bytes transferred = "
452 if sz:
453 expected_text += "%d" % sz
454 assert "TIMEOUT" not in output
455 assert expected_text in output
456
Simon Glassddba5202025-02-09 09:07:14 -0700457 output = ubman.run_command("crc32 $fileaddr $filesize")
Love Kumar49f87492023-11-08 12:40:31 +0530458 assert expected_tftpb_crc in output