From: Marvin Liu <yong.liu@intel.com>
To: dts@dpdk.org
Cc: Marvin Liu <yong.liu@intel.com>
Subject: [dts] [PATCH v1 2/2] framework: add command history recording
Date: Thu, 25 Jan 2018 14:48:13 -0500 [thread overview]
Message-ID: <1516909693-68447-2-git-send-email-yong.liu@intel.com> (raw)
In-Reply-To: <1516909693-68447-1-git-send-email-yong.liu@intel.com>
Save DUT&Tester command into history list. After debug flag is enable,
command history will be dump when error happend.
Signed-off-by: Marvin Liu <yong.liu@intel.com>
diff --git a/framework/packet.py b/framework/packet.py
index 208c9a2..c8c2efd 100755
--- a/framework/packet.py
+++ b/framework/packet.py
@@ -77,6 +77,9 @@ from Dot1BR import Dot1BR
from logger import getLogger
logger = getLogger('tester')
+# for saving command history
+from utils import get_backtrace_object
+
# packet generator type should be configured later
PACKETGEN = "scapy"
@@ -355,6 +358,11 @@ class scapy(object):
crb.send_expect("scapy -c scapy_%s.cmd &" % intf, "# ")
def print_summary(self):
+ # save command into test case history
+ history_list = get_backtrace_object('test_case.py', 'test_history')
+ if type(history_list) is list:
+ history_list.append({"command": self.pkt.command(), "name": "Scapy", "output": ""})
+
logger.info("%s" % self.pkt.command())
def send_pkt(self, intf='', count=1):
diff --git a/framework/ssh_connection.py b/framework/ssh_connection.py
index 915d081..c265bf7 100644
--- a/framework/ssh_connection.py
+++ b/framework/ssh_connection.py
@@ -50,21 +50,29 @@ class SSHConnection(object):
connection = {}
connection[self.name] = self.session
CONNECTIONS.append(connection)
+ self.history = None
def init_log(self, logger):
self.logger = logger
self.session.init_log(logger, self.name)
+ def set_history(self, history):
+ self.history = history
+
def send_expect(self, cmds, expected, timeout=15, verify=False):
self.logger.info(cmds)
out = self.session.send_expect(cmds, expected, timeout, verify)
self.logger.debug(out)
+ if type(self.history) is list:
+ self.history.append({"command": cmds, "name": self.name, "output": out})
return out
def send_command(self, cmds, timeout=1):
self.logger.info(cmds)
out = self.session.send_command(cmds, timeout)
self.logger.debug(out)
+ if type(self.history) is list:
+ self.history.append({"command": cmds, "name": self.name, "output": out})
return out
def get_session_before(self, timeout=15):
diff --git a/framework/test_case.py b/framework/test_case.py
index a84e2bb..616ca3b 100644
--- a/framework/test_case.py
+++ b/framework/test_case.py
@@ -45,6 +45,7 @@ from rst import RstReport
from test_result import ResultTable, Result
from logger import getLogger
from config import SuiteConf
+from utils import BLUE, RED
class TestCase(object):
@@ -113,6 +114,10 @@ class TestCase(object):
self._suite_conf = SuiteConf(self.suite_name)
self._suite_cfg = self._suite_conf.suite_cfg
+ # command history
+ self.setup_history = list()
+ self.test_history = list()
+
def init_log(self):
# get log handler
class_name = self.__class__.__name__
@@ -152,6 +157,11 @@ class TestCase(object):
def verify(self, passed, description):
if not passed:
+ if self._enable_debug:
+ print RED("Error happened, dump command history...")
+ self.dump_history()
+ print "Error \"%s\" happened" % RED(description)
+ print RED("History dump finished.")
raise VerifyFailure(description)
def _get_nic_driver(self, nic_name):
@@ -227,6 +237,9 @@ class TestCase(object):
dutobj.get_session_output(timeout=0.1)
self.tester.get_session_output(timeout=0.1)
+ # save into setup history list
+ self.enable_history(self.setup_history)
+
try:
self.set_up_all()
return True
@@ -253,6 +266,10 @@ class TestCase(object):
self._rst_obj.write_title("Test Case: " + case_name)
+ # save into test command history
+ self.test_history = []
+ self.enable_history(self.test_history)
+
# load suite configuration file here for rerun command
self._suite_conf = SuiteConf(self.suite_name)
self._suite_cfg = self._suite_conf.suite_cfg
@@ -393,6 +410,18 @@ class TestCase(object):
# destroy all vfs
dutobj.destroy_all_sriov_vfs()
+ def enable_history(self, history):
+ # enable history for all CRBs default session
+ for dutobj in self.duts:
+ dutobj.session.set_history(history)
+
+ self.tester.session.set_history(history)
+
+ def dump_history(self):
+ for cmd_history in self.setup_history:
+ print '%-20s: %s' % (BLUE(cmd_history['name']), cmd_history['command'])
+ for cmd_history in self.test_history:
+ print '%-20s: %s' % (BLUE(cmd_history['name']), cmd_history['command'])
def wirespeed(self, nic, frame_size, num_ports):
"""
--
1.9.3
next prev parent reply other threads:[~2018-01-26 2:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-25 19:48 [dts] [PATCH v1 1/2] framework/utils: add function to retrieve object from backtrace Marvin Liu
2018-01-25 19:48 ` Marvin Liu [this message]
2018-01-28 22:56 ` [dts] [PATCH v2 2/2] framework: add command history recording Marvin Liu
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=1516909693-68447-2-git-send-email-yong.liu@intel.com \
--to=yong.liu@intel.com \
--cc=dts@dpdk.org \
/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).