test suite reviews and discussions
 help / color / mirror / Atom feed
* [PATCH 0/2] tests/speed_capabilities: Document and convert to a common speed unit
@ 2023-07-03 19:25 Niklas Söderlund
  2023-07-03 19:25 ` [PATCH 1/2] framework/pmd_output: report link speed in Mbps Niklas Söderlund
  2023-07-03 19:25 ` [PATCH 2/2] tests/speed_capabilities: optimize code sequence of test case Niklas Söderlund
  0 siblings, 2 replies; 3+ messages in thread
From: Niklas Söderlund @ 2023-07-03 19:25 UTC (permalink / raw)
  To: dts; +Cc: oss-drivers, Qin Ke, Niklas Söderlund

Hello,

This small series addresses and issue where the speed read from a PMD 
may have different unit (Mbps vs Gbps). As the existing use-case depends 
on the speed read from the PMD is in Mbps document this and convert to 
it if it's read in Gbps.

The second patch is a small optimization where the test can fail faster 
if it can't read the speed from the PMD.

Qin Ke (2):
  framework/pmd_output: report link speed in Mbps
  tests/speed_capabilities: optimize code sequence of test case

 framework/pmd_output.py               | 12 +++++++++++-
 tests/TestSuite_pmd_bonded.py         | 12 +++++++++++-
 tests/TestSuite_speed_capabilities.py | 16 ++++++++--------
 tests/TestSuite_vf_pmd_bonded.py      | 12 +++++++++++-
 4 files changed, 41 insertions(+), 11 deletions(-)

-- 
2.41.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] framework/pmd_output: report link speed in Mbps
  2023-07-03 19:25 [PATCH 0/2] tests/speed_capabilities: Document and convert to a common speed unit Niklas Söderlund
@ 2023-07-03 19:25 ` Niklas Söderlund
  2023-07-03 19:25 ` [PATCH 2/2] tests/speed_capabilities: optimize code sequence of test case Niklas Söderlund
  1 sibling, 0 replies; 3+ messages in thread
From: Niklas Söderlund @ 2023-07-03 19:25 UTC (permalink / raw)
  To: dts; +Cc: oss-drivers, Qin Ke, Niklas Söderlund

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(-)

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] tests/speed_capabilities: optimize code sequence of test case
  2023-07-03 19:25 [PATCH 0/2] tests/speed_capabilities: Document and convert to a common speed unit Niklas Söderlund
  2023-07-03 19:25 ` [PATCH 1/2] framework/pmd_output: report link speed in Mbps Niklas Söderlund
@ 2023-07-03 19:25 ` Niklas Söderlund
  1 sibling, 0 replies; 3+ messages in thread
From: Niklas Söderlund @ 2023-07-03 19:25 UTC (permalink / raw)
  To: dts; +Cc: oss-drivers, Qin Ke, Niklas Söderlund

From: Qin Ke <qin.ke@corigine.com>

The verification code of interface_name and interface_speed can be
moved forward, it can reduce unnecessary code execution if the
verification failed.

Adjust the code sequence of related code.

Signed-off-by: Qin Ke <qin.ke@corigine.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com>
---
 tests/TestSuite_speed_capabilities.py | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/tests/TestSuite_speed_capabilities.py b/tests/TestSuite_speed_capabilities.py
index 3bda904e8a81..2b950a541e7c 100644
--- a/tests/TestSuite_speed_capabilities.py
+++ b/tests/TestSuite_speed_capabilities.py
@@ -39,15 +39,20 @@ class TestSpeedCapabilities(TestCase):
         for port in self.ports:
             interface_name = self.tester.get_interface(self.tester.get_local_port(port))
 
-            # Gives the speed in Mb/s
-            interface_speed = self.pmdout.get_port_link_speed(port)
-
             self.verify(
                 interface_name in expected_speeds,
                 f"The interface {interface_name} does not have an expected "
                 f"speed associated with it.",
             )
 
+            # Gives the speed in Mb/s
+            interface_speed = self.pmdout.get_port_link_speed(port)
+
+            self.verify(
+                len(interface_speed) > 0,
+                f"A valid speed could not be read for the interface {interface_name}.",
+            )
+
             detected_interfaces.append(interface_name)
 
             expected_speed = expected_speeds[interface_name]
@@ -58,11 +63,6 @@ class TestSpeedCapabilities(TestCase):
             # Removes the unit from the speed
             expected_speed = "".join(i for i in expected_speed if i.isdigit())
 
-            self.verify(
-                len(interface_speed) > 0,
-                f"A valid speed could not be read for the interface {interface_name}.",
-            )
-
             # Converts Gb/s to Mb/s for consistent comparison
             if expected_speed_unit == "G":
                 expected_speed += "000"
-- 
2.41.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-07-03 19:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-03 19:25 [PATCH 0/2] tests/speed_capabilities: Document and convert to a common speed unit Niklas Söderlund
2023-07-03 19:25 ` [PATCH 1/2] framework/pmd_output: report link speed in Mbps Niklas Söderlund
2023-07-03 19:25 ` [PATCH 2/2] tests/speed_capabilities: optimize code sequence of test case Niklas Söderlund

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).