[dts] [PATCH V1] Add test suite about qemu mtu setting

lihong lihongx.ma at intel.com
Tue Apr 17 03:02:22 CEST 2018


Signed-off-by: lihong <lihongx.ma at intel.com>
---
 tests/TestSuite_vhost_qemu_mtu.py | 183 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 183 insertions(+)
 create mode 100644 tests/TestSuite_vhost_qemu_mtu.py

diff --git a/tests/TestSuite_vhost_qemu_mtu.py b/tests/TestSuite_vhost_qemu_mtu.py
new file mode 100644
index 0000000..d241441
--- /dev/null
+++ b/tests/TestSuite_vhost_qemu_mtu.py
@@ -0,0 +1,183 @@
+# BSD LICENSE
+#
+# Copyright(c) 2010-2018 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.
+
+"""
+DPDK Test suite.
+test the mtu seting.
+"""
+import re
+import time
+import utils
+from test_case import TestCase
+from virt_common import VM
+
+
+class TestVhostUserSetMTU(TestCase):
+
+    def set_up_all(self):
+        # Get and verify the ports
+        self.dut_ports = self.dut.get_ports()
+        self.verify(len(self.dut_ports) >= 1, "Insufficient ports for testing")
+
+        # Get the port's socket
+        self.pf = self.dut_ports[0]
+        netdev = self.dut.ports_info[self.pf]['port']
+        self.socket = netdev.get_nic_socket()
+        self.cores = self.dut.get_core_list("1S/3C/1T", socket=self.socket)
+
+        self.host_mtu = [68, 9000, 65535]
+        self.virtio1_mac = "52:54:00:00:00:01"
+        self.vm_dut = None
+
+    def set_up(self):
+        """
+        Run before each test case.
+        """
+        self.dut.send_expect("rm -rf ./vhost.out", "#")
+        self.dut.send_expect("rm -rf ./vhost-net*", "#")
+        self.dut.send_expect("killall -s INT vhost-switch", "#")
+
+    def launch_testpmd(self):
+        self.testcmd = "./x86_64-native-linuxapp-gcc/app/testpmd -c %s -n 4 --socket-mem 1024,1024" \
+                + " --vdev 'net_vhost0,iface=vhost-net,queues=1' -- -i --nb-cores=1 --port-topology=chained"
+        self.coremask = utils.create_mask(self.cores)
+        self.testcmd_start = self.testcmd % (self.coremask)
+
+        self.dut.send_expect(self.testcmd_start, "testpmd> ", 120)
+        self.dut.send_expect("start", "testpmd> ", 120)
+
+    def start_onevm(self, mtu_value):
+        """
+        Start One VM with one virtio device
+        The qemu version should greater than 2.9
+        """
+
+        self.vm = VM(self.dut, 'vm0', 'vhost_sample')
+        vm_params = {}
+        vm_params['driver'] = 'vhost-user'
+        vm_params['opt_path'] = './vhost-net'
+        vm_params['opt_mac'] = self.virtio1_mac
+        vm_params['opt_settings'] = 'mrg_rxbuf=on,host_mtu=%d' % mtu_value
+        self.vm.set_vm_device(**vm_params)
+
+        try:
+            self.vm_dut = self.vm.start()
+            if self.vm_dut is None:
+                out = self.vm.host_session.send_expect("%s -version" % self.vm.qemu_emulator, "#")
+                ver = re.findall('version (\S*)', out)
+                index = ver[0].find(".", 2)
+                ver_num = ver[0][0:index].replace(".", "")
+                self.verify(int(ver_num) >= 29, "The qemu version should greater than 2.9")
+                raise Exception("Set up VM ENV failed")
+        except Exception as e:
+            self.logger.error("ERROR: Failure for %s" % str(e))
+
+        return True
+
+    def verify_vm_kernel(self):
+        """
+        The vm kernel version shouled greater than 4.10
+        """
+        if(self.vm_dut is not None):
+            out = self.vm_dut.send_expect("uname -r", "#", 10)
+            index = out.find(".", 2)
+            cur_kernel = out[0:index]
+            ker_str = cur_kernel.replace(".", "")
+            self.verify(int(ker_str) >= 410, "The VM kernel version should grand than 4.10!!")
+
+    def test_perf_vm_hostmtu_seting_testcase(self):
+        """
+        Test seting of host_mtu
+        """
+        self.launch_testpmd()
+
+        for mtu in self.host_mtu:
+            self.start_onevm(mtu)
+            self.verify_vm_kernel()
+
+            # verify the mtu in testpmd
+            vm_testpmd = self.target + "/app/testpmd -c 0x03 -n 3 -- -i"
+            self.vm_dut.send_expect(vm_testpmd, "testpmd>", 60)
+            out = self.vm_dut.send_expect("show port info 0", "testpmd>", 20)
+            lines = re.search("MTU:\s*(\d*)", out)
+            result = lines.group(1)
+            results = float(result)
+            self.verify(results == mtu,
+                        "The seting host mtu:%d no equal the vm virtio testpmd mtu:%d" % (mtu, results))
+            self.logger.info('The MTU setting in testpmd has passed, mtu in testpmd: %d' % results)
+            self.vm_dut.send_expect("quit", "#", 60)
+
+            # verify the mtu in kernel driver
+            # unbind the vritio network device
+            for port in self.vm_dut.ports_info:
+                self.vm_intf = port['intf']
+                pp = port['port']
+                pp.bind_driver()
+
+            findmtu = 0
+            out = self.vm_dut.send_expect("ifconfig", "#", 20)
+            lines = re.findall("MTU:(.*)", out)
+            for line in lines:
+                dd = re.search("(\d*)(.*)", line)
+                result = dd.group(1)
+                results = float(result)
+                if results == mtu:
+                    findmtu = 1
+                    break
+            self.verify(findmtu == 1,
+                        "The seting host mtu:%d no equal the vm virtio mtu:%d" % (mtu, results))
+            self.logger.info('The MTU setting of kernel network has passed, mtu in kernel driver:%d' % results)
+
+            # verify the mtu in host testpmd
+            out = self.dut.send_expect("show port info 1", "testpmd>", 60)
+            lines = re.search("MTU:\s*(\d*)", out)
+            result = lines.group(1)
+            results = float(result)
+            self.verify(results == mtu,
+                        "The seting host mtu:%d no equal the virtio mtu on host testpmd:%d" % (mtu, results))
+            self.logger.info('The MTU setting in host testpmd has passed, mtu in testpmd: %d' % results)
+
+            self.vm.stop()
+
+        self.dut.send_expect("quit", "#", 60)
+
+    def tear_down(self):
+        """
+        Run after each test case.
+        Clear vhost-switch and qemu to avoid blocking the following TCs
+        """
+        pass
+
+    def tear_down_all(self):
+        """
+        Run after each test suite.
+        """
+        pass
-- 
2.7.4



More information about the dts mailing list