diff options
author | Love Kumar <love.kumar@amd.com> | 2024-01-30 13:37:01 +0530 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2024-03-01 18:34:08 -0500 |
commit | 783ba859ad8f2b2511b27b9aa8cef7652402c6d4 (patch) | |
tree | 33c5e11a77e0da9667a4823bd38206faaff56753 /test | |
parent | 934dec0af0f74c0ff1f53885e6e97b114f66e77b (diff) | |
download | u-boot-783ba859ad8f2b2511b27b9aa8cef7652402c6d4.tar.gz u-boot-783ba859ad8f2b2511b27b9aa8cef7652402c6d4.tar.bz2 u-boot-783ba859ad8f2b2511b27b9aa8cef7652402c6d4.zip |
test/py: net: Add dhcp abort test
Abort the dhcp request in the middle by pressing ctrl + c on u-boot
prompt and validate the abort status.
Signed-off-by: Love Kumar <love.kumar@amd.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/py/tests/test_net.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/test/py/tests/test_net.py b/test/py/tests/test_net.py index 4ff3dafd62..038a473b23 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. |