[1/2] framework/pmd_output: report link speed in Mbps

Message ID 20230703192542.36809-2-niklas.soderlund@corigine.com (mailing list archive)
State New
Headers
Series tests/speed_capabilities: Document and convert to a common speed unit |

Commit Message

Niklas Söderlund July 3, 2023, 7:25 p.m. UTC
  From: Qin Ke <qin.ke@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@corigine.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@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(-)
  

Patch

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):
         """