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") |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 25 | def test_mii_info(ubman): |
| 26 | if ubman.config.env.get("env__mii_device_test_skip", False): |
Love Kumar | 77830a2 | 2024-01-02 12:14:35 +0530 | [diff] [blame] | 27 | pytest.skip("MII device test is not enabled!") |
| 28 | expected_output = "PHY" |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 29 | output = ubman.run_command("mii info") |
Love Kumar | 77830a2 | 2024-01-02 12:14:35 +0530 | [diff] [blame] | 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") |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 35 | def test_mii_list(ubman): |
| 36 | if ubman.config.env.get("env__mii_device_test_skip", False): |
Love Kumar | 77830a2 | 2024-01-02 12:14:35 +0530 | [diff] [blame] | 37 | pytest.skip("MII device test is not enabled!") |
| 38 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 39 | f = ubman.config.env.get("env__mii_device_test", None) |
Love Kumar | 77830a2 | 2024-01-02 12:14:35 +0530 | [diff] [blame] | 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" |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 48 | output = ubman.run_command("mii device") |
Love Kumar | 77830a2 | 2024-01-02 12:14:35 +0530 | [diff] [blame] | 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") |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 57 | def test_mii_set_device(ubman): |
| 58 | test_mii_list(ubman) |
| 59 | f = ubman.config.env.get("env__mii_device_test", None) |
Love Kumar | 77830a2 | 2024-01-02 12:14:35 +0530 | [diff] [blame] | 60 | dev_list = f.get("device_list") |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 61 | output = ubman.run_command("mii device") |
Love Kumar | 77830a2 | 2024-01-02 12:14:35 +0530 | [diff] [blame] | 62 | current_dev = re.search(r"Current device: '(.+?)'", output).groups()[0] |
| 63 | |
| 64 | for dev in dev_list: |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 65 | ubman.run_command(f"mii device {dev}") |
| 66 | output = ubman.run_command("echo $?") |
Love Kumar | 77830a2 | 2024-01-02 12:14:35 +0530 | [diff] [blame] | 67 | assert output.endswith("0") |
| 68 | |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 69 | ubman.run_command(f"mii device {current_dev}") |
| 70 | output = ubman.run_command("mii device") |
Love Kumar | 77830a2 | 2024-01-02 12:14:35 +0530 | [diff] [blame] | 71 | dev = re.search(r"Current device: '(.+?)'", output).groups()[0] |
| 72 | assert current_dev == dev |
| 73 | |
| 74 | @pytest.mark.buildconfigspec("cmd_mii") |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 75 | def test_mii_read(ubman): |
| 76 | test_mii_list(ubman) |
| 77 | output = ubman.run_command("mii info") |
Love Kumar | 77830a2 | 2024-01-02 12:14:35 +0530 | [diff] [blame] | 78 | eth_addr = hex(int(re.search(r"PHY (.+?):", output).groups()[0], 16)) |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 79 | ubman.run_command(f"mii read {eth_addr} 0") |
| 80 | output = ubman.run_command("echo $?") |
Love Kumar | 77830a2 | 2024-01-02 12:14:35 +0530 | [diff] [blame] | 81 | assert output.endswith("0") |
| 82 | |
| 83 | @pytest.mark.buildconfigspec("cmd_mii") |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 84 | def test_mii_dump(ubman): |
| 85 | test_mii_list(ubman) |
Love Kumar | 77830a2 | 2024-01-02 12:14:35 +0530 | [diff] [blame] | 86 | expected_response = "PHY control register" |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 87 | output = ubman.run_command("mii info") |
Love Kumar | 77830a2 | 2024-01-02 12:14:35 +0530 | [diff] [blame] | 88 | eth_addr = hex(int(re.search(r"PHY (.+?):", output).groups()[0], 16)) |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 89 | response = ubman.run_command(f"mii dump {eth_addr} 0") |
Love Kumar | 77830a2 | 2024-01-02 12:14:35 +0530 | [diff] [blame] | 90 | assert expected_response in response |
Simon Glass | ddba520 | 2025-02-09 09:07:14 -0700 | [diff] [blame] | 91 | output = ubman.run_command("echo $?") |
Love Kumar | 77830a2 | 2024-01-02 12:14:35 +0530 | [diff] [blame] | 92 | assert output.endswith("0") |