From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 1DF3E9AD8 for ; Fri, 29 May 2015 10:39:59 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP; 29 May 2015 01:39:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,515,1427785200"; d="scan'208";a="578683832" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by orsmga003.jf.intel.com with ESMTP; 29 May 2015 01:39:57 -0700 Received: from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com [10.239.29.90]) by shvmail01.sh.intel.com with ESMTP id t4T8dsDs025871; Fri, 29 May 2015 16:39:54 +0800 Received: from shecgisg003.sh.intel.com (localhost [127.0.0.1]) by shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id t4T8dqOV025403; Fri, 29 May 2015 16:39:54 +0800 Received: (from huilongx@localhost) by shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id t4T8dpfq025399; Fri, 29 May 2015 16:39:51 +0800 From: "huilong,xu" To: dts@dpdk.org Date: Fri, 29 May 2015 16:39:46 +0800 Message-Id: <1432888786-25354-3-git-send-email-huilongx.xu@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1432888786-25354-1-git-send-email-huilongx.xu@intel.com> References: <1432888786-25354-1-git-send-email-huilongx.xu@intel.com> Cc: jingguox.fu@intel.com Subject: [dts] [dts 3/3] [PATCH V1] add queue start queue test code 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: Fri, 29 May 2015 08:40:00 -0000 From: huilong xu Signed-off-by: huilong xu --- tests/TestSuite_queue_start_stop.py | 207 +++++++++++++++++++++++++++++++++++ 1 files changed, 207 insertions(+), 0 deletions(-) create mode 100644 tests/TestSuite_queue_start_stop.py diff --git a/tests/TestSuite_queue_start_stop.py b/tests/TestSuite_queue_start_stop.py new file mode 100644 index 0000000..4fdc921 --- /dev/null +++ b/tests/TestSuite_queue_start_stop.py @@ -0,0 +1,207 @@ +# BSD LICENSE +# +# Copyright(c) 2010-2015 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 queue start stop Feature + +""" + +import dts +import time +import re +import os +from test_case import TestCase +from pmd_output import PmdOutput + +# +# +# Test class. +# + + +class TestQueueStartStop(TestCase): + # + # + # + # Test cases. + # + + def set_up_all(self): + """ + Run at the start of each test suite. + """ + self.ports = self.dut.get_ports(self.nic) + self.verify(len(self.ports) >= 2, "Insufficient number of ports.") + + def set_up(self): + """ + Run before each test case. + """ + pass + + def check_forwarding(self, ports, nic, testerports=[None, None], pktSize=64, received=True): + self.send_packet(ports[0], ports[1], self.nic, testerports[1], pktSize, received) + + def send_packet(self, txPort, rxPort, nic, testerports=None, pktSize=64, received=True): + """ + Send packages according to parameters. + """ + + if testerports is None: + rxitf = self.tester.get_interface(self.tester.get_local_port(rxPort)) + txitf = self.tester.get_interface(self.tester.get_local_port(txPort)) + else: + itf = testerports + mac = self.dut.get_mac_address(txPort) + + self.tester.scapy_background() + self.tester.scapy_append('p=sniff(iface="%s",count=1,timeout=5)' % rxitf) + self.tester.scapy_append('RESULT=str(p)') + + self.tester.scapy_foreground() + + if self.nic in ["fortville_eagle", "fortville_spirit", + "fortville_spirit_single", "bartonhills", + "powerville", "springville", "hartwell"]: + pktlen = pktSize - 22 + else: + pktlen = pktSize - 18 + padding = pktlen - 20 + self.tester.scapy_append('sendp([Ether(dst="%s")/IP()/Raw(load="\x50"*%s)], iface="%s")' % (mac, padding, txitf)) + + self.tester.scapy_execute() + time.sleep(3) + + out = self.tester.scapy_get_result() + if received: + self.verify('\x50\x50\x50' in out, "start queue failed") + else: + self.verify('\x50\x50\x50' not in out, "stop queue failed") + + def add_code_to_dpdk(self, file_name, standard_row, add_rows, offset=0): + """ + this function for add code in dpdk src code file. + file: source code full path + standard_row: standard row for find the place that add code + offset: need offset row number + add_rows:add source code + + return: source code lines + """ + file_handel = open(file_name, "r+w") + source_lines = file_handel.readlines() + + write_lines = source_lines + + # get the index that need add code + index = -1 + for line in write_lines: + if standard_row in line: + index = write_lines.index(line) + offset + break + + # add source code and re-write the file + # print write_lines,index + for line in add_rows: + write_lines.insert(index, line) + index += 1 + # print write_lines + file_handel.seek(file_handel.tell() * -1, 2) + file_handel.writelines(write_lines) + file_handel.close() + + return source_lines + + def test_queue_start_stop(self): + """ + queue start/stop test for fortville nic + """ + fwdmac_file = os.getcwd() + r'/dep/dpdk/app/test-pmd/macfwd.c' + printf_lines = ['printf("ports %u queue %u revice %u packages", fs->rx_port, fs->rx_queue, nb_rx);\n', r'printf("\n");',"\n"] + sourcelines = self.add_code_to_dpdk(fwdmac_file, r'(unlikely(nb_rx == 0)', printf_lines, 2) + self.dut.session.copy_file_to(fwdmac_file) + self.dut.send_expect('scp /root/macfwd.c /root/dpdk/app/test-pmd/macfwd.c', "#") + self.dut.build_dpdk_apps('./app/test-pmd') + + self.dut.send_expect("./app/test-pmd/testpmd -c 0xf -n 4 -- -i", "testpmd>", 120) + self.dut.send_expect("set fwd mac", "testpmd>") + self.dut.send_expect("start", "testpmd>") + self.check_forwarding([0, 1], self.nic) + + # stop rx queue test + print "test stop rx queue" + self.dut.send_expect("stop", "testpmd>") + self.dut.send_expect("port 0 rxq 0 stop", "testpmd>") + self.dut.send_expect("start", "testpmd>") + self.check_forwarding([0, 1], self.nic, received=False) + + # start rx queue test + print "test start rx queue stop tx queue" + self.dut.send_expect("stop", "testpmd>") + self.dut.send_expect("port 0 rxq 0 start", "testpmd>") + self.dut.send_expect("port 1 txq 0 stop", "testpmd>") + self.dut.send_expect("start", "testpmd>") + self.check_forwarding([0, 1], self.nic, received=False) + out = self.dut.send_expect("\n", "testpmd>") + # print out + self.verify("ports 0 queue 0 revice 1 packages" in out, "start queue revice package failed") + + # start tx queue test + print "test start rx and tx queue" + self.dut.send_expect("stop", "testpmd>") + self.dut.send_expect("port 0 rxq 0 start", "testpmd>") + self.dut.send_expect("port 1 txq 0 start", "testpmd>") + self.dut.send_expect("start", "testpmd>") + self.check_forwarding([0, 1], self.nic) + + # recover testpmd changed + file_handel = open(fwdmac_file, "w") + file_handel.writelines(sourcelines) + file_handel.close() + + def tear_down(self): + """ + Run after each test case. + """ + self.dut.kill_all() + + def tear_down_all(self): + """ + Run after each test suite. + """ + self.dut.kill_all() + #self.dut.send_expect("rm -rf ./app/test-pmd/testpmd", "#") + #self.dut.send_expect("rm -rf ./app/test-pmd/*.o", "#") + #self.dut.send_expect("rm -rf ./app/test-pmd/build", "#") -- 1.7.4.4