test suite reviews and discussions
 help / color / mirror / Atom feed
* [dts] [PATCH v1 1/2] framework/utils: add function to retrieve object from backtrace
@ 2018-01-25 19:48 Marvin Liu
  2018-01-25 19:48 ` [dts] [PATCH v1 2/2] framework: add command history recording Marvin Liu
  2018-01-28 22:56 ` [dts] [PATCH v2 " Marvin Liu
  0 siblings, 2 replies; 3+ messages in thread
From: Marvin Liu @ 2018-01-25 19:48 UTC (permalink / raw)
  To: dts; +Cc: Marvin Liu

Sometimes can't find required variable for overall arch. Add one
function can retrieve those variables from callback frame.

Signed-off-by: Marvin Liu <yong.liu@intel.com>

diff --git a/framework/utils.py b/framework/utils.py
index 762c927..a0dcf8f 100644
--- a/framework/utils.py
+++ b/framework/utils.py
@@ -233,3 +233,22 @@ def convert_ip2int(ip_str, ip_type):
         ip_val = (h << 64) | l
 
     return ip_val
+
+def get_backtrace_object(file_name, obj_name):
+    import inspect
+    frame = inspect.currentframe()
+    obj = None
+    found = False
+    while frame:
+        file_path = inspect.getsourcefile(frame)
+        call_file = file_path.split(os.sep)[-1]
+        if file_name == call_file:
+            found = True
+            break
+
+        frame = frame.f_back
+
+    if found:
+        obj = getattr(frame.f_locals['self'], obj_name, None)
+
+    return obj
-- 
1.9.3

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [dts] [PATCH v1 2/2] framework: add command history recording
  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
  2018-01-28 22:56 ` [dts] [PATCH v2 " Marvin Liu
  1 sibling, 0 replies; 3+ messages in thread
From: Marvin Liu @ 2018-01-25 19:48 UTC (permalink / raw)
  To: dts; +Cc: Marvin Liu

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [dts] [PATCH v2 2/2] framework: add command history recording
  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 ` [dts] [PATCH v1 2/2] framework: add command history recording Marvin Liu
@ 2018-01-28 22:56 ` Marvin Liu
  1 sibling, 0 replies; 3+ messages in thread
From: Marvin Liu @ 2018-01-28 22:56 UTC (permalink / raw)
  To: dts; +Cc: Marvin Liu

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@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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-01-29  6:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [dts] [PATCH v1 2/2] framework: add command history recording Marvin Liu
2018-01-28 22:56 ` [dts] [PATCH v2 " Marvin Liu

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).