From nobody Tue Nov 26 17:40:19 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 2901314EC47; Thu, 17 Oct 2024 04:47: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=1729140480; cv=none; b=Wk8IheumqyGRVNsqEYxDzgykIDovUxMRWpjDXZeUXU1XCMmBfQ/7tRcFR+uozDv/pd1LZmB6tAHevwqHFiyqFpwruVeGkDFlqTIf5aGXxEE8n4a+L0qZ2dceAwG4qaZjR+BrG0oB+F13AJtMEO+txNp8MhmPkdCS78Y+NZ1o2vs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729140480; c=relaxed/simple; bh=z6t5jam2u2/qWSb3wbi2/QDu1djFH81oyHBk5nMiNsg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iAVs+yIy8YgPNrcCeU76aLmPMUakBb4pWotN6qYDL/WmrUYZlypoRgVbRVTF33QheQ0cMr1dzNWcO4aTpopeZNI/IyFFLDsEyb6z6kjqAtH1qld0/z1bBuEAgQcycW1sojAzinlfy4iuKdaVGXZzhW/xs+T7hDC8qKJLQNj+710= 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=qGMQL8yN; 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="qGMQL8yN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1729140475; x=1760676475; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=z6t5jam2u2/qWSb3wbi2/QDu1djFH81oyHBk5nMiNsg=; b=qGMQL8yNzP0Fd1DIssaBSVEupGUEdoDMA7mwB/5qJIW+hQoOHby94WDs Yzzd0QMlLwc9BOkOkbtUVl/kNUyelkI1xAVKFoZKWjSEHejIwuNbOfybk /q9vm4ANkGMwIX2VDFsWqqxu4gaZGgBZ8cnUkxZmzTKl76QoDD4q/gmrN xGXZ1nZg4MgglBJWP033vV1e0FpSxmmxF/HCrOEQloBkb/WT5Csuf9rIF 1/C7Q6K3JDWNPPceavVC8kCe+wWYMA1JIOR4FZbNanIdYSnCf2skbg9LQ O1OudMq8Nu5Caqq1GYksrmjqA255NxQMwEJ0AjqtfGbK7lo7UGBahEMUe w==; X-CSE-ConnectionGUID: 8pbTCNeqT7aHxiJ1HBLGWw== X-CSE-MsgGUID: xiMjuXNmTMS+F8IIOLsAwA== X-IronPort-AV: E=Sophos;i="6.11,210,1725346800"; d="scan'208";a="200553966" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 16 Oct 2024 21:47:50 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 16 Oct 2024 21:47:27 -0700 Received: from nisar-OptiPlex-9020.microchip.com (10.10.85.11) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Wed, 16 Oct 2024 21:47:22 -0700 From: Mohan Prasad J To: , , , CC: , , , , , , , , , , , Subject: [PATCH net-next v3 1/3] selftests: nic_link_layer: Add link layer selftest for NIC driver Date: Thu, 17 Oct 2024 03:20:05 +0530 Message-ID: <20241016215014.401476-2-mohan.prasad@microchip.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241016215014.401476-1-mohan.prasad@microchip.com> References: <20241016215014.401476-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 | 1 + .../drivers/net/hw/lib/py/__init__.py | 1 + .../drivers/net/hw/lib/py/linkconfig.py | 220 ++++++++++++++++++ .../drivers/net/hw/nic_link_layer.py | 84 +++++++ 4 files changed, 306 insertions(+) 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 c9f2f48fc..0dac40c4e 100644 --- a/tools/testing/selftests/drivers/net/hw/Makefile +++ b/tools/testing/selftests/drivers/net/hw/Makefile @@ -10,6 +10,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..86cbf10a3 --- /dev/null +++ b/tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py @@ -0,0 +1,220 @@ +# SPDX-License-Identifier: GPL-2.0 + +from lib.py import cmd +from lib.py import ethtool +from lib.py import ksft_pr, ksft_eq +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 +#The ethtool and ip would require authentication to make changes, so better +# to check them for sudo privileges for interruption free testing. + +class LinkConfig: + """Class for handling the link layer configurations""" + def __init__(self, cfg): + 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): + partner_netif =3D None + try: + """Get partner interface name""" + partner_cmd =3D f"ip -o -f inet addr show | grep '{self.cfg.re= mote_addr}' " + "| awk '{print $2}'" + partner_output =3D cmd(partner_cmd, host=3Dself.cfg.remote) + partner_netif =3D partner_output.stdout.strip() + ksft_pr(f"Partner Interface name: {partner_netif}") + except Exception as e: + print(f"Unexpected error occurred: {e}") + self.partner_netif =3D partner_netif + return partner_netif + + def verify_link_up(self): + """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=3DTrue, remote=3DTrue): + ksft_pr("Resetting interfaces in local and remote") + if remote: + if self.partner_netif is not None: + ifname =3D self.partner_netif + link_up_cmd =3D f"sudo ip link set up {ifname}" + link_down_cmd =3D f"sudo ip link set down {ifname}" + reset_cmd =3D f"{link_down_cmd} && sleep 5 && {link_up_cmd= }" + try: + cmd(f"{reset_cmd}", host=3Dself.cfg.remote) + except Exception as e: + ksft_pr("Check sudo permission for ip command") + ksft_pr(f"Unexpected error occurred: {e}") + else: + ksft_pr("Partner interface not available") + if local: + ifname =3D self.cfg.ifname + link_up_cmd =3D f"sudo ip link set up {ifname}" + link_down_cmd =3D f"sudo ip link set down {ifname}" + reset_cmd =3D f"{link_down_cmd} && sleep 5 && {link_up_cmd}" + try: + cmd(f"{reset_cmd}") + except Exception as e: + ksft_pr("Check sudo permission for ip command") + ksft_pr(f"Unexpected error occurred: {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: + return False + + def set_speed_and_duplex(self, speed: str, duplex: str, autoneg=3DTrue= ): + """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: {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): + if self.verify_link_up() =3D=3D False: + 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=3DFalse): + 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=3D=3DTrue: + """Set the autonegotiation state for the partner""" + command =3D f"sudo ethtool -s {self.partner_netif} {speed_dupl= ex_cmd} autoneg {state}" + partner_autoneg_change =3D None + """Set autonegotiation state for interface in remote pc""" + try: + partner_autoneg_change =3D cmd(command, host=3Dself.cfg.re= mote) + except Exception as e: + ksft_pr("Check sudo permission for ethtool") + ksft_pr(f"Unexpected error occurred: {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}. Check permissions for ethtool.") + return False + ksft_pr(f"Autoneg set as {state} for {self.partner_netif}") + else: + process =3D None + """Set the autonegotiation state for the interface""" + try: + process =3D ethtool(f"-s {self.cfg.ifname} {speed_duplex_c= md} autoneg {state}") + except Exception as e: + ksft_pr("Check sudo permission for ethtool") + ksft_pr(f"Unexpected error occurred: {e}") + if process is None or process.ret !=3D 0: + ksft_pr(f"Not able to set autoneg parameter for interface = {self.cfg.ifname}") + return False + ksft_pr(f"Autoneg set as {state} for {self.cfg.ifname}") + return True + + def check_autoneg_supported(self, remote=3DFalse): + if remote=3D=3DFalse: + 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""" + status =3D True if local_autoneg =3D=3D True else False + return status + else: + """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 {partner_netif}") + status =3D True if partner_autoneg is True else False + return status + + def get_common_link_modes(self): + common_link_modes =3D None + """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 Exception(f"Link modes not available for {self.cfg.ifnam= e}") + if partner_link_modes is None: + raise Exception(f"Partner link modes not available for {self.c= fg.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): + 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=3DFalse): + process =3D None + if remote =3D=3D False: + """Get the ethtool field value for the local interface""" + ifname =3D self.cfg.ifname + try: + process =3D ethtool(f"--json {ifname}") + except Exception as e: + ksft_pr("Required minimum ethtool version is 6.10") + ksft_pr(f"Unexpected error occurred: {e}") + else: + """Get the ethtool field value for the remote interface""" + remote =3D True + ifname =3D self.partner_netif + self.cfg.require_cmd("ethtool", remote) + command =3D f"ethtool --json {ifname}" + try: + process =3D cmd(command, host=3Dself.cfg.remote) + except Exception as e: + ksft_pr("Required minimum ethtool version is 6.10") + ksft_pr("Unexpected error occurred: {e}") + if process is None or process.ret !=3D 0: + print(f"Error while getting the ethtool content for interface = {ifname}. Required minimum ethtool version is 6.10") + return None + output =3D json.loads(process.stdout) + json_data =3D output[0] + """Check if the field exist in the json data""" + if field not in json_data: + raise Exception(f"Field {field} does not exist in the output o= f interface {json_data["ifname"]}") + return None + 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..fb046efbe --- /dev/null +++ b/tools/testing/selftests/drivers/net/hw/nic_link_layer.py @@ -0,0 +1,84 @@ +#!/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: +#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 seconds. +test_duration =3D 10 #performance test duration for the throughput check,= in seconds. + +import time +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 verify_autonegotiation(cfg, expected_state: str, link_config) -> None: + if link_config.verify_link_up() =3D=3D False: + 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""" + 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, link_config) -> None: + if link_config.partner_netif =3D=3D None: + KsftSkipEx("Partner interface name 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}") + for state in ["off", "on"]: + if link_config.set_autonegotiation_state(state, remote=3DTrue) =3D= =3D False: + raise KsftSkipEx(f"Unable to set auto-negotiation state for in= terface {link_config.partner_netif}") + if link_config.set_autonegotiation_state(state) =3D=3D False: + 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: + 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,)) + link_config.reset_interface() + ksft_exit() + +if __name__ =3D=3D "__main__": + main() --=20 2.43.0 From nobody Tue Nov 26 17:40:19 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 C26E715C139; Thu, 17 Oct 2024 04:47: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=1729140478; cv=none; b=gi/Cxt9AfNnbe4AsCJ3cb7yiQc1wxVhlHDa8TqTBaFPSzOdmmSjxi6BcHdF13GiC319uYXbIuW54U2Lar65Kiz0dykSqX/be4Nnh/mP1taeJyqnQthttg+dqRFrEWfETH1pRBSNK+leFOJeIH8mqBm4arXqMz9sIjTnE9j8m4Zo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729140478; c=relaxed/simple; bh=7LgSNHRO6Vnu+y4V9uslcARGBrj2FWHJd03mIg0UZ5s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RmPRwBkoCUha4lsfrB2zqvBDnyCNnnU9rxgXhAjYO9E3pGxOkIwA7Xgq8kWNCxQ0A3aaSJ/+wqZ6rop6feO6+V4Wt92QsACVS+NPUaLSamNTulUdcl/jfGDT9o7CZ04dyxNIDNbYBk2nkMoRE6eoiRUD9uOYnYXtmhgqZRPuYe0= 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=guDISHgE; 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="guDISHgE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1729140475; x=1760676475; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7LgSNHRO6Vnu+y4V9uslcARGBrj2FWHJd03mIg0UZ5s=; b=guDISHgEF2dcSLSRuJZOn/dUlvxHgQoLBujtaNcqZicHDlZWkGpPh4SV lZKZWf33akDMBDZh7sc4YZhVlYmooGJ+XgVtHTPrUyVvdIPeTQIg10UcL u6fLruAiMZna+Ff/2B2CNhDlslU8NeUsd7aNVJY/H1/xKwCjRAUYBrv9q /assH7acD5ZjbwEK2b2z2RoT0AYzT/5n3IT8P2pygFdnzn2JJosvLU0Aw +ls+R6oMVwXCXMl1s3xd4cfMJDEM37AloYT7VDbQfVSAZ3zF1/yQjkYuB 2r8RVSU6oZtNunmq/HeVVuBPx649NwmiH87voKfgHHkQuelJdmskdJF15 Q==; X-CSE-ConnectionGUID: 8pbTCNeqT7aHxiJ1HBLGWw== X-CSE-MsgGUID: LZS7e8iGREuinqFeL0j2qg== X-IronPort-AV: E=Sophos;i="6.11,210,1725346800"; d="scan'208";a="200553967" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 16 Oct 2024 21:47:51 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 16 Oct 2024 21:47:34 -0700 Received: from nisar-OptiPlex-9020.microchip.com (10.10.85.11) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Wed, 16 Oct 2024 21:47:29 -0700 From: Mohan Prasad J To: , , , CC: , , , , , , , , , , , Subject: [PATCH net-next v3 2/3] selftests: nic_link_layer: Add selftest case for speed and duplex states Date: Thu, 17 Oct 2024 03:20:06 +0530 Message-ID: <20241016215014.401476-3-mohan.prasad@microchip.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241016215014.401476-1-mohan.prasad@microchip.com> References: <20241016215014.401476-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 | 21 +++++++++++++++++++ 1 file changed, 21 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 fb046efbe..4548da3d9 100644 --- a/tools/testing/selftests/drivers/net/hw/nic_link_layer.py +++ b/tools/testing/selftests/drivers/net/hw/nic_link_layer.py @@ -73,6 +73,27 @@ def test_autonegotiation(cfg, link_config) -> None: time.sleep(time_delay) verify_autonegotiation(cfg, state, link_config) =20 +def test_network_speed(cfg, link_config) -> None: + 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 link_config.set_speed_and_duplex(speed, duplex) =3D=3D Fals= e: + raise KsftFailEx(f"Unable to set speed and duplex paramete= rs for {cfg.ifname}") + time.sleep(time_delay) + if link_config.verify_speed_and_duplex(speed, duplex) =3D=3D F= alse: + raise KsftSkipEx(f"Unable to verify speed and duplex state= s 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: with NetDrvEpEnv(__file__, nsim_test=3DFalse) as cfg: link_config =3D LinkConfig(cfg) --=20 2.43.0 From nobody Tue Nov 26 17:40:19 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 1F5D01791EB; Thu, 17 Oct 2024 04:47:59 +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=1729140482; cv=none; b=XeewoW5kvP5BxgS6UEHSDvMPsGqnttz/m0rXsKmGKjkHE1dWRJCMHSYcPOafcGDwfUjQYUJbdoGqJRdEH9scoGDnfPsyLSvqslQ+VLDAhDEAuQo8KbHxmmsffJpYJ5eiz2eMXnINoBYXODNUlaKivYnCEj8IvtbSzQntsIyMKfw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729140482; c=relaxed/simple; bh=hGoy1m3iAmRAPhSfvDXhU4J22za0qmzPoPvGb1PP6Ek=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=m/nic+XFrVd/O/YoOvGKdqRFQP8EE5cw8OoyjPHfn4DAFB/piJ01BUZL1ymiWqWwSUo9XllPSKN40dx1OdHHWQ3MB9SxYsdGOK++ENqyOsFW5HjhG5aNXVgOHFJznDzwhgLu/oSIMFon3qUu36XjCqja7b25bxmhu2ckM9gFMvI= 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=Y9EDVH5S; 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="Y9EDVH5S" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1729140479; x=1760676479; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hGoy1m3iAmRAPhSfvDXhU4J22za0qmzPoPvGb1PP6Ek=; b=Y9EDVH5Sj/hXkAiJEpVHr1TlbdlUYxpBgOKiwDou3dzmVTt3ZkTseHFi 7EXVWn1zIjbi1IxGEP2d6Z1lFInGywj8oihGohodwma5sGelhB8xD1tsM lUf/OKHE2P1jmr+78muUx1UCcNxzoWgXV9vfPBs5JiOTiuTplPlV94d+7 T5AeiqQ7LHE4A/vcm6XopmmLmt694lOP8MzkD70kHVltROF4qOAfdfWJ3 mc32mllk5ZRp9TuTVx6f/RMl7552pzkd/u0ptLYSLzFRcrhEa9k7ZOpNb Mzwyaqm3+Kxk/m+ga/YyeDv3/8xp/IGb2qak7A0sHwmvd8SmjvH0Q7B+t A==; X-CSE-ConnectionGUID: 8pbTCNeqT7aHxiJ1HBLGWw== X-CSE-MsgGUID: JcJNttygRZG6oNzePtkFsw== X-IronPort-AV: E=Sophos;i="6.11,210,1725346800"; d="scan'208";a="200553968" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 16 Oct 2024 21:47:51 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 16 Oct 2024 21:47:41 -0700 Received: from nisar-OptiPlex-9020.microchip.com (10.10.85.11) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Wed, 16 Oct 2024 21:47:36 -0700 From: Mohan Prasad J To: , , , CC: , , , , , , , , , , , Subject: [PATCH net-next v3 3/3] selftests: nic_performance: Add selftest for performance of NIC driver Date: Thu, 17 Oct 2024 03:20:07 +0530 Message-ID: <20241016215014.401476-4-mohan.prasad@microchip.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241016215014.401476-1-mohan.prasad@microchip.com> References: <20241016215014.401476-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. Signed-off-by: Mohan Prasad J --- .../testing/selftests/drivers/net/hw/Makefile | 1 + .../drivers/net/hw/nic_performance.py | 121 ++++++++++++++++++ 2 files changed, 122 insertions(+) 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 0dac40c4e..289512092 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_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..152c62511 --- /dev/null +++ b/tools/testing/selftests/drivers/net/hw/nic_performance.py @@ -0,0 +1,121 @@ +#!/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 seconds. +test_duration =3D 10 #performance test duration for the throughput check,= in seconds. +send_throughput_threshold =3D 80 #percentage of send throughput required t= o pass the check +receive_throughput_threshold =3D 50 #percentage of receive throughput requ= ired to pass the check + +import time +import json +from lib.py import ksft_run, ksft_exit, ksft_pr, ksft_true +from lib.py import KsftFailEx, KsftSkipEx +from lib.py import NetDrvEpEnv +from lib.py import cmd +from lib.py import LinkConfig + +def verify_throughput(cfg, link_config) -> None: + protocols =3D ["TCP", "UDP"] + 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_duration + target_ip =3D cfg.remote_addr + + for protocol in protocols: + 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)): + bit_rate =3D f"-b {speeds[idx]}M" if protocol =3D=3D "UDP" els= e "" + 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 parame= ters for {cfg.ifname}") + time.sleep(time_delay) + if link_config.verify_link_up() =3D=3D False: + raise KsftSkipEx(f"Link state of interface {cfg.ifname} is= DOWN") + send_command=3Df"iperf3 {test_type} -c {target_ip} {bit_rate} = -t {duration} --json" + receive_command=3Df"iperf3 {test_type} -c {target_ip} {bit_rat= e} -t {duration} --reverse --json" + send_result =3D cmd(send_command) + receive_result =3D cmd(receive_command) + if send_result.ret !=3D 0 or receive_result.ret !=3D 0: + raise KsftSkipEx("Unexpected error occurred during transmi= t/receive") + + send_output =3D send_result.stdout + receive_output =3D receive_result.stdout + + send_data =3D json.loads(send_output) + receive_data =3D json.loads(receive_output) + """Convert throughput to Mbps""" + send_throughput.append(round(send_data['end']['sum_sent']['bit= s_per_second'] / 1e6, 2)) + receive_throughput.append(round(receive_data['end']['sum_recei= ved']['bits_per_second'] / 1e6, 2)) + + ksft_pr(f"{protocol}: Send throughput: {send_throughput[idx]} = Mbps, Receive throughput: {receive_throughput[idx]} Mbps") + + """Check whether throughput is not below the threshold (default va= lues set at start)""" + for idx in range(0, len(speeds)): + send_threshold =3D float(speeds[idx]) * float(send_throughput_= threshold / 100) + receive_threshold =3D float(speeds[idx]) * float(receive_throu= ghput_threshold / 100) + ksft_true(send_throughput[idx] >=3D send_threshold, f"{protoco= l}: Send throughput is below threshold for {speeds[idx]} Mbps in {duplex_mo= des[idx]} duplex") + ksft_true(receive_throughput[idx] >=3D receive_threshold, f"{p= rotocol}: Receive throughput is below threshold for {speeds[idx]} Mbps in {= duplex_modes[idx]} duplex") + +def test_throughput(cfg, link_config) -> None: + common_link_modes =3D link_config.common_link_modes + if not common_link_modes: + KsftSkipEx("No common link modes found") + if link_config.partner_netif =3D=3D None: + KsftSkipEx("Partner interface name not available") + if link_config.check_autoneg_supported() and link_config.check_autoneg= _supported(remote=3DTrue): + KsftSkipEx("Auto-negotiation not supported by local or remote") + cfg.require_cmd("iperf3", remote=3DTrue) + try: + """iperf3 server to be run in the remote pc""" + command =3D "iperf3 -s -D" + process =3D cmd(command, host=3Dcfg.remote) + if "Address already in use" in process.stdout: + ksft_pr("Iperf server already running in remote") + elif process.ret !=3D 0: + raise KsftSkipEx("Unable to start server in remote PC") + verify_throughput(cfg, link_config) + except Exception as e: + raise KsftSkipEx(f"Unexpected error occurred: {e}") + finally: + """Kill existing iperf server in remote pc""" + try: + cmd("pkill iperf3", host=3Dcfg.remote) + except Exception as e: + ksft_pr("Unable to stop iperf3 server in remote") + +def main() -> None: + 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,)) + link_config.reset_interface() + ksft_exit() + +if __name__ =3D=3D "__main__": + main() --=20 2.43.0