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 D1B04A04DD; Tue, 31 Dec 2019 10:31:47 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 92C911BFEE; Tue, 31 Dec 2019 10:31:47 +0100 (CET) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 06DA71BFEB for ; Tue, 31 Dec 2019 10:31:44 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Dec 2019 01:31:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,378,1571727600"; d="scan'208";a="221366350" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga003.jf.intel.com with ESMTP; 31 Dec 2019 01:31:43 -0800 Received: from fmsmsx113.amr.corp.intel.com (10.18.116.7) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 31 Dec 2019 01:31:43 -0800 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by FMSMSX113.amr.corp.intel.com (10.18.116.7) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 31 Dec 2019 01:31:42 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.202]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.197]) with mapi id 14.03.0439.000; Tue, 31 Dec 2019 17:31:41 +0800 From: "Lu, Nannan" To: "Zeng, XiaoxiaoX" , "dts@dpdk.org" CC: "Zeng, XiaoxiaoX" Thread-Topic: [dts] [PATCH V1] tests/port_control: automation port_contol Thread-Index: AQHVv7iLODTbegzpOE2kn9V6g+kpZKfT+n9A Date: Tue, 31 Dec 2019 09:31:40 +0000 Message-ID: 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: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYzU5NzU5YjUtNDQyNS00YTQwLTlkZjYtZDE5MTkyOGU1NGY0IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiZDI1NGhWV01yZ0ZmNzlyMCtUazdOZ05IdkRBQ0F3VWJmekcwUjhCWFwvQ3ZkaHFNTFZXaUh6MDhKUWNpYkxkcDUifQ== x-ctpclassification: CTP_NT 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" Acked-by: Nannan Lu -----Original Message----- From: dts 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 *.according to port_control_test_plan.rst,automation suite port_control Signed-off-by: Zeng Xiaoxiao --- tests/TestSuite_port_control.py | 260 ++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 260 insertions(+) create mode 100644 tests/TestSuite_port_control.py diff --git a/tests/TestSuite_port_control.py b/tests/TestSuite_port_control= .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 #=20 +modification, are permitted provided that the following conditions #=20 +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 #=20 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT #=20 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR #=20 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT #=20 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, #=20 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT #=20 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, #=20 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY #=20 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT #=20 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE #=20 +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 te= sting") + 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_por= t(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]['v= fs_port'] + self.dut.send_expect("ip link set %s vf 0 mac %s" % (self.host_int= f, 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_pop= t) + 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],=20 + 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(sta= rt_stats['RX-packets']) + ret_stats['TX-packets'] =3D int(end_stats['TX-packets']) - int(sta= rt_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)' %= =20 + 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,=20 + pf_end_stats) + + self.verify(pf_ret_stats['RX-packets'] =3D=3D self.pkt_count and p= f_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