summaryrefslogtreecommitdiff
path: root/test/py
diff options
context:
space:
mode:
Diffstat (limited to 'test/py')
-rw-r--r--test/py/tests/test_net.py58
-rw-r--r--test/py/tests/test_reset.py63
-rw-r--r--test/py/tests/test_saveenv.py137
3 files changed, 258 insertions, 0 deletions
diff --git a/test/py/tests/test_net.py b/test/py/tests/test_net.py
index 4ff3dafd629..038a473b239 100644
--- a/test/py/tests/test_net.py
+++ b/test/py/tests/test_net.py
@@ -8,6 +8,7 @@ import pytest
import u_boot_utils
import uuid
import datetime
+import re
"""
Note: This test relies on boardenv_* containing configuration values to define
@@ -31,6 +32,12 @@ env__net_uses_pci = True
# set to False.
env__net_dhcp_server = True
+# False or omitted if a DHCP server is attached to the network, and dhcp abort
+# case should be tested.
+# If DHCP abort testing is not possible or desired, set this variable to True.
+# For example: On some setup, dhcp is too fast and this case may not work.
+env__dhcp_abort_test_skip = True
+
# True if a DHCPv6 server is attached to the network, and should be tested.
# If DHCPv6 testing is not possible or desired, this variable may be omitted or
# set to False.
@@ -120,6 +127,57 @@ def test_net_dhcp(u_boot_console):
global net_set_up
net_set_up = True
+@pytest.mark.buildconfigspec('cmd_dhcp')
+@pytest.mark.buildconfigspec('cmd_mii')
+def test_net_dhcp_abort(u_boot_console):
+ """Test the dhcp command by pressing ctrl+c in the middle of dhcp request
+
+ The boardenv_* file may be used to enable/disable this test; see the
+ comment at the beginning of this file.
+ """
+
+ test_dhcp = u_boot_console.config.env.get('env__net_dhcp_server', False)
+ if not test_dhcp:
+ pytest.skip('No DHCP server available')
+
+ if u_boot_console.config.env.get('env__dhcp_abort_test_skip', True):
+ pytest.skip('DHCP abort test is not enabled!')
+
+ u_boot_console.run_command('setenv autoload no')
+
+ # Phy reset before running dhcp command
+ output = u_boot_console.run_command('mii device')
+ if not re.search(r"Current device: '(.+?)'", output):
+ pytest.skip('PHY device does not exist!')
+ eth_num = re.search(r"Current device: '(.+?)'", output).groups()[0]
+ u_boot_console.run_command(f'mii device {eth_num}')
+ output = u_boot_console.run_command('mii info')
+ eth_addr = hex(int(re.search(r'PHY (.+?):', output).groups()[0], 16))
+ u_boot_console.run_command(f'mii modify {eth_addr} 0 0x8000 0x8000')
+
+ u_boot_console.run_command('dhcp', wait_for_prompt=False)
+ try:
+ u_boot_console.wait_for('Waiting for PHY auto negotiation to complete')
+ except:
+ pytest.skip('Timeout waiting for PHY auto negotiation to complete')
+
+ u_boot_console.wait_for('done')
+
+ try:
+ # Sending Ctrl-C
+ output = u_boot_console.run_command(
+ chr(3), wait_for_echo=False, send_nl=False
+ )
+ assert 'TIMEOUT' not in output
+ assert 'DHCP client bound to address ' not in output
+ assert 'Abort' in output
+ finally:
+ # Provide a time to recover from Abort - if it is not performed
+ # There is message like: ethernet@ff0e0000: No link.
+ u_boot_console.run_command('sleep 1')
+ # Run the dhcp test to setup the network configuration
+ test_net_dhcp(u_boot_console)
+
@pytest.mark.buildconfigspec('cmd_dhcp6')
def test_net_dhcp6(u_boot_console):
"""Test the dhcp6 command.
diff --git a/test/py/tests/test_reset.py b/test/py/tests/test_reset.py
new file mode 100644
index 00000000000..00fc31da57d
--- /dev/null
+++ b/test/py/tests/test_reset.py
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: GPL-2.0
+# (C) Copyright 2023, Advanced Micro Devices, Inc.
+
+"""
+Note: This test doesn't rely on boardenv_* configuration value but they can
+change test behavior.
+
+For example:
+
+# Setup env__reset_test_skip to True if reset test is not possible or desired
+# and should be skipped.
+env__reset_test_skip = True
+
+# Setup env__reset_test to set the bootmode if 'modeboot' u-boot environment
+# variable is not set. Test will be skipped if bootmode is not set in both
+# places i.e, boardenv and modeboot u-boot environment variable
+env__reset_test = {
+ 'bootmode': 'qspiboot',
+}
+
+# This test will be also skipped if the bootmode is detected to JTAG.
+"""
+
+import pytest
+import test_000_version
+
+def setup_reset_env(u_boot_console):
+ if u_boot_console.config.env.get('env__reset_test_skip', False):
+ pytest.skip('reset test is not enabled')
+
+ output = u_boot_console.run_command('echo $modeboot')
+ if output:
+ bootmode = output
+ else:
+ f = u_boot_console.config.env.get('env__reset_test', None)
+ if not f:
+ pytest.skip('bootmode cannot be determined')
+ bootmode = f.get('bootmode', 'jtagboot')
+
+ if 'jtag' in bootmode:
+ pytest.skip('skipping reset test due to jtag bootmode')
+
+@pytest.mark.buildconfigspec('hush_parser')
+def test_reset(u_boot_console):
+ """Test the reset command in non-JTAG bootmode.
+ It does COLD reset, which resets CPU, DDR and peripherals
+ """
+ setup_reset_env(u_boot_console)
+ u_boot_console.run_command('reset', wait_for_reboot=True)
+
+ # Checks the u-boot command prompt's functionality after reset
+ test_000_version.test_version(u_boot_console)
+
+@pytest.mark.buildconfigspec('hush_parser')
+def test_reset_w(u_boot_console):
+ """Test the reset -w command in non-JTAG bootmode.
+ It does WARM reset, which resets CPU but keep DDR/peripherals active.
+ """
+ setup_reset_env(u_boot_console)
+ u_boot_console.run_command('reset -w', wait_for_reboot=True)
+
+ # Checks the u-boot command prompt's functionality after reset
+ test_000_version.test_version(u_boot_console)
diff --git a/test/py/tests/test_saveenv.py b/test/py/tests/test_saveenv.py
new file mode 100644
index 00000000000..7faa3bdf93d
--- /dev/null
+++ b/test/py/tests/test_saveenv.py
@@ -0,0 +1,137 @@
+# SPDX-License-Identifier: GPL-2.0
+# (C) Copyright 2023, Advanced Micro Devices, Inc.
+
+"""
+Note: This test doesn't rely on boardenv_* configuration value but they can
+change test behavior.
+
+For example:
+
+# Setup env__saveenv_test_skip to True if saveenv test is not possible or
+# desired and should be skipped.
+env__saveenv_test_skip = True
+
+# Setup env__saveenv_test to set the bootmode if 'modeboot' u-boot environment
+# variable is not set. Test will be skipped if bootmode is not set in both
+# places i.e, boardenv and modeboot u-boot environment variable
+env__saveenv_test = {
+ 'bootmode': 'qspiboot',
+}
+
+# This test will be also skipped if the bootmode is detected to JTAG.
+"""
+
+import pytest
+import random
+import ipaddress
+import string
+import uuid
+
+# Setup the env
+def setup_saveenv_env(u_boot_console):
+ if u_boot_console.config.env.get('env__saveenv_test_skip', False):
+ pytest.skip('saveenv test is not enabled')
+
+ output = u_boot_console.run_command('echo $modeboot')
+ if output:
+ bootmode = output
+ else:
+ f = u_boot_console.config.env.get('env__saveenv_test', None)
+ if not f:
+ pytest.skip('bootmode cannot be determined')
+ bootmode = f.get('bootmode', 'jtagboot')
+
+ if 'jtag' in bootmode:
+ pytest.skip('skipping saveenv test due to jtag bootmode')
+
+# Check return code
+def ret_code(u_boot_console):
+ return u_boot_console.run_command('echo $?')
+
+# Verify env variable
+def check_env(u_boot_console, var_name, var_value):
+ if var_value:
+ output = u_boot_console.run_command(f'printenv {var_name}')
+ var_value = str(var_value)
+ if (var_value.startswith("'") and var_value.endswith("'")) or (
+ var_value.startswith('"') and var_value.endswith('"')
+ ):
+ var_value = var_value.split(var_value[-1])[1]
+ assert var_value in output
+ assert ret_code(u_boot_console).endswith('0')
+ else:
+ u_boot_console.p.send(f'printenv {var_name}\n')
+ output = u_boot_console.p.expect(['not defined'])
+ assert output == 0
+ assert ret_code(u_boot_console).endswith('1')
+
+# Set env variable
+def set_env(u_boot_console, var_name, var_value):
+ u_boot_console.run_command(f'setenv {var_name} {var_value}')
+ assert ret_code(u_boot_console).endswith('0')
+ check_env(u_boot_console, var_name, var_value)
+
+@pytest.mark.buildconfigspec('cmd_saveenv')
+@pytest.mark.buildconfigspec('hush_parser')
+def test_saveenv(u_boot_console):
+ """Test the saveenv command in non-JTAG bootmode.
+ It saves the U-Boot environment in persistent storage.
+ """
+ setup_saveenv_env(u_boot_console)
+
+ # Set env for random mac address
+ rand_mac = '%02x:%02x:%02x:%02x:%02x:%02x' % (
+ random.randint(0, 255),
+ random.randint(0, 255),
+ random.randint(0, 255),
+ random.randint(0, 255),
+ random.randint(0, 255),
+ random.randint(0, 255),
+ )
+ set_env(u_boot_console, 'mac_addr', rand_mac)
+
+ # Set env for random IPv4 address
+ rand_ipv4 = ipaddress.IPv4Address._string_from_ip_int(
+ random.randint(0, ipaddress.IPv4Address._ALL_ONES)
+ )
+ set_env(u_boot_console, 'ipv4_addr', rand_ipv4)
+
+ # Set env for random IPv6 address
+ rand_ipv6 = ipaddress.IPv6Address._string_from_ip_int(
+ random.randint(0, ipaddress.IPv6Address._ALL_ONES)
+ )
+ set_env(u_boot_console, 'ipv6_addr', rand_ipv6)
+
+ # Set env for random number
+ rand_num = random.randrange(1, 10**9)
+ set_env(u_boot_console, 'num_var', rand_num)
+
+ # Set env for uuid
+ uuid_str = uuid.uuid4().hex.lower()
+ set_env(u_boot_console, 'uuid_var', uuid_str)
+
+ # Set env for random string including special characters
+ sc = "!#%&()*+,-./:;<=>?@[\\]^_`{|}~"
+ rand_str = ''.join(
+ random.choices(' ' + string.ascii_letters + sc + string.digits, k=300)
+ )
+ set_env(u_boot_console, 'str_var', f'"{rand_str}"')
+
+ # Set env for empty string
+ set_env(u_boot_console, 'empty_var', '')
+
+ # Save the env variables
+ u_boot_console.run_command('saveenv')
+ assert ret_code(u_boot_console).endswith('0')
+
+ # Reboot
+ u_boot_console.run_command('reset', wait_for_reboot=True)
+
+ # Verify the saved env variables
+ check_env(u_boot_console, 'mac_addr', rand_mac)
+ check_env(u_boot_console, 'ipv4_addr', rand_ipv4)
+ check_env(u_boot_console, 'ipv6_addr', rand_ipv6)
+ check_env(u_boot_console, 'num_var', rand_num)
+ check_env(u_boot_console, 'uuid_var', uuid_str)
+ check_env(u_boot_console, 'str_var', rand_str)
+ check_env(u_boot_console, 'empty_var', '')