* [dts] [PATCH V1] framework/pmd_output: add function to wait link up
@ 2019-07-17 18:14 lihong
2019-07-18 3:24 ` Zhu, ShuaiX
2019-08-07 6:35 ` Tu, Lijuan
0 siblings, 2 replies; 3+ messages in thread
From: lihong @ 2019-07-17 18:14 UTC (permalink / raw)
To: dts; +Cc: lihong
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [dts] [PATCH V1] framework/pmd_output: add function to wait link up
2019-07-17 18:14 [dts] [PATCH V1] framework/pmd_output: add function to wait link up lihong
@ 2019-07-18 3:24 ` Zhu, ShuaiX
2019-08-07 6:35 ` Tu, Lijuan
1 sibling, 0 replies; 3+ messages in thread
From: Zhu, ShuaiX @ 2019-07-18 3:24 UTC (permalink / raw)
To: Ma, LihongX, dts; +Cc: Ma, LihongX, Zhu, ShuaiX
Tested-by: Zhu, ShuaiX <shuaix.zhu@intel.com>
> -----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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [dts] [PATCH V1] framework/pmd_output: add function to wait link up
2019-07-17 18:14 [dts] [PATCH V1] framework/pmd_output: add function to wait link up lihong
2019-07-18 3:24 ` Zhu, ShuaiX
@ 2019-08-07 6:35 ` Tu, Lijuan
1 sibling, 0 replies; 3+ messages in thread
From: Tu, Lijuan @ 2019-08-07 6:35 UTC (permalink / raw)
To: Ma, LihongX, dts; +Cc: Ma, LihongX
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-08-07 6:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-17 18:14 [dts] [PATCH V1] framework/pmd_output: add function to wait link up lihong
2019-07-18 3:24 ` Zhu, ShuaiX
2019-08-07 6:35 ` Tu, Lijuan
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).