From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 33C5A1B1CA for ; Mon, 29 Jan 2018 07:03:07 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Jan 2018 22:03:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,429,1511856000"; d="scan'208";a="27074812" Received: from dpdk-test38.sh.intel.com ([10.67.119.87]) by orsmga001.jf.intel.com with ESMTP; 28 Jan 2018 22:03:06 -0800 From: Marvin Liu To: dts@dpdk.org Cc: Marvin Liu Date: Sun, 28 Jan 2018 17:56:14 -0500 Message-Id: <1517180174-58782-1-git-send-email-yong.liu@intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1516909693-68447-1-git-send-email-yong.liu@intel.com> References: <1516909693-68447-1-git-send-email-yong.liu@intel.com> Subject: [dts] [PATCH v2 2/2] framework: add command history recording 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: , X-List-Received-Date: Mon, 29 Jan 2018 06:03:08 -0000 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 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