[PATCH 2/2] tests/speed_capabilities: optimize code sequence of test case
Niklas Söderlund
niklas.soderlund at corigine.com
Mon Jul 3 21:25:42 CEST 2023
From: Qin Ke <qin.ke at 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 at corigine.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund at 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
More information about the dts
mailing list