From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id C431EA0613 for ; Fri, 27 Sep 2019 10:48:54 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B9D582D13; Fri, 27 Sep 2019 10:48:54 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id E76872BE9 for ; Fri, 27 Sep 2019 10:48:52 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Sep 2019 01:48:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,554,1559545200"; d="scan'208";a="219706377" Received: from unknown (HELO dpdk-meijianwei-tester.sh.intel.com) ([10.240.179.33]) by fmsmga002.fm.intel.com with ESMTP; 27 Sep 2019 01:48:51 -0700 From: Jianwei Mei To: dts@dpdk.org Cc: zhaoyan.chen@intel.com, lihongx.ma@intel.com, meijx Date: Sat, 28 Sep 2019 01:34:55 +0800 Message-Id: <1569605698-316544-3-git-send-email-jianweix.mei@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1569605698-316544-1-git-send-email-jianweix.mei@intel.com> References: <1569605698-316544-1-git-send-email-jianweix.mei@intel.com> Subject: [dts] [PATCH V1 3/6] framework/crb.py: only scan configured ports from ports.cfg and overwrite kill all 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: , Errors-To: dts-bounces@dpdk.org Sender: "dts" From: meijx only scan configured ports when dts start pretreatment ENV and overwrite kill all. Signed-off-by: meijx --- framework/crb.py | 106 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 85 insertions(+), 21 deletions(-) diff --git a/framework/crb.py b/framework/crb.py index 6e5f56f..91f2946 100644 --- a/framework/crb.py +++ b/framework/crb.py @@ -35,6 +35,7 @@ import os from settings import TIMEOUT, IXIA from ssh_connection import SSHConnection from logger import getLogger +from config import PortConf, PORTCONF """ CRB (customer reference board) basic functions and handlers @@ -278,6 +279,37 @@ class Crb(object): pattern = re.compile(rexp) match = pattern.findall(out) self.pci_devices_info = [] + + obj_str = str(self) + if 'VirtDut' in obj_str: + # there is no port.cfg in VM, so need to scan all pci in VM. + pass + else: + # only scan configured pcis + portconf = PortConf(PORTCONF) + portconf.load_ports_config(self.crb['IP']) + configed_pcis = portconf.get_ports_config() + if configed_pcis: + if 'tester' in str(self): + tester_pci_in_cfg = [] + for item in configed_pcis.values(): + for pci_info in match: + if item['peer'] == pci_info[0]: + tester_pci_in_cfg.append(pci_info) + match = tester_pci_in_cfg[:] + else: + dut_pci_in_cfg = [] + for key in configed_pcis.keys(): + for pci_info in match: + if key == pci_info[0]: + dut_pci_in_cfg.append(pci_info) + match = dut_pci_in_cfg[:] + # keep the original pci sequence + match = sorted(match) + else: + # INVALID CONFIG FOR NO PCI ADDRESS!!! eg: port.cfg for freeBSD + pass + for i in range(len(match)): #check if device is cavium and check its linkspeed, append only if it is 10G if "177d:" in match[i][1]: @@ -434,31 +466,63 @@ class Crb(object): f.write(contents) self.session.copy_file_to(fileName, password=self.get_password()) - def kill_all(self, alt_session=True): + def get_dpdk_pids(self, prefix_list, alt_session): """ - Kill all dpdk applications on CRB. + get all dpdk applications on CRB. """ + file_directorys = ['/var/run/dpdk/%s/config' % file_prefix for file_prefix in prefix_list] pids = [] pid_reg = r'p(\d+)' - cmd = 'lsof -Fp /var/run/dpdk/rte/config' - out = self.send_expect(cmd, "# ", 20, alt_session) - if len(out): - lines = out.split('\r\n') - for line in lines: - m = re.match(pid_reg, line) - if m: - pids.append(m.group(1)) - for pid in pids: - self.send_expect('kill -9 %s' % pid, '# ', 20, alt_session) - self.get_session_output(timeout=2) - - cmd = 'lsof -Fp /var/run/dpdk/rte/hugepage_info' - out = self.send_expect(cmd, "# ", 20, alt_session) - if len(out) and "No such file or directory" not in out: - self.logger.warning("There are some dpdk process not free hugepage") - self.logger.warning("**************************************") - self.logger.warning(out) - self.logger.warning("**************************************") + for config_file in file_directorys: + cmd = 'lsof -Fp %s' % config_file + out = self.send_expect(cmd, "# ", 20, alt_session) + if len(out): + lines = out.split('\r\n') + for line in lines: + m = re.match(pid_reg, line) + if m: + pids.append(m.group(1)) + for pid in pids: + self.send_expect('kill -9 %s' % pid, '# ', 20, alt_session) + self.get_session_output(timeout=2) + + hugepage_info = ['/var/run/dpdk/%s/hugepage_info' % file_prefix for file_prefix in prefix_list] + for hugepage in hugepage_info: + cmd = 'lsof -Fp %s' % hugepage + out = self.send_expect(cmd, "# ", 20, alt_session) + if len(out) and "No such file or directory" not in out: + self.logger.warning("There are some dpdk process not free hugepage") + self.logger.warning("**************************************") + self.logger.warning(out) + self.logger.warning("**************************************") + + # remove directory + directorys = ['/var/run/dpdk/%s' % file_prefix for file_prefix in prefix_list] + for directory in directorys: + cmd = 'rm -rf %s' % directory + self.send_expect(cmd, "# ", 20, alt_session) + + def kill_all(self, alt_session=True): + """ + Kill all dpdk applications on CRB. + """ + if 'tester' in str(self): + self.logger.info('kill_all: called by tester') + pass + else: + if self.prefix_list: + self.logger.info('kill_all: called by dut and prefix list has value.') + self.get_dpdk_pids(self.prefix_list, alt_session) + # init prefix_list + self.prefix_list = [] + else: + self.logger.info('kill_all: called by dut and has no prefix list.') + session = self.create_session('dut_session') + out = session.send_command("ls -l /var/run/dpdk |awk '/^d/ {print $NF}'", timeout=0.5) + # the last directory is expect string, eg: [PEXPECT]# + if out != '': + dir_list = out.split('\r\n') + self.get_dpdk_pids(dir_list[:-1], alt_session) def close(self): """ -- 1.8.3.1