From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 270F51B1BE for ; Fri, 26 Jan 2018 03:55:09 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jan 2018 18:55:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,414,1511856000"; d="scan'208";a="29585205" Received: from dpdk-test38.sh.intel.com ([10.67.119.87]) by orsmga002.jf.intel.com with ESMTP; 25 Jan 2018 18:55:07 -0800 From: Marvin Liu To: dts@dpdk.org Cc: Marvin Liu Date: Thu, 25 Jan 2018 14:48:13 -0500 Message-Id: <1516909693-68447-2-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 v1 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: Fri, 26 Jan 2018 02:55:09 -0000 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..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