[dts] [PATCH v2 2/2] framework: add command history recording
Marvin Liu
yong.liu at intel.com
Sun Jan 28 23:56:14 CET 2018
v2: optimize history format in packet module
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 at intel.com>
diff --git a/framework/packet.py b/framework/packet.py
index 208c9a2..908e855 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": "p=%s" % self.pkt.command(), "name": "Scapy", "output": ""})
+
logger.info("%s" % self.pkt.command())
def send_pkt(self, intf='', count=1):
@@ -379,6 +387,10 @@ class scapy(object):
self.pkt.getlayer(0).src = get_if_hwaddr(intf)
sendp(self.pkt, iface=intf, count=count)
+ # 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": "sendp(p, iface=\"%s\")" % intf, "name": "Scapy", "output": ""})
class Packet(object):
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..d78dcf9 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 = list()
+ 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,23 @@ class TestCase(object):
# destroy all vfs
dutobj.destroy_all_sriov_vfs()
+ def enable_history(self, history):
+ """
+ Enable history for all CRB's default session
+ """
+ for dutobj in self.duts:
+ dutobj.session.set_history(history)
+
+ self.tester.session.set_history(history)
+
+ def dump_history(self):
+ """
+ Dump recorded command history
+ """
+ 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
More information about the dts
mailing list