From patchwork Thu Oct 28 10:59:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jiale, SongX" X-Patchwork-Id: 103155 Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 28ED4A0547; Thu, 28 Oct 2021 13:15:44 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E8C9141100; Thu, 28 Oct 2021 13:15:43 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id 4476940DF4 for ; Thu, 28 Oct 2021 13:15:42 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10150"; a="230644997" X-IronPort-AV: E=Sophos;i="5.87,189,1631602800"; d="scan'208";a="230644997" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2021 03:59:16 -0700 X-IronPort-AV: E=Sophos;i="5.87,189,1631602800"; d="scan'208";a="447647810" Received: from unknown (HELO dpdk-zhaohy-t.sh.intel.com) ([10.240.183.68]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2021 03:59:14 -0700 From: Jiale Song To: dts@dpdk.org Cc: Jiale Song Date: Thu, 28 Oct 2021 18:59:06 +0800 Message-Id: <1635418746-195687-1-git-send-email-songx.jiale@intel.com> X-Mailer: git-send-email 1.8.3.1 Subject: [dts] [PATCH V3] tests/link_status_interrupt: optimize the method of checking priv_flags X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dts-bounces@dpdk.org Sender: "dts" Signed-off-by: Jiale Song --- framework/crb.py | 17 +++++++++++++++++ tests/TestSuite_link_status_interrupt.py | 20 +++++++------------- 2 files changed, 24 insertions(+), 13 deletions(-) mode change 100644 => 100755 framework/crb.py diff --git a/framework/crb.py b/framework/crb.py old mode 100644 new mode 100755 index 9d78e51d..c9909add --- a/framework/crb.py +++ b/framework/crb.py @@ -890,3 +890,20 @@ class Crb(object): def enable_promisc(self, intf): if intf != 'N/A': self.send_expect("ifconfig %s promisc" % intf, "# ", alt_session=True) + + def get_priv_flags_state(self, intf, flag, timeout=TIMEOUT): + ''' + + :param intf: nic name + :param flag: priv-flags flag + :return: flag state + ''' + check_flag = "ethtool --show-priv-flags %s" % intf + out = self.send_expect(check_flag, "# ", timeout) + p = re.compile('%s\s+:\s+(\w+)' % flag) + state = re.search(p, out) + if state: + return state.group(1) + else: + self.logger.info("NIC %s may be not find %s" % (intf, flag)) + return False diff --git a/tests/TestSuite_link_status_interrupt.py b/tests/TestSuite_link_status_interrupt.py index bdb43f42..422f1f4e 100755 --- a/tests/TestSuite_link_status_interrupt.py +++ b/tests/TestSuite_link_status_interrupt.py @@ -75,18 +75,12 @@ 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_default_stats = self.tester.get_priv_flags_state(intf, self.flag) + if self.flag_default_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.tester.get_priv_flags_state(intf, self.flag) == "on", "set %s %s on failed" % (intf, self.flag)) def set_link_status_and_verify(self, dutPort, status): """ @@ -94,7 +88,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_default_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 +204,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_default_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_default_stats), "# ")