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 18F0EA0471 for ; Thu, 18 Jul 2019 05:24:55 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id AEC381D9E; Thu, 18 Jul 2019 05:24:54 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 3327E1D9E for ; Thu, 18 Jul 2019 05:24:51 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jul 2019 20:24:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,276,1559545200"; d="scan'208";a="195471268" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga002.fm.intel.com with ESMTP; 17 Jul 2019 20:24:50 -0700 Received: from fmsmsx122.amr.corp.intel.com (10.18.125.37) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 17 Jul 2019 20:24:50 -0700 Received: from shsmsx153.ccr.corp.intel.com (10.239.6.53) by fmsmsx122.amr.corp.intel.com (10.18.125.37) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 17 Jul 2019 20:24:49 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.134]) by SHSMSX153.ccr.corp.intel.com ([169.254.12.60]) with mapi id 14.03.0439.000; Thu, 18 Jul 2019 11:24:48 +0800 From: "Zhu, ShuaiX" To: "Ma, LihongX" , "dts@dpdk.org" CC: "Ma, LihongX" , "Zhu, ShuaiX" Thread-Topic: [dts] [PATCH V1] framework/pmd_output: add function to wait link up Thread-Index: AQHVPQlUqIARgNWt5kW5/6vfG1kCw6bPtoog Date: Thu, 18 Jul 2019 03:24:47 +0000 Message-ID: <4DC48DF9BDA3E54A836D2D3C057DEC6F0B1C2E2C@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: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.0.600.7 dlp-reaction: no-action 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" Tested-by: Zhu, ShuaiX > -----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_channels(), 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(port_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