1 # Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
3 # SPDX-License-Identifier: GPL-2.0
5 # Test various network-related functionality, such as the dhcp, ping, and
12 Note: This test relies on boardenv_* containing configuration values to define
13 which the network environment available for testing. Without this, this test
14 will be automatically skipped.
18 # Any commands that need to be executed prior to testing,
19 # to get the network hardware into an operational state.
21 # If no commands are required, this variable may be omitted, or set to an
23 env__net_pre_commands = [
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",
52 def test_net_pre_commands(u_boot_console):
53 '''Execute any commands required to enable network hardware.
55 These commands are provided by the boardenv_* file; see the comment at the
56 beginning of this file.
59 cmds = u_boot_console.config.env.get('env__net_pre_commands', None)
61 pytest.skip('No network pre-commands defined')
64 u_boot_console.run_command(cmd)
66 @pytest.mark.buildconfigspec('cmd_dhcp')
67 def test_net_dhcp(u_boot_console):
68 '''Test the dhcp command.
70 The boardenv_* file may be used to enable/disable this test; see the
71 comment at the beginning of this file.
74 test_dhcp = u_boot_console.config.env.get('env__net_dhcp_server', False)
76 pytest.skip('No DHCP server available')
78 u_boot_console.run_command('setenv autoload no')
79 output = u_boot_console.run_command('dhcp')
80 assert 'DHCP client bound to address ' in output
85 @pytest.mark.buildconfigspec('net')
86 def test_net_setup_static(u_boot_console):
87 '''Set up a static IP configuration.
89 The configuration is provided by the boardenv_* file; see the comment at
90 the beginning of this file.
93 env_vars = u_boot_console.config.env.get('env__net_static_env_vars', None)
95 pytest.skip('No static network configuration is defined')
97 for (var, val) in env_vars:
98 u_boot_console.run_command('setenv %s %s' % (var, val))
103 @pytest.mark.buildconfigspec('cmd_ping')
104 def test_net_ping(u_boot_console):
105 '''Test the ping command.
107 The $serverip (as set up by either test_net_dhcp or test_net_setup_static)
108 is pinged. The test validates that the host is alive, as reported by the
109 ping command's output.
113 pytest.skip("Network not initialized")
115 output = u_boot_console.run_command('ping $serverip')
116 assert 'is alive' in output
118 @pytest.mark.buildconfigspec('cmd_net')
119 def test_net_tftpboot(u_boot_console):
120 '''Test the tftpboot command.
122 A file is downloaded from the TFTP server, its size and optionally its
125 The details of the file to download are provided by the boardenv_* file;
126 see the comment at the beginning of this file.
130 pytest.skip("Network not initialized")
132 f = u_boot_console.config.env.get('env__net_tftp_readable_file', None)
134 pytest.skip('No TFTP readable file to read')
136 addr = u_boot_utils.find_ram_base(u_boot_console)
138 output = u_boot_console.run_command('tftpboot %x %s' % (addr, fn))
139 expected_text = 'Bytes transferred = '
140 sz = f.get('size', None)
142 expected_text += '%d' % sz
143 assert expected_text in output
145 expected_crc = f.get('crc32', None)
149 if u_boot_console.config.buildconfig.get('config_cmd_crc32', 'n') != 'y':
152 output = u_boot_console.run_command('crc32 %x $filesize' % addr)
153 assert expected_crc in output