Love Kumar | 77830a2 | 2024-01-02 12:14:35 +0530 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
| 2 | # (C) Copyright 2023, Advanced Micro Devices, Inc. |
| 3 | |
| 4 | import pytest |
| 5 | import re |
| 6 | |
| 7 | """ |
| 8 | Note: This test doesn't rely on boardenv_* configuration value but they can |
| 9 | change test behavior. |
| 10 | |
| 11 | For example: |
| 12 | |
| 13 | # Setup env__mii_deive_test_skip to True if tests with ethernet PHY devices |
| 14 | # should be skipped. For example: Missing PHY device |
| 15 | env__mii_device_test_skip = True |
| 16 | |
| 17 | # Setup env__mii_device_test to set the MII device names. Test will be skipped |
| 18 | # if env_mii_device_test is not set |
| 19 | env__mii_device_test = { |
| 20 | 'device_list': ['eth0', 'eth1'], |
| 21 | } |
| 22 | """ |
| 23 | |
| 24 | @pytest.mark.buildconfigspec("cmd_mii") |
| 25 | def test_mii_info(u_boot_console): |
| 26 | if u_boot_console.config.env.get("env__mii_device_test_skip", False): |
| 27 | pytest.skip("MII device test is not enabled!") |
| 28 | expected_output = "PHY" |
| 29 | output = u_boot_console.run_command("mii info") |
| 30 | if not re.search(r"PHY (.+?):", output): |
| 31 | pytest.skip("PHY device does not exist!") |
| 32 | assert expected_output in output |
| 33 | |
| 34 | @pytest.mark.buildconfigspec("cmd_mii") |
| 35 | def test_mii_list(u_boot_console): |
| 36 | if u_boot_console.config.env.get("env__mii_device_test_skip", False): |
| 37 | pytest.skip("MII device test is not enabled!") |
| 38 | |
| 39 | f = u_boot_console.config.env.get("env__mii_device_test", None) |
| 40 | if not f: |
| 41 | pytest.skip("No MII device to test!") |
| 42 | |
| 43 | dev_list = f.get("device_list") |
| 44 | if not dev_list: |
| 45 | pytest.fail("No MII device list provided via env__mii_device_test!") |
| 46 | |
| 47 | expected_output = "Current device" |
| 48 | output = u_boot_console.run_command("mii device") |
| 49 | mii_devices = ( |
| 50 | re.search(r"MII devices: '(.+)'", output).groups()[0].replace("'", "").split() |
| 51 | ) |
| 52 | |
| 53 | assert len([x for x in dev_list if x in mii_devices]) == len(dev_list) |
| 54 | assert expected_output in output |
| 55 | |
| 56 | @pytest.mark.buildconfigspec("cmd_mii") |
| 57 | def test_mii_set_device(u_boot_console): |
| 58 | test_mii_list(u_boot_console) |
| 59 | f = u_boot_console.config.env.get("env__mii_device_test", None) |
| 60 | dev_list = f.get("device_list") |
| 61 | output = u_boot_console.run_command("mii device") |
| 62 | current_dev = re.search(r"Current device: '(.+?)'", output).groups()[0] |
| 63 | |
| 64 | for dev in dev_list: |
| 65 | u_boot_console.run_command(f"mii device {dev}") |
| 66 | output = u_boot_console.run_command("echo $?") |
| 67 | assert output.endswith("0") |
| 68 | |
| 69 | u_boot_console.run_command(f"mii device {current_dev}") |
| 70 | output = u_boot_console.run_command("mii device") |
| 71 | dev = re.search(r"Current device: '(.+?)'", output).groups()[0] |
| 72 | assert current_dev == dev |
| 73 | |
| 74 | @pytest.mark.buildconfigspec("cmd_mii") |
| 75 | def test_mii_read(u_boot_console): |
| 76 | test_mii_list(u_boot_console) |
| 77 | output = u_boot_console.run_command("mii info") |
| 78 | eth_addr = hex(int(re.search(r"PHY (.+?):", output).groups()[0], 16)) |
| 79 | u_boot_console.run_command(f"mii read {eth_addr} 0") |
| 80 | output = u_boot_console.run_command("echo $?") |
| 81 | assert output.endswith("0") |
| 82 | |
| 83 | @pytest.mark.buildconfigspec("cmd_mii") |
| 84 | def test_mii_dump(u_boot_console): |
| 85 | test_mii_list(u_boot_console) |
| 86 | expected_response = "PHY control register" |
| 87 | output = u_boot_console.run_command("mii info") |
| 88 | eth_addr = hex(int(re.search(r"PHY (.+?):", output).groups()[0], 16)) |
| 89 | response = u_boot_console.run_command(f"mii dump {eth_addr} 0") |
| 90 | assert expected_response in response |
| 91 | output = u_boot_console.run_command("echo $?") |
| 92 | assert output.endswith("0") |