From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id C169EA00E6 for ; Wed, 7 Aug 2019 08:35:26 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A555A375B; Wed, 7 Aug 2019 08:35:26 +0200 (CEST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 99E762C16 for ; Wed, 7 Aug 2019 08:35:24 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Aug 2019 23:35:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,356,1559545200"; d="scan'208";a="165218235" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by orsmga007.jf.intel.com with ESMTP; 06 Aug 2019 23:35:23 -0700 Received: from shsmsx153.ccr.corp.intel.com (10.239.6.53) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 6 Aug 2019 23:35:22 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.80]) by SHSMSX153.ccr.corp.intel.com ([169.254.12.215]) with mapi id 14.03.0439.000; Wed, 7 Aug 2019 14:35:21 +0800 From: "Tu, Lijuan" To: "Ma, LihongX" , "dts@dpdk.org" CC: "Ma, LihongX" Thread-Topic: [dts] [PATCH V1] framework/pmd_output: add function to wait link up Thread-Index: AQHVPQlUEKcpgyhT80idgb/ezQbb6abvWnYQ Date: Wed, 7 Aug 2019 06:35:20 +0000 Message-ID: <8CE3E05A3F976642AAB0F4675D0AD20E0BAFEED4@SHSMSX101.ccr.corp.intel.com> References: <1563387268-19830-1-git-send-email-lihongx.ma@intel.com> In-Reply-To: <1563387268-19830-1-git-send-email-lihongx.ma@intel.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiODUxZDBlMTYtNDM2NS00OGI2LTk4ZmEtNTMyMWRhMmMwNTEyIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiZGxzNVlwaHFaZFg2K2lIZ0lUblwvN0NBcVY2WXpFSVduMTg0VUNHMTlHeVlcL0luYVByUm42U2xMbTZveGNNWWNJIn0= x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dts] [PATCH V1] framework/pmd_output: add function to wait link up X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.15 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" Applied, thanks > -----Original Message----- > From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of lihong > Sent: Thursday, July 18, 2019 2:14 AM > To: dts@dpdk.org > Cc: Ma, LihongX > Subject: [dts] [PATCH V1] framework/pmd_output: add function to wait link > up >=20 > 1. add function to wait the link status up 2. add session param to class > PmdOutput, all command run on this session, default is dut >=20 > Signed-off-by: lihong > --- > framework/pmd_output.py | 47 > +++++++++++++++++++++++++++++++++++++++-------- > 1 file changed, 39 insertions(+), 8 deletions(-) >=20 > diff --git a/framework/pmd_output.py b/framework/pmd_output.py index > 9cc84bb..4cb8fed 100644 > --- a/framework/pmd_output.py > +++ b/framework/pmd_output.py > @@ -42,8 +42,11 @@ class PmdOutput(): > Module for get all statics value by port in testpmd > """ >=20 > - def __init__(self, dut): > + def __init__(self, dut, session=3DNone): > self.dut =3D dut > + if session is None: > + session =3D dut > + self.session =3D session > self.dut.testpmd =3D self > self.rx_pkts_prefix =3D "RX-packets:" > self.rx_missed_prefix =3D "RX-missed:" > @@ -79,7 +82,7 @@ class PmdOutput(): >=20 > def get_pmd_stats(self, portid): > stats =3D {} > - out =3D self.dut.send_expect("show port stats %d" % portid, "tes= tpmd> ") > + out =3D self.session.send_expect("show port stats %d" % portid, > + "testpmd> ") > stats["RX-packets"] =3D self.get_pmd_value(self.rx_pkts_prefix, = out) > stats["RX-missed"] =3D self.get_pmd_value(self.rx_missed_prefix,= out) > stats["RX-bytes"] =3D self.get_pmd_value(self.rx_bytes_prefix, o= ut) @@ - > 111,7 +114,7 @@ class PmdOutput(): > self.coremask =3D create_mask(core_list) > command =3D "./%s/app/testpmd -c %s -n %d %s -- -i %s" \ > % (self.dut.target, self.coremask, self.dut.get_memory_chann= els(), > eal_param, param) > - out =3D self.dut.send_expect(command, "testpmd> ", 120) > + out =3D self.session.send_expect(command, "testpmd> ", 120) > self.command =3D command > # wait 10s to ensure links getting up before test start. > sleep(10) > @@ -119,11 +122,14 @@ class PmdOutput(): >=20 > def execute_cmd(self, pmd_cmd, expected=3D'testpmd> ', > timeout=3DTIMEOUT, > alt_session=3DFalse): > - return self.dut.send_expect('%s' % pmd_cmd, expected, > timeout=3Dtimeout, > + return self.session.send_expect('%s' % pmd_cmd, expected, > + timeout=3Dtimeout, > alt_session=3Dalt_session) >=20 > def get_output(self, timeout=3D1): > - return self.dut.get_session_output(timeout=3Dtimeout) > + if 'dut' in str(self.session): > + return self.session.get_session_output(timeout=3Dtimeout) > + else: > + return self.session.get_session_before(timeout=3Dtimeout) >=20 > def get_value_from_string(self, key_str, regx_str, string): > """ > @@ -137,11 +143,23 @@ class PmdOutput(): > else: > return res.group(0) >=20 > + def get_all_value_from_string(self, key_str, regx_str, string): > + """ > + Get some values from the given string by the regular expression. > + """ > + pattern =3D r"(?<=3D%s)%s" % (key_str, regx_str) > + s =3D re.compile(pattern) > + res =3D s.findall(string) > + if type(res).__name__ =3D=3D 'NoneType': > + return ' ' > + else: > + return res > + > def get_detail_from_port_info(self, key_str, regx_str, port): > """ > Get the detail info from the output of pmd cmd 'show port info <= port > num>'. > """ > - out =3D self.dut.send_expect("show port info %d" % port, "testpm= d> ") > + out =3D self.session.send_expect("show port info %d" % port, > + "testpmd> ") > find_value =3D self.get_value_from_string(key_str, regx_str, out= ) > return find_value >=20 > @@ -167,7 +185,7 @@ class PmdOutput(): > """ > Get the specified port link status now. > """ > - return self.get_detail_from_port_info("Link status: ", "\d+", po= rt_id) > + return self.get_detail_from_port_info("Link status: ", "\S+", > + port_id) >=20 > def get_port_link_speed(self, port_id): > """ > @@ -224,4 +242,17 @@ class PmdOutput(): > return vlan_info >=20 > def quit(self): > - self.dut.send_expect("quit", "# ") > + self.session.send_expect("quit", "# ") > + > + def wait_link_status_up(self, port_id, timeout=3D10): > + """ > + check the link status is up > + if not, loop wait > + """ > + for i in range(timeout): > + out =3D self.session.send_expect("show port info %s" % str(p= ort_id), > "testpmd> ") > + status =3D self.get_all_value_from_string("Link status: ", "= \S+", out) > + if 'down' not in status: > + break > + sleep(1) > + return 'down' not in status > -- > 2.7.4