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 E4A0EA2EFC for ; Mon, 16 Sep 2019 11:22:54 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D5CBC1BF92; Mon, 16 Sep 2019 11:22:54 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id 4702A1BF79 for ; Mon, 16 Sep 2019 11:22:53 +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; 16 Sep 2019 02:22:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,512,1559545200"; d="scan'208";a="216147231" Received: from unknown (HELO dpdk-wenjielx-dtspatch135.sh.intel.com) ([10.240.176.135]) by fmsmga002.fm.intel.com with ESMTP; 16 Sep 2019 02:22:51 -0700 From: "zhang,yan" To: dts@dpdk.org Cc: lei.a.yao@intel.com, "zhang,yan" Date: Mon, 16 Sep 2019 17:27:22 +0800 Message-Id: <1568626042-4315-1-git-send-email-yanx.a.zhang@intel.com> X-Mailer: git-send-email 1.9.3 Subject: [dts] [PATCH V1] tests:add new test suite mdd 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" add new test suite mdd. Signed-off-by: zhang,yan --- tests/TestSuite_mdd.py | 206 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 tests/TestSuite_mdd.py diff --git a/tests/TestSuite_mdd.py b/tests/TestSuite_mdd.py new file mode 100644 index 0000000..7baea2c --- /dev/null +++ b/tests/TestSuite_mdd.py @@ -0,0 +1,206 @@ +# + +import re +import time +from packet import Packet +from virt_common import VM +from test_case import TestCase +from pmd_output import PmdOutput + +VM_CORES_MASK = 'all' +send_pks_num = 2000 + +class TestMDD(TestCase): + + supported_vf_driver = ['pci-stub', 'vfio-pci'] + + def set_up_all(self): + + self.dut_ports = self.dut.get_ports(self.nic) + self.verify(len(self.dut_ports) > 1, "Insufficient ports") + self.vm0 = None + + # set vf assign method and vf driver + self.vf_driver = self.get_suite_cfg()['vf_driver'] + if self.vf_driver is None: + self.vf_driver = 'pci-stub' + self.verify(self.vf_driver in self.supported_vf_driver, "Unspported vf driver") + if self.vf_driver == 'pci-stub': + self.vf_assign_method = 'pci-assign' + else: + self.vf_assign_method = 'vfio-pci' + self.dut.send_expect('modprobe vfio-pci', '#') + self.dut.send_expect('dmesg -c', '#') + + self.port_id_0 = 0 + self.port_id_1 = 1 + + self.tx_port = self.tester.get_local_port(self.dut_ports[0]) + self.rx_port = self.tester.get_local_port(self.dut_ports[1]) + + def set_up(self): + pass + + def setup_2pf_2vf_1vm_env(self): + self.used_dut_port_0 = self.dut_ports[0] + self.dut.generate_sriov_vfs_by_port(self.used_dut_port_0, 1, driver='ixgbe') + self.sriov_vfs_port_0 = self.dut.ports_info[self.used_dut_port_0]['vfs_port'] + self.used_dut_port_1 = self.dut_ports[1] + self.dut.generate_sriov_vfs_by_port(self.used_dut_port_1, 1, driver='ixgbe') + self.sriov_vfs_port_1 = self.dut.ports_info[self.used_dut_port_1]['vfs_port'] + + try: + + for port in self.sriov_vfs_port_0: + port.bind_driver(self.vf_driver) + + for port in self.sriov_vfs_port_1: + port.bind_driver(self.vf_driver) + + time.sleep(1) + vf0_prop = {'opt_host': self.sriov_vfs_port_0[0].pci} + vf1_prop = {'opt_host': self.sriov_vfs_port_1[0].pci} + # not support driver=igb_uio,because driver is kernel driver + # set up VM0 ENV + self.vm0 = VM(self.dut, 'vm0', 'mdd') + self.vm0.set_vm_device(driver=self.vf_assign_method, **vf0_prop) + self.vm0.set_vm_device(driver=self.vf_assign_method, **vf1_prop) + self.vm_dut_0 = self.vm0.start() + if self.vm_dut_0 is None: + raise Exception("Set up VM0 ENV failed!") + + except Exception as e: + self.destroy_2pf_2vf_1vm_env() + raise Exception(e) + + def destroy_2pf_2vf_1vm_env(self): + if getattr(self, 'vm0', None): + # destroy testpmd in vm0 + if getattr(self, 'vm0_testpmd', None): + self.vm0_testpmd.execute_cmd('stop') + self.vm0_testpmd.execute_cmd('quit', '# ') + self.vm0_testpmd = None + + self.vm0_dut_ports = None + # destroy vm0 + self.vm0.stop() + self.vm0 = None + + self.dut.virt_exit() + + if getattr(self, 'used_dut_port_0', None) != None: + self.dut.destroy_sriov_vfs_by_port(self.used_dut_port_0) + port = self.dut.ports_info[self.used_dut_port_0]['port'] + port.bind_driver() + self.used_dut_port_0 = None + + if getattr(self, 'used_dut_port_1', None) != None: + self.dut.destroy_sriov_vfs_by_port(self.used_dut_port_1) + port = self.dut.ports_info[self.used_dut_port_1]['port'] + port.bind_driver() + self.used_dut_port_1 = None + + for port_id in self.dut_ports: + port = self.dut.ports_info[port_id]['port'] + port.bind_driver() + + def start_testpmd_in_vm(self, txoffload=''): + self.vm0_dut_ports = self.vm_dut_0.get_ports('any') + self.vm0_testpmd = PmdOutput(self.vm_dut_0) + + self.vm0_testpmd.start_testpmd(VM_CORES_MASK, "--portmask=0x3 --tx-offloads=%s" % txoffload) + self.vm0_testpmd.execute_cmd('set fwd mac') + self.vm0_testpmd.execute_cmd('set promisc all off') + self.vm0_testpmd.execute_cmd('start') + + def send_packets(self): + + tgen_ports = [] + self.tester_intf = self.tester.get_interface(self.tx_port) + tgen_ports.append((self.tx_port, self.rx_port)) + self.pmd_vf0_mac = self.vm0_testpmd.get_port_mac(self.port_id_0) + + dst_mac = self.pmd_vf0_mac + src_mac = self.tester.get_mac(self.tx_port) + + pkt = Packet(pkt_type='UDP', pkt_len=64) + pkt.config_layer('ether', {'dst': dst_mac, 'src': src_mac}) + time.sleep(2) + self.vm0_testpmd.execute_cmd('clear port stats all') + self.vm0_testpmd.execute_cmd('show port stats all') + pkt.send_pkt(tx_port=self.tester_intf, count=send_pks_num) + time.sleep(2) + + def result_verify(self, pkt_fwd=True): + pmd0_vf0_stats = self.vm0_testpmd.get_pmd_stats(self.port_id_0) + pmd0_vf1_stats = self.vm0_testpmd.get_pmd_stats(self.port_id_1) + time.sleep(2) + + vf0_rx_cnt = pmd0_vf0_stats['RX-packets'] + self.verify(vf0_rx_cnt >= send_pks_num, "no packet was received by vm0_VF0") + + vf0_rx_err = pmd0_vf0_stats['RX-errors'] + self.verify(vf0_rx_err == 0, "vm0_VF0 rx-errors") + + vf1_tx_cnt = pmd0_vf1_stats['TX-packets'] + if pkt_fwd: + self.verify(vf1_tx_cnt == send_pks_num, "Packet forwarding failed") + else: + self.verify(vf1_tx_cnt == 0, "Packet is forwarded") + + def config_mdd(self, value): + self.dut.restore_interfaces() + self.dut.send_expect("rmmod ixgbe", "# ", 10) + time.sleep(2) + count = self.dut.send_expect("./usertools/dpdk-devbind.py -s | grep ixgbe | wc -l", "#") + m = [value for i in range(int(count))] + mdd = "MDD=" + str(m).replace("[", "").replace("]", "").replace(" ", "") + self.dut.send_expect("modprobe ixgbe %s" % mdd, "# ", 10) + time.sleep(5) + for port_info in self.dut.ports_info: + port = port_info['port'] + intf = port.get_interface_name() + self.dut.send_expect("ifconfig %s up" % intf, "# ", 10) + time.sleep(2) + + def test_1enable_mdd_dpdk_disable(self): + self.config_mdd(1) + self.setup_2pf_2vf_1vm_env() + self.start_testpmd_in_vm(txoffload='0x1') + self.send_packets() + self.result_verify(False) + dmesg = self.dut.send_expect("dmesg -c |grep 'event'", "# ", 10) + self.verify("Malicious event" in dmesg,"mdd error") + + def test_2enable_mdd_dpdk_enable(self): + self.config_mdd(1) + self.setup_2pf_2vf_1vm_env() + self.start_testpmd_in_vm(txoffload='0x0') + self.send_packets() + self.result_verify(False) + dmesg = self.dut.send_expect("dmesg -c |grep 'event'", "# ", 10) + self.verify("Malicious event" in dmesg,"mdd error") + + def test_3disable_mdd_dpdk_disable(self): + self.config_mdd(0) + self.setup_2pf_2vf_1vm_env() + self.start_testpmd_in_vm(txoffload='0x1') + self.send_packets() + self.result_verify(True) + dmesg = self.dut.send_expect("dmesg -c |grep 'event'", "# ", 10) + self.verify("Malicious event" not in dmesg,"mdd error") + + def test_4disable_mdd_dpdk_enable(self): + self.config_mdd(0) + self.setup_2pf_2vf_1vm_env() + self.start_testpmd_in_vm(txoffload='0x0') + self.send_packets() + self.result_verify(True) + dmesg = self.dut.send_expect("dmesg -c |grep 'event'", "# ", 10) + self.verify("Malicious event" not in dmesg,"mdd error") + + def tear_down(self): + self.destroy_2pf_2vf_1vm_env() + + def tear_down_all(self): + pass -- 2.17.2