blob: 4732e4b57f8ad966ff02fafec9401224784723ec [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
Simon Glassfb916372025-02-09 09:07:15 -07008import 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 Glass86bf4ef2025-02-09 09:07:19 -070094
95@pytest.mark.buildconfigspec('cmd_net')
Simon Glassddba5202025-02-09 09:07:14 -070096def test_net_pre_commands(ubman):
Stephen Warren75e731e2016-01-26 13:41:30 -070097 """Execute any commands required to enable network hardware.
Stephen Warren1a218552016-01-21 16:05:31 -070098
99 These commands are provided by the boardenv_* file; see the comment at the
100 beginning of this file.
Stephen Warren75e731e2016-01-26 13:41:30 -0700101 """
Stephen Warren1a218552016-01-21 16:05:31 -0700102
Simon Glassddba5202025-02-09 09:07:14 -0700103 init_usb = ubman.config.env.get('env__net_uses_usb', False)
Stephen Warren8d57b922016-01-26 11:10:14 -0700104 if init_usb:
Simon Glassddba5202025-02-09 09:07:14 -0700105 ubman.run_command('usb start')
Stephen Warren1a218552016-01-21 16:05:31 -0700106
Simon Glassddba5202025-02-09 09:07:14 -0700107 init_pci = ubman.config.env.get('env__net_uses_pci', False)
Stephen Warren8d57b922016-01-26 11:10:14 -0700108 if init_pci:
Simon Glassddba5202025-02-09 09:07:14 -0700109 ubman.run_command('pci enum')
Stephen Warren1a218552016-01-21 16:05:31 -0700110
Simon Glassddba5202025-02-09 09:07:14 -0700111 ubman.run_command('net list')
Maxim Uvarovb5977fc2023-12-26 21:46:12 +0600112
Stephen Warren1a218552016-01-21 16:05:31 -0700113@pytest.mark.buildconfigspec('cmd_dhcp')
Simon Glassddba5202025-02-09 09:07:14 -0700114def test_net_dhcp(ubman):
Stephen Warren75e731e2016-01-26 13:41:30 -0700115 """Test the dhcp command.
Stephen Warren1a218552016-01-21 16:05:31 -0700116
117 The boardenv_* file may be used to enable/disable this test; see the
118 comment at the beginning of this file.
Stephen Warren75e731e2016-01-26 13:41:30 -0700119 """
Stephen Warren1a218552016-01-21 16:05:31 -0700120
Simon Glassddba5202025-02-09 09:07:14 -0700121 test_dhcp = ubman.config.env.get('env__net_dhcp_server', False)
Stephen Warren1a218552016-01-21 16:05:31 -0700122 if not test_dhcp:
123 pytest.skip('No DHCP server available')
124
Simon Glassddba5202025-02-09 09:07:14 -0700125 ubman.run_command('setenv autoload no')
126 output = ubman.run_command('dhcp')
Stephen Warren1a218552016-01-21 16:05:31 -0700127 assert 'DHCP client bound to address ' in output
128
129 global net_set_up
130 net_set_up = True
131
Love Kumar4578d152024-01-30 13:37:01 +0530132@pytest.mark.buildconfigspec('cmd_dhcp')
133@pytest.mark.buildconfigspec('cmd_mii')
Simon Glassddba5202025-02-09 09:07:14 -0700134def test_net_dhcp_abort(ubman):
Love Kumar4578d152024-01-30 13:37:01 +0530135 """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 Glassddba5202025-02-09 09:07:14 -0700141 test_dhcp = ubman.config.env.get('env__net_dhcp_server', False)
Love Kumar4578d152024-01-30 13:37:01 +0530142 if not test_dhcp:
143 pytest.skip('No DHCP server available')
144
Simon Glassddba5202025-02-09 09:07:14 -0700145 if ubman.config.env.get('env__dhcp_abort_test_skip', True):
Love Kumar4578d152024-01-30 13:37:01 +0530146 pytest.skip('DHCP abort test is not enabled!')
147
Simon Glassddba5202025-02-09 09:07:14 -0700148 ubman.run_command('setenv autoload no')
Love Kumar4578d152024-01-30 13:37:01 +0530149
150 # Phy reset before running dhcp command
Simon Glassddba5202025-02-09 09:07:14 -0700151 output = ubman.run_command('mii device')
Love Kumar4578d152024-01-30 13:37:01 +0530152 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 Glassddba5202025-02-09 09:07:14 -0700155 ubman.run_command(f'mii device {eth_num}')
156 output = ubman.run_command('mii info')
Love Kumar4578d152024-01-30 13:37:01 +0530157 eth_addr = hex(int(re.search(r'PHY (.+?):', output).groups()[0], 16))
Simon Glassddba5202025-02-09 09:07:14 -0700158 ubman.run_command(f'mii modify {eth_addr} 0 0x8000 0x8000')
Love Kumar4578d152024-01-30 13:37:01 +0530159
Simon Glassddba5202025-02-09 09:07:14 -0700160 ubman.run_command('dhcp', wait_for_prompt=False)
Love Kumar4578d152024-01-30 13:37:01 +0530161 try:
Simon Glassddba5202025-02-09 09:07:14 -0700162 ubman.wait_for('Waiting for PHY auto negotiation to complete')
Love Kumar4578d152024-01-30 13:37:01 +0530163 except:
164 pytest.skip('Timeout waiting for PHY auto negotiation to complete')
165
Simon Glassddba5202025-02-09 09:07:14 -0700166 ubman.wait_for('done')
Love Kumar4578d152024-01-30 13:37:01 +0530167
168 try:
169 # Sending Ctrl-C
Simon Glassddba5202025-02-09 09:07:14 -0700170 output = ubman.run_command(
Love Kumar4578d152024-01-30 13:37:01 +0530171 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 Glassddba5202025-02-09 09:07:14 -0700179 ubman.run_command('sleep 1')
Love Kumar4578d152024-01-30 13:37:01 +0530180 # Run the dhcp test to setup the network configuration
Simon Glassddba5202025-02-09 09:07:14 -0700181 test_net_dhcp(ubman)
Love Kumar4578d152024-01-30 13:37:01 +0530182
Sean Edmondd407acf2023-04-11 10:48:48 -0700183@pytest.mark.buildconfigspec('cmd_dhcp6')
Simon Glassddba5202025-02-09 09:07:14 -0700184def test_net_dhcp6(ubman):
Sean Edmondd407acf2023-04-11 10:48:48 -0700185 """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 Glassddba5202025-02-09 09:07:14 -0700191 test_dhcp6 = ubman.config.env.get('env__net_dhcp6_server', False)
Sean Edmondd407acf2023-04-11 10:48:48 -0700192 if not test_dhcp6:
193 pytest.skip('No DHCP6 server available')
194
Simon Glassddba5202025-02-09 09:07:14 -0700195 ubman.run_command('setenv autoload no')
196 output = ubman.run_command('dhcp6')
Sean Edmondd407acf2023-04-11 10:48:48 -0700197 assert 'DHCP6 client bound to ' in output
198
199 global net6_set_up
200 net6_set_up = True
201
Stephen Warren1a218552016-01-21 16:05:31 -0700202@pytest.mark.buildconfigspec('net')
Simon Glassddba5202025-02-09 09:07:14 -0700203def test_net_setup_static(ubman):
Stephen Warren75e731e2016-01-26 13:41:30 -0700204 """Set up a static IP configuration.
Stephen Warren1a218552016-01-21 16:05:31 -0700205
206 The configuration is provided by the boardenv_* file; see the comment at
207 the beginning of this file.
Stephen Warren75e731e2016-01-26 13:41:30 -0700208 """
Stephen Warren1a218552016-01-21 16:05:31 -0700209
Simon Glassddba5202025-02-09 09:07:14 -0700210 env_vars = ubman.config.env.get('env__net_static_env_vars', None)
Stephen Warren1a218552016-01-21 16:05:31 -0700211 if not env_vars:
212 pytest.skip('No static network configuration is defined')
213
214 for (var, val) in env_vars:
Simon Glassddba5202025-02-09 09:07:14 -0700215 ubman.run_command('setenv %s %s' % (var, val))
Stephen Warren1a218552016-01-21 16:05:31 -0700216
217 global net_set_up
218 net_set_up = True
219
220@pytest.mark.buildconfigspec('cmd_ping')
Simon Glassddba5202025-02-09 09:07:14 -0700221def test_net_ping(ubman):
Stephen Warren75e731e2016-01-26 13:41:30 -0700222 """Test the ping command.
Stephen Warren1a218552016-01-21 16:05:31 -0700223
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 Warren75e731e2016-01-26 13:41:30 -0700227 """
Stephen Warren1a218552016-01-21 16:05:31 -0700228
229 if not net_set_up:
Stephen Warren3deb8962016-01-26 13:41:31 -0700230 pytest.skip('Network not initialized')
Stephen Warren1a218552016-01-21 16:05:31 -0700231
Simon Glassddba5202025-02-09 09:07:14 -0700232 output = ubman.run_command('ping $serverip')
Stephen Warren1a218552016-01-21 16:05:31 -0700233 assert 'is alive' in output
234
Ehsan Mohandesi3eb50532023-04-21 17:08:22 -0700235@pytest.mark.buildconfigspec('IPV6_ROUTER_DISCOVERY')
Simon Glassddba5202025-02-09 09:07:14 -0700236def test_net_network_discovery(ubman):
Ehsan Mohandesi3eb50532023-04-21 17:08:22 -0700237 """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 Glassddba5202025-02-09 09:07:14 -0700249 router_on_net = ubman.config.env.get('env__router_on_net', False)
Ehsan Mohandesi3eb50532023-04-21 17:08:22 -0700250 if not router_on_net:
251 pytest.skip('No router on network')
252
253 fake_host_ip = 'fe80::215:5dff:fef6:2ec6'
Simon Glassddba5202025-02-09 09:07:14 -0700254 output = ubman.run_command('ping6 ' + fake_host_ip)
Ehsan Mohandesi3eb50532023-04-21 17:08:22 -0700255 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 Rini5568cc32024-06-18 14:23:43 -0600259@pytest.mark.buildconfigspec('cmd_tftpboot')
Simon Glassddba5202025-02-09 09:07:14 -0700260def test_net_tftpboot(ubman):
Stephen Warren75e731e2016-01-26 13:41:30 -0700261 """Test the tftpboot command.
Stephen Warren1a218552016-01-21 16:05:31 -0700262
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 Warren75e731e2016-01-26 13:41:30 -0700268 """
Stephen Warren1a218552016-01-21 16:05:31 -0700269
270 if not net_set_up:
Stephen Warren3deb8962016-01-26 13:41:31 -0700271 pytest.skip('Network not initialized')
Stephen Warren1a218552016-01-21 16:05:31 -0700272
Simon Glassddba5202025-02-09 09:07:14 -0700273 f = ubman.config.env.get('env__net_tftp_readable_file', None)
Stephen Warren1a218552016-01-21 16:05:31 -0700274 if not f:
275 pytest.skip('No TFTP readable file to read')
276
Michal Simek6596e032016-04-04 20:06:14 +0200277 addr = f.get('addr', None)
Michal Simek6596e032016-04-04 20:06:14 +0200278
Stephen Warren1a218552016-01-21 16:05:31 -0700279 fn = f['fn']
Heinrich Schuchardt23287c82019-01-26 15:25:12 +0100280 if not addr:
Simon Glassddba5202025-02-09 09:07:14 -0700281 output = ubman.run_command('tftpboot %s' % (fn))
Heinrich Schuchardt23287c82019-01-26 15:25:12 +0100282 else:
Simon Glassddba5202025-02-09 09:07:14 -0700283 output = ubman.run_command('tftpboot %x %s' % (addr, fn))
Stephen Warren1a218552016-01-21 16:05:31 -0700284 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 Glassddba5202025-02-09 09:07:14 -0700294 if ubman.config.buildconfig.get('config_cmd_crc32', 'n') != 'y':
Stephen Warren1a218552016-01-21 16:05:31 -0700295 return
296
Simon Glassddba5202025-02-09 09:07:14 -0700297 output = ubman.run_command('crc32 $fileaddr $filesize')
Stephen Warren1a218552016-01-21 16:05:31 -0700298 assert expected_crc in output
Guillaume GARDET1b0102d2016-09-14 10:29:12 +0200299
300@pytest.mark.buildconfigspec('cmd_nfs')
Simon Glassddba5202025-02-09 09:07:14 -0700301def test_net_nfs(ubman):
Guillaume GARDET1b0102d2016-09-14 10:29:12 +0200302 """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 Glassddba5202025-02-09 09:07:14 -0700314 f = ubman.config.env.get('env__net_nfs_readable_file', None)
Guillaume GARDET1b0102d2016-09-14 10:29:12 +0200315 if not f:
316 pytest.skip('No NFS readable file to read')
317
318 addr = f.get('addr', None)
319 if not addr:
Simon Glassfb916372025-02-09 09:07:15 -0700320 addr = utils.find_ram_base(ubman)
Guillaume GARDET1b0102d2016-09-14 10:29:12 +0200321
322 fn = f['fn']
Simon Glassddba5202025-02-09 09:07:14 -0700323 output = ubman.run_command('nfs %x %s' % (addr, fn))
Guillaume GARDET1b0102d2016-09-14 10:29:12 +0200324 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 Glassddba5202025-02-09 09:07:14 -0700334 if ubman.config.buildconfig.get('config_cmd_crc32', 'n') != 'y':
Guillaume GARDET1b0102d2016-09-14 10:29:12 +0200335 return
336
Simon Glassddba5202025-02-09 09:07:14 -0700337 output = ubman.run_command('crc32 %x $filesize' % addr)
Guillaume GARDET1b0102d2016-09-14 10:29:12 +0200338 assert expected_crc in output
Love Kumar55ef4532023-10-03 18:42:46 +0530339
Love Kumar55ef4532023-10-03 18:42:46 +0530340@pytest.mark.buildconfigspec("cmd_pxe")
Simon Glassddba5202025-02-09 09:07:14 -0700341def test_net_pxe_get(ubman):
Love Kumar55ef4532023-10-03 18:42:46 +0530342 """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 Glassddba5202025-02-09 09:07:14 -0700354 test_net_setup_static(ubman)
Love Kumar55ef4532023-10-03 18:42:46 +0530355
Simon Glassddba5202025-02-09 09:07:14 -0700356 f = ubman.config.env.get("env__net_pxe_readable_file", None)
Love Kumar55ef4532023-10-03 18:42:46 +0530357 if not f:
358 pytest.skip("No PXE readable file to read")
359
360 addr = f.get("addr", None)
Simon Glassddba5202025-02-09 09:07:14 -0700361 timeout = f.get("timeout", ubman.p.timeout)
Love Kumar55ef4532023-10-03 18:42:46 +0530362
363 pxeuuid = uuid.uuid1()
Simon Glassddba5202025-02-09 09:07:14 -0700364 ubman.run_command(f"setenv pxeuuid {pxeuuid}")
Love Kumar55ef4532023-10-03 18:42:46 +0530365 expected_text_uuid = f"Retrieving file: pxelinux.cfg/{pxeuuid}"
366
Simon Glassddba5202025-02-09 09:07:14 -0700367 ethaddr = ubman.run_command("echo $ethaddr")
Love Kumar55ef4532023-10-03 18:42:46 +0530368 ethaddr = ethaddr.replace(':', '-')
369 expected_text_ethaddr = f"Retrieving file: pxelinux.cfg/01-{ethaddr}"
370
Simon Glassddba5202025-02-09 09:07:14 -0700371 ip = ubman.run_command("echo $ipaddr")
Love Kumar55ef4532023-10-03 18:42:46 +0530372 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 Glassddba5202025-02-09 09:07:14 -0700377 with ubman.temporary_timeout(timeout):
378 output = ubman.run_command("pxe get")
Love Kumar55ef4532023-10-03 18:42:46 +0530379
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 Kumar49f87492023-11-08 12:40:31 +0530393
394@pytest.mark.buildconfigspec("cmd_crc32")
Tom Rini5568cc32024-06-18 14:23:43 -0600395@pytest.mark.buildconfigspec("cmd_tftpboot")
Love Kumar49f87492023-11-08 12:40:31 +0530396@pytest.mark.buildconfigspec("cmd_tftpput")
Simon Glassddba5202025-02-09 09:07:14 -0700397def test_net_tftpput(ubman):
Love Kumar49f87492023-11-08 12:40:31 +0530398 """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 Glassddba5202025-02-09 09:07:14 -0700410 f = ubman.config.env.get("env__net_tftp_readable_file", None)
Love Kumar49f87492023-11-08 12:40:31 +0530411 if not f:
412 pytest.skip("No TFTP readable file to read")
413
414 addr = f.get("addr", None)
415 if not addr:
Simon Glassfb916372025-02-09 09:07:15 -0700416 addr = utils.find_ram_base(ubman)
Love Kumar49f87492023-11-08 12:40:31 +0530417
418 sz = f.get("size", None)
Simon Glassddba5202025-02-09 09:07:14 -0700419 timeout = f.get("timeout", ubman.p.timeout)
Love Kumar49f87492023-11-08 12:40:31 +0530420 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 Glassddba5202025-02-09 09:07:14 -0700426 with ubman.temporary_timeout(timeout):
427 output = ubman.run_command("tftpboot %x %s" % (addr, fn))
Love Kumar49f87492023-11-08 12:40:31 +0530428
429 assert "TIMEOUT" not in output
430 assert expected_text in output
431
432 expected_tftpb_crc = f.get("crc32", None)
433
Simon Glassddba5202025-02-09 09:07:14 -0700434 output = ubman.run_command("crc32 $fileaddr $filesize")
Love Kumar49f87492023-11-08 12:40:31 +0530435 assert expected_tftpb_crc in output
436
Simon Glassddba5202025-02-09 09:07:14 -0700437 with ubman.temporary_timeout(timeout):
438 output = ubman.run_command(
Love Kumar49f87492023-11-08 12:40:31 +0530439 "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 Glassddba5202025-02-09 09:07:14 -0700450 with ubman.temporary_timeout(timeout):
451 output = ubman.run_command("tftpboot %x %s" % (addr, fnu))
Love Kumar49f87492023-11-08 12:40:31 +0530452
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 Glassddba5202025-02-09 09:07:14 -0700459 output = ubman.run_command("crc32 $fileaddr $filesize")
Love Kumar49f87492023-11-08 12:40:31 +0530460 assert expected_tftpb_crc in output