[dts] [PATCH V1] add test suite pf pass through

xu,gang gangx.xu at intel.com
Thu May 18 11:24:02 CEST 2017


Signed-off-by: xu,gang <gangx.xu at intel.com>
---
 tests/TestSuite_pf_pass_through.py | 121 +++++++++++++++++++++++++++++++++++++
 1 file changed, 121 insertions(+)
 create mode 100644 tests/TestSuite_pf_pass_through.py

diff --git a/tests/TestSuite_pf_pass_through.py b/tests/TestSuite_pf_pass_through.py
new file mode 100644
index 0000000..8885744
--- /dev/null
+++ b/tests/TestSuite_pf_pass_through.py
@@ -0,0 +1,121 @@
+# <COPYRIGHT_TAG>
+
+import re
+import time
+
+from qemu_kvm import QEMUKvm
+from test_case import TestCase
+from pmd_output import PmdOutput
+
+VM_CORES_MASK = 'all'
+
+
+class TestPfPassThrough(TestCase):
+
+    def set_up_all(self):
+        '''
+        Run at the start of each test suite.
+        '''
+        self.dut_ports = self.dut.get_ports(self.nic)
+        self.verify(len(self.dut_ports) > 1, "Insufficient ports")
+        self.vm0 = None
+        self.env_done = False
+        self.dut.send_expect("modprobe vfio", "#", 5)
+        self.dut.send_expect("modprobe vfio-pci", "#", 5)
+
+    def set_up(self):
+        '''
+        Run before each test case.
+        '''
+        self.setup_vm_env()
+
+    def setup_vm_env(self, driver='default'):
+
+        # Start vm with the two PFs on the DUT
+        self.used_dut_port_0 = self.dut_ports[0]
+        port = self.dut.ports_info[self.used_dut_port_0]['port']
+        port.bind_driver('vfio-pci')
+
+        self.used_dut_port_1 = self.dut_ports[1]
+        port = self.dut.ports_info[self.used_dut_port_1]['port']
+        port.bind_driver('vfio-pci')
+
+        try:
+
+            time.sleep(1)
+            self.pci0 = self.dut.ports_info[self.used_dut_port_0]['pci']
+            self.pci1 = self.dut.ports_info[self.used_dut_port_1]['pci']
+            vf0_prop = {'opt_host': self.pci0}
+            vf1_prop = {'opt_host': self.pci1}
+
+            # Set up VM0 ENV
+            self.vm0 = QEMUKvm(self.dut, 'vm0', 'pf_pass_through')
+            self.vm0.set_vm_device(driver='vfio-pci', **vf0_prop)
+            self.vm0.set_vm_device(driver='vfio-pci', **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_vm_env()
+            raise Exception(e)
+
+        self.env_done = True
+
+    def destroy_vm_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()
+        time.sleep(3)
+
+        for port_id in self.dut_ports:
+            port = self.dut.ports_info[port_id]['port']
+            port.bind_driver()
+
+        self.env_done = False
+
+    def test_pf_pass_through(self):
+
+        self.verify(
+            self.kdriver in ["ixgbe", "i40e"], "%s NIC not support pf pass-through" % self.kdriver)
+        # Start testpmd in VM
+        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)
+        self.vm0_testpmd.execute_cmd('set fwd mac')
+        self.vm0_testpmd.execute_cmd('start')
+
+        tgen_ports = []
+        tx_port = self.tester.get_local_port(self.dut_ports[0])
+        rx_port = self.tester.get_local_port(self.dut_ports[1])
+        tgen_ports.append((tx_port, rx_port))
+
+        dst_mac = self.vm0_testpmd.get_port_mac(0)
+        src_mac = self.tester.get_mac(tx_port)
+        pkt_param = [("ether", {'dst': dst_mac, 'src': src_mac})]
+
+        result = self.tester.check_random_pkts(
+            tgen_ports, allow_miss=False, params=pkt_param)
+        self.verify(result != False, "VF0 failed to forward packets to VF1")
+
+    def tear_down(self):
+        """
+        Run after each test case.
+        """
+        pass
+
+    def tear_down_all(self):
+        """
+        Run after each test suite.
+        """
+        self.destroy_vm_env()
+        pass
-- 
1.9.3



More information about the dts mailing list