From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 9B91C2B97 for ; Mon, 5 Sep 2016 04:38:19 +0200 (CEST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 04 Sep 2016 19:38:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.30,284,1470726000"; d="scan'208";a="1035468041" Received: from unknown (HELO dpdk-fedora20.icx.intel.com) ([10.239.254.239]) by fmsmga001.fm.intel.com with ESMTP; 04 Sep 2016 19:38:17 -0700 From: "xu,gang" To: dts@dpdk.org Cc: "xu,gang" Date: Mon, 5 Sep 2016 10:33:44 +0800 Message-Id: <1473042825-18521-1-git-send-email-gangx.xu@intel.com> X-Mailer: git-send-email 1.9.3 Subject: [dts] [PATCH V3 1/2] add test ip_pipeline config file code V3 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: , X-List-Received-Date: Mon, 05 Sep 2016 02:38:20 -0000 Signed-off-by: xu,gang --- tests/TestSuite_ip_pipeline_config_file.py | 245 +++++++++++++++++++++++++++++ 1 file changed, 245 insertions(+) create mode 100644 tests/TestSuite_ip_pipeline_config_file.py diff --git a/tests/TestSuite_ip_pipeline_config_file.py b/tests/TestSuite_ip_pipeline_config_file.py new file mode 100644 index 0000000..7800af5 --- /dev/null +++ b/tests/TestSuite_ip_pipeline_config_file.py @@ -0,0 +1,245 @@ +#BSD LICENSE +# +# Copyright(c) 2010-2016 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 ip_pipeline_configuration file. +""" + +import dts +import string +import time +import re +import os +from test_case import TestCase +from plotting import Plotting +from settings import HEADER_SIZE +from etgen import IxiaPacketGenerator +from packet import Packet, sniff_packets, load_sniff_packets + +class Test_ip_pipeline_configuration_file(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) >= 4, "Insufficient ports") + cores = self.dut.get_core_list("1S/4C/1T") + self.coremask = dts.create_mask(cores) + + self.dut.send_expect("chmod 777 /root/","#",30) + self.dut.send_expect("sed -i -e 's/CONFIG_RTE_PORT_PCAP=.*$/" + + "CONFIG_RTE_PORT_PCAP=y/' config/common_base", "# ", 30) + self.dut.build_install_dpdk(self.target) + + #unpack test configuration + cwd = os.getcwd() + self.tester.send_expect("cd %s/dep/" % cwd,"# ",50) + result = self.tester.send_expect("tar xzvf ip_pipeline.tar.gz","# ",50) + self.verify("error" not in result, "ip_pipeline unpack fail ") + + self.update_ip_pipeline_config() + + #copy configuration file to dut and unpack + self.dut.session.copy_file_to("dep/ip_pipeline.tar.gz") + put = self.dut.send_expect("tar zxvf ~/ip_pipeline.tar.gz -C ~","#",500) + #self.verify("error" not in put, "ip_pipeline unpack fail") + + self.path = "./examples/ip_pipeline/build/ip_pipeline" + + self.filepath = self.get_filepath() + # build sample app + out = self.dut.build_dpdk_apps("./examples/ip_pipeline") + self.verify("Error" not in out, "compilation error 1") + self.verify("No such file" not in out, "compilation error 2") + + def set_up(self): + """ + Run before each test case. + """ + pass + + def replace_pci(self,filename,old,new): + """ + modify the file by new code + """ + try: + lines = open(filename,'r').readlines() + flen = len(lines) + for i in range(flen): + if old in lines[i]: + lines[i] = lines[i].replace(old,new) + open(filename,'w').writelines(lines) + except Exception,e: + print e + + def get_filepath(self): + filepatch = [] + sourc_work_path = os.getcwd() + os.chdir("./dep") + rootdir = "ip_pipeline/" + for parent,dirnames,filenames in os.walk(rootdir): + for filename in filenames: + filepatch.append(os.path.join(parent,filename)) + os.chdir(sourc_work_path) + return filepatch + def update_ip_pipeline_config(self): + """ + modify the ip_pipeline cfg file's pci and pack again + """ + po_rootdir = "dep/ip_pipeline/ip_pipeline_link_identification/" + for po_parent,po_dirnames,po_filenames in os.walk(po_rootdir): + for i in po_filenames: + filename = os.path.join(po_parent,i) + self.replace_pci(filename,"port0","%s" % self.dut.ports_info[0]['pci']) + self.replace_pci(filename,"port1","%s" % self.dut.ports_info[1]['pci']) + self.replace_pci(filename,"port2","%s" % self.dut.ports_info[2]['pci']) + self.replace_pci(filename,"port3","%s" % self.dut.ports_info[3]['pci']) + self.tester.send_expect("rm -rf ip_pipeline.tar.gz","#",10) + result = self.tester.send_expect("tar -czvf ip_pipeline.tar.gz ip_pipeline/","#",50) + self.verify("error" not in result, "ip_pipeline compression fail") + self.tester.send_expect("cd ../","#",10) + + def scapy_send_package(self,num): + """ + Send a packet to port + """ + txport = self.tester.get_local_port(self.dut_ports[0]) + mac = self.dut.get_mac_address(self.dut_ports[0]) + txItf = self.tester.get_interface(txport) + self.tester.scapy_append('sendp([Ether(dst="%s")/IP()/UDP()/Raw(\'X\'*18)], iface="%s",count=%s)' % (mac, txItf,num)) + self.tester.scapy_execute() + + def test_ip_pipeline_cfg(self): + for filename in self.filepath: + if "ip_pipeline_cfg/postive" in filename: + cmd = self.path + " -p 0x3 -f ~/%s" % filename + self.dut.send_expect(cmd,"[PIPELINE1]",50) + out = self.dut.send_expect("quit","# ",10) + self.verify("Bye!" in out, "Test failed on %s" % filename) + elif "ip_pipeline_cfg/negative" in filename: + cmd = self.path + " -p 0x3 -f ~/%s" % filename + out = self.dut.send_expect(cmd,"# ",50) + self.dut.send_expect("quit","# ",10) + self.verify("error" in out, "Test failed on %s" % filename) + + def test_ip_pipeline_cpu_utilization(self): + cmd = self.path + " -p 0xf -f ./examples/ip_pipeline/config/edge_router_downstream.cfg -s ./examples/ip_pipeline/config/edge_router_downstream.sh" + self.dut.send_expect(cmd,"#p 1 route ls",50) + self.scapy_send_package(1000) + self.dut.send_expect("","pipeline> ",5) + out = self.dut.send_expect("t 1 headroom","pipeline> ",10) + self.dut.send_expect("quit","# ",10) + self.verify(out == "100%" , "headroom error") + + def test_ip_pipeline_link_identification(self): + for filename in self.filepath: + if "ip_pipeline_link_identification/postive" in filename: + if "_f" in filename: + cmd = self.path + " -f ~/%s" % filename + self.dut.send_expect(cmd,"[PIPELINE1]",50) + out = self.dut.send_expect("quit","# ",10) + self.verify("Bye!" in out, "Test failed on %s" % filename) + elif "_pf" in filename: + cmd = self.path + " -p f -f ~/%s" % filename + self.dut.send_expect(cmd,"[PIPELINE1]",50) + out = self.dut.send_expect("quit","# ",10) + self.verify("Bye!" in out, "Test failed on %s" % filename) + elif "ip_pipeline_link_identification/negative" in filename: + if "_f" in filename: + cmd = self.path + " -p 0x3 -f ~/%s" % filename + out = self.dut.send_expect(cmd,"# ",50) + self.dut.send_expect("quit","# ",10) + self.verify("error" in out, "Test failed on %s" % filename) + elif "_1p" in filename: + cmd = self.path + " -p 1 -f ~/" % filename + out = self.dut.send_expect(cmd,"# ",50) + self.dut.send_expect("quit","# ",10) + self.verify("error" in out, "Test failed on %s" % filename) + elif "_3p" in filename: + cmd = self.path + " -p 3 -f ~/%s" % filename + out = self.dut.send_expect(cmd,"#",50) + self.dut.send_expect("quit","# ",10) + self.verify("error" in out, "Test failed on %s" % filename) + + + def test_ip_pipeline_parser_cleanup(self): + for filename in self.filepath: + if "ip_pipeline_parser_cleanup/postive" in filename: + cmd = self.path + " -p 0x3 -f ~/%s" % filename + self.dut.send_expect(cmd,"[PIPELINE1]",50) + out = self.dut.send_expect("quit","# ",10) + self.verify("Bye!" in out, "Test failed on %s" % filename) + elif "ip_pipeline_parser_cleanup/negative" in filename: + cmd = self.path + " -p 0x3 -f ~/%s" % filename + out = self.dut.send_expect(cmd,"# ",50) + self.verify("error" in out, "Test failed on %s" % filename) + + def test_ip_pipeline_source_sink(self): + for filename in self.filepath: + if "ip_pipeline_source_sink/postive" in filename: + self.dut.send_expect("cp ~/ip_pipeline/*.pcap ~","#",50) + if "_com" in filename: + cmd = self.path + " -f ~/%s" % filename + self.dut.send_expect(cmd,"PORT: Dumped",50) + time.sleep(10) + out = self.dut.send_expect("quit","# ",10) + self.verify("Bye!" in out, "Test failed on %s" % filename) + else: + cmd = self.path + " -f ~/%s" % filename + self.dut.send_expect(cmd,"[PIPELINE1]",50) + out = self.dut.send_expect("quit","# ",10) + self.verify("Bye!" in out, "Test failed on %s" % filename) + self.dut.send_expect("rm -rf ~/*.pcap","#",50) + elif "ip_pipeline_source_sink/negative" in filename: + self.dut.send_expect("cp ~/ip_pipeline/*.pcap ~","#",50) + cmd = self.path + " -f ~/%s" % filename + out = self.dut.send_expect(cmd,"# ",50) + self.verify("error" in out, "Test failed on %s" % filename) + self.dut.send_expect("rm -rf ~/*.pcap","#",50) + + def tear_down(self): + """ + Run after each test case. + """ + self.dut.kill_all() + time.sleep(2) + + def tear_down_all(self): + """ + Run after each test suite. + """ + self.dut.send_expect("sed -i -e 's/CONFIG_RTE_PORT_PCAP=.*$/" + + "CONFIG_RTE_PORT_PCAP=n/' config/common_base", "# ", 30) + self.dut.build_install_dpdk(self.target) + -- 1.9.3