[2/2] tests/speed_capabilities: optimize code sequence of test case

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

Checks

Context Check Description
ci/Intel-dts-format-test success Testing OK
ci/Intel-dts-pylama-test success Testing OK
ci/Intel-dts-suite-test success Testing OK

Commit Message

Niklas Söderlund July 3, 2023, 7:25 p.m. UTC
  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(-)
  

Patch

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"