[PATCH 1/2] framework/pmd_output: report link speed in Mbps
Niklas Söderlund
niklas.soderlund at corigine.com
Mon Jul 3 21:25:41 CEST 2023
From: Qin Ke <qin.ke at corigine.com>
Link speeds read with get_port_link_speed() have no documented unit.
This leads to issues as different PMD reports speed in both Mbps and
Gbps. The only test-case making use of get_port_link_speed(),
TestSuite_speed_capabilities.py, assumes the speed is returned in Mbps
or an empty string if the speed could not be read.
Document this behavior and extend the get_port_link_speed()
implementations to convert links speeds reported by in Gbps to Mbps.
Signed-off-by: Qin Ke <qin.ke at corigine.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund at corigine.com>
---
framework/pmd_output.py | 12 +++++++++++-
tests/TestSuite_pmd_bonded.py | 12 +++++++++++-
tests/TestSuite_vf_pmd_bonded.py | 12 +++++++++++-
3 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/framework/pmd_output.py b/framework/pmd_output.py
index c8e8b50f1711..274a02eb32da 100644
--- a/framework/pmd_output.py
+++ b/framework/pmd_output.py
@@ -235,8 +235,18 @@ class PmdOutput:
def get_port_link_speed(self, port_id):
"""
Get the specified port link speed now.
+ Return the link speed in Mbps or an empty string if speed can't be read.
"""
- return self.get_detail_from_port_info("Link speed: ", "\d+", port_id)
+ linkspeed = self.get_detail_from_port_info("Link speed: ", ".+", port_id)
+ s = re.compile(r"(\d+).*([MG])")
+ res = s.search(linkspeed)
+ if res:
+ if res.group(2) == "M":
+ return res.group(1)
+
+ if res.group(2) == "G":
+ return f"{res.group(1)}000"
+ return ""
def get_port_link_duplex(self, port_id):
"""
diff --git a/tests/TestSuite_pmd_bonded.py b/tests/TestSuite_pmd_bonded.py
index f957d4e75077..931f74c77d5a 100644
--- a/tests/TestSuite_pmd_bonded.py
+++ b/tests/TestSuite_pmd_bonded.py
@@ -364,8 +364,18 @@ UDP(sport=srcport, dport=destport)/Raw(load="\x50"*%s)], iface="%s", count=%d)'
def get_port_link_speed(self, port_id):
"""
Get the specified port link speed now.
+ Return the link speed in Mbps or an empty string if speed can't be read.
"""
- return self.get_detail_from_port_info("Link speed: ", "\d+", port_id)
+ linkspeed = self.get_detail_from_port_info("Link speed: ", ".+", port_id)
+ s = re.compile(r"(\d+).*([MG])")
+ res = s.search(linkspeed)
+ if res:
+ if res.group(2) == "M":
+ return res.group(1)
+
+ if res.group(2) == "G":
+ return f"{res.group(1)}000"
+ return ""
def get_port_link_duplex(self, port_id):
"""
diff --git a/tests/TestSuite_vf_pmd_bonded.py b/tests/TestSuite_vf_pmd_bonded.py
index 8cc45380283a..ae74822ea259 100644
--- a/tests/TestSuite_vf_pmd_bonded.py
+++ b/tests/TestSuite_vf_pmd_bonded.py
@@ -335,8 +335,18 @@ UDP(sport=srcport, dport=destport)/Raw(load="\x50"*%s)], iface="%s", count=%d, v
def get_port_link_speed(self, port_id):
"""
Get the specified port link speed now.
+ Return the link speed in Mbps or an empty string if speed can't be read.
"""
- return self.get_detail_from_port_info("Link speed: ", "\d+", port_id)
+ linkspeed = self.get_detail_from_port_info("Link speed: ", ".+", port_id)
+ s = re.compile(r"(\d+).*([MG])")
+ res = s.search(linkspeed)
+ if res:
+ if res.group(2) == "M":
+ return res.group(1)
+
+ if res.group(2) == "G":
+ return f"{res.group(1)}000"
+ return ""
def get_port_link_duplex(self, port_id):
"""
--
2.41.0
More information about the dts
mailing list