test suite reviews and discussions
 help / color / mirror / Atom feed
* [dts] [PATCH 0/2] support user input commands in different stage
@ 2016-06-21  7:20 Marvin Liu
  2016-06-21  7:20 ` [dts] [PATCH 1/2] framework: crb add stage variable for demonstrate status Marvin Liu
  2016-06-21  7:20 ` [dts] [PATCH 2/2] framework: support execute user input command Marvin Liu
  0 siblings, 2 replies; 3+ messages in thread
From: Marvin Liu @ 2016-06-21  7:20 UTC (permalink / raw)
  To: dts

This patch set support to execute user input commands on dut or tester.
Timing of command execution can also be configured to pre-init and post-init.
Pre-init mean the stage when ssh sessions created and no more command run on
crb. Post-init mean the stage when environment has been ready for running.

Marvin Liu (2):
  framework: crb add stage variable for demonstrate status
  framework: support execute user input command

 framework/crb.py          |  1 +
 framework/dts.py          | 87 ++++++++++++++++++++++++++++++++++++++++++-----
 framework/main.py         |  7 +++-
 framework/project_dpdk.py |  3 ++
 4 files changed, 89 insertions(+), 9 deletions(-)

-- 
1.9.3

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

* [dts] [PATCH 1/2] framework: crb add stage variable for demonstrate status
  2016-06-21  7:20 [dts] [PATCH 0/2] support user input commands in different stage Marvin Liu
@ 2016-06-21  7:20 ` Marvin Liu
  2016-06-21  7:20 ` [dts] [PATCH 2/2] framework: support execute user input command Marvin Liu
  1 sibling, 0 replies; 3+ messages in thread
From: Marvin Liu @ 2016-06-21  7:20 UTC (permalink / raw)
  To: dts; +Cc: Marvin Liu

After created session between crb, stage will be "pre-init".
When crb has been setup for dpdk running, stage will be "post-init".

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

diff --git a/framework/crb.py b/framework/crb.py
index 3194f69..b302a76 100644
--- a/framework/crb.py
+++ b/framework/crb.py
@@ -57,6 +57,7 @@ class Crb(object):
         self.serializer = serializer
         self.ports_info = None
         self.sessions = []
+        self.stage = 'pre-init'
 
         self.logger = getLogger(name)
         self.session = SSHConnection(self.get_ip_address(), name,
diff --git a/framework/project_dpdk.py b/framework/project_dpdk.py
index 2560bd7..05930ad 100644
--- a/framework/project_dpdk.py
+++ b/framework/project_dpdk.py
@@ -260,6 +260,7 @@ class DPDKdut(Dut):
         """
         self.prepare_package(pkgName, patch)
         self.dut_prerequisites()
+        self.stage = "post-init"
 
     def extra_nic_setup(self):
         """
@@ -399,6 +400,8 @@ class DPDKtester(Tester):
                 assert ("No such file or directory" not in out), "Can not find /root/igb_uio.ko for performance"
                 self.setup_memory()
 
+        self.stage = "post-init"
+
     def setup_memory(self, hugepages=-1):
         """
         Setup hugepage on tester.
-- 
1.9.3

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

* [dts] [PATCH 2/2] framework: support execute user input command
  2016-06-21  7:20 [dts] [PATCH 0/2] support user input commands in different stage Marvin Liu
  2016-06-21  7:20 ` [dts] [PATCH 1/2] framework: crb add stage variable for demonstrate status Marvin Liu
@ 2016-06-21  7:20 ` Marvin Liu
  1 sibling, 0 replies; 3+ messages in thread
From: Marvin Liu @ 2016-06-21  7:20 UTC (permalink / raw)
  To: dts; +Cc: Marvin Liu

Add new argument "commands" which will allow user to input commands and
designate in which stage those commands will be executed.

The argument format will be like below
"[commands]:dut|tester:pre-init|post-init:check|ignore"

One sample for run python script on dut before environment initialized.
"--commands=[python,do_something.py]:dut:pre-init:check"

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

diff --git a/framework/dts.py b/framework/dts.py
index 7310bda..08a9406 100644
--- a/framework/dts.py
+++ b/framework/dts.py
@@ -53,7 +53,7 @@ from test_result import Result
 from stats_reporter import StatsReporter
 from excel_reporter import ExcelReporter
 from utils import *
-from exception import TimeoutException, ConfigParseException
+from exception import TimeoutException, ConfigParseException, VerifyFailure
 from logger import getLogger
 import logger
 import debugger
@@ -89,6 +89,7 @@ Package = ''
 Patches = []
 drivername = ""
 interrupttypr = ""
+dts_commands = []
 
 
 def report(text, frame=False, annex=False):
@@ -106,9 +107,10 @@ def close_all_sessions():
     Close session to DUT and tester.
     """
     # close all nics
-    for port_info in dut.ports_info:
-        netdev = port_info['port']
-        netdev.close()
+    if getattr(dut, 'ports_info', None) and dut.ports_info:
+        for port_info in dut.ports_info:
+            netdev = port_info['port']
+            netdev.close()
     # close all session
     if dut is not None:
         dut.close()
@@ -183,6 +185,66 @@ def dts_parse_config(section):
     return duts[0], targets, test_suites, nic, scenario
 
 
+def dts_parse_commands(commands):
+    """
+    Parse command information from dts arguments
+    """
+    args_format = {"shell": 0,
+                   "crb": 1,
+                   "stage": 2,
+                   "check": 3,
+                   "max_num": 4}
+    global dts_commands
+    cmd_fmt = r"\[(.*)\]"
+    for command in commands:
+        args = command.split(':')
+        if len(args) != args_format['max_num']:
+            log_handler.error("Command is lack of arguments" % command)
+            continue
+        dts_command = {}
+
+        m = re.match(cmd_fmt, args[0])
+        if m:
+            cmds = m.group(1).split(',')
+            shell_cmd = ""
+            for cmd in cmds:
+                shell_cmd += cmd
+                shell_cmd += ' '
+            dts_command['command'] = shell_cmd[:-1]
+        else:
+            dts_command['command'] = args[0]
+        if args[1] == "tester":
+            dts_command['host'] = "tester"
+        else:
+            dts_command['host'] = "dut"
+        if args[2] == "post-init":
+            dts_command['stage'] = "post-init"
+        else:
+            dts_command['stage'] = "pre-init"
+        if args[3] == "ignore":
+            dts_command["verify"] = False
+        else:
+            dts_command["verify"] = True
+
+        dts_commands.append(dts_command)
+
+
+def dts_run_commands(crb):
+    """
+    Run dts input commands
+    """
+    global dts_commands
+    for dts_command in dts_commands:
+        command = dts_command['command']
+        if crb.NAME == dts_command['host']:
+            if crb.stage == dts_command['stage']:
+                ret = crb.send_expect(command, expected="# ", verify=True)
+                if type(ret) is int:
+                    log_handler.error("[%s] return failure" % command)
+                    if dts_command['verify'] is True:
+                        raise VerifyFailure("Command execution failed")
+
+
 def get_project_obj(project_name, super_class, crbInst, serializer):
     """
     Load project module and return crb instance.
@@ -254,10 +316,10 @@ def dts_crbs_init(crbInst, skip_setup, read_cache, project, base_dir, nic, virtt
     serializer.load_from_file()
 
     dutInst = copy.copy(crbInst)
-    dutInst['My IP'] =  crbInst['IP']
+    dutInst['My IP'] = crbInst['IP']
     dut = get_project_obj(project, Dut, dutInst, serializer)
     testInst = copy.copy(crbInst)
-    testInst['My IP'] =  crbInst['tester IP']
+    testInst['My IP'] = crbInst['tester IP']
     tester = get_project_obj(project, Tester, testInst, serializer)
     dts_log_execution(log_handler)
     dut.tester = tester
@@ -286,8 +348,12 @@ def dts_run_prerequisties(pkgName, patch):
     Run dts prerequisties function.
     """
     try:
+        dts_run_commands(tester)
         tester.prerequisites(performance_only)
+        dts_run_commands(tester)
+        dts_run_commands(dut)
         dut.prerequisites(pkgName, patch)
+        dts_run_commands(dut)
 
         serializer.save_to_file()
     except Exception as ex:
@@ -311,7 +377,7 @@ def dts_run_target(crbInst, targets, test_suites, nic, scenario):
     if scene:
         scene.load_config()
         scene.create_scene()
-    
+
     for target in targets:
         log_handler.info("\nTARGET " + target)
         result.target = target
@@ -400,7 +466,8 @@ def dts_run_suite(crbInst, test_suites, target, nic, scene):
 
 def run_all(config_file, pkgName, git, patch, skip_setup,
             read_cache, project, suite_dir, test_cases,
-            base_dir, output_dir, verbose, virttype, debug, debugcase):
+            base_dir, output_dir, verbose, virttype, debug,
+            debugcase, commands):
     """
     Main process of DTS, it will run all test suites in the config file.
     """
@@ -459,6 +526,9 @@ def run_all(config_file, pkgName, git, patch, skip_setup,
     if len(load_cfg) == 0:
         raise ConfigParseException(config_file)
 
+    # parse commands
+    dts_parse_commands(commands)
+
     # register exit action
     atexit.register(close_all_sessions)
 
@@ -773,6 +843,7 @@ def save_all_results():
     excel_report.save(result)
     stats.save(result)
 
+
 def accepted_nic(pci_id):
     """
     Return True if the pci_id is a known NIC card in the settings file and if
diff --git a/framework/main.py b/framework/main.py
index 9e9c45c..5d7d051 100755
--- a/framework/main.py
+++ b/framework/main.py
@@ -135,6 +135,11 @@ parser.add_argument('--debugcase',
                     action='store_true',
                     help='enable debug mode in the first case, user can further debug')
 
+parser.add_argument('--commands',
+                    action='append',
+                    help='run command on tester or dut. The command format is ' +
+                    '[commands]:dut|tester:pre-init|post-init:check|ignore')
+
 args = parser.parse_args()
 
 
@@ -151,4 +156,4 @@ 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.virttype,
-            args.debug, args.debugcase)
+            args.debug, args.debugcase, args.commands)
-- 
1.9.3

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

end of thread, other threads:[~2016-06-21  7:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-21  7:20 [dts] [PATCH 0/2] support user input commands in different stage Marvin Liu
2016-06-21  7:20 ` [dts] [PATCH 1/2] framework: crb add stage variable for demonstrate status Marvin Liu
2016-06-21  7:20 ` [dts] [PATCH 2/2] framework: support execute user input command 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).