[dts] [PATCH V2] tests/link_status_interrupt: optimize the method of checking priv_flags
Jiale Song
songx.jiale at intel.com
Thu Oct 28 09:12:11 CEST 2021
Signed-off-by: Jiale Song <songx.jiale at intel.com>
---
tests/TestSuite_link_status_interrupt.py | 37 +++++++++++++++---------
1 file changed, 24 insertions(+), 13 deletions(-)
diff --git a/tests/TestSuite_link_status_interrupt.py b/tests/TestSuite_link_status_interrupt.py
index bdb43f42..bdee2155 100755
--- a/tests/TestSuite_link_status_interrupt.py
+++ b/tests/TestSuite_link_status_interrupt.py
@@ -75,18 +75,29 @@ class TestLinkStatusInterrupt(TestCase):
# check link-down-on-close flag
self.flag = "link-down-on-close"
for intf in self.intfs:
- check_flag = "ethtool --show-priv-flags %s" % intf
set_flag = "ethtool --set-priv-flags %s %s on" % (intf, self.flag)
- out = self.tester.send_expect(check_flag, "#")
- p = re.compile('%s\s+:\s+(\w+)' % self.flag)
- res = re.search(p, out).group(1)
- if res == "off":
- self.tester.send_expect(set_flag, "#")
+ self.flag_stats = self.get_priv_flags_default_state(intf, self.flag)
+ if self.flag_stats == "off":
+ self.tester.send_expect(set_flag, "# ")
time.sleep(0.5)
- out = self.tester.send_expect(check_flag, "#")
- self.verify(re.search(p, out).group(1) == "on", "set %s %s on failed" % (intf, self.flag))
- elif not res:
- self.logger.info("NIC %s might not support this case" % intf)
+ self.verify(self.get_priv_flags_default_state(intf, self.flag) == "on", "set %s %s on failed" % (intf, self.flag))
+
+ def get_priv_flags_default_state(self, intf, flag):
+ '''
+
+ :param intf: nic name
+ :param flag: priv-flags flag
+ :return: flag default state
+ '''
+ check_flag = "ethtool --show-priv-flags %s" % intf
+ out = self.tester.send_expect(check_flag, "# ")
+ p = re.compile('%s\s+:\s+(\w+)' % flag)
+ default_state = re.search(p, out)
+ if default_state:
+ return default_state.group(1)
+ else:
+ self.logger.info("NIC %s may be not find %s" % (intf, self.flag))
+ return False
def set_link_status_and_verify(self, dutPort, status):
"""
@@ -94,7 +105,7 @@ class TestLinkStatusInterrupt(TestCase):
"""
self.intf = self.tester.get_interface(
self.tester.get_local_port(dutPort))
- if self.dut.get_os_type() != 'freebsd':
+ if self.dut.get_os_type() != 'freebsd' and self.flag_stats:
self.tester.send_expect("ethtool --set-priv-flags %s link-down-on-close on" % self.intf, "#", 10)
self.tester.send_expect("ifconfig %s %s" %
(self.intf, status.lower()), "# ", 10)
@@ -210,6 +221,6 @@ class TestLinkStatusInterrupt(TestCase):
"""
Run after each test suite.
"""
- if self.dut.get_os_type() != 'freebsd':
+ if self.dut.get_os_type() != 'freebsd' and self.flag_stats:
for intf in self.intfs:
- self.tester.send_expect("ethtool --set-priv-flags %s %s off" % (intf, self.flag), "#", 10)
+ self.tester.send_expect("ethtool --set-priv-flags %s %s %s" % (intf, self.flag, self.flag_stats), "# ")
--
2.17.1
More information about the dts
mailing list