From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 4E7EAC37E for ; Fri, 22 May 2015 11:04:39 +0200 (CEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP; 22 May 2015 02:04:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,474,1427785200"; d="scan'208";a="698791798" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by orsmga001.jf.intel.com with ESMTP; 22 May 2015 02:04:37 -0700 Received: from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com [10.239.29.90]) by shvmail01.sh.intel.com with ESMTP id t4M94ZZV003012; Fri, 22 May 2015 17:04:35 +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 t4M94XjL014377; Fri, 22 May 2015 17:04:35 +0800 Received: (from yliu84x@localhost) by shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id t4M94XXI014373; Fri, 22 May 2015 17:04:33 +0800 From: "Jiajia, Sun" To: dts@dpdk.org Date: Fri, 22 May 2015 17:04:01 +0800 Message-Id: <1432285452-14286-9-git-send-email-sunx.jiajia@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1432285452-14286-1-git-send-email-sunx.jiajia@intel.com> References: <1432285452-14286-1-git-send-email-sunx.jiajia@intel.com> Subject: [dts] [PATCH v2 08/19] Add and move some functions because of the virtual tests and network device instantiation 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: Fri, 22 May 2015 09:04:40 -0000 From: sjiajiax Signed-off-by: sjiajiax --- framework/crb.py | 126 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 76 insertions(+), 50 deletions(-) diff --git a/framework/crb.py b/framework/crb.py index a699bfc..3160fa0 100644 --- a/framework/crb.py +++ b/framework/crb.py @@ -80,7 +80,9 @@ class Crb(object): """ Get the huge page number of CRB. """ - huge_pages = self.send_expect("awk '/HugePages_Total/ { print $2 }' /proc/meminfo", "# ") + huge_pages = self.send_expect( + "awk '/HugePages_Total/ { print $2 }' /proc/meminfo", + "# ", alt_session=True) if huge_pages != "": return int(huge_pages) return 0 @@ -127,13 +129,15 @@ class Crb(object): Force set remote interface link status in FreeBSD. """ eth = self.ports_info[port]['intf'] - self.send_expect("ifconfig %s %s" % (eth, status), "# ") + self.send_expect("ifconfig %s %s" % + (eth, status), "# ", alt_session=True) def admin_ports_linux(self, eth, status): """ Force set remote interface link status in Linux. """ - self.send_expect("ip link set %s %s" % (eth, status), "# ") + self.send_expect("ip link set %s %s" % + (eth, status), "# ", alt_session=True) def pci_devices_information(self): """ @@ -157,8 +161,9 @@ class Crb(object): """ Look for the NIC's information (PCI Id and card type). """ - out = self.send_expect("lspci -nn | grep -i eth", "# ") - rexp = r"([\da-f]{2}:[\da-f]{2}.\d{1}) Ethernet .*?([\da-f]{4}:[\da-f]{4})" + out = self.send_expect( + "lspci -nn | grep -i eth", "# ", alt_session=True) + rexp = r"([\da-f]{2}:[\da-f]{2}.\d{1}) .*Eth.*?ernet .*?([\da-f]{4}:[\da-f]{4})" pattern = re.compile(rexp) match = pattern.findall(out) self.pci_devices_info = [] @@ -169,7 +174,7 @@ class Crb(object): """ Look for the NIC's information (PCI Id and card type). """ - out = self.send_expect("pciconf -l", "# ") + out = self.send_expect("pciconf -l", "# ", alt_session=True) rexp = r"pci0:([\da-f]{1,3}:[\da-f]{1,2}:\d{1}):\s*class=0x020000.*chip=0x([\da-f]{4})8086" pattern = re.compile(rexp) match = pattern.findall(out) @@ -179,66 +184,69 @@ class Crb(object): card_type = "8086:%s" % match[i][1] self.pci_devices_info.append((match[i][0], card_type)) - def get_interface_name(self, bus_id, devfun_id=''): + def get_pci_dev_driver(self, bus_id, devfun_id): """ - Get interface name of specified pci device. + Get the driver of specified pci device. """ - get_interface_name = getattr(self, 'get_interface_name_%s' % self.get_os_type()) - return get_interface_name(bus_id, devfun_id) + get_pci_dev_driver = getattr( + self, 'get_pci_dev_driver_%s' % self.get_os_type()) + return get_pci_dev_driver(bus_id, devfun_id) - def get_interface_name_linux(self, bus_id, devfun_id): + def get_pci_dev_driver_linux(self, bus_id, devfun_id): """ - Get interface name of specified pci device on linux. + Get the driver of specified pci device on linux. """ - command = 'ls --color=never /sys/bus/pci/devices/0000:%s:%s/net' % (bus_id, devfun_id) - out = self.send_expect(command, '# ', verify=True) - if out == -1: - name = "" - else: - name = out.split()[0] - return name - - def get_interface_name_freebsd(self, bus_id, devfun_id): - """ - Get interface name of specified pci device on Freebsd. - """ - out = self.send_expect("pciconf -l", "# ") - rexp = r"(\w*)@pci0:%s" % bus_id + out = self.send_expect("cat /sys/bus/pci/devices/0000\:%s\:%s/uevent" % + (bus_id, devfun_id), "# ", alt_session=True) + rexp = r"DRIVER=(.+?)\r" pattern = re.compile(rexp) - match = pattern.findall(out) - return match[0] + match = pattern.search(out) + if not match: + return None + return match.group(1) - def get_mac_addr(self, intf, bus_id='', devfun_id=''): + def get_pci_dev_driver_freebsd(self, bus_id, devfun_id): """ - Get mac address of specified pci device. + Get the driver of specified pci device. """ - get_mac_addr = getattr(self, 'get_mac_addr_%s' % self.get_os_type()) - return get_mac_addr(intf, bus_id, devfun_id) + return True - def get_mac_addr_linux(self, intf, bus_id, devfun_id): + def get_pci_dev_id(self, bus_id, devfun_id): """ - Get mac address of specified pci device on linux. + Get the pci id of specified pci device. """ - command = ('cat /sys/bus/pci/devices/0000:%s:%s/net/%s/address' % - (bus_id, devfun_id, intf)) - return self.send_expect(command, '# ') + get_pci_dev_id = getattr( + self, 'get_pci_dev_id_%s' % self.get_os_type()) + return get_pci_dev_id(bus_id, devfun_id) - def get_mac_addr_freebsd(self, intf, bus_id, devfun_id): + def get_pci_dev_id_linux(self, bus_id, devfun_id): """ - Get mac address of specified pci device on Freebsd. + Get the pci id of specified pci device on linux. """ - out = self.send_expect('ifconfig %s' % intf, '# ') - rexp = r"ether ([\da-f:]*)" + out = self.send_expect("cat /sys/bus/pci/devices/0000\:%s\:%s/uevent" % + (bus_id, devfun_id), "# ", alt_session=True) + rexp = r"PCI_ID=(.+)" pattern = re.compile(rexp) - match = pattern.findall(out) - return match[0] + match = re.search(out) + if not match: + return None + return match.group(1) def get_device_numa(self, bus_id, devfun_id): """ - Get numa id of specified pci device + Get numa number of specified pci device. """ - numa = self.send_expect("cat /sys/bus/pci/devices/0000\:%s\:%s/numa_node" % - (bus_id, devfun_id), "# ") + get_device_numa = getattr( + self, "get_device_numa_%s" % self.get_os_type()) + return get_device_numa(bus_id, devfun_id) + + def get_device_numa_linux(self, bus_id, devfun_id): + """ + Get numa number of specified pci device on Linux. + """ + numa = self.send_expect( + "cat /sys/bus/pci/devices/0000\:%s\:%s/numa_node" % + (bus_id, devfun_id), "# ", alt_session=True) try: numa = int(numa) @@ -259,14 +267,14 @@ class Crb(object): Get ipv6 address of specified pci device on linux. """ out = self.send_expect("ip -family inet6 address show dev %s | awk '/inet6/ { print $2 }'" - % intf, "# ") + % intf, "# ", alt_session=True) return out.split('/')[0] def get_ipv6_addr_freebsd(self, intf): """ Get ipv6 address of specified pci device on Freebsd. """ - out = self.send_expect('ifconfig %s' % intf, '# ') + out = self.send_expect('ifconfig %s' % intf, '# ', alt_session=True) rexp = r"inet6 ([\da-f:]*)%" pattern = re.compile(rexp) match = pattern.findall(out) @@ -275,6 +283,22 @@ class Crb(object): return match[0] + def disable_ipv6(self, intf): + """ + Disable ipv6 of of specified interface + """ + if intf != 'N/A': + self.send_expect("sysctl net.ipv6.conf.%s.disable_ipv6=1" % + intf, "# ", alt_session=True) + + def enable_ipv6(self, intf): + """ + Enable ipv6 of of specified interface + """ + if intf != 'N/A': + self.send_expect("sysctl net.ipv6.conf.%s.disable_ipv6=0" % + intf, "# ", alt_session=True) + def create_file(self, contents, fileName): """ Create file with contents and copy it to CRB. @@ -318,7 +342,7 @@ class Crb(object): if isinstance(self, Dut) and self.get_os_type() == 'freebsd': expected = 'FreeBSD.*#' - self.send_expect('uname', expected, 2) + self.send_expect('uname', expected, 2, alt_session=True) def init_core_list(self): """ @@ -378,7 +402,9 @@ class Crb(object): self.cores = [] cpuinfo = \ - self.send_expect("grep \"processor\\|physical id\\|core id\\|^$\" /proc/cpuinfo", "#") + self.send_expect( + "grep --color=never \"processor\\|physical id\\|core id\\|^$\" /proc/cpuinfo", + "#", alt_session=True) cpuinfo = cpuinfo.split('\r\n\r\n') for line in cpuinfo: m = re.search("processor\t: (\d+)\r\n" + -- 1.9.3