test suite reviews and discussions
 help / color / mirror / Atom feed
* [dts] [PATCH 0/4] Support debug mode in DTS
@ 2015-04-28 14:56 Yong Liu
  2015-04-28 14:56 ` [dts] [PATCH 1/4] framework: add debugger module for enable debug in the running process Yong Liu
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Yong Liu @ 2015-04-28 14:56 UTC (permalink / raw)
  To: dts

From: Marvin Liu <yong.liu@intel.com>

This patch support debug mode in dts. In debug mode, user can directly take 
operation on ssh connections or call python debug interpreter.

DTS can enter debug mode by input keyboard interrupt "ctrl+c" at anytime.
Then user can take ownership of session by command like "connect("dut")".
The connected session can be listed by command "list()".
After debug done, can return from ssh connection to debug mode by command 
"ctrl+]".
Debug mode can also return to normal mode by command "quit()".

There's one bug in pexpect module need manually fixed.
/usr/lib/python2.7/site-packages/pexpect/__init__.py should changed as below.
        #  if err.errno == errno.EINTR:
        if err[0] == errno.EINTR:

Marvin Liu (4):
  framework: add debugger module for enable debug in the running process
  framework: maintain connected session list and disable debug mode in
    send_expect
  framework: change alt session name for easy to distinguish
  framework: enlarge hugepage number for dpdk2.0 request more memory

 framework/debugger.py       | 147 ++++++++++++++++++++++++++++++++++++++++++++
 framework/dut.py            |   4 +-
 framework/project_dpdk.py   |   4 +-
 framework/ssh_connection.py |   7 +++
 framework/ssh_pexpect.py    |  10 ++-
 framework/tester.py         |   2 +-
 6 files changed, 166 insertions(+), 8 deletions(-)
 create mode 100644 framework/debugger.py

-- 
1.9.3

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

* [dts] [PATCH 1/4] framework: add debugger module for enable debug in the running process
  2015-04-28 14:56 [dts] [PATCH 0/4] Support debug mode in DTS Yong Liu
@ 2015-04-28 14:56 ` Yong Liu
  2015-04-28 14:56 ` [dts] [PATCH 2/4] framework: maintain connected session list and disable debug mode in send_expect Yong Liu
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Yong Liu @ 2015-04-28 14:56 UTC (permalink / raw)
  To: dts

From: Marvin Liu <yong.liu@intel.com>

There're only few commands supported in debug mode. They're listed below.
help(): show help message
list(): list all connected sessions
connect(name): connect to session directly
exit(): exit dts
quit(): quit debug mode and into noraml mode
debug(): call python debug module

Signed-off-by: Marvin Liu <yong.liu@intel.com>
---
 framework/debugger.py | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 147 insertions(+)
 create mode 100644 framework/debugger.py

diff --git a/framework/debugger.py b/framework/debugger.py
new file mode 100644
index 0000000..a2bfe7f
--- /dev/null
+++ b/framework/debugger.py
@@ -0,0 +1,147 @@
+# BSD LICENSE
+#
+# Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+#   * Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+#   * Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in
+#     the documentation and/or other materials provided with the
+#     distribution.
+#   * Neither the name of Intel Corporation nor the names of its
+#     contributors may be used to endorse or promote products derived
+#     from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+
+import sys
+import os
+import signal
+import code
+import time
+import dts
+
+
+console = None  # global console object
+debug_cmd = ''  # global debug state
+
+
+def help_command():
+    console.push('print \'Help on debug module\'')
+    console.push('print \'DESCRIPTION\'')
+    console.push('print \'DTS debug module support few debug commands\'')
+    console.push('print \'  - help: help messages\'')
+    console.push('print \'  - list: list all connections\'')
+    console.push('print \'  - connect: bind to specified connection\'')
+    console.push('print \'  -        : connect(\"dut\")\'')
+    console.push('print \'  - quit: quit debug module\'')
+    console.push('print \'  - exit: exit processing procedure\'')
+    console.push('print \'  - debug: call python debug module for further debug\'')
+
+
+def list_command():
+    """
+    List all connection sessions and can be reference of connect command.
+    """
+    index = 0
+    from ssh_connection import CONNECTIONS
+    for connection in CONNECTIONS:
+        for name, session in connection.items():
+            console.push('print \'connect %d: %10s\'' % (index, name))
+            index += 1
+
+
+def connect_command(connect):
+    """
+    Connect to ssh session and give control to user.
+    """
+    from ssh_connection import CONNECTIONS
+    for connection in CONNECTIONS:
+        for name, session in connection.items():
+            if name == connect:
+                session.session.interact()
+
+
+def exit_command():
+    """
+    Exit dts framework.
+    """
+    global debug_cmd
+    debug_cmd = 'exit'
+    sys.exit(0)
+
+
+def debug_command():
+    """
+    Give control to python debugger pdb.
+    """
+    global debug_cmd
+    debug_cmd = 'debug'
+    sys.exit(0)
+
+
+def capture_handle(signum, frame):
+    """
+    Capture keyboard interrupt in the process of send_expect.
+    """
+    global debug_cmd
+    debug_cmd = 'waiting'
+
+
+def keyboard_handle(signum, frame):
+    """
+    Interrupt handler for SIGINT and call code module create python interpreter.
+    """
+    global console
+    console = code.InteractiveConsole()
+    command = {}
+    command['list'] = list_command
+    command['exit'] = exit_command
+    command['debug'] = debug_command
+    command['help'] = help_command
+    command['connect'] = connect_command
+    console.push('print \"Use help command for detail information\"')
+    try:
+        code.interact(local=command)
+    except SystemExit:
+        # reopen sys.stdin for after exit function stdin will be closed
+        fd = os.open('/dev/stdin', 600)
+        sys.stdin = os.fdopen(fd, 'r')
+
+    global debug_cmd
+    if debug_cmd == 'debug':
+        # call pyton debugger
+        import pdb
+        pdb.set_trace()
+    elif debug_cmd == 'exit':
+        sys.exit(0)
+
+    debug_cmd = ''
+
+
+def ignore_keyintr():
+    """
+    Temporary disable interrupt handler.
+    """
+    global debug_cmd
+    signal.siginterrupt(signal.SIGINT, True)
+    # if there's waiting request, first handler it
+    if debug_cmd == 'waiting':
+        keyboard_handle(signal.SIGINT, None)
+
+    return signal.signal(signal.SIGINT, capture_handle)
+
+
+def aware_keyintr():
+    """
+    Reenable interrupt handler.
+    """
+    return signal.signal(signal.SIGINT, keyboard_handle)
-- 
1.9.3

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

* [dts] [PATCH 2/4] framework: maintain connected session list and disable debug mode in send_expect
  2015-04-28 14:56 [dts] [PATCH 0/4] Support debug mode in DTS Yong Liu
  2015-04-28 14:56 ` [dts] [PATCH 1/4] framework: add debugger module for enable debug in the running process Yong Liu
@ 2015-04-28 14:56 ` Yong Liu
  2015-04-28 14:56 ` [dts] [PATCH 3/4] framework: change alt session name for easy to distinguish Yong Liu
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Yong Liu @ 2015-04-28 14:56 UTC (permalink / raw)
  To: dts

From: Marvin Liu <yong.liu@intel.com>

Signed-off-by: Marvin Liu <yong.liu@intel.com>
---
 framework/ssh_connection.py |  7 +++++++
 framework/ssh_pexpect.py    | 10 +++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/framework/ssh_connection.py b/framework/ssh_connection.py
index b10cb4f..18a6517 100644
--- a/framework/ssh_connection.py
+++ b/framework/ssh_connection.py
@@ -32,6 +32,10 @@
 from ssh_pexpect import SSHPexpect
 from settings import USERNAME
 
+"""
+Global structure for saving connections
+"""
+CONNECTIONS = []
 
 class SSHConnection(object):
 
@@ -43,6 +47,9 @@ class SSHConnection(object):
     def __init__(self, host, session_name, password=''):
         self.session = SSHPexpect(host, USERNAME, password)
         self.name = session_name
+        connection = {}
+        connection[self.name] = self.session
+        CONNECTIONS.append(connection)
 
     def init_log(self, logger):
         self.logger = logger
diff --git a/framework/ssh_pexpect.py b/framework/ssh_pexpect.py
index eaa3a42..735df44 100644
--- a/framework/ssh_pexpect.py
+++ b/framework/ssh_pexpect.py
@@ -1,6 +1,7 @@
 import time
 import pexpect
 import pxssh
+from debugger import ignore_keyintr, aware_keyintr
 from exception import TimeoutException, SSHConnectionException
 
 """
@@ -31,12 +32,15 @@ class SSHPexpect(object):
         self.logger.info("ssh %s@%s" % (self.username, self.host))
 
     def send_expect_base(self, command, expected, timeout=15):
-        # clear buffer
-        self.__flush()
+        ignore_keyintr()
+        self.__flush() # clear buffer
         self.session.PROMPT = expected
         self.__sendline(command)
         self.__prompt(command, timeout)
-        return self.get_output_before()
+        aware_keyintr()
+
+        before = self.get_output_before()
+        return before
 
     def send_expect(self, command, expected, timeout=15, verify=False):
         ret = self.send_expect_base(command, expected, timeout)
-- 
1.9.3

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

* [dts] [PATCH 3/4] framework: change alt session name for easy to distinguish
  2015-04-28 14:56 [dts] [PATCH 0/4] Support debug mode in DTS Yong Liu
  2015-04-28 14:56 ` [dts] [PATCH 1/4] framework: add debugger module for enable debug in the running process Yong Liu
  2015-04-28 14:56 ` [dts] [PATCH 2/4] framework: maintain connected session list and disable debug mode in send_expect Yong Liu
@ 2015-04-28 14:56 ` Yong Liu
  2015-04-28 14:56 ` [dts] [PATCH 4/4] framework: enlarge hugepage number for dpdk2.0 request more memory Yong Liu
  2015-05-11  6:25 ` [dts] [PATCH] framework: add argument for debug mode enable and disable Yong Liu
  4 siblings, 0 replies; 6+ messages in thread
From: Yong Liu @ 2015-04-28 14:56 UTC (permalink / raw)
  To: dts

From: Marvin Liu <yong.liu@intel.com>

Signed-off-by: Marvin Liu <yong.liu@intel.com>
---
 framework/dut.py    | 4 ++--
 framework/tester.py | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/framework/dut.py b/framework/dut.py
index e186d99..5b7aba2 100644
--- a/framework/dut.py
+++ b/framework/dut.py
@@ -64,7 +64,7 @@ class Dut(Crb):
         self.session = SSHConnection(self.get_ip_address(), self.NAME,
                                      self.get_password())
         self.session.init_log(self.logger)
-        self.alt_session = SSHConnection(self.get_ip_address(), self.NAME,
+        self.alt_session = SSHConnection(self.get_ip_address(), self.NAME + '_alt',
                                          self.get_password())
         self.alt_session.init_log(self.logger)
         self.number_of_cores = 0
@@ -232,7 +232,7 @@ class Dut(Crb):
 
         if int(hugepages_size) < (1024 * 1024):
             if self.architecture == "x86_64":
-                arch_huge_pages = hugepages if hugepages > 0 else 1024
+                arch_huge_pages = hugepages if hugepages > 0 else 4096
             elif self.architecture == "i686":
                 arch_huge_pages = hugepages if hugepages > 0 else 512
             # set huge pagesize for x86_x32 abi target
diff --git a/framework/tester.py b/framework/tester.py
index 2debcd6..aba0356 100644
--- a/framework/tester.py
+++ b/framework/tester.py
@@ -64,7 +64,7 @@ class Tester(Crb):
                                      self.NAME, self.get_password())
         self.session.init_log(self.logger)
         self.alt_session = SSHConnection(self.get_ip_address(),
-                                         self.NAME, self.get_password())
+                                         self.NAME + '_alt', self.get_password())
         self.alt_session.init_log(self.logger)
 
         self.bgProcIsRunning = False
-- 
1.9.3

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

* [dts] [PATCH 4/4] framework: enlarge hugepage number for dpdk2.0 request more memory
  2015-04-28 14:56 [dts] [PATCH 0/4] Support debug mode in DTS Yong Liu
                   ` (2 preceding siblings ...)
  2015-04-28 14:56 ` [dts] [PATCH 3/4] framework: change alt session name for easy to distinguish Yong Liu
@ 2015-04-28 14:56 ` Yong Liu
  2015-05-11  6:25 ` [dts] [PATCH] framework: add argument for debug mode enable and disable Yong Liu
  4 siblings, 0 replies; 6+ messages in thread
From: Yong Liu @ 2015-04-28 14:56 UTC (permalink / raw)
  To: dts

From: Marvin Liu <yong.liu@intel.com>

Signed-off-by: Marvin Liu <yong.liu@intel.com>
---
 framework/project_dpdk.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/framework/project_dpdk.py b/framework/project_dpdk.py
index bc6ccca..8963924 100644
--- a/framework/project_dpdk.py
+++ b/framework/project_dpdk.py
@@ -354,7 +354,7 @@ class DPDKtester(Tester):
             total_huge_pages = self.get_total_huge_pages()
             if total_huge_pages == 0:
                 self.mount_huge_pages()
-                self.set_huge_pages(1024)
+                self.set_huge_pages(4096)
 
             self.session.copy_file_to("dep/tgen.tgz")
             self.session.copy_file_to("dep/tclclient.tgz")
@@ -387,7 +387,7 @@ class DPDKtester(Tester):
         hugepages_size = self.send_expect("awk '/Hugepagesize/ {print $2}' /proc/meminfo", "# ")
 
         if int(hugepages_size) < (1024 * 1024):
-            arch_huge_pages = hugepages if hugepages > 0 else 1024
+            arch_huge_pages = hugepages if hugepages > 0 else 4096
             total_huge_pages = self.get_total_huge_pages()
 
             self.mount_huge_pages()
-- 
1.9.3

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

* [dts] [PATCH] framework: add argument for debug mode enable and disable
  2015-04-28 14:56 [dts] [PATCH 0/4] Support debug mode in DTS Yong Liu
                   ` (3 preceding siblings ...)
  2015-04-28 14:56 ` [dts] [PATCH 4/4] framework: enlarge hugepage number for dpdk2.0 request more memory Yong Liu
@ 2015-05-11  6:25 ` Yong Liu
  4 siblings, 0 replies; 6+ messages in thread
From: Yong Liu @ 2015-05-11  6:25 UTC (permalink / raw)
  To: dts

From: Marvin Liu <yong.liu@intel.com>

When debug mode enable, before and after every send_expect function will
change signal handler. Althrough it only toke 0.x second, hundreds call of
send_expect will also take few minutes. This patch add one argument of dts to
enable and disable debug mode, and default debug mode will be disabled.

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

diff --git a/framework/debugger.py b/framework/debugger.py
index a2bfe7f..a5f3e84 100644
--- a/framework/debugger.py
+++ b/framework/debugger.py
@@ -131,6 +131,9 @@ def ignore_keyintr():
     """
     Temporary disable interrupt handler.
     """
+    if dts.debug_mode is False:
+        return
+
     global debug_cmd
     signal.siginterrupt(signal.SIGINT, True)
     # if there's waiting request, first handler it
@@ -144,4 +147,7 @@ def aware_keyintr():
     """
     Reenable interrupt handler.
     """
+    if dts.debug_mode is False:
+        return
+
     return signal.signal(signal.SIGINT, keyboard_handle)
diff --git a/framework/dts.py b/framework/dts.py
index ae12dc9..c9ecccb 100644
--- a/framework/dts.py
+++ b/framework/dts.py
@@ -58,6 +58,7 @@ reload(sys)
 sys.setdefaultencoding('UTF8')
 
 
+debug_mode = False
 config = None
 table = None
 results_table_rows = []
@@ -385,7 +386,7 @@ def dts_run_suite(crbInst, test_suites, target, nic):
 
 def run_all(config_file, pkgName, git, patch, skip_setup,
             read_cache, project, suite_dir, test_cases,
-            base_dir, output_dir, verbose):
+            base_dir, output_dir, verbose, debug):
     """
     Main process of DTS, it will run all test suites in the config file.
     """
@@ -398,6 +399,7 @@ def run_all(config_file, pkgName, git, patch, skip_setup,
     global excel_report
     global stats
     global log_handler
+    global debug_mode
 
     # prepare the output folder
     if not os.path.exists(output_dir):
@@ -408,6 +410,10 @@ def run_all(config_file, pkgName, git, patch, skip_setup,
         sys.path.append(folder)
     sys.path.append(suite_dir)
 
+    # enable debug mode
+    if debug is True:
+        debug_mode = True
+
     # init log_handler handler
     if verbose is True:
         logger.set_verbose()
diff --git a/framework/main.py b/framework/main.py
index 11b7513..3e467d0 100755
--- a/framework/main.py
+++ b/framework/main.py
@@ -117,6 +117,10 @@ parser.add_argument('-v', '--verbose',
                     action='store_true',
                     help='enable verbose output, all message output on screen')
 
+parser.add_argument('--debug',
+                    action='store_true',
+                    help='enable debug mode, user can enter debug mode in process')
+
 args = parser.parse_args()
 
 
@@ -132,4 +136,4 @@ if args.git is not None:
 dts.run_all(args.config_file, args.snapshot, args.git,
             args.patch, args.skip_setup, args.read_cache,
             args.project, args.suite_dir, args.test_cases,
-            args.dir, args.output, args.verbose)
+            args.dir, args.output, args.verbose, args.debug)
-- 
1.9.3

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

end of thread, other threads:[~2015-05-11  6:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-28 14:56 [dts] [PATCH 0/4] Support debug mode in DTS Yong Liu
2015-04-28 14:56 ` [dts] [PATCH 1/4] framework: add debugger module for enable debug in the running process Yong Liu
2015-04-28 14:56 ` [dts] [PATCH 2/4] framework: maintain connected session list and disable debug mode in send_expect Yong Liu
2015-04-28 14:56 ` [dts] [PATCH 3/4] framework: change alt session name for easy to distinguish Yong Liu
2015-04-28 14:56 ` [dts] [PATCH 4/4] framework: enlarge hugepage number for dpdk2.0 request more memory Yong Liu
2015-05-11  6:25 ` [dts] [PATCH] framework: add argument for debug mode enable and disable Yong 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).