From nobody Sat Nov 23 03:04:06 2024 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E37514375C; Fri, 15 Nov 2024 02:23:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.153.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731637439; cv=none; b=q9phmUMzKm4haPmKROoO5bpbHTQZ1vrXk302cEPq8H9qd7J9uMn7ZOo/JRP3GJEHD5PlMLfGbXZqaEreSQ4Yc0KUrSTBn7KzqniDb16Tubc+/6nJnpRAF7L/C+uKTXxGaweKMaRphizXXKtF0keDJsZoQHJHQ2020RWZ+RyOcI0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731637439; c=relaxed/simple; bh=pimSIS07xfTY+krQp46V4R99Vq3TX/rxIP4Tzm9ti1A=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lOYgStBQYDoPqp39/FGYCAJcG5FaxWfCfxwnc3DgF9AvkqwCP+ZrodZQhVeyALKzNwbYrfrf6bSR0KOEz6BjQFf7GPGho+qSYTDOOcfEoJ35Izkvt8gWKQozes29+zzH/QrAwmGw57EiJQkkZq7p8Fq2kZ0H585HgwyT7DakIDM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=VaEjkRKC; arc=none smtp.client-ip=68.232.153.233 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="VaEjkRKC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1731637437; x=1763173437; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pimSIS07xfTY+krQp46V4R99Vq3TX/rxIP4Tzm9ti1A=; b=VaEjkRKC/R6Scs8hpdqaVdUbfr5xbxFMfwZe0kqLhtJ8hgQgHG3lNApC BhIYnFB4IqXnPvWpheCV2lZ7yH222nTNVbSrE5Unp8Y56pRbIEc5sNLhL UpwJeoPY0dE5QNAY1hHYHRYCw5gFh7W5W2GlBDzUIpuir0xdC+sZKc80u 8KmcpOES5m8ihO++iwU3YUPxAbeqC1kbJEzp14UT1rjcBDuNff6D1JMOY oryqQ4Igwp/WXrt7aCrajOQKNGD/xdi6Ex0Fy9I9jJkAORQmYnc4NiAPG CRAKdjyXed7sHEpCexC54spe4QJkE8OkVNdP/n7tGNai0fj3CtCvbe4zt w==; X-CSE-ConnectionGUID: 44dLkhyPQcCnPJiBO6oYOQ== X-CSE-MsgGUID: 9XAuJ7JTRrOOz9qtbOBYxw== X-IronPort-AV: E=Sophos;i="6.12,155,1728975600"; d="scan'208";a="34348660" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa3.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Nov 2024 19:23:49 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 14 Nov 2024 19:23:18 -0700 Received: from nisar-OptiPlex-9020.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 14 Nov 2024 19:23:13 -0700 From: Mohan Prasad J To: , , , CC: , , , , , , , , , , , Subject: [PATCH net-next v4 1/3] selftests: nic_link_layer: Add link layer selftest for NIC driver Date: Fri, 15 Nov 2024 00:55:18 +0530 Message-ID: <20241114192545.1742514-2-mohan.prasad@microchip.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241114192545.1742514-1-mohan.prasad@microchip.com> References: <20241114192545.1742514-1-mohan.prasad@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Add selftest file for the link layer tests of a NIC driver. Test for auto-negotiation is added. Add LinkConfig class for changing link layer configs. Selftest makes use of ksft modules and ethtool. Include selftest file in the Makefile. Signed-off-by: Mohan Prasad J --- .../testing/selftests/drivers/net/hw/Makefile | 5 +- .../drivers/net/hw/lib/py/__init__.py | 1 + .../drivers/net/hw/lib/py/linkconfig.py | 222 ++++++++++++++++++ .../drivers/net/hw/nic_link_layer.py | 91 +++++++ 4 files changed, 317 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/drivers/net/hw/lib/py/linkconfi= g.py create mode 100644 tools/testing/selftests/drivers/net/hw/nic_link_layer.py diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testin= g/selftests/drivers/net/hw/Makefile index 1c6a77480..7939f81fe 100644 --- a/tools/testing/selftests/drivers/net/hw/Makefile +++ b/tools/testing/selftests/drivers/net/hw/Makefile @@ -11,6 +11,7 @@ TEST_PROGS =3D \ hw_stats_l3.sh \ hw_stats_l3_gre.sh \ loopback.sh \ + nic_link_layer.py \ pp_alloc_fail.py \ rss_ctx.py \ # diff --git a/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py b/to= ols/testing/selftests/drivers/net/hw/lib/py/__init__.py index b58288578..399789a96 100644 --- a/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py +++ b/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py @@ -9,6 +9,7 @@ try: sys.path.append(KSFT_DIR.as_posix()) from net.lib.py import * from drivers.net.lib.py import * + from .linkconfig import LinkConfig except ModuleNotFoundError as e: ksft_pr("Failed importing `net` library from kernel sources") ksft_pr(str(e)) diff --git a/tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py b/= tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py new file mode 100644 index 000000000..db84000fc --- /dev/null +++ b/tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py @@ -0,0 +1,222 @@ +# SPDX-License-Identifier: GPL-2.0 + +from lib.py import cmd, ethtool, ip +from lib.py import ksft_pr, ksft_eq, KsftSkipEx +from typing import Optional +import re +import time +import json + +#The LinkConfig class is implemented to handle the link layer configuratio= ns. +#Required minimum ethtool version is 6.10 + +class LinkConfig: + """Class for handling the link layer configurations""" + def __init__(self, cfg: object) -> None: + self.cfg =3D cfg + self.partner_netif =3D self.get_partner_netif_name() + + """Get the initial link configuration of local interface""" + self.common_link_modes =3D self.get_common_link_modes() + + def get_partner_netif_name(self) -> Optional[str]: + partner_netif =3D None + try: + if not self.verify_link_up(): + return None + """Get partner interface name""" + partner_json_output =3D ip("addr show", json=3DTrue, host=3Dse= lf.cfg.remote) + for interface in partner_json_output: + for addr in interface.get('addr_info', []): + if addr.get('local') =3D=3D self.cfg.remote_addr: + partner_netif =3D interface['ifname'] + ksft_pr(f"Partner Interface name: {partner_netif}") + if partner_netif is None: + ksft_pr("Unable to get the partner interface name") + except Exception as e: + print(f"Unexpected error occurred while getting partner interf= ace name: {e}") + self.partner_netif =3D partner_netif + return partner_netif + + def verify_link_up(self) -> bool: + """Verify whether the local interface link is up""" + with open(f"/sys/class/net/{self.cfg.ifname}/operstate", "r") as f= p: + link_state =3D fp.read().strip() + + if link_state =3D=3D "down": + ksft_pr(f"Link state of interface {self.cfg.ifname} is DOWN") + return False + else: + return True + + def reset_interface(self, local: bool =3D True, remote: bool =3D True)= -> bool: + ksft_pr("Resetting interfaces in local and remote") + if remote: + if self.verify_link_up(): + if self.partner_netif is not None: + ifname =3D self.partner_netif + link_up_cmd =3D f"ip link set up {ifname}" + link_down_cmd =3D f"ip link set down {ifname}" + reset_cmd =3D f"{link_down_cmd} && sleep 5 && {link_up= _cmd}" + try: + cmd(reset_cmd, host=3Dself.cfg.remote) + except Exception as e: + ksft_pr(f"Unexpected error occurred while resettin= g remote: {e}") + else: + ksft_pr("Partner interface not available") + if local: + ifname =3D self.cfg.ifname + link_up_cmd =3D f"ip link set up {ifname}" + link_down_cmd =3D f"ip link set down {ifname}" + reset_cmd =3D f"{link_down_cmd} && sleep 5 && {link_up_cmd}" + try: + cmd(reset_cmd) + except Exception as e: + ksft_pr(f"Unexpected error occurred while resetting local:= {e}") + time.sleep(10) + if self.verify_link_up() and self.get_ethtool_field("link-detected= "): + ksft_pr("Local and remote interfaces reset to original state") + return True + else: + ksft_pr("Error occurred after resetting interfaces. Link is DO= WN.") + return False + + def set_speed_and_duplex(self, speed: str, duplex: str, autoneg: bool = =3D True) -> bool: + """Set the speed and duplex state for the interface""" + autoneg_state =3D "on" if autoneg is True else "off" + process =3D None + try: + process =3D ethtool(f"--change {self.cfg.ifname} speed {speed}= duplex {duplex} autoneg {autoneg_state}") + except Exception as e: + ksft_pr(f"Unexpected error occurred while setting speed/duplex= : {e}") + if process is None or process.ret !=3D 0: + return False + else: + ksft_pr(f"Speed: {speed} Mbps, Duplex: {duplex} set for Interf= ace: {self.cfg.ifname}") + return True + + def verify_speed_and_duplex(self, expected_speed: str, expected_duplex= : str) -> bool: + if not self.verify_link_up(): + return False + """Verifying the speed and duplex state for the interface""" + with open(f"/sys/class/net/{self.cfg.ifname}/speed", "r") as fp: + actual_speed =3D fp.read().strip() + with open(f"/sys/class/net/{self.cfg.ifname}/duplex", "r") as fp: + actual_duplex =3D fp.read().strip() + + ksft_eq(actual_speed, expected_speed) + ksft_eq(actual_duplex, expected_duplex) + return True + + def set_autonegotiation_state(self, state: str, remote: bool =3D False= ) -> bool: + common_link_modes =3D self.common_link_modes + speeds, duplex_modes =3D self.get_speed_duplex_values(self.common_= link_modes) + speed =3D speeds[0] + duplex =3D duplex_modes[0] + if not speed or not duplex: + ksft_pr("No speed or duplex modes found") + return False + + speed_duplex_cmd =3D f"speed {speed} duplex {duplex}" if state =3D= =3D "off" else "" + if remote: + if not self.verify_link_up(): + return False + """Set the autonegotiation state for the partner""" + command =3D f"-s {self.partner_netif} {speed_duplex_cmd} auton= eg {state}" + partner_autoneg_change =3D None + """Set autonegotiation state for interface in remote pc""" + try: + partner_autoneg_change =3D ethtool(command, host=3Dself.cf= g.remote) + except Exception as e: + ksft_pr(f"Unexpected error occurred while changing auto-ne= g in remote: {e}") + if partner_autoneg_change is None or partner_autoneg_change.re= t !=3D 0: + ksft_pr(f"Not able to set autoneg parameter for interface = {self.partner_netif}.") + return False + ksft_pr(f"Autoneg set as {state} for {self.partner_netif}") + else: + """Set the autonegotiation state for the interface""" + try: + process =3D ethtool(f"-s {self.cfg.ifname} {speed_duplex_c= md} autoneg {state}") + if process.ret !=3D 0: + ksft_pr(f"Not able to set autoneg parameter for interf= ace {self.cfg.ifname}") + return False + except Exception as e: + ksft_pr(f"Unexpected error occurred while changing auto-ne= g in local: {e}") + return False + ksft_pr(f"Autoneg set as {state} for {self.cfg.ifname}") + return True + + def check_autoneg_supported(self, remote: bool =3D False) -> bool: + if not remote: + local_autoneg =3D self.get_ethtool_field("supports-auto-negoti= ation") + if local_autoneg is None: + ksft_pr(f"Unable to fetch auto-negotiation status for inte= rface {self.cfg.ifname}") + """Return autoneg status of the local interface""" + return local_autoneg + else: + if not self.verify_link_up(): + raise KsftSkipEx("Link is DOWN") + """Check remote auto-negotiation support status""" + partner_autoneg =3D False + if self.partner_netif is not None: + partner_autoneg =3D self.get_ethtool_field("supports-auto-= negotiation", remote=3DTrue) + if partner_autoneg is None: + ksft_pr(f"Unable to fetch auto-negotiation status for = interface {self.partner_netif}") + return partner_autoneg + + def get_common_link_modes(self) -> set[str]: + common_link_modes =3D [] + """Populate common link modes""" + link_modes =3D self.get_ethtool_field("supported-link-modes") + partner_link_modes =3D self.get_ethtool_field("link-partner-advert= ised-link-modes") + if link_modes is None: + raise KsftSkipEx(f"Link modes not available for {self.cfg.ifna= me}") + if partner_link_modes is None: + raise KsftSkipEx(f"Partner link modes not available for {self.= cfg.ifname}") + common_link_modes =3D set(link_modes) and set(partner_link_modes) + return common_link_modes + + def get_speed_duplex_values(self, link_modes: list[str]) -> tuple[list= [str], list[str]]: + speed =3D [] + duplex =3D [] + """Check the link modes""" + for data in link_modes: + parts =3D data.split('/') + speed_value =3D re.match(r'\d+', parts[0]) + if speed_value: + speed.append(speed_value.group()) + else: + ksft_pr(f"No speed value found for interface {self.ifname}= ") + return None, None + duplex.append(parts[1].lower()) + return speed, duplex + + def get_ethtool_field(self, field: str, remote: bool =3D False) -> Opt= ional[str]: + process =3D None + if not remote: + """Get the ethtool field value for the local interface""" + try: + process =3D ethtool(self.cfg.ifname, json=3DTrue) + except Exception as e: + ksft_pr("Required minimum ethtool version is 6.10") + ksft_pr(f"Unexpected error occurred while getting ethtool = field in local: {e}") + return None + else: + if not self.verify_link_up(): + return None + """Get the ethtool field value for the remote interface""" + self.cfg.require_cmd("ethtool", remote=3DTrue) + if self.partner_netif is None: + ksft_pr(f"Partner interface name is unavailable.") + return None + try: + process =3D ethtool(self.partner_netif, json=3DTrue, host= =3Dself.cfg.remote) + except Exception as e: + ksft_pr("Required minimum ethtool version is 6.10") + ksft_pr(f"Unexpected error occurred while getting ethtool = field in remote: {e}") + return None + json_data =3D process[0] + """Check if the field exist in the json data""" + if field not in json_data: + raise KsftSkipEx(f"Field {field} does not exist in the output = of interface {json_data["ifname"]}") + return json_data[field] diff --git a/tools/testing/selftests/drivers/net/hw/nic_link_layer.py b/too= ls/testing/selftests/drivers/net/hw/nic_link_layer.py new file mode 100644 index 000000000..d8cc12e84 --- /dev/null +++ b/tools/testing/selftests/drivers/net/hw/nic_link_layer.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +#Introduction: +#This file has basic link layer tests for generic NIC drivers. +#The test comprises of auto-negotiation, speed and duplex checks. +# +#Setup: +#Connect the DUT PC with NIC card to partner pc back via ethernet medium o= f your choice(RJ45, T1) +# +# DUT PC Partner PC +#=E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =90 =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 +#=E2=94=82 =E2=94=82 =E2=94= =82 =E2=94=82 +#=E2=94=82 =E2=94=82 =E2=94= =82 =E2=94=82 +#=E2=94=82 =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 = =E2=94=82 =E2=94=82 +#=E2=94=82 =E2=94=82DUT NIC =E2=94=82 Eth = =E2=94=82 =E2=94=82 +#=E2=94=82 =E2=94=82Interface =E2=94=80=E2=94=BC=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94= =80 any eth Interface =E2=94=82 +#=E2=94=82 =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=98 = =E2=94=82 =E2=94=82 +#=E2=94=82 =E2=94=82 =E2=94= =82 =E2=94=82 +#=E2=94=82 =E2=94=82 =E2=94= =82 =E2=94=82 +#=E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =98 =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=98 +# +#Configurations: +#Required minimum ethtool version is 6.10 (supports json) +#Default values: +#time_delay =3D 8 #time taken to wait for transitions to happen, in second= s. + +import time +import argparse +from lib.py import ksft_run, ksft_exit, ksft_pr, ksft_eq +from lib.py import KsftFailEx, KsftSkipEx +from lib.py import NetDrvEpEnv +from lib.py import LinkConfig + +def _pre_test_checks(cfg: object, link_config: LinkConfig) -> None: + if link_config.partner_netif is None: + KsftSkipEx("Partner interface is not available") + if not link_config.check_autoneg_supported() or not link_config.check_= autoneg_supported(remote=3DTrue): + KsftSkipEx(f"Auto-negotiation not supported for interface {cfg.ifn= ame} or {link_config.partner_netif}") + if not link_config.verify_link_up(): + raise KsftSkipEx(f"Link state of interface {cfg.ifname} is DOWN") + +def verify_autonegotiation(cfg: object, expected_state: str, link_config: = LinkConfig) -> None: + if not link_config.verify_link_up(): + raise KsftSkipEx(f"Link state of interface {cfg.ifname} is DOWN") + """Verifying the autonegotiation state in partner""" + partner_autoneg_output =3D link_config.get_ethtool_field("auto-negotia= tion", remote=3DTrue) + if partner_autoneg_output is None: + KsftSkipEx(f"Auto-negotiation state not available for interface {l= ink_config.partner_netif}") + partner_autoneg_state =3D "on" if partner_autoneg_output is True else = "off" + + ksft_eq(partner_autoneg_state, expected_state) + + """Verifying the autonegotiation state of local""" + autoneg_output =3D link_config.get_ethtool_field("auto-negotiation") + if autoneg_output is None: + KsftSkipEx(f"Auto-negotiation state not available for interface {c= fg.ifname}") + actual_state =3D "on" if autoneg_output is True else "off" + + ksft_eq(actual_state, expected_state) + + """Verifying the link establishment""" + link_available =3D link_config.get_ethtool_field("link-detected") + if link_available is None: + KsftSkipEx(f"Link status not available for interface {cfg.ifname}") + if link_available !=3D True: + raise KsftSkipEx("Link not established at interface {cfg.ifname} a= fter changing auto-negotiation") + +def test_autonegotiation(cfg: object, link_config: LinkConfig, time_delay:= int) -> None: + _pre_test_checks(cfg, link_config) + for state in ["off", "on"]: + if not link_config.set_autonegotiation_state(state, remote=3DTrue): + raise KsftSkipEx(f"Unable to set auto-negotiation state for in= terface {link_config.partner_netif}") + if not link_config.set_autonegotiation_state(state): + raise KsftSkipEx(f"Unable to set auto-negotiation state for in= terface {cfg.ifname}") + time.sleep(time_delay) + verify_autonegotiation(cfg, state, link_config) + +def main() -> None: + parser =3D argparse.ArgumentParser(description=3D"Run basic link layer= tests for NIC driver") + parser.add_argument('--time-delay', type=3Dint, default=3D8, help=3D'T= ime taken to wait for transitions to happen(in seconds). Default is 8 secon= ds.') + args =3D parser.parse_args() + time_delay =3D args.time_delay + with NetDrvEpEnv(__file__, nsim_test=3DFalse) as cfg: + link_config =3D LinkConfig(cfg) + ksft_run(globs=3Dglobals(), case_pfx=3D{"test_"}, args=3D(cfg, lin= k_config, time_delay,)) + link_config.reset_interface() + ksft_exit() + +if __name__ =3D=3D "__main__": + main() --=20 2.43.0 From nobody Sat Nov 23 03:04:06 2024 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C3E2558BC; Fri, 15 Nov 2024 02:25:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.154.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731637557; cv=none; b=H8E+nKhY5X3qKpP4iRKaZHhMrknVXbWWVKvU2zyrMT2N890/k46xkITQH21/M1aasHe1F6rJuEToeleW7sqLks47xYAK7Hu6YKFIapNV8iY8x9v/w3T+OQlMv47LFu9qOixvgQki0zzK86yq3M26/NgerpRneWUFBLRLr5IXsyE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731637557; c=relaxed/simple; bh=diQYWzRLt6DbkP9+0LMg4OfquCgvtMnxE6BA39LxF7I=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uKil3O1lZO+kD53LlzTN/CeTaFkSprkR1E2FkrjA9u8DOKhHIr0iurMgpkAkS8MC18mtkm/odv41XSTaXpNfeOOn/S3ZPaMxWmvIaNXAHFsLH7Km4RKyHpGvZIihNJUSBFlay/Xi+Br+WMOQ7VZ8kPOtinQRtZzGhDZ4SylejEg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=hHdVYJSt; arc=none smtp.client-ip=68.232.154.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="hHdVYJSt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1731637555; x=1763173555; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=diQYWzRLt6DbkP9+0LMg4OfquCgvtMnxE6BA39LxF7I=; b=hHdVYJStsTVdfQh+W049JySGWab3Y8Ac5LpHkbMSsGEOZdFAbqsuM5bG eHUNxWtnqsXVeKmPSKJk0hpLAVLKQCk1kLkXqVNTooqha4AgvCcdCrOEm YSg/AZymLVZTIlTBaTMCxNbz7cvc4gq7hU8nDqNn08LCKMIPqmVucIv0b 0zfk8dT4125b3SMhlvQ7kxHt9lQ5XjNkkQvrq/BSZFDYH6zqJaDeK7lXZ DiWIz11Xsjfd1kUvlSxBPnSYOQmoiNqt8JjIctLRQ9Xf7zzBYnuD/MHtW 9b5rSlKITP+b1/AHZ8IKOtkl6H8BPa124TdhycQmmTVn/qkF4XjLstbOt Q==; X-CSE-ConnectionGUID: QjuG0j+zR8eJOiYtRT/ezA== X-CSE-MsgGUID: HaiGjlfdScaLkx2o1349fw== X-IronPort-AV: E=Sophos;i="6.12,155,1728975600"; d="scan'208";a="34078313" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa4.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Nov 2024 19:23:38 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 14 Nov 2024 19:23:27 -0700 Received: from nisar-OptiPlex-9020.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 14 Nov 2024 19:23:22 -0700 From: Mohan Prasad J To: , , , CC: , , , , , , , , , , , Subject: [PATCH net-next v4 2/3] selftests: nic_link_layer: Add selftest case for speed and duplex states Date: Fri, 15 Nov 2024 00:55:19 +0530 Message-ID: <20241114192545.1742514-3-mohan.prasad@microchip.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241114192545.1742514-1-mohan.prasad@microchip.com> References: <20241114192545.1742514-1-mohan.prasad@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add selftest case for testing the speed and duplex state of local NIC driver and the partner based on the supported link modes obtained from the ethtool. Speed and duplex states are varied and verified using ethtool. Signed-off-by: Mohan Prasad J --- .../drivers/net/hw/nic_link_layer.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tools/testing/selftests/drivers/net/hw/nic_link_layer.py b/too= ls/testing/selftests/drivers/net/hw/nic_link_layer.py index d8cc12e84..efd921180 100644 --- a/tools/testing/selftests/drivers/net/hw/nic_link_layer.py +++ b/tools/testing/selftests/drivers/net/hw/nic_link_layer.py @@ -76,6 +76,28 @@ def test_autonegotiation(cfg: object, link_config: LinkC= onfig, time_delay: int) time.sleep(time_delay) verify_autonegotiation(cfg, state, link_config) =20 +def test_network_speed(cfg: object, link_config: LinkConfig, time_delay: i= nt) -> None: + _pre_test_checks(cfg, link_config) + common_link_modes =3D link_config.common_link_modes + if not common_link_modes: + KsftSkipEx("No common link modes exist") + speeds, duplex_modes =3D link_config.get_speed_duplex_values(common_li= nk_modes) + + if speeds and duplex_modes and len(speeds) =3D=3D len(duplex_modes): + for idx in range(len(speeds)): + speed =3D speeds[idx] + duplex =3D duplex_modes[idx] + if not link_config.set_speed_and_duplex(speed, duplex): + raise KsftFailEx(f"Unable to set speed and duplex paramete= rs for {cfg.ifname}") + time.sleep(time_delay) + if not link_config.verify_speed_and_duplex(speed, duplex): + raise KsftSkipEx(f"Error occurred while verifying speed an= d duplex states for interface {cfg.ifname}") + else: + if not speeds or not duplex_modes: + KsftSkipEx(f"No supported speeds or duplex modes found for int= erface {cfg.ifname}") + else: + KsftSkipEx("Mismatch in the number of speeds and duplex modes") + def main() -> None: parser =3D argparse.ArgumentParser(description=3D"Run basic link layer= tests for NIC driver") parser.add_argument('--time-delay', type=3Dint, default=3D8, help=3D'T= ime taken to wait for transitions to happen(in seconds). Default is 8 secon= ds.') --=20 2.43.0 From nobody Sat Nov 23 03:04:06 2024 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 201A21442F4; Fri, 15 Nov 2024 02:25:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.154.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731637559; cv=none; b=GEzqOgIcX4UsM46GLUJJtv4ChLBZx5Le1SN0cp5Y4+Jl7RoN0e91rVzowEyubxgo1t8CklVigiFcyPaWs5mz/4CIEstLiGP8tGAv4+6PWwaStmZxsHmVkNPxQULNnrN9eBn8+X36TbrSj9TWGz4XDv06fZD6U8CbBVZZZZ+HRXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731637559; c=relaxed/simple; bh=Q/FqzVI86T2PL06lpAwTVGipB5NTfw5oUN3fUT9Pudo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QX3vhoKhiAqHFz8MfZ8uF9sayOhVZ9K3itWqm1tdSFgNXIHewXQeAgLPosGCGdYVDLzp7cwGxKHEizr50bZKA1vR/kcsyqYDHrqDGh1G2mueGriTu7IghV7uW3KyBnWQ7UIdsel5muKMASGXK6urcEvO0tZ/dAePfpRc3K+yeeY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=VK7hJ5zq; arc=none smtp.client-ip=68.232.154.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="VK7hJ5zq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1731637557; x=1763173557; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Q/FqzVI86T2PL06lpAwTVGipB5NTfw5oUN3fUT9Pudo=; b=VK7hJ5zqXCTMngsMd7qlpbMIxU/vxs3NOJ4x/S/UtWA6N4Huqx9tLJ+p jM1oSc2x+TbRXZDhZEnWB/FwsbkFZyh7zEdEkt4Ic3z8WAfznEk8yGjEK x1NQGP7XHtk/XmzX7s7fZtPWeHsv3hNrEWX142vxkueQI6Kwt71H+fHJK WSWJTCPAEfCQ9xPSdz/I7aqoEK/Cq1tPP+e8DvJhQ8eOUSQ3RqyrcwcRf 8TmeHNf6dC/tR/c5Iw6bqAaQoTKdAva6GSuinazKw8SHtjIeXrC1+uLu6 s/DyJXGJVMFpkrncOWV+DhPzpHX+NEOoQcRSo6bQyVq5KIbzxRBm1ikCZ A==; X-CSE-ConnectionGUID: QjuG0j+zR8eJOiYtRT/ezA== X-CSE-MsgGUID: f9zCoi30QROEMbR52xbuZA== X-IronPort-AV: E=Sophos;i="6.12,155,1728975600"; d="scan'208";a="34078315" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa4.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Nov 2024 19:23:38 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 14 Nov 2024 19:23:38 -0700 Received: from nisar-OptiPlex-9020.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 14 Nov 2024 19:23:33 -0700 From: Mohan Prasad J To: , , , CC: , , , , , , , , , , , Subject: [PATCH net-next v4 3/3] selftests: nic_performance: Add selftest for performance of NIC driver Date: Fri, 15 Nov 2024 00:55:20 +0530 Message-ID: <20241114192545.1742514-4-mohan.prasad@microchip.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241114192545.1742514-1-mohan.prasad@microchip.com> References: <20241114192545.1742514-1-mohan.prasad@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Add selftest case to check the send and receive throughput. Supported link modes between local NIC driver and partner are varied. Then send and receive throughput is captured and verified. Test uses iperf3 tool. Add iperf3 server/client function in GenerateTraffic class. Signed-off-by: Mohan Prasad J --- .../testing/selftests/drivers/net/hw/Makefile | 1 + .../drivers/net/hw/nic_performance.py | 137 ++++++++++++++++++ .../selftests/drivers/net/lib/py/load.py | 20 ++- 3 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/drivers/net/hw/nic_performance.= py diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testin= g/selftests/drivers/net/hw/Makefile index 7939f81fe..e400fd097 100644 --- a/tools/testing/selftests/drivers/net/hw/Makefile +++ b/tools/testing/selftests/drivers/net/hw/Makefile @@ -12,6 +12,7 @@ TEST_PROGS =3D \ hw_stats_l3_gre.sh \ loopback.sh \ nic_link_layer.py \ + nic_performance.py \ pp_alloc_fail.py \ rss_ctx.py \ # diff --git a/tools/testing/selftests/drivers/net/hw/nic_performance.py b/to= ols/testing/selftests/drivers/net/hw/nic_performance.py new file mode 100644 index 000000000..201403b76 --- /dev/null +++ b/tools/testing/selftests/drivers/net/hw/nic_performance.py @@ -0,0 +1,137 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +#Introduction: +#This file has basic performance test for generic NIC drivers. +#The test comprises of throughput check for TCP and UDP streams. +# +#Setup: +#Connect the DUT PC with NIC card to partner pc back via ethernet medium o= f your choice(RJ45, T1) +# +# DUT PC Partner PC +#=E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =90 =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 +#=E2=94=82 =E2=94=82 =E2=94= =82 =E2=94=82 +#=E2=94=82 =E2=94=82 =E2=94= =82 =E2=94=82 +#=E2=94=82 =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 = =E2=94=82 =E2=94=82 +#=E2=94=82 =E2=94=82DUT NIC =E2=94=82 Eth = =E2=94=82 =E2=94=82 +#=E2=94=82 =E2=94=82Interface =E2=94=80=E2=94=BC=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94= =80 any eth Interface =E2=94=82 +#=E2=94=82 =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=98 = =E2=94=82 =E2=94=82 +#=E2=94=82 =E2=94=82 =E2=94= =82 =E2=94=82 +#=E2=94=82 =E2=94=82 =E2=94= =82 =E2=94=82 +#=E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =98 =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=98 +# +#Configurations: +#To prevent interruptions, Add ethtool, ip to the sudoers list in remote P= C and get the ssh key from remote. +#Required minimum ethtool version is 6.10 +#Change the below configuration based on your hw needs. +# """Default values""" +#time_delay =3D 8 #time taken to wait for transitions to happen, in second= s. +#test_duration =3D 10 #performance test duration for the throughput check= , in seconds. +#send_throughput_threshold =3D 80 #percentage of send throughput required = to pass the check +#receive_throughput_threshold =3D 50 #percentage of receive throughput req= uired to pass the check + +import time +import json +import argparse +from lib.py import ksft_run, ksft_exit, ksft_pr, ksft_true +from lib.py import KsftFailEx, KsftSkipEx, GenerateTraffic +from lib.py import NetDrvEpEnv, bkg, wait_port_listen +from lib.py import cmd +from lib.py import LinkConfig + +class TestConfig: + def __init__(self, time_delay: int, test_duration: int, send_throughpu= t_threshold: int, receive_throughput_threshold: int) -> None: + self.time_delay =3D time_delay + self.test_duration =3D test_duration + self.send_throughput_threshold =3D send_throughput_threshold + self.receive_throughput_threshold =3D receive_throughput_threshold + +def _pre_test_checks(cfg: object, link_config: LinkConfig) -> None: + if not link_config.verify_link_up(): + KsftSkipEx(f"Link state of interface {cfg.ifname} is DOWN") + common_link_modes =3D link_config.common_link_modes + if common_link_modes is None: + KsftSkipEx("No common link modes found") + if link_config.partner_netif =3D=3D None: + KsftSkipEx("Partner interface is not available") + if link_config.check_autoneg_supported(): + KsftSkipEx("Auto-negotiation not supported by local") + if link_config.check_autoneg_supported(remote=3DTrue): + KsftSkipEx("Auto-negotiation not supported by remote") + cfg.require_cmd("iperf3", remote=3DTrue) + +def check_throughput(cfg: object, link_config: LinkConfig, test_config: Te= stConfig, protocol: str, traffic: GenerateTraffic) -> None: + common_link_modes =3D link_config.common_link_modes + speeds, duplex_modes =3D link_config.get_speed_duplex_values(common_li= nk_modes) + """Test duration in seconds""" + duration =3D test_config.test_duration + + ksft_pr(f"{protocol} test") + test_type =3D "-u" if protocol =3D=3D "UDP" else "" + + send_throughput =3D [] + receive_throughput =3D [] + for idx in range(0, len(speeds)): + if link_config.set_speed_and_duplex(speeds[idx], duplex_modes[idx]= ) =3D=3D False: + raise KsftFailEx(f"Not able to set speed and duplex parameters= for {cfg.ifname}") + time.sleep(test_config.time_delay) + if not link_config.verify_link_up(): + raise KsftSkipEx(f"Link state of interface {cfg.ifname} is DOW= N") + + send_command=3Df"{test_type} -b 0 -t {duration} --json" + receive_command=3Df"{test_type} -b 0 -t {duration} --reverse --jso= n" + + send_result =3D traffic.run_remote_test(cfg, command=3Dsend_comman= d) + if send_result.ret !=3D 0: + raise KsftSkipEx("Error occurred during data transmit: {send_r= esult.stdout}") + + send_output =3D send_result.stdout + send_data =3D json.loads(send_output) + + """Convert throughput to Mbps""" + send_throughput.append(round(send_data['end']['sum_sent']['bits_pe= r_second'] / 1e6, 2)) + ksft_pr(f"{protocol}: Send throughput: {send_throughput[idx]} Mbps= ") + + receive_result =3D traffic.run_remote_test(cfg, command=3Dreceive_= command) + if receive_result.ret !=3D 0: + raise KsftSkipEx("Error occurred during data receive: {receive= _result.stdout}") + + receive_output =3D receive_result.stdout + receive_data =3D json.loads(receive_output) + + """Convert throughput to Mbps""" + receive_throughput.append(round(receive_data['end']['sum_received'= ]['bits_per_second'] / 1e6, 2)) + ksft_pr(f"{protocol}: Receive throughput: {receive_throughput[idx]= } Mbps") + + """Check whether throughput is not below the threshold (default values= set at start)""" + for idx in range(0, len(speeds)): + send_threshold =3D float(speeds[idx]) * float(test_config.send_thr= oughput_threshold / 100) + receive_threshold =3D float(speeds[idx]) * float(test_config.recei= ve_throughput_threshold / 100) + ksft_true(send_throughput[idx] >=3D send_threshold, f"{protocol}: = Send throughput is below threshold for {speeds[idx]} Mbps in {duplex_modes[= idx]} duplex") + ksft_true(receive_throughput[idx] >=3D receive_threshold, f"{proto= col}: Receive throughput is below threshold for {speeds[idx]} Mbps in {dupl= ex_modes[idx]} duplex") + +def test_tcp_throughput(cfg: object, link_config: LinkConfig, test_config:= TestConfig, traffic: GenerateTraffic) -> None: + _pre_test_checks(cfg, link_config) + check_throughput(cfg, link_config, test_config, 'TCP', traffic) + +def test_udp_throughput(cfg: object, link_config: LinkConfig, test_config:= TestConfig, traffic: GenerateTraffic) -> None: + _pre_test_checks(cfg, link_config) + check_throughput(cfg, link_config, test_config, 'UDP', traffic) + +def main() -> None: + parser =3D argparse.ArgumentParser(description=3D"Run basic performanc= e test for NIC driver") + parser.add_argument('--time-delay', type=3Dint, default=3D8, help=3D'T= ime taken to wait for transitions to happen(in seconds). Default is 8 secon= ds.') + parser.add_argument('--test-duration', type=3Dint, default=3D10, help= =3D'Performance test duration for the throughput check, in seconds. Default= is 10 seconds.') + parser.add_argument('--stt', type=3Dint, default=3D80, help=3D'Send th= roughput Threshold: Percentage of send throughput upon actual throughput re= quired to pass the throughput check (in percentage). Default is 80.') + parser.add_argument('--rtt', type=3Dint, default=3D50, help=3D'Receive= throughput Threshold: Percentage of receive throughput upon actual through= put required to pass the throughput check (in percentage). Default is 50.') + args=3Dparser.parse_args() + test_config =3D TestConfig(args.time_delay, args.test_duration, args.s= tt, args.rtt) + with NetDrvEpEnv(__file__, nsim_test=3DFalse) as cfg: + traffic =3D GenerateTraffic(cfg) + link_config =3D LinkConfig(cfg) + ksft_run(globs=3Dglobals(), case_pfx=3D{"test_"}, args=3D(cfg, lin= k_config, test_config, traffic, )) + link_config.reset_interface() + ksft_exit() + +if __name__ =3D=3D "__main__": + main() diff --git a/tools/testing/selftests/drivers/net/lib/py/load.py b/tools/tes= ting/selftests/drivers/net/lib/py/load.py index d9c10613a..da5af2c68 100644 --- a/tools/testing/selftests/drivers/net/lib/py/load.py +++ b/tools/testing/selftests/drivers/net/lib/py/load.py @@ -2,7 +2,7 @@ =20 import time =20 -from lib.py import ksft_pr, cmd, ip, rand_port, wait_port_listen +from lib.py import ksft_pr, cmd, ip, rand_port, wait_port_listen, bkg =20 class GenerateTraffic: def __init__(self, env, port=3DNone): @@ -23,6 +23,24 @@ class GenerateTraffic: self.stop(verbose=3DTrue) raise Exception("iperf3 traffic did not ramp up") =20 + def run_remote_test(self, env: object, port=3DNone, command=3DNone): + if port is None: + port =3D rand_port() + try: + server_cmd =3D f"iperf3 -s 1 -p {port} --one-off" + with bkg(server_cmd, host=3Denv.remote): + #iperf3 opens TCP connection as default in server + #-u to be specified in client command for UDP + wait_port_listen(port, host=3Denv.remote) + except Exception as e: + raise Exception(f"Unexpected error occurred while running serv= er command: {e}") + try: + client_cmd =3D f"iperf3 -c {env.remote_addr} -p {port} {comman= d}" + proc =3D cmd(client_cmd) + return proc + except Exception as e: + raise Exception(f"Unexpected error occurred while running clie= nt command: {e}") + def _wait_pkts(self, pkt_cnt=3DNone, pps=3DNone): """ Wait until we've seen pkt_cnt or until traffic ramps up to pps. --=20 2.43.0