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 08A5DA04DD; Thu, 2 Jan 2020 06:16:33 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D6E3C1BF9C; Thu, 2 Jan 2020 06:16:32 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id 01BEC1BF9B for ; Thu, 2 Jan 2020 06:16:30 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Jan 2020 21:16:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,385,1571727600"; d="scan'208";a="209692298" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by orsmga007.jf.intel.com with ESMTP; 01 Jan 2020 21:16:30 -0800 Received: from fmsmsx114.amr.corp.intel.com (10.18.116.8) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 1 Jan 2020 21:16:30 -0800 Received: from shsmsx105.ccr.corp.intel.com (10.239.4.158) by FMSMSX114.amr.corp.intel.com (10.18.116.8) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 1 Jan 2020 21:16:29 -0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.30]) by SHSMSX105.ccr.corp.intel.com ([169.254.11.28]) with mapi id 14.03.0439.000; Thu, 2 Jan 2020 13:16:27 +0800 From: "Tu, Lijuan" To: "Zeng, XiaoxiaoX" , "dts@dpdk.org" CC: "Zeng, XiaoxiaoX" Thread-Topic: [dts] [PATCH V1] tests/port_control: automation port_contol Thread-Index: AQHVv7iLWHq0fSQiDUCPBydT1bZz9KfW2BoQ Date: Thu, 2 Jan 2020 05:16:26 +0000 Message-ID: <8CE3E05A3F976642AAB0F4675D0AD20E0BBA104B@SHSMSX101.ccr.corp.intel.com> References: <1577782742-84298-1-git-send-email-xiaoxiaox.zeng@intel.com> In-Reply-To: <1577782742-84298-1-git-send-email-xiaoxiaox.zeng@intel.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dts] [PATCH V1] tests/port_control: automation port_contol 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" applied > -----Original Message----- > From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of Zeng Xiaoxiao > Sent: Tuesday, December 31, 2019 4:59 PM > To: dts@dpdk.org > Cc: Zeng, XiaoxiaoX > Subject: [dts] [PATCH V1] tests/port_control: automation port_contol >=20 > *.according to port_control_test_plan.rst,automation suite port_control >=20 > Signed-off-by: Zeng Xiaoxiao > --- > tests/TestSuite_port_control.py | 260 > ++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 260 insertions(+) > create mode 100644 tests/TestSuite_port_control.py >=20 > diff --git a/tests/TestSuite_port_control.py b/tests/TestSuite_port_contr= ol.py > new file mode 100644 index 0000000..a458add > --- /dev/null > +++ b/tests/TestSuite_port_control.py > @@ -0,0 +1,260 @@ > +# BSD LICENSE > +# > +# Copyright(c) <2019> 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 # > +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, > INCIDENTAL, # > +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT > NOT # > +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF > USE, # > +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND > ON ANY # > +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT > # > +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF > THE USE # > +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH > DAMAGE. > + > +import os > +import utils > +import time > +import re > +import packet > +from test_case import TestCase > +from pmd_output import PmdOutput > +from virt_common import VM > + > + > +class TestPortControl(TestCase): > + > + def set_up_all(self): > + """ > + Run before each test suite > + """ > + # initialize ports topology > + self.vm0 =3D None > + self.env_done =3D False > + self.port_id_0 =3D 0 > + self.pkt_count =3D 1000 > + self.dut_ports =3D self.dut.get_ports(self.nic) > + # Verify that enough ports are available > + self.verify(len(self.dut_ports) >=3D 1, "Insufficient ports for = testing") > + self.pf_mac =3D self.dut.get_mac_address(self.dut_ports[0]) > + self.vf_mac =3D "00:01:23:45:67:89" > + self.txitf =3D > self.tester.get_interface(self.tester.get_local_port(self.dut_ports[0])) > + self.host_testpmd =3D PmdOutput(self.dut) > + self.vf_assign_method =3D 'vfio-pci' > + self.dut.send_expect('modprobe vfio-pci', '#') > + self.socket =3D self.dut.get_numa_id(self.dut_ports[0]) > + port =3D self.dut.ports_info[0]['port'] > + self.pf_default_driver =3D port.get_nic_driver() > + > + def set_up(self): > + """ > + Run before each test case. > + """ > + pass > + > + def setup_vm_env(self, driver=3D'default'): > + """ > + Create testing environment with 1VF generated from 1PF > + """ > + if self.env_done: > + return > + > + # bind to default driver > + self.bind_nic_driver(self.dut_ports[:1], driver=3D"") > + self.used_dut_port =3D self.dut_ports[0] > + self.host_intf =3D self.dut.ports_info[self.used_dut_port]['intf= '] > + self.dut.generate_sriov_vfs_by_port(self.used_dut_port, 1, > driver=3Ddriver) > + self.sriov_vfs_port =3D self.dut.ports_info[self.used_dut_port][= 'vfs_port'] > + self.dut.send_expect("ip link set %s vf 0 mac %s" % (self.host_i= ntf, > self.vf_mac), "# ") > + try: > + for port in self.sriov_vfs_port: > + port.bind_driver(self.vf_assign_method) > + time.sleep(1) > + vf_popt =3D {'opt_host': self.sriov_vfs_port[0].pci} > + > + # set up VM ENV > + self.vm =3D VM(self.dut, 'vm0', 'port_control') > + self.vm.set_vm_device(driver=3Dself.vf_assign_method, **vf_p= opt) > + self.vm_dut =3D self.vm.start() > + if self.vm_dut is None: > + raise Exception("Set up VM ENV failed!") > + > + self.vm_testpmd =3D PmdOutput(self.vm_dut) > + > + except Exception as e: > + self.destroy_vm_env() > + raise Exception(e) > + > + self.env_done =3D True > + > + def destroy_vm_env(self): > + if getattr(self, 'vm', None): > + if getattr(self, 'vm_dut', None): > + self.vm_dut.kill_all() > + self.vm_testpmd =3D None > + self.vm_dut_ports =3D None > + # destroy vm0 > + self.vm.stop() > + self.dut.virt_exit() > + time.sleep(3) > + self.vm =3D None > + > + if getattr(self, 'used_dut_port', None) !=3D None: > + self.dut.destroy_sriov_vfs_by_port(self.used_dut_port) > + self.used_dut_port =3D None > + self.bind_nic_driver(self.dut_ports[:1], > + driver=3Dself.pf_default_driver) > + > + self.env_done =3D False > + > + def bind_nic_driver(self, ports, driver=3D""): > + # modprobe vfio driver > + if driver =3D=3D "vfio-pci": > + for port in ports: > + netdev =3D self.dut.ports_info[port]['port'] > + driver =3D netdev.get_nic_driver() > + if driver !=3D 'vfio-pci': > + netdev.bind_driver(driver=3Dself.d) > + > + elif driver =3D=3D "igb_uio": > + # igb_uio should insmod as default, no need to check > + for port in ports: > + netdev =3D self.dut.ports_info[port]['port'] > + driver =3D netdev.get_nic_driver() > + if driver !=3D 'igb_uio': > + netdev.bind_driver(driver=3D'igb_uio') > + else: > + for port in ports: > + netdev =3D self.dut.ports_info[port]['port'] > + driver_now =3D netdev.get_nic_driver() > + if driver is None: > + driver =3D netdev.default_driver > + if driver !=3D driver_now: > + netdev.bind_driver(driver=3Ddriver) > + > + def start_testpmd(self, terminal): > + terminal.start_testpmd(ports=3D[0], socket=3Dself.socket) > + res =3D terminal.wait_link_status_up('all', timeout=3D5) > + self.verify(res is True, 'there have port link is down') > + terminal.execute_cmd('set fwd mac') > + terminal.execute_cmd('set promisc all off') > + > + def start_pmd_port(self, terminal): > + terminal.execute_cmd("port start all") > + terminal.execute_cmd("start") > + terminal.wait_link_status_up('all', timeout=3D5) > + ret =3D terminal.get_port_link_status(self.port_id_0) > + self.verify(ret =3D=3D "up", "port not up!") > + > + def stop_pmd_port(self, terminal): > + terminal.execute_cmd("stop") > + terminal.execute_cmd("port stop all") > + ret =3D terminal.get_port_link_status(self.port_id_0) > + self.verify(ret =3D=3D "down", "port not down!") > + > + def reset_pmd_port(self, terminal): > + terminal.execute_cmd("port reset all") > + ret =3D terminal.get_port_link_status(self.port_id_0) > + self.verify(ret =3D=3D "down", "port reset fail!") > + > + def close_pmd_port(self, terminal): > + terminal.execute_cmd("port close all") > + ret =3D terminal.execute_cmd("show port info all") > + ret =3D ret.split('\r') > + self.verify(ret[1] =3D=3D '', "close all port fail!") > + > + def calculate_stats(self, start_stats, end_stats): > + ret_stats =3D {} > + ret_stats['RX-packets'] =3D int(end_stats['RX-packets']) - > int(start_stats['RX-packets']) > + ret_stats['TX-packets'] =3D int(end_stats['TX-packets']) - > int(start_stats['TX-packets']) > + return ret_stats > + > + def send_and_verify_packets(self, terminal): > + """ > + Send packets according to parameters. > + """ > + if terminal is self.host_testpmd: > + self.dts_mac =3D self.pf_mac > + else: > + self.dts_mac =3D self.vf_mac > + > + self.pkt =3D packet.Packet('Ether(dst=3D"%s")/IP()/Raw("x"*40)' = % > + self.dts_mac) > + > + pf_start_stats =3D terminal.get_pmd_stats(self.port_id_0) > + self.pkt.send_pkt(crb=3Dself.tester, tx_port=3Dself.txitf, > count=3Dself.pkt_count, timeout=3D30) > + pf_end_stats =3D terminal.get_pmd_stats(self.port_id_0) > + pf_ret_stats =3D self.calculate_stats(pf_start_stats, > + pf_end_stats) > + > + self.verify(pf_ret_stats['RX-packets'] =3D=3D self.pkt_count and > pf_ret_stats['TX-packets'] =3D=3D self.pkt_count, > + "Packets receive and forward fail!") > + > + def test_pf_start_stop_reset_close(self): > + self.start_testpmd(self.host_testpmd) > + # start port > + self.start_pmd_port(self.host_testpmd) > + self.send_and_verify_packets(self.host_testpmd) > + # stop port and start port > + self.stop_pmd_port(self.host_testpmd) > + self.start_pmd_port(self.host_testpmd) > + self.send_and_verify_packets(self.host_testpmd) > + # reset port > + self.stop_pmd_port(self.host_testpmd) > + self.reset_pmd_port(self.host_testpmd) > + self.start_pmd_port(self.host_testpmd) > + self.send_and_verify_packets(self.host_testpmd) > + # close all port > + self.stop_pmd_port(self.host_testpmd) > + self.close_pmd_port(self.host_testpmd) > + > + def test_e1000_start_stop_reset_close(self): > + self.setup_vm_env() > + self.start_testpmd(self.vm_testpmd) > + # start port > + self.start_pmd_port(self.vm_testpmd) > + self.send_and_verify_packets(self.vm_testpmd) > + # stop port and start port > + self.stop_pmd_port(self.vm_testpmd) > + self.start_pmd_port(self.vm_testpmd) > + self.send_and_verify_packets(self.vm_testpmd) > + # reset port > + self.stop_pmd_port(self.vm_testpmd) > + self.reset_pmd_port(self.vm_testpmd) > + self.start_pmd_port(self.vm_testpmd) > + self.send_and_verify_packets(self.vm_testpmd) > + # close all port > + self.stop_pmd_port(self.vm_testpmd) > + self.close_pmd_port(self.vm_testpmd) > + > + def tear_down(self): > + """ > + Run after each test case. > + """ > + if self.env_done: > + self.vm_testpmd.quit() > + self.destroy_vm_env() > + else: > + self.host_testpmd.quit() > + > + def tear_down_all(self): > + """ > + Run after each test suite. > + """ > + if self.env_done: > + self.destroy_vm_env() > + self.dut.kill_all() > -- > 1.8.3.1