test suite reviews and discussions
 help / color / mirror / Atom feed
From: "Tu, Lijuan" <lijuan.tu@intel.com>
To: "Ma, LihongX" <lihongx.ma@intel.com>, "dts@dpdk.org" <dts@dpdk.org>
Cc: "Ma, LihongX" <lihongx.ma@intel.com>
Subject: Re: [dts] [PATCH V1] framework/pmd_output: add function to wait link up
Date: Wed, 7 Aug 2019 06:35:20 +0000	[thread overview]
Message-ID: <8CE3E05A3F976642AAB0F4675D0AD20E0BAFEED4@SHSMSX101.ccr.corp.intel.com> (raw)
In-Reply-To: <1563387268-19830-1-git-send-email-lihongx.ma@intel.com>

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 <lihongx.ma@intel.com>
> Subject: [dts] [PATCH V1] framework/pmd_output: add function to wait link
> up
> 
> 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
> 
> Signed-off-by: lihong <lihongx.ma@intel.com>
> ---
>  framework/pmd_output.py | 47
> +++++++++++++++++++++++++++++++++++++++--------
>  1 file changed, 39 insertions(+), 8 deletions(-)
> 
> 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
>      """
> 
> -    def __init__(self, dut):
> +    def __init__(self, dut, session=None):
>          self.dut = dut
> +        if session is None:
> +            session = dut
> +        self.session = session
>          self.dut.testpmd = self
>          self.rx_pkts_prefix = "RX-packets:"
>          self.rx_missed_prefix = "RX-missed:"
> @@ -79,7 +82,7 @@ class PmdOutput():
> 
>      def get_pmd_stats(self, portid):
>          stats = {}
> -        out = self.dut.send_expect("show port stats %d" % portid, "testpmd> ")
> +        out = self.session.send_expect("show port stats %d" % portid,
> + "testpmd> ")
>          stats["RX-packets"] = self.get_pmd_value(self.rx_pkts_prefix, out)
>          stats["RX-missed"] = self.get_pmd_value(self.rx_missed_prefix, out)
>          stats["RX-bytes"] = self.get_pmd_value(self.rx_bytes_prefix, out) @@ -
> 111,7 +114,7 @@ class PmdOutput():
>          self.coremask = create_mask(core_list)
>          command = "./%s/app/testpmd -c %s -n %d %s -- -i %s" \
>              % (self.dut.target, self.coremask, self.dut.get_memory_channels(),
> eal_param, param)
> -        out = self.dut.send_expect(command, "testpmd> ", 120)
> +        out = self.session.send_expect(command, "testpmd> ", 120)
>          self.command = command
>          # wait 10s to ensure links getting up before test start.
>          sleep(10)
> @@ -119,11 +122,14 @@ class PmdOutput():
> 
>      def execute_cmd(self, pmd_cmd, expected='testpmd> ',
> timeout=TIMEOUT,
>                      alt_session=False):
> -        return self.dut.send_expect('%s' % pmd_cmd, expected,
> timeout=timeout,
> +        return self.session.send_expect('%s' % pmd_cmd, expected,
> + timeout=timeout,
>                                      alt_session=alt_session)
> 
>      def get_output(self, timeout=1):
> -        return self.dut.get_session_output(timeout=timeout)
> +        if 'dut' in str(self.session):
> +            return self.session.get_session_output(timeout=timeout)
> +        else:
> +            return self.session.get_session_before(timeout=timeout)
> 
>      def get_value_from_string(self, key_str, regx_str, string):
>          """
> @@ -137,11 +143,23 @@ class PmdOutput():
>          else:
>              return res.group(0)
> 
> +    def get_all_value_from_string(self, key_str, regx_str, string):
> +        """
> +        Get some values from the given string by the regular expression.
> +        """
> +        pattern = r"(?<=%s)%s" % (key_str, regx_str)
> +        s = re.compile(pattern)
> +        res = s.findall(string)
> +        if type(res).__name__ == '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 = self.dut.send_expect("show port info %d" % port, "testpmd> ")
> +        out = self.session.send_expect("show port info %d" % port,
> + "testpmd> ")
>          find_value = self.get_value_from_string(key_str, regx_str, out)
>          return find_value
> 
> @@ -167,7 +185,7 @@ class PmdOutput():
>          """
>          Get the specified port link status now.
>          """
> -        return self.get_detail_from_port_info("Link status: ", "\d+", port_id)
> +        return self.get_detail_from_port_info("Link status: ", "\S+",
> + port_id)
> 
>      def get_port_link_speed(self, port_id):
>          """
> @@ -224,4 +242,17 @@ class PmdOutput():
>          return vlan_info
> 
>      def quit(self):
> -        self.dut.send_expect("quit", "# ")
> +        self.session.send_expect("quit", "# ")
> +
> +    def wait_link_status_up(self, port_id, timeout=10):
> +        """
> +        check the link status is up
> +        if not, loop wait
> +        """
> +        for i in range(timeout):
> +            out = self.session.send_expect("show port info %s" % str(port_id),
> "testpmd> ")
> +            status = 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


      parent reply	other threads:[~2019-08-07  6:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-17 18:14 lihong
2019-07-18  3:24 ` Zhu, ShuaiX
2019-08-07  6:35 ` Tu, Lijuan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8CE3E05A3F976642AAB0F4675D0AD20E0BAFEED4@SHSMSX101.ccr.corp.intel.com \
    --to=lijuan.tu@intel.com \
    --cc=dts@dpdk.org \
    --cc=lihongx.ma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).