1 # SPDX-License-Identifier: GPL-2.0
2 # Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
4 # Test various network-related functionality, such as the dhcp, ping, and
11 Note: This test relies on boardenv_* containing configuration values to define
12 which the network environment available for testing. Without this, this test
13 will be automatically skipped.
17 # Boolean indicating whether the Ethernet device is attached to USB, and hence
18 # USB enumeration needs to be performed prior to network tests.
19 # This variable may be omitted if its value is False.
20 env__net_uses_usb = False
22 # Boolean indicating whether the Ethernet device is attached to PCI, and hence
23 # PCI enumeration needs to be performed prior to network tests.
24 # This variable may be omitted if its value is False.
25 env__net_uses_pci = True
27 # True if a DHCP server is attached to the network, and should be tested.
28 # If DHCP testing is not possible or desired, this variable may be omitted or
30 env__net_dhcp_server = True
32 # A list of environment variables that should be set in order to configure a
33 # static IP. If solely relying on DHCP, this variable may be omitted or set to
35 env__net_static_env_vars = [
36 ('ipaddr', '10.0.0.100'),
37 ('netmask', '255.255.255.0'),
38 ('serverip', '10.0.0.1'),
41 # Details regarding a file that may be read from a TFTP server. This variable
42 # may be omitted or set to None if TFTP testing is not possible or desired.
43 env__net_tftp_readable_file = {
44 'fn': 'ubtest-readable.bin',
50 # Details regarding a file that may be read from a NFS server. This variable
51 # may be omitted or set to None if NFS testing is not possible or desired.
52 env__net_nfs_readable_file = {
53 'fn': 'ubtest-readable.bin',
62 def test_net_pre_commands(u_boot_console):
63 """Execute any commands required to enable network hardware.
65 These commands are provided by the boardenv_* file; see the comment at the
66 beginning of this file.
69 init_usb = u_boot_console.config.env.get('env__net_uses_usb', False)
71 u_boot_console.run_command('usb start')
73 init_pci = u_boot_console.config.env.get('env__net_uses_pci', False)
75 u_boot_console.run_command('pci enum')
77 @pytest.mark.buildconfigspec('cmd_dhcp')
78 def test_net_dhcp(u_boot_console):
79 """Test the dhcp command.
81 The boardenv_* file may be used to enable/disable this test; see the
82 comment at the beginning of this file.
85 test_dhcp = u_boot_console.config.env.get('env__net_dhcp_server', False)
87 pytest.skip('No DHCP server available')
89 u_boot_console.run_command('setenv autoload no')
90 output = u_boot_console.run_command('dhcp')
91 assert 'DHCP client bound to address ' in output
96 @pytest.mark.buildconfigspec('net')
97 def test_net_setup_static(u_boot_console):
98 """Set up a static IP configuration.
100 The configuration is provided by the boardenv_* file; see the comment at
101 the beginning of this file.
104 env_vars = u_boot_console.config.env.get('env__net_static_env_vars', None)
106 pytest.skip('No static network configuration is defined')
108 for (var, val) in env_vars:
109 u_boot_console.run_command('setenv %s %s' % (var, val))
114 @pytest.mark.buildconfigspec('cmd_ping')
115 def test_net_ping(u_boot_console):
116 """Test the ping command.
118 The $serverip (as set up by either test_net_dhcp or test_net_setup_static)
119 is pinged. The test validates that the host is alive, as reported by the
120 ping command's output.
124 pytest.skip('Network not initialized')
126 output = u_boot_console.run_command('ping $serverip')
127 assert 'is alive' in output
129 @pytest.mark.buildconfigspec('cmd_net')
130 def test_net_tftpboot(u_boot_console):
131 """Test the tftpboot command.
133 A file is downloaded from the TFTP server, its size and optionally its
136 The details of the file to download are provided by the boardenv_* file;
137 see the comment at the beginning of this file.
141 pytest.skip('Network not initialized')
143 f = u_boot_console.config.env.get('env__net_tftp_readable_file', None)
145 pytest.skip('No TFTP readable file to read')
147 addr = f.get('addr', None)
151 output = u_boot_console.run_command('tftpboot %s' % (fn))
153 output = u_boot_console.run_command('tftpboot %x %s' % (addr, fn))
154 expected_text = 'Bytes transferred = '
155 sz = f.get('size', None)
157 expected_text += '%d' % sz
158 assert expected_text in output
160 expected_crc = f.get('crc32', None)
164 if u_boot_console.config.buildconfig.get('config_cmd_crc32', 'n') != 'y':
167 output = u_boot_console.run_command('crc32 $fileaddr $filesize')
168 assert expected_crc in output
170 @pytest.mark.buildconfigspec('cmd_nfs')
171 def test_net_nfs(u_boot_console):
172 """Test the nfs command.
174 A file is downloaded from the NFS server, its size and optionally its
177 The details of the file to download are provided by the boardenv_* file;
178 see the comment at the beginning of this file.
182 pytest.skip('Network not initialized')
184 f = u_boot_console.config.env.get('env__net_nfs_readable_file', None)
186 pytest.skip('No NFS readable file to read')
188 addr = f.get('addr', None)
190 addr = u_boot_utils.find_ram_base(u_boot_console)
193 output = u_boot_console.run_command('nfs %x %s' % (addr, fn))
194 expected_text = 'Bytes transferred = '
195 sz = f.get('size', None)
197 expected_text += '%d' % sz
198 assert expected_text in output
200 expected_crc = f.get('crc32', None)
204 if u_boot_console.config.buildconfig.get('config_cmd_crc32', 'n') != 'y':
207 output = u_boot_console.run_command('crc32 %x $filesize' % addr)
208 assert expected_crc in output