[UBOOT PATCH v4] test/py: net: Add dhcp abort test

Michal Simek michal.simek at amd.com
Thu Jan 18 15:24:26 CET 2024



On 1/18/24 15:06, Tom Rini wrote:
> On Thu, Jan 18, 2024 at 09:56:58AM +0100, neil.armstrong at linaro.org wrote:
>> Hi,
>>
>> On 21/11/2023 14:02, Love Kumar wrote:
>>> 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 at amd.com>
>>> ---
>>> Changes in v2:
>>>    - Mark CMD_MII command dependency
>>>
>>> Changes in v3:
>>>    - Skip the test if PHY device not present
>>>
>>> Changes in v4:
>>>    - Setup the network configuration by running dhcp test at the end of
>>>    test
>>>    - Add option to skip the test if it is not desired or possible
>>> ---
>>>    test/py/tests/test_net.py | 57 +++++++++++++++++++++++++++++++++++++++
>>>    1 file changed, 57 insertions(+)
>>>
>>> diff --git a/test/py/tests/test_net.py b/test/py/tests/test_net.py
>>> index b2241ae6a482..e0749125fd53 100644
>>> --- a/test/py/tests/test_net.py
>>> +++ b/test/py/tests/test_net.py
>>> @@ -7,6 +7,7 @@
>>>    import pytest
>>>    import u_boot_utils
>>>    import uuid
>>> +import re
>>>    """
>>>    Note: This test relies on boardenv_* containing configuration values to define
>>> @@ -30,6 +31,11 @@ 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.
>>> +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.
>>> @@ -115,6 +121,57 @@ def test_net_dhcp(u_boot_console):
>>>        global net_set_up
>>>        net_set_up = True
>>> + at pytest.mark.buildconfigspec("cmd_dhcp")
>>> + at 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", False):
>>> +        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")
>>> +
>>> +    # 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
>>> +
>>> +    # Provide a time to recover from Abort - if it is not performed
>>> +    # There is message like: ethernet at 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.
>>
>> This test fails on the BPI-M2S and BPI-M5 boards:
>>
>> Section: test_net_dhcp_abort
>> TIME: NOW: 2024/01/18 08:43:48.152149
>> TIME: SINCE-PREV: 0:00:00.000629
>> TIME: SINCE-START: 0:02:17.928462
>> Stream: console
>> => setenv autoload no
>> =>
>> End stream: console
>> TIME: NOW: 2024/01/18 08:43:48.232597
>> TIME: SINCE-PREV: 0:00:00.080448
>> TIME: SINCE-START: 0:02:18.008910
>> Stream: console
>> => mii device
>> MII devices: 'mdio' 'mdio at 0'
>> Current device: 'mdio'
>> =>
>> End stream: console
>> TIME: NOW: 2024/01/18 08:43:48.277449
>> TIME: SINCE-PREV: 0:00:00.044852
>> TIME: SINCE-START: 0:02:18.053762
>> Stream: console
>> => mii device mdio
>> =>
>> End stream: console
>> TIME: NOW: 2024/01/18 08:43:48.318273
>> TIME: SINCE-PREV: 0:00:00.040824
>> TIME: SINCE-START: 0:02:18.094586
>> Stream: console
>> => mii info
>> PHY 0x00: OUI = 0x0732, Model = 0x11, Rev = 0x06, 100baseT, FDX
>> PHY 0x01: OUI = 0x0732, Model = 0x11, Rev = 0x06, 100baseT, FDX
>> =>
>> End stream: console
>> TIME: NOW: 2024/01/18 08:43:48.370420
>> TIME: SINCE-PREV: 0:00:00.052147
>> TIME: SINCE-START: 0:02:18.146733
>> Stream: console
>> => mii modify 0x0 0 0x8000 0x8000
>> =>
>> End stream: console
>> TIME: NOW: 2024/01/18 08:43:48.451550
>> TIME: SINCE-PREV: 0:00:00.081130
>> TIME: SINCE-START: 0:02:18.227863
>> Stream: console
>> => dhcp
>> End stream: console
>> TIME: NOW: 2024/01/18 08:43:48.493680
>> TIME: SINCE-PREV: 0:00:00.042130
>> TIME: SINCE-START: 0:02:18.269993
>> Stream: console
>> ethernet at ff3f0000 Waiting for PHY auto negotiation to complete..... done
>> Speed: 100, full duplex
>> BOOTP broadcast 1
>> DHCP client bound to address 10.34.56.144 (3 ms)
>> =>
>> End stream: console
>> TIME: NOW: 2024/01/18 08:43:51.002287
>> TIME: SINCE-PREV: 0:00:02.508607
>> TIME: SINCE-START: 0:02:20.778600
>> Stream: console
>> =>
>> End stream: console
>> FAILED:
>> test/py/tests/test_net.py:171: in test_net_dhcp_abort
>>      assert "DHCP client bound to address " not in output
>> E   AssertionError: assert 'DHCP client... to address ' not in 'Speed: 100,...6.144 (3 ms)'
>> E     'DHCP client bound to address ' is contained here:
>> E       dcast 1
>> E
>> E       DHCP client bound to address 10.34.56.144 (3 ms)
>> TIME: SINCE-SECTION: 0:00:03.866916
>> End section: test_net_dhcp_abort
>>
>> Full test logs:
>> Job https://gitlab.com/amlogic-foss/amlogic-u-boot-autotest/-/jobs/5956146503 :
>> https://amlogic-foss.gitlab.io/-/amlogic-u-boot-autotest/-/jobs/5956146503/artifacts/test-log.html
>> Job https://gitlab.com/amlogic-foss/amlogic-u-boot-autotest/-/jobs/5956097398 :
>> https://amlogic-foss.gitlab.io/-/amlogic-u-boot-autotest/-/jobs/5956097398/artifacts/test-log.html
>>
>> It seems it makes DHCP fail on subsequent board reboots.
> 
> We need to rework this test to be opt-in rather than opt-out, I'll
> revert for now.

yes. It should be disabled by default for sure. I told to Love to designed all 
new tests like that.

Thanks,
Michal



More information about the U-Boot mailing list