2016-01-21 23:05:31 +00:00
|
|
|
# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
# Test various network-related functionality, such as the dhcp, ping, and
|
|
|
|
# tftpboot commands.
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
import u_boot_utils
|
|
|
|
|
2016-01-26 20:41:30 +00:00
|
|
|
"""
|
2016-01-21 23:05:31 +00:00
|
|
|
Note: This test relies on boardenv_* containing configuration values to define
|
|
|
|
which the network environment available for testing. Without this, this test
|
|
|
|
will be automatically skipped.
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
test/py: make net test aware of USB and PCI enumeration
The existing net test executes a list of commands supplied by boardenv
variable env__net_pre_commands. The idea was that boardenv would know
whether the Ethernet device was attached to USB, PCI, ... and hence was
the best place to put any commands required to probe the device.
However, this approach doesn't scale well when attempting to use a single
boardenv across multiple branches of U-Boot, some of which require "pci
enum" to enumerate PCI and others of which don't, or don't /yet/ simply
because various upstream changes haven't been merged down.
This patch updates the test to require that the boardenv state which HW
features are required for Ethernet to work, and lets the test itself map
that knowledge to the set of commands to execute. Since this mapping is
part of the test script, which is part of the U-Boot code/branch, this
approach is more scalable. It also feels cleaner, since again boardenv
is only providing data, rather than test logic.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2016-01-26 18:10:14 +00:00
|
|
|
# Boolean indicating whether the Ethernet device is attached to USB, and hence
|
|
|
|
# USB enumeration needs to be performed prior to network tests.
|
|
|
|
# This variable may be omitted if its value is False.
|
|
|
|
env__net_uses_usb = False
|
|
|
|
|
|
|
|
# Boolean indicating whether the Ethernet device is attached to PCI, and hence
|
|
|
|
# PCI enumeration needs to be performed prior to network tests.
|
|
|
|
# This variable may be omitted if its value is False.
|
|
|
|
env__net_uses_pci = True
|
2016-01-21 23:05:31 +00:00
|
|
|
|
|
|
|
# True if a DHCP server is attached to the network, and should be tested.
|
|
|
|
# If DHCP testing is not possible or desired, this variable may be omitted or
|
|
|
|
# set to False.
|
|
|
|
env__net_dhcp_server = True
|
|
|
|
|
|
|
|
# A list of environment variables that should be set in order to configure a
|
|
|
|
# static IP. If solely relying on DHCP, this variable may be omitted or set to
|
|
|
|
# an empty list.
|
|
|
|
env__net_static_env_vars = [
|
|
|
|
("ipaddr", "10.0.0.100"),
|
|
|
|
("netmask", "255.255.255.0"),
|
|
|
|
("serverip", "10.0.0.1"),
|
|
|
|
]
|
|
|
|
|
|
|
|
# Details regarding a file that may be read from a TFTP server. This variable
|
|
|
|
# may be omitted or set to None if TFTP testing is not possible or desired.
|
|
|
|
env__net_tftp_readable_file = {
|
|
|
|
"fn": "ubtest-readable.bin",
|
|
|
|
"size": 5058624,
|
|
|
|
"crc32": "c2244b26",
|
|
|
|
}
|
2016-01-26 20:41:30 +00:00
|
|
|
"""
|
2016-01-21 23:05:31 +00:00
|
|
|
|
|
|
|
net_set_up = False
|
|
|
|
|
|
|
|
def test_net_pre_commands(u_boot_console):
|
2016-01-26 20:41:30 +00:00
|
|
|
"""Execute any commands required to enable network hardware.
|
2016-01-21 23:05:31 +00:00
|
|
|
|
|
|
|
These commands are provided by the boardenv_* file; see the comment at the
|
|
|
|
beginning of this file.
|
2016-01-26 20:41:30 +00:00
|
|
|
"""
|
2016-01-21 23:05:31 +00:00
|
|
|
|
test/py: make net test aware of USB and PCI enumeration
The existing net test executes a list of commands supplied by boardenv
variable env__net_pre_commands. The idea was that boardenv would know
whether the Ethernet device was attached to USB, PCI, ... and hence was
the best place to put any commands required to probe the device.
However, this approach doesn't scale well when attempting to use a single
boardenv across multiple branches of U-Boot, some of which require "pci
enum" to enumerate PCI and others of which don't, or don't /yet/ simply
because various upstream changes haven't been merged down.
This patch updates the test to require that the boardenv state which HW
features are required for Ethernet to work, and lets the test itself map
that knowledge to the set of commands to execute. Since this mapping is
part of the test script, which is part of the U-Boot code/branch, this
approach is more scalable. It also feels cleaner, since again boardenv
is only providing data, rather than test logic.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2016-01-26 18:10:14 +00:00
|
|
|
init_usb = u_boot_console.config.env.get('env__net_uses_usb', False)
|
|
|
|
if init_usb:
|
|
|
|
u_boot_console.run_command('usb start')
|
2016-01-21 23:05:31 +00:00
|
|
|
|
test/py: make net test aware of USB and PCI enumeration
The existing net test executes a list of commands supplied by boardenv
variable env__net_pre_commands. The idea was that boardenv would know
whether the Ethernet device was attached to USB, PCI, ... and hence was
the best place to put any commands required to probe the device.
However, this approach doesn't scale well when attempting to use a single
boardenv across multiple branches of U-Boot, some of which require "pci
enum" to enumerate PCI and others of which don't, or don't /yet/ simply
because various upstream changes haven't been merged down.
This patch updates the test to require that the boardenv state which HW
features are required for Ethernet to work, and lets the test itself map
that knowledge to the set of commands to execute. Since this mapping is
part of the test script, which is part of the U-Boot code/branch, this
approach is more scalable. It also feels cleaner, since again boardenv
is only providing data, rather than test logic.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2016-01-26 18:10:14 +00:00
|
|
|
init_pci = u_boot_console.config.env.get('env__net_uses_pci', False)
|
|
|
|
if init_pci:
|
|
|
|
u_boot_console.run_command('pci enum')
|
2016-01-21 23:05:31 +00:00
|
|
|
|
|
|
|
@pytest.mark.buildconfigspec('cmd_dhcp')
|
|
|
|
def test_net_dhcp(u_boot_console):
|
2016-01-26 20:41:30 +00:00
|
|
|
"""Test the dhcp command.
|
2016-01-21 23:05:31 +00:00
|
|
|
|
|
|
|
The boardenv_* file may be used to enable/disable this test; see the
|
|
|
|
comment at the beginning of this file.
|
2016-01-26 20:41:30 +00:00
|
|
|
"""
|
2016-01-21 23:05:31 +00:00
|
|
|
|
|
|
|
test_dhcp = u_boot_console.config.env.get('env__net_dhcp_server', False)
|
|
|
|
if not test_dhcp:
|
|
|
|
pytest.skip('No DHCP server available')
|
|
|
|
|
|
|
|
u_boot_console.run_command('setenv autoload no')
|
|
|
|
output = u_boot_console.run_command('dhcp')
|
|
|
|
assert 'DHCP client bound to address ' in output
|
|
|
|
|
|
|
|
global net_set_up
|
|
|
|
net_set_up = True
|
|
|
|
|
|
|
|
@pytest.mark.buildconfigspec('net')
|
|
|
|
def test_net_setup_static(u_boot_console):
|
2016-01-26 20:41:30 +00:00
|
|
|
"""Set up a static IP configuration.
|
2016-01-21 23:05:31 +00:00
|
|
|
|
|
|
|
The configuration is provided by the boardenv_* file; see the comment at
|
|
|
|
the beginning of this file.
|
2016-01-26 20:41:30 +00:00
|
|
|
"""
|
2016-01-21 23:05:31 +00:00
|
|
|
|
|
|
|
env_vars = u_boot_console.config.env.get('env__net_static_env_vars', None)
|
|
|
|
if not env_vars:
|
|
|
|
pytest.skip('No static network configuration is defined')
|
|
|
|
|
|
|
|
for (var, val) in env_vars:
|
|
|
|
u_boot_console.run_command('setenv %s %s' % (var, val))
|
|
|
|
|
|
|
|
global net_set_up
|
|
|
|
net_set_up = True
|
|
|
|
|
|
|
|
@pytest.mark.buildconfigspec('cmd_ping')
|
|
|
|
def test_net_ping(u_boot_console):
|
2016-01-26 20:41:30 +00:00
|
|
|
"""Test the ping command.
|
2016-01-21 23:05:31 +00:00
|
|
|
|
|
|
|
The $serverip (as set up by either test_net_dhcp or test_net_setup_static)
|
|
|
|
is pinged. The test validates that the host is alive, as reported by the
|
|
|
|
ping command's output.
|
2016-01-26 20:41:30 +00:00
|
|
|
"""
|
2016-01-21 23:05:31 +00:00
|
|
|
|
|
|
|
if not net_set_up:
|
2016-01-26 20:41:31 +00:00
|
|
|
pytest.skip('Network not initialized')
|
2016-01-21 23:05:31 +00:00
|
|
|
|
|
|
|
output = u_boot_console.run_command('ping $serverip')
|
|
|
|
assert 'is alive' in output
|
|
|
|
|
|
|
|
@pytest.mark.buildconfigspec('cmd_net')
|
|
|
|
def test_net_tftpboot(u_boot_console):
|
2016-01-26 20:41:30 +00:00
|
|
|
"""Test the tftpboot command.
|
2016-01-21 23:05:31 +00:00
|
|
|
|
|
|
|
A file is downloaded from the TFTP server, its size and optionally its
|
|
|
|
CRC32 are validated.
|
|
|
|
|
|
|
|
The details of the file to download are provided by the boardenv_* file;
|
|
|
|
see the comment at the beginning of this file.
|
2016-01-26 20:41:30 +00:00
|
|
|
"""
|
2016-01-21 23:05:31 +00:00
|
|
|
|
|
|
|
if not net_set_up:
|
2016-01-26 20:41:31 +00:00
|
|
|
pytest.skip('Network not initialized')
|
2016-01-21 23:05:31 +00:00
|
|
|
|
|
|
|
f = u_boot_console.config.env.get('env__net_tftp_readable_file', None)
|
|
|
|
if not f:
|
|
|
|
pytest.skip('No TFTP readable file to read')
|
|
|
|
|
|
|
|
addr = u_boot_utils.find_ram_base(u_boot_console)
|
|
|
|
fn = f['fn']
|
|
|
|
output = u_boot_console.run_command('tftpboot %x %s' % (addr, fn))
|
|
|
|
expected_text = 'Bytes transferred = '
|
|
|
|
sz = f.get('size', None)
|
|
|
|
if sz:
|
|
|
|
expected_text += '%d' % sz
|
|
|
|
assert expected_text in output
|
|
|
|
|
|
|
|
expected_crc = f.get('crc32', None)
|
|
|
|
if not expected_crc:
|
|
|
|
return
|
|
|
|
|
|
|
|
if u_boot_console.config.buildconfig.get('config_cmd_crc32', 'n') != 'y':
|
|
|
|
return
|
|
|
|
|
|
|
|
output = u_boot_console.run_command('crc32 %x $filesize' % addr)
|
|
|
|
assert expected_crc in output
|