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 DECC8A05A1; Wed, 22 Apr 2020 04:44:54 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7024B1BFE6; Wed, 22 Apr 2020 04:44:54 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 1C96E2B96 for ; Wed, 22 Apr 2020 04:44:52 +0200 (CEST) IronPort-SDR: ffSBtwLsSiSRoHsRQcmthXZZzaxdoSHQAvvardkEo39Ef6iZXtYEzhllAO6/3Feb8prUeYog9J pFvhf8DXRpfQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Apr 2020 19:44:52 -0700 IronPort-SDR: 5YPUtaQtC7SHskzqWtu6my+NvgTD1r9cjhaXVjRRSVPn11Y3ZiARw48FX+UdRg51XMdFSxBZNe wq8XM9pBOa3A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,412,1580803200"; d="scan'208";a="456985798" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga006.fm.intel.com with ESMTP; 21 Apr 2020 19:44:52 -0700 Received: from shsmsx603.ccr.corp.intel.com (10.109.6.143) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 21 Apr 2020 19:44:51 -0700 Received: from shsmsx602.ccr.corp.intel.com (10.109.6.142) by SHSMSX603.ccr.corp.intel.com (10.109.6.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Wed, 22 Apr 2020 10:44:49 +0800 Received: from shsmsx602.ccr.corp.intel.com ([10.109.6.142]) by SHSMSX602.ccr.corp.intel.com ([10.109.6.142]) with mapi id 15.01.1713.004; Wed, 22 Apr 2020 10:44:49 +0800 From: "Zhao, XinfengX" To: "dts@dpdk.org" , "Wang, Yinan" Thread-Topic: [dts][PATCH V1] tests: add a new suite for ntb test Thread-Index: AQHWGE+4PuL7sSQfVESTMnU4+IMqg6iEbzXw Date: Wed, 22 Apr 2020 02:44:49 +0000 Message-ID: References: <20200421193713.5407-1-xinfengx.zhao@intel.com> In-Reply-To: <20200421193713.5407-1-xinfengx.zhao@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.36] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dts] [PATCH V1] tests: add a new suite for ntb test 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" Tested-by: Zhao, Xinfeng -----Original Message----- From: Zhao, XinfengX=20 Sent: Wednesday, April 22, 2020 3:37 AM To: dts@dpdk.org Cc: Zhao, XinfengX Subject: [dts][PATCH V1] tests: add a new suite for ntb test Signed-off-by: xinfengx --- tests/TestSuite_ntb.py | 340 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 340 insertions(+) create mode 100644 tests/TestSuite_ntb.py diff --git a/tests/TestSuite_ntb.py b/tests/TestSuite_ntb.py new file mode = 100644 index 0000000..e01bd4b --- /dev/null +++ b/tests/TestSuite_ntb.py @@ -0,0 +1,340 @@ +# BSD LICENSE +# +# Copyright(c) <2020> Intel Corporation. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without #=20 +modification, are permitted provided that the following conditions #=20 +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 #=20 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT #=20 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR #=20 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT #=20 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, #=20 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT #=20 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, #=20 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY #=20 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT #=20 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE #=20 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import re +import time +from test_case import TestCase +from net_device import GetNicObj +from settings import HEADER_SIZE +from packet import Packet +from pktgen import PacketGeneratorHelper + +class TestNtb(TestCase): + + def set_up_all(self): + self.verify(len(self.duts) >=3D 2, "Insufficient duts for NTB!!!") + self.ntb_host =3D self.duts[0] + self.ntb_client =3D self.duts[1] + + # each dut required one ports + self.verify(len(self.ntb_host.get_ports()) >=3D 1 and + len(self.ntb_client.get_ports()) >=3D 1, + "Insufficient ports for testing") + + self.host_port =3D self.ntb_host.get_ports()[0] + self.client_port =3D self.ntb_client.get_ports()[0] + self.host_mac =3D self.ntb_host.get_mac_address(self.host_port) + self.client_mac =3D=20 + self.ntb_client.get_mac_address(self.client_port) + + self.tester.extend_external_packet_generator(TestNtb, self) + self.frame_sizes =3D [64, 128, 256, 512, 1024, 1518] + self.header_size =3D HEADER_SIZE['eth'] + HEADER_SIZE['ip'] + HEAD= ER_SIZE['udp'] + self.pktgen_helper =3D PacketGeneratorHelper() + + self.out_path =3D '/tmp' + out =3D self.tester.send_expect('ls -d %s' % self.out_path, '# ') + if 'No such file or directory' in out: + self.tester.send_expect('mkdir -p %s' % self.out_path, '# ') + out =3D self.ntb_host.send_expect('ls -d %s' % self.out_path, '# '= ) + if 'No such file or directory' in out: + self.ntb_host.send_expect('mkdir -p %s' % self.out_path, '#=20 + ') + + self.prepare_dpdk_app(self.ntb_host) + self.prepare_dpdk_app(self.ntb_client) + + def set_up(self): + pass + + def create_table(self, index=3D1): + self.table_header =3D ["FrameSize(B)", "Throughput(Mpps)", "% line= rate"] + self.result_table_create(self.table_header) + + def prepare_dpdk_app(self, crb): + out =3D crb.send_expect("ls ./" + crb.target + "/kmod/igb_uio.ko",= "#", 10) + if "No such file or directory" in out: + crb.build_install_dpdk(crb.target) + + out =3D crb.build_dpdk_apps("./examples/ntb") + self.verify("Error" not in out, "Compilation error") + self.verify("No such" not in out, "Compilation error") + + def get_core_list(self): + core_number =3D 5 + core_config =3D '1S/{}C/1T'.format(core_number) + self.host_core_list =3D self.ntb_host.get_core_list(core_config) + self.client_core_list =3D self.ntb_client.get_core_list(core_confi= g) + self.verify(len(self.host_core_list) >=3D core_number and len(self= .client_core_list) >=3D core_number, + 'There have not enough cores to start testpmd on=20 + duts') + + def get_ntb_port(self, crb): + device =3D crb.send_expect("lspci -D | grep Non-Transparent |awk '= {{print $1}}'", "# ", 10) + self.verify(device, "Falied to find ntb device") + addr_array =3D device.strip().split(':') + domain_id =3D addr_array[0] + bus_id =3D addr_array[1] + devfun_id =3D addr_array[2] + port =3D GetNicObj(crb, domain_id, bus_id, devfun_id) + return port + + def set_driver(self, driver=3D""): + self.ntb_host.restore_interfaces() + self.ntb_client.restore_interfaces() + + for crb in [self.ntb_host, self.ntb_client]: + crb.setup_modules(crb.target, driver, None) + if driver =3D=3D "igb_uio": + crb.send_expect("rmmod -f igb_uio", "#", 30) + crb.send_expect("insmod ./" + crb.target + "/kmod/igb_uio.= ko wc_activate=3D1", "#", 30) + if driver =3D=3D "vfio-pci": + crb.send_expect("echo 'base=3D0x39bfa0000000 size=3D0x4000= 00 type=3Dwrite-combining' >> /proc/mtrr", "#", 10) + crb.send_expect("echo 'base=3D0x39bfa0000000=20 + size=3D0x4000000 type=3Dwrite-combining' >> /proc/mtrr", "#", 10) + + def port_bind_driver(self, driver=3D""): + self.ntb_host.bind_interfaces_linux(driver=3Ddriver) + self.ntb_client.bind_interfaces_linux(driver=3Ddriver) + + def ntb_bind_driver(self, driver=3D""): + ntb =3D self.get_ntb_port(self.ntb_host) + ntb.bind_driver(driver) + + ntb =3D self.get_ntb_port(self.ntb_client) + ntb.bind_driver(driver) + + def launch_ntb_fwd(self, **param): + """ + launch ntb_fwd on ntb host and ntb client + """ + cmd_opt =3D " ".join(["{}=3D{}".format(key, param[key]) for key in= =20 + param.keys()]) + + self.get_core_list() + app =3D "./examples/ntb/build/ntb_fwd" + eal_host =3D self.ntb_host.create_eal_parameters(cores=3Dself.host= _core_list) + eal_client =3D self.ntb_client.create_eal_parameters(cores=3Dself.= client_core_list) + host_cmd_line =3D ' '.join([app, eal_host, cmd_opt]) + client_cmd_line =3D ' '.join([app, eal_client, cmd_opt]) + self.ntb_host.send_expect(host_cmd_line, 'Checking ntb link status= ', 30) + self.ntb_client.send_expect(client_cmd_line, 'Checking ntb link st= atus', 30) + time.sleep(3) + self.ntb_host.send_expect(" ", 'ntb> ', 10) + self.ntb_client.send_expect(" ", 'ntb> ', 10) + + def start_ntb_fwd_on_dut(self, crb, fwd_mode=3D'io'): + crb.send_expect('set fwd %s' % fwd_mode, 'ntb> ', 30) + crb.send_expect('start', 'ntb> ', 30) + + def config_stream(self, frame_size): + payload =3D frame_size - self.header_size + tgen_input =3D [] + + for i, each_mac in enumerate([self.host_mac, self.client_mac]): + flow =3D 'Ether(dst=3D"%s")/IP(dst=3D"192.168.%d.1", proto=3D2= 55)/UDP()/("X"*%d)' % (each_mac, i, payload) + pkt =3D Packet(pkt_str=3Dflow) + pcap =3D os.path.join(self.out_path, "ntb_%d_%d.pcap" % + (i, frame_size)) + pkt.save_pcapfile(None, pcap) + tgen_input.append((i, (i+1)%2, pcap)) + + return tgen_input + + def calculate_avg_throughput(self, frame_size, tgen_input): + """ + send packet and get the throughput + """ + # set traffic option + traffic_opt =3D {'delay': 5} + + # clear streams before add new streams + self.tester.pktgen.clear_streams() + + # run packet generator + fields_config =3D {'ip': {'dst': {'action': 'random'}, }, } + streams =3D self.pktgen_helper.prepare_stream_from_tginput(tgen_in= put, 100, + fields_config, self.tester.pkt= gen) + _, pps =3D=20 + self.tester.pktgen.measure_throughput(stream_ids=3Dstreams,=20 + options=3Dtraffic_opt) + + Mpps =3D pps / 1000000.0 + + throughput =3D Mpps * 100 / \ + float(self.wirespeed(self.nic, frame_size, 1)) + return Mpps, throughput + + def get_packets_of_each_port(self, crb): + out =3D crb.send_expect('show port stats', 'ntb> ', 10) + info =3D re.findall("statistics for NTB port", out) + index =3D out.find(info[0]) + tx =3D re.search("Tx-packets:\s*(\d*)", out[index:]) + rx =3D re.search("Rx-packets:\s*(\d*)", out[index:]) + rx_packets =3D int(rx.group(1)) + tx_packets =3D int(tx.group(1)) + self.logger.info("tx-packets:%d, rx-packets:%d" % + (tx_packets, rx_packets)) + return tx_packets, rx_packets + + def check_packets_for_iofwd(self): + """ + check transmit/receive packets for iofwd mode + """ + tx, rx =3D self.get_packets_of_each_port(self.ntb_host) + self.verify(tx > 0 and rx > 0, + "tx-packets:%d, rx-packets:%d" % (tx, rx)) + + tx, rx =3D self.get_packets_of_each_port(self.ntb_client) + self.verify(tx > 0 and rx > 0, + "tx-packets:%d, rx-packets:%d" % (tx, rx)) + + def check_packets_for_rxtx(self): + """ + check transmit/receive packets for rxonly and txonly mode + """ + tx, rx =3D self.get_packets_of_each_port(self.ntb_host) + self.verify(tx =3D=3D 0 and rx > 0, + "tx-packets:%d, rx-packets:%d" % (tx, rx)) + + tx, rx =3D self.get_packets_of_each_port(self.ntb_client) + self.verify(tx > 0 and rx =3D=3D 0, + "tx-packets:%d, rx-packets:%d" % (tx, rx)) + + def send_file_and_verify(self): + # Send file from host + src_file =3D "{}/ntb.txt".format(self.out_path) + base_dir =3D self.ntb_client.base_dir.replace('~', '/root') + dst_file =3D "{}/ntb_recv_file0".format(base_dir) + content =3D "ntb!123" + self.ntb_client.alt_session.send_expect("rm {}".format(dst_file), = '# ') + self.ntb_host.alt_session.send_expect("echo '{}' >{}".format(conte= nt, src_file), '# ') + self.ntb_host.send_expect('send {}'.format(src_file), 'ntb> ', 30) + time.sleep(3) + + # Check file received on client. + cnt =3D self.ntb_client.alt_session.send_expect('cat %s' % dst_fil= e, '# ') + self.verify(cnt =3D=3D content, "the content can't match with the= =20 + sent") + + def send_pkg_and_verify(self): + for frame_size in self.frame_sizes: + info =3D "Running test: %s, frame size: %d." % (self.running_c= ase, frame_size) + self.logger.info(info) + self.ntb_host.send_expect("stop", "ntb> ", 60) + self.ntb_host.send_expect("start", "ntb> ", 60) + self.ntb_client.send_expect("stop", "ntb> ", 60) + self.ntb_client.send_expect("start", "ntb> ", 60) + time.sleep(1) + + result =3D [frame_size] + tgen_input =3D self.config_stream(frame_size) + Mpps, throughput =3D self.calculate_avg_throughput(frame_size,= tgen_input) + result.append(Mpps) + result.append(throughput) + + self.check_packets_for_iofwd() + self.update_table_info(result) + + def test_file_tran_mode_and_igb_uio(self): + driver =3D "igb_uio" + self.set_driver(driver) + self.ntb_bind_driver(driver) + + self.launch_ntb_fwd(**{"buf-size": 65407}) + self.start_ntb_fwd_on_dut(self.ntb_host, fwd_mode=3D"file-trans") + self.start_ntb_fwd_on_dut(self.ntb_client, fwd_mode=3D"file-trans"= ) + self.send_file_and_verify() + + def test_file_tran_mode_and_vfio_pci(self): + driver =3D "vfio-pci" + self.set_driver(driver) + self.ntb_bind_driver(driver) + + self.launch_ntb_fwd(**{"buf-size": 65407}) + self.start_ntb_fwd_on_dut(self.ntb_host, fwd_mode=3D"file-trans") + self.start_ntb_fwd_on_dut(self.ntb_client, fwd_mode=3D"file-trans"= ) + self.send_file_and_verify() + + def test_pkt_rxtx_mode_and_igb_uio(self): + driver =3D "igb_uio" + self.set_driver(driver) + self.ntb_bind_driver(driver) + + self.launch_ntb_fwd(**{"buf-size": 65407}) + self.start_ntb_fwd_on_dut(self.ntb_host, fwd_mode=3D"rxonly") + self.start_ntb_fwd_on_dut(self.ntb_client, fwd_mode=3D"txonly") + time.sleep(1) + self.check_packets_for_rxtx() + + def test_pkt_rxtx_mode_and_vfio_pci(self): + driver =3D "vfio-pci" + self.set_driver(driver) + self.ntb_bind_driver(driver) + + self.launch_ntb_fwd(**{"buf-size": 65407}) + self.start_ntb_fwd_on_dut(self.ntb_host, fwd_mode=3D"rxonly") + self.start_ntb_fwd_on_dut(self.ntb_client, fwd_mode=3D"txonly") + time.sleep(1) + self.check_packets_for_rxtx() + + def test_perf_iofwd_mode_and_igb_uio(self): + driver =3D "igb_uio" + self.set_driver(driver) + self.ntb_bind_driver(driver) + self.port_bind_driver(driver) + + self.create_table() + self.launch_ntb_fwd(**{"burst": 32}) + self.start_ntb_fwd_on_dut(self.ntb_host, fwd_mode=3D"iofwd") + self.start_ntb_fwd_on_dut(self.ntb_client, fwd_mode=3D"iofwd") + self.send_pkg_and_verify() + + self.result_table_print() + + def test_perf_iofwd_mode_and_vfio_pci(self): + driver =3D "vfio-pci" + self.set_driver(driver) + self.ntb_bind_driver(driver) + self.port_bind_driver(driver) + + self.create_table() + self.launch_ntb_fwd(**{"burst": 32}) + self.start_ntb_fwd_on_dut(self.ntb_host, fwd_mode=3D"iofwd") + self.start_ntb_fwd_on_dut(self.ntb_client, fwd_mode=3D"iofwd") + self.send_pkg_and_verify() + + self.result_table_print() + + def update_table_info(self, *param): + for each in param: + self.result_table_add(each) + + def tear_down(self): + self.ntb_host.send_expect('quit', '# ', 30) + self.ntb_client.send_expect('quit', '# ', 30) + + def tear_down_all(self): + self.ntb_host.kill_all() + self.ntb_client.kill_all() -- 2.17.1