From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id EE2C5ADB0 for ; Tue, 21 Jun 2016 09:21:17 +0200 (CEST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP; 21 Jun 2016 00:21:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,502,1459839600"; d="scan'208";a="991934664" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by fmsmga001.fm.intel.com with ESMTP; 21 Jun 2016 00:21:13 -0700 Received: from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com [10.239.29.90]) by shvmail01.sh.intel.com with ESMTP id u5L7LBth009955; Tue, 21 Jun 2016 15:21:11 +0800 Received: from shecgisg003.sh.intel.com (localhost [127.0.0.1]) by shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id u5L7L8Tl015569; Tue, 21 Jun 2016 15:21:10 +0800 Received: (from yliu84x@localhost) by shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id u5L7L8Sx015565; Tue, 21 Jun 2016 15:21:08 +0800 From: Marvin Liu To: dts@dpdk.org Cc: Marvin Liu Date: Tue, 21 Jun 2016 15:20:58 +0800 Message-Id: <1466493658-15519-3-git-send-email-yong.liu@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1466493658-15519-1-git-send-email-yong.liu@intel.com> References: <1466493658-15519-1-git-send-email-yong.liu@intel.com> Subject: [dts] [PATCH 2/2] framework: support execute user input command 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: Tue, 21 Jun 2016 07:21:18 -0000 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 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