blob: e282add5ee83167780ea994dcbccab7bf2c8c142 [file] [log] [blame]
Love Kumar77830a22024-01-02 12:14:35 +05301# SPDX-License-Identifier: GPL-2.0
2# (C) Copyright 2023, Advanced Micro Devices, Inc.
3
4import pytest
5import re
6
7"""
8Note: This test doesn't rely on boardenv_* configuration value but they can
9change test behavior.
10
11For 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
15env__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
19env__mii_device_test = {
20 'device_list': ['eth0', 'eth1'],
21}
22"""
23
24@pytest.mark.buildconfigspec("cmd_mii")
Simon Glassddba5202025-02-09 09:07:14 -070025def test_mii_info(ubman):
26 if ubman.config.env.get("env__mii_device_test_skip", False):
Love Kumar77830a22024-01-02 12:14:35 +053027 pytest.skip("MII device test is not enabled!")
28 expected_output = "PHY"
Simon Glassddba5202025-02-09 09:07:14 -070029 output = ubman.run_command("mii info")
Love Kumar77830a22024-01-02 12:14:35 +053030 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 Glassddba5202025-02-09 09:07:14 -070035def test_mii_list(ubman):
36 if ubman.config.env.get("env__mii_device_test_skip", False):
Love Kumar77830a22024-01-02 12:14:35 +053037 pytest.skip("MII device test is not enabled!")
38
Simon Glassddba5202025-02-09 09:07:14 -070039 f = ubman.config.env.get("env__mii_device_test", None)
Love Kumar77830a22024-01-02 12:14:35 +053040 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 Glassddba5202025-02-09 09:07:14 -070048 output = ubman.run_command("mii device")
Love Kumar77830a22024-01-02 12:14:35 +053049 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 Glassddba5202025-02-09 09:07:14 -070057def test_mii_set_device(ubman):
58 test_mii_list(ubman)
59 f = ubman.config.env.get("env__mii_device_test", None)
Love Kumar77830a22024-01-02 12:14:35 +053060 dev_list = f.get("device_list")
Simon Glassddba5202025-02-09 09:07:14 -070061 output = ubman.run_command("mii device")
Love Kumar77830a22024-01-02 12:14:35 +053062 current_dev = re.search(r"Current device: '(.+?)'", output).groups()[0]
63
64 for dev in dev_list:
Simon Glassddba5202025-02-09 09:07:14 -070065 ubman.run_command(f"mii device {dev}")
66 output = ubman.run_command("echo $?")
Love Kumar77830a22024-01-02 12:14:35 +053067 assert output.endswith("0")
68
Simon Glassddba5202025-02-09 09:07:14 -070069 ubman.run_command(f"mii device {current_dev}")
70 output = ubman.run_command("mii device")
Love Kumar77830a22024-01-02 12:14:35 +053071 dev = re.search(r"Current device: '(.+?)'", output).groups()[0]
72 assert current_dev == dev
73
74@pytest.mark.buildconfigspec("cmd_mii")
Simon Glassddba5202025-02-09 09:07:14 -070075def test_mii_read(ubman):
76 test_mii_list(ubman)
77 output = ubman.run_command("mii info")
Love Kumar77830a22024-01-02 12:14:35 +053078 eth_addr = hex(int(re.search(r"PHY (.+?):", output).groups()[0], 16))
Simon Glassddba5202025-02-09 09:07:14 -070079 ubman.run_command(f"mii read {eth_addr} 0")
80 output = ubman.run_command("echo $?")
Love Kumar77830a22024-01-02 12:14:35 +053081 assert output.endswith("0")
82
83@pytest.mark.buildconfigspec("cmd_mii")
Simon Glassddba5202025-02-09 09:07:14 -070084def test_mii_dump(ubman):
85 test_mii_list(ubman)
Love Kumar77830a22024-01-02 12:14:35 +053086 expected_response = "PHY control register"
Simon Glassddba5202025-02-09 09:07:14 -070087 output = ubman.run_command("mii info")
Love Kumar77830a22024-01-02 12:14:35 +053088 eth_addr = hex(int(re.search(r"PHY (.+?):", output).groups()[0], 16))
Simon Glassddba5202025-02-09 09:07:14 -070089 response = ubman.run_command(f"mii dump {eth_addr} 0")
Love Kumar77830a22024-01-02 12:14:35 +053090 assert expected_response in response
Simon Glassddba5202025-02-09 09:07:14 -070091 output = ubman.run_command("echo $?")
Love Kumar77830a22024-01-02 12:14:35 +053092 assert output.endswith("0")