Skip to contentSkip to conversation

selftests: Add selftest for link layer and performance testing

PATCH Superseded Mohan Prasad J 2 participants 8 messages Oct 17, 2024 – Oct 24, 2024

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover selftests: Add selftest for link layer and performance testing

The series of patches are for doing basic tests of NIC driver. Test comprises checks for auto-negotiation, speed, duplex state and throughput between local NIC and partner. Tools such as ethtool, iperf3 are used.

---
Changes in v3:
- LinkConfig class is included in the hw library. This contains generic APIs for doing link layer operations.
- Auto-negotiation checks involve changing the auto-neg state both in local and partner NIC.
- Link layer test and performance test are separated to different selftest files.
- Resetting of NIC driver done after test completion.

Changes in v2:
- Changed the hardcoded implementation of speed, duplex states, throughput to generic values, in order to support all type of NIC drivers.
- Test executes based on the supported link modes between local NIC driver and partner.
- Instead of lan743x directory, selftest file is now relocated to /selftests/drivers/net/hw.
---
Mohan Prasad J (3):
selftests: nic_link_layer: Add link layer selftest for NIC driver
selftests: nic_link_layer: Add selftest case for speed and duplex
states
selftests: nic_performance: Add selftest for performance of NIC driver

 .../testing/selftests/drivers/net/hw/Makefile |   2 +
 .../drivers/net/hw/lib/py/__init__.py         |   1 +
 .../drivers/net/hw/lib/py/linkconfig.py       | 220 ++++++++++++++++++
 .../drivers/net/hw/nic_link_layer.py          | 105 +++++++++
 .../drivers/net/hw/nic_performance.py         | 121 ++++++++++
 5 files changed, 449 insertions(+)
 create mode 100644 tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py
 create mode 100644 tools/testing/selftests/drivers/net/hw/nic_link_layer.py
 create mode 100644 tools/testing/selftests/drivers/net/hw/nic_performance.py
Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 1/3 selftests: nic_link_layer: Add link layer selftest for NIC driver

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.

---
 .../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/linkconfig.py
 create mode 100644 tools/testing/selftests/drivers/net/hw/nic_link_layer.py
tools/testing/selftests/drivers/net/hw/Makefile +1 -0
index c9f2f48fc..0dac40c4e 100644
@@ -10,6 +10,7 @@ TEST_PROGS = \
 	hw_stats_l3.sh \
 	hw_stats_l3_gre.sh \
 	loopback.sh \
+	nic_link_layer.py \
 	pp_alloc_fail.py \
 	rss_ctx.py \
 	#
tools/testing/selftests/drivers/net/hw/lib/py/__init__.py +1 -0
index b58288578..399789a96 100644
@@ -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))
tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py new file +220 -0

220 lines not on this page · raw message

tools/testing/selftests/drivers/net/hw/nic_link_layer.py new file +84 -0

84 lines not on this page · raw message

Signature · 1 line
2.43.0
maintainer
#2 lore raw

Re: [PATCH net-next v3 1/3] selftests: nic_link_layer: Add link layer selftest for NIC driver

Quoted 60 lines · Mohan Prasad J

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.

---
 .../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/linkconfig.py
 create mode 100644 tools/testing/selftests/drivers/net/hw/nic_link_layer.py
tools/testing/selftests/drivers/net/hw/Makefile +1 -0
index c9f2f48fc..0dac40c4e 100644
@@ -10,6 +10,7 @@ TEST_PROGS = \
 	hw_stats_l3.sh \
 	hw_stats_l3_gre.sh \
 	loopback.sh \
+	nic_link_layer.py \
 	pp_alloc_fail.py \
 	rss_ctx.py \
 	#
tools/testing/selftests/drivers/net/hw/lib/py/__init__.py +1 -0
index b58288578..399789a96 100644
@@ -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))
tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py new file +14 -0
new file mode 100644
index 000000000..86cbf10a3
@@ -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 configurations.
+#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.
+

tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py line 24

Quoted 10 lines
tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py new file +10 -0
+class LinkConfig:
+    """Class for handling the link layer configurations"""
+    def __init__(self, cfg):
+        self.cfg = cfg
+        self.partner_netif = self.get_partner_netif_name()
+
+        """Get the initial link configuration of local interface"""
+        self.common_link_modes = self.get_common_link_modes()
+
+    def get_partner_netif_name(self):

You should use type hints for both the arguments and the return type.

tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py line 28

Quoted 4 lines
tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py new file +4 -0
+        partner_netif = None
+        try:
+            """Get partner interface name"""
+            partner_cmd = f"ip -o -f inet addr show | grep '{self.cfg.remote_addr}' " + "| awk '{print $2}'"

It's better if you use json output even here

[...]

tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py line 60

Quoted 13 lines
tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py new file +13 -0
+    def reset_interface(self, local=True, remote=True):
+        ksft_pr("Resetting interfaces in local and remote")
+        if remote:
+            if self.partner_netif is not None:
+                ifname = self.partner_netif
+                link_up_cmd = f"sudo ip link set up {ifname}"
+                link_down_cmd = f"sudo ip link set down {ifname}"
+                reset_cmd = f"{link_down_cmd} && sleep 5 && {link_up_cmd}"
+                try:
+                    cmd(f"{reset_cmd}", host=self.cfg.remote)
+                except Exception as e:
+                    ksft_pr("Check sudo permission for ip command")
+                    ksft_pr(f"Unexpected error occurred: {e}")

Please, don't use sudo, just run the command directly. The selftests should be executed only by privileged users.

[...]

tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py line 152

Quoted 8 lines
tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py new file +8 -0
+    def check_autoneg_supported(self, remote=False):
+        if remote==False:
+            local_autoneg = self.get_ethtool_field("supports-auto-negotiation")
+            if local_autoneg is None:
+                ksft_pr(f"Unable to fetch auto-negotiation status for interface {self.cfg.ifname}")
+            """Return autoneg status of the local interface"""
+            status = True if local_autoneg == True else False
+            return status

Out of sheer ignorance, in't

return local_autoneg

enough?

Quoted 93 lines
tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py new file +68 -0
+        else:
+            """Check remote auto-negotiation support status"""
+            partner_autoneg = False
+            if self.partner_netif is not None:
+                partner_autoneg = self.get_ethtool_field("supports-auto-negotiation", remote=True)
+                if partner_autoneg is None:
+                    ksft_pr(f"Unable to fetch auto-negotiation status for interface {partner_netif}")
+            status = True if partner_autoneg is True else False
+            return status
+
+    def get_common_link_modes(self):
+        common_link_modes = None
+        """Populate common link modes"""
+        link_modes = self.get_ethtool_field("supported-link-modes")
+        partner_link_modes = self.get_ethtool_field("link-partner-advertised-link-modes")
+        if link_modes is None:
+            raise Exception(f"Link modes not available for {self.cfg.ifname}")
+        if partner_link_modes is None:
+            raise Exception(f"Partner link modes not available for {self.cfg.ifname}")
+        common_link_modes = set(link_modes) and set(partner_link_modes)
+        return common_link_modes
+
+    def get_speed_duplex_values(self, link_modes):
+        speed = []
+        duplex = []
+        """Check the link modes"""
+        for data in link_modes:
+            parts = data.split('/')
+            speed_value = 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=False):
+        process = None
+        if remote == False:
+            """Get the ethtool field value for the local interface"""
+            ifname = self.cfg.ifname
+            try:
+                process = 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 = True
+            ifname = self.partner_netif
+            self.cfg.require_cmd("ethtool", remote)
+            command = f"ethtool --json {ifname}"
+            try:
+                process = cmd(command, host=self.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 != 0:
+            print(f"Error while getting the ethtool content for interface {ifname}. Required minimum ethtool version is 6.10")
+            return None
+        output = json.loads(process.stdout)
+        json_data = 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 of interface {json_data["ifname"]}")
+            return None
+        return json_data[field]
tools/testing/selftests/drivers/net/hw/nic_link_layer.py new file +19 -0
new file mode 100644
index 000000000..fb046efbe
@@ -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 of your choice(RJ45, T1)
+#
+#        DUT PC                                              Partner PC
+#┌───────────────────────┐                         ┌──────────────────────────┐
+#│                       │                         │                          │
+#│                       │                         │                          │
+#│           ┌───────────┐                         │                          │
+#│           │DUT NIC    │         Eth             │                          │
+#│           │Interface ─┼─────────────────────────┼─    any eth Interface    │
+#│           └───────────┘                         │                          │
+#│                       │                         │                          │

tools/testing/selftests/drivers/net/hw/nic_link_layer.py line 29

Quoted 10 lines
tools/testing/selftests/drivers/net/hw/nic_link_layer.py new file +10 -0
+#│                       │                         │                          │
+#└───────────────────────┘                         └──────────────────────────┘
+#
+#Configurations:
+#To prevent interruptions, Add ethtool, ip to the sudoers list in remote PC 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 = 8 #time taken to wait for transitions to happen, in seconds.
+test_duration = 10  #performance test duration for the throughput check, in seconds.

It would be probably useful to allow the user overriding the above values via env variables and/or command line arguments.

'test_duration' declaration should probably moved to a later patch, where it's used.

Thanks,

Paolo

#3 lore raw

RE: [PATCH net-next v3 1/3] selftests: nic_link_layer: Add link layer selftest for NIC driver

Hello Paolo,

Thank you for the review comments.

Quoted 63 lines
Quoted 52 lines

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.

---
 .../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/linkconfig.py
 create mode 100644

tools/testing/selftests/drivers/net/hw/nic_link_layer.py

tools/testing/selftests/drivers/net/hw/Makefile +1 -0
index c9f2f48fc..0dac40c4e 100644
@@ -10,6 +10,7 @@ TEST_PROGS = \
      hw_stats_l3.sh \
      hw_stats_l3_gre.sh \
      loopback.sh \
+     nic_link_layer.py \
      pp_alloc_fail.py \
      rss_ctx.py \
      #
tools/testing/selftests/drivers/net/hw/lib/py/__init__.py +1 -0
index b58288578..399789a96 100644
@@ -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

tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py line 10

Quoted 10 lines
tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py new file +10 -0
@@ -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

configurations.

Quoted 16 lines
Quoted 4 lines
tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py new file +4 -0
+#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.
+

tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py line 24

Quoted 10 lines
tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py new file +10 -0
+class LinkConfig:
+    """Class for handling the link layer configurations"""
+    def __init__(self, cfg):
+        self.cfg = cfg
+        self.partner_netif = self.get_partner_netif_name()
+
+        """Get the initial link configuration of local interface"""
+        self.common_link_modes = self.get_common_link_modes()
+
+    def get_partner_netif_name(self):

You should use type hints for both the arguments and the return type.

I will update the type hints wherever applicable, you can find it in the next revision.

Quoted 8 lines

tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py

Quoted 5 lines
tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py new file +4 -0
+        partner_netif = None
+        try:
+            """Get partner interface name"""
+            partner_cmd = f"ip -o -f inet addr show | grep

'{self.cfg.remote_addr}' " + "| awk '{print $2}'"

It's better if you use json output even here

I will update it for json output, you can find it in next version.

Quoted 16 lines

[...]

tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py line 60

Quoted 13 lines
tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py new file +13 -0
+    def reset_interface(self, local=True, remote=True):
+        ksft_pr("Resetting interfaces in local and remote")
+        if remote:
+            if self.partner_netif is not None:
+                ifname = self.partner_netif
+                link_up_cmd = f"sudo ip link set up {ifname}"
+                link_down_cmd = f"sudo ip link set down {ifname}"
+                reset_cmd = f"{link_down_cmd} && sleep 5 && {link_up_cmd}"
+                try:
+                    cmd(f"{reset_cmd}", host=self.cfg.remote)
+                except Exception as e:
+                    ksft_pr("Check sudo permission for ip command")
+                    ksft_pr(f"Unexpected error occurred: {e}")
Quoted 2 lines

Please, don't use sudo, just run the command directly. The selftests should be executed only by privileged users.

The sudo will be removed in the next revision.

Quoted 12 lines

[...]

tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py

Quoted 5 lines
tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py new file +5 -0
+    def check_autoneg_supported(self, remote=False):
+        if remote==False:
+            local_autoneg = self.get_ethtool_field("supports-auto-negotiation")
+            if local_autoneg is None:
+                ksft_pr(f"Unable to fetch auto-negotiation status for interface

{self.cfg.ifname}")

tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py line 152

Quoted 3 lines
tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py new file +3 -0
+            """Return autoneg status of the local interface"""
+            status = True if local_autoneg == True else False
+            return status
Quoted 5 lines

Out of sheer ignorance, in't

return local_autoneg

enough?

This will be updated to return just the local_autoneg.

Quoted 118 lines

tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py

Quoted 7 lines
tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py new file +5 -0
+        else:
+            """Check remote auto-negotiation support status"""
+            partner_autoneg = False
+            if self.partner_netif is not None:
+                partner_autoneg = self.get_ethtool_field("supports-auto-

negotiation", remote=True)

tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py

Quoted 2 lines
tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py new file +2 -0
+                if partner_autoneg is None:
+                    ksft_pr(f"Unable to fetch auto-negotiation status for interface

{partner_netif}")

tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py

Quoted 8 lines
tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py new file +8 -0
+            status = True if partner_autoneg is True else False
+            return status
+
+    def get_common_link_modes(self):
+        common_link_modes = None
+        """Populate common link modes"""
+        link_modes = self.get_ethtool_field("supported-link-modes")
+        partner_link_modes = self.get_ethtool_field("link-partner-advertised-

link-modes")

tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py

Quoted 4 lines
tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py new file +4 -0
+        if link_modes is None:
+            raise Exception(f"Link modes not available for {self.cfg.ifname}")
+        if partner_link_modes is None:
+            raise Exception(f"Partner link modes not available for

{self.cfg.ifname}")

Quoted 31 lines
tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py new file +31 -0
+        common_link_modes = set(link_modes) and set(partner_link_modes)
+        return common_link_modes
+
+    def get_speed_duplex_values(self, link_modes):
+        speed = []
+        duplex = []
+        """Check the link modes"""
+        for data in link_modes:
+            parts = data.split('/')
+            speed_value = 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=False):
+        process = None
+        if remote == False:
+            """Get the ethtool field value for the local interface"""
+            ifname = self.cfg.ifname
+            try:
+                process = 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 = True

tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py

Quoted 10 lines
tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py new file +10 -0
+            ifname = self.partner_netif
+            self.cfg.require_cmd("ethtool", remote)
+            command = f"ethtool --json {ifname}"
+            try:
+                process = cmd(command, host=self.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 != 0:
+            print(f"Error while getting the ethtool content for interface {ifname}.

Required minimum ethtool version is 6.10")

tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py

Quoted 6 lines
tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py new file +6 -0
+            return None
+        output = json.loads(process.stdout)
+        json_data = 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 of

interface {json_data["ifname"]}")

Quoted 11 lines
tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py new file +2 -0
+            return None
+        return json_data[field]
tools/testing/selftests/drivers/net/hw/nic_link_layer.py new file +2 -0
new file mode 100644
index 000000000..fb046efbe
@@ -0,0 +1,84 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0

tools/testing/selftests/drivers/net/hw/nic_link_layer.py line 12

Quoted 10 lines
tools/testing/selftests/drivers/net/hw/nic_link_layer.py new file +10 -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 of your choice(RJ45, T1) #
+#        DUT PC                                              Partner PC
+#┌───────────────────────┐
┌──────────────────────────┐
> +#│                       │                         │                          │
> +#│                       │                         │                          │
> +#│           ┌───────────┐                         │                          │
> +#│           │DUT NIC    │         Eth             │                          │
> +#│           │Interface ─┼─────────────────────────┼─    any eth Interface
│
> +#│           └───────────┘                         │                          │
> +#│                       │                         │                          │
> +#│                       │                         │                          │
> +#└───────────────────────┘
└──────────────────────────┘

tools/testing/selftests/drivers/net/hw/nic_link_layer.py

Quoted 3 lines
tools/testing/selftests/drivers/net/hw/nic_link_layer.py new file +3 -0
+#
+#Configurations:
+#To prevent interruptions, Add ethtool, ip to the sudoers list in remote PC

and get the ssh key from remote.

tools/testing/selftests/drivers/net/hw/nic_link_layer.py line 20

Quoted 5 lines
tools/testing/selftests/drivers/net/hw/nic_link_layer.py new file +5 -0
+#Required minimum ethtool version is 6.10 #Change the below
+configuration based on your hw needs.
+# """Default values"""
+time_delay = 8 #time taken to wait for transitions to happen, in seconds.
+test_duration = 10  #performance test duration for the throughput check,

in seconds.

Quoted 2 lines

It would be probably useful to allow the user overriding the above values via env variables and/or command line arguments.

This shall be changed to take variables from env variables or command line arguments, given that, command line arguments given more priority.

Quoted 3 lines

'test_duration' declaration should probably moved to a later patch, where it's used.

This will be moved to later patch where it is used. You shall find all the changes in the next revision.

Thanks,
Mohan Prasad J

#4 lore raw

PATCH v3 2/3 selftests: nic_link_layer: Add selftest case for speed and duplex states

In reply to Mohan Prasad J

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.

---
 .../drivers/net/hw/nic_link_layer.py          | 21 +++++++++++++++++++
 1 file changed, 21 insertions(+)
tools/testing/selftests/drivers/net/hw/nic_link_layer.py +21 -0
index fb046efbe..4548da3d9 100644
@@ -73,6 +73,27 @@ def test_autonegotiation(cfg, link_config) -> None:
         time.sleep(time_delay)
         verify_autonegotiation(cfg, state, link_config)
 
+def test_network_speed(cfg, link_config) -> None:
+    common_link_modes = link_config.common_link_modes
+    if not common_link_modes:
+        KsftSkipEx("No common link modes exist")
+    speeds, duplex_modes = link_config.get_speed_duplex_values(common_link_modes)
+
+    if speeds and duplex_modes and len(speeds) == len(duplex_modes):
+        for idx in range(len(speeds)):
+            speed = speeds[idx]
+            duplex = duplex_modes[idx]
+            if link_config.set_speed_and_duplex(speed, duplex) == False:
+                raise KsftFailEx(f"Unable to set speed and duplex parameters for {cfg.ifname}")
+            time.sleep(time_delay)
+            if link_config.verify_speed_and_duplex(speed, duplex) == False:
+                raise KsftSkipEx(f"Unable to verify speed and duplex states for interface {cfg.ifname}")
+    else:
+        if not speeds or not duplex_modes:
+            KsftSkipEx(f"No supported speeds or duplex modes found for interface {cfg.ifname}")
+        else:
+            KsftSkipEx("Mismatch in the number of speeds and duplex modes")
+
 def main() -> None:
     with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
         link_config = LinkConfig(cfg)
Signature · 1 line
2.43.0
#5 lore raw

PATCH v3 3/3 selftests: nic_performance: Add selftest for performance of NIC driver

In reply to Mohan Prasad J

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.

---
 .../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
tools/testing/selftests/drivers/net/hw/Makefile +1 -0
index 0dac40c4e..289512092 100644
@@ -11,6 +11,7 @@ TEST_PROGS = \
 	hw_stats_l3_gre.sh \
 	loopback.sh \
 	nic_link_layer.py \
+	nic_performance.py \
 	pp_alloc_fail.py \
 	rss_ctx.py \
 	#
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +121 -0

121 lines not on this page · raw message

Signature · 1 line
2.43.0
maintainer
#6 lore raw

Re: [PATCH net-next v3 3/3] selftests: nic_performance: Add selftest for performance of NIC driver

Quoted 51 lines · Mohan Prasad J

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.

---
 .../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
tools/testing/selftests/drivers/net/hw/Makefile +1 -0
index 0dac40c4e..289512092 100644
@@ -11,6 +11,7 @@ TEST_PROGS = \
 	hw_stats_l3_gre.sh \
 	loopback.sh \
 	nic_link_layer.py \
+	nic_performance.py \
 	pp_alloc_fail.py \
 	rss_ctx.py \
 	#
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +21 -0
new file mode 100644
index 000000000..152c62511
@@ -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 of your choice(RJ45, T1)
+#
+#        DUT PC                                              Partner PC
+#┌───────────────────────┐                         ┌──────────────────────────┐
+#│                       │                         │                          │
+#│                       │                         │                          │
+#│           ┌───────────┐                         │                          │
+#│           │DUT NIC    │         Eth             │                          │
+#│           │Interface ─┼─────────────────────────┼─    any eth Interface    │
+#│           └───────────┘                         │                          │
+#│                       │                         │                          │
+#│                       │                         │                          │
+#└───────────────────────┘                         └──────────────────────────┘

tools/testing/selftests/drivers/net/hw/nic_performance.py line 31

Quoted 10 lines
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +10 -0
+#
+#Configurations:
+#To prevent interruptions, Add ethtool, ip to the sudoers list in remote PC 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 = 8 #time taken to wait for transitions to happen, in seconds.
+test_duration = 10  #performance test duration for the throughput check, in seconds.
+send_throughput_threshold = 80 #percentage of send throughput required to pass the check
+receive_throughput_threshold = 50 #percentage of receive throughput required to pass the check

Please allow the user to override this parameters with env variable and/or with the command line.

Quoted 14 lines
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +14 -0
+
+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 = ["TCP", "UDP"]
+    common_link_modes = link_config.common_link_modes
+    speeds, duplex_modes = link_config.get_speed_duplex_values(common_link_modes)
+    """Test duration in seconds"""

tools/testing/selftests/drivers/net/hw/nic_performance.py line 55

Quoted 10 lines
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +10 -0
+    duration = test_duration
+    target_ip = cfg.remote_addr
+
+    for protocol in protocols:
+        ksft_pr(f"{protocol} test")
+        test_type = "-u" if protocol == "UDP" else ""
+        send_throughput = []
+        receive_throughput = []
+        for idx in range(0, len(speeds)):
+            bit_rate = f"-b {speeds[idx]}M" if protocol == "UDP" else ""

Always use '-b 0'. Will work with both TCP and UDP and is usually more efficient than forcing a specific speed.

Quoted 33 lines
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +33 -0
+            if link_config.set_speed_and_duplex(speeds[idx], duplex_modes[idx]) == False:
+                raise KsftFailEx(f"Not able to set speed and duplex parameters for {cfg.ifname}")
+            time.sleep(time_delay)
+            if link_config.verify_link_up() == False:
+                raise KsftSkipEx(f"Link state of interface {cfg.ifname} is DOWN")
+            send_command=f"iperf3 {test_type} -c {target_ip} {bit_rate} -t {duration} --json"
+            receive_command=f"iperf3 {test_type} -c {target_ip} {bit_rate} -t {duration} --reverse --json"
+            send_result = cmd(send_command)
+            receive_result = cmd(receive_command)
+            if send_result.ret != 0 or receive_result.ret != 0:
+                raise KsftSkipEx("Unexpected error occurred during transmit/receive")
+
+            send_output = send_result.stdout
+            receive_output = receive_result.stdout
+
+            send_data = json.loads(send_output)
+            receive_data = json.loads(receive_output)
+            """Convert throughput to Mbps"""
+            send_throughput.append(round(send_data['end']['sum_sent']['bits_per_second'] / 1e6, 2))
+            receive_throughput.append(round(receive_data['end']['sum_received']['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 values set at start)"""
+        for idx in range(0, len(speeds)):
+            send_threshold = float(speeds[idx]) * float(send_throughput_threshold / 100)
+            receive_threshold = float(speeds[idx]) * float(receive_throughput_threshold / 100)
+            ksft_true(send_throughput[idx] >= send_threshold, f"{protocol}: Send throughput is below threshold for {speeds[idx]} Mbps in {duplex_modes[idx]} duplex")
+            ksft_true(receive_throughput[idx] >= receive_threshold, f"{protocol}: Receive throughput is below threshold for {speeds[idx]} Mbps in {duplex_modes[idx]} duplex")
+
+def test_throughput(cfg, link_config) -> None:
+    common_link_modes = link_config.common_link_modes
+    if not common_link_modes:

tools/testing/selftests/drivers/net/hw/nic_performance.py line 98

Quoted 10 lines
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +10 -0
+        KsftSkipEx("No common link modes found")
+    if link_config.partner_netif == None:
+        KsftSkipEx("Partner interface name not available")
+    if link_config.check_autoneg_supported() and link_config.check_autoneg_supported(remote=True):
+        KsftSkipEx("Auto-negotiation not supported by local or remote")
+    cfg.require_cmd("iperf3", remote=True)
+    try:
+        """iperf3 server to be run in the remote pc"""
+        command = "iperf3 -s -D"
+        process = cmd(command, host=cfg.remote)

It's probably better use '--one-off' and run the command in background.

You should wait for the listener to be available with wait_port_listen()

Also you can consider extending the existing GenerateTraffic() class in

tools/testing/selftests/drivers/net/lib/py/load.py

[...]

tools/testing/selftests/drivers/net/hw/nic_performance.py line 116

Quoted 4 lines
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +4 -0
+def main() -> None:
+    with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
+        link_config = LinkConfig(cfg)
+        ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg, link_config,))

Instead of having a single test with all proto and speeds, what about using a tests list, each of them using a given protocol and speed, so that the user see more fine grain results?

Thanks

Paolo

#7 lore raw

RE: [PATCH net-next v3 3/3] selftests: nic_performance: Add selftest for performance of NIC driver

Hello Paolo,

Thank you for the review comments.

Quoted 67 lines
Quoted 35 lines

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.

---
 .../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

tools/testing/selftests/drivers/net/hw/Makefile +1 -0
index 0dac40c4e..289512092 100644
@@ -11,6 +11,7 @@ TEST_PROGS = \
      hw_stats_l3_gre.sh \
      loopback.sh \
      nic_link_layer.py \
+     nic_performance.py \
      pp_alloc_fail.py \
      rss_ctx.py \
      #
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +2 -0
new file mode 100644
index 000000000..152c62511
@@ -0,0 +1,121 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0

tools/testing/selftests/drivers/net/hw/nic_performance.py line 12

Quoted 10 lines
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +10 -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 of your choice(RJ45, T1) #
+#        DUT PC                                              Partner PC
+#┌───────────────────────┐
┌──────────────────────────┐
> +#│                       │                         │                          │
> +#│                       │                         │                          │
> +#│           ┌───────────┐                         │                          │
> +#│           │DUT NIC    │         Eth             │                          │
> +#│           │Interface ─┼─────────────────────────┼─    any eth Interface
│
> +#│           └───────────┘                         │                          │
> +#│                       │                         │                          │
> +#│                       │                         │                          │
> +#└───────────────────────┘
└──────────────────────────┘

tools/testing/selftests/drivers/net/hw/nic_performance.py

Quoted 3 lines
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +3 -0
+#
+#Configurations:
+#To prevent interruptions, Add ethtool, ip to the sudoers list in remote PC

and get the ssh key from remote.

tools/testing/selftests/drivers/net/hw/nic_performance.py line 20

Quoted 5 lines
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +5 -0
+#Required minimum ethtool version is 6.10 #Change the below
+configuration based on your hw needs.
+# """Default values"""
+time_delay = 8 #time taken to wait for transitions to happen, in seconds.
+test_duration = 10  #performance test duration for the throughput check,

in seconds.

Quoted 6 lines

tools/testing/selftests/drivers/net/hw/nic_performance.py line 23

Quoted 3 lines
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +3 -0
+send_throughput_threshold = 80 #percentage of send throughput
+required to pass the check receive_throughput_threshold = 50
+#percentage of receive throughput required to pass the check

Please allow the user to override this parameters with env variable and/or with the command line.

I will update it to take these parameters from env variable and/or command line.

Quoted 25 lines

tools/testing/selftests/drivers/net/hw/nic_performance.py

Quoted 12 lines
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +11 -0
+
+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 = ["TCP", "UDP"]
+    common_link_modes = link_config.common_link_modes
+    speeds, duplex_modes =

link_config.get_speed_duplex_values(common_link_modes)

tools/testing/selftests/drivers/net/hw/nic_performance.py line 55

Quoted 11 lines
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +11 -0
+    """Test duration in seconds"""
+    duration = test_duration
+    target_ip = cfg.remote_addr
+
+    for protocol in protocols:
+        ksft_pr(f"{protocol} test")
+        test_type = "-u" if protocol == "UDP" else ""
+        send_throughput = []
+        receive_throughput = []
+        for idx in range(0, len(speeds)):
+            bit_rate = f"-b {speeds[idx]}M" if protocol == "UDP" else ""
Quoted 2 lines

Always use '-b 0'. Will work with both TCP and UDP and is usually more efficient than forcing a specific speed.

As suggested, this will be updated to use '-b 0'. You can find it in next revision.

Quoted 64 lines

tools/testing/selftests/drivers/net/hw/nic_performance.py line 46

Quoted 2 lines
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +1 -0
+            if link_config.set_speed_and_duplex(speeds[idx],

duplex_modes[idx]) == False:

tools/testing/selftests/drivers/net/hw/nic_performance.py line 47

Quoted 1 line
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +1 -0
+                raise KsftFailEx(f"Not able to set speed and duplex parameters for

{cfg.ifname}")

tools/testing/selftests/drivers/net/hw/nic_performance.py

Quoted 4 lines
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +4 -0
+            time.sleep(time_delay)
+            if link_config.verify_link_up() == False:
+                raise KsftSkipEx(f"Link state of interface {cfg.ifname} is DOWN")
+            send_command=f"iperf3 {test_type} -c {target_ip} {bit_rate} -t

{duration} --json"

tools/testing/selftests/drivers/net/hw/nic_performance.py line 52

Quoted 1 line
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +1 -0
+            receive_command=f"iperf3 {test_type} -c {target_ip} {bit_rate} -t

{duration} --reverse --json"

tools/testing/selftests/drivers/net/hw/nic_performance.py line 76

Quoted 13 lines
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +13 -0
+            send_result = cmd(send_command)
+            receive_result = cmd(receive_command)
+            if send_result.ret != 0 or receive_result.ret != 0:
+                raise KsftSkipEx("Unexpected error occurred during
+ transmit/receive")
+
+            send_output = send_result.stdout
+            receive_output = receive_result.stdout
+
+            send_data = json.loads(send_output)
+            receive_data = json.loads(receive_output)
+            """Convert throughput to Mbps"""
+

send_throughput.append(round(send_data['end']['sum_sent']['bits_per_sec ond'] / 1e6, 2))

tools/testing/selftests/drivers/net/hw/nic_performance.py line 74

Quoted 9 lines
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +9 -0
+
+ receive_throughput.append(round(receive_data['end']['sum_received'][
+ '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

values set at start)"""

tools/testing/selftests/drivers/net/hw/nic_performance.py line 76

Quoted 2 lines
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +2 -0
+        for idx in range(0, len(speeds)):
+            send_threshold = float(speeds[idx]) *

float(send_throughput_threshold / 100)

tools/testing/selftests/drivers/net/hw/nic_performance.py line 77

Quoted 1 line
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +1 -0
+            receive_threshold = float(speeds[idx]) *

float(receive_throughput_threshold / 100)

tools/testing/selftests/drivers/net/hw/nic_performance.py line 78

Quoted 1 line
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +1 -0
+            ksft_true(send_throughput[idx] >= send_threshold, f"{protocol}:

Send throughput is below threshold for {speeds[idx]} Mbps in {duplex_modes[idx]} duplex")

tools/testing/selftests/drivers/net/hw/nic_performance.py

Quoted 11 lines
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +11 -0
+            ksft_true(receive_throughput[idx] >= receive_threshold,
+ f"{protocol}: Receive throughput is below threshold for
+ {speeds[idx]} Mbps in {duplex_modes[idx]} duplex")
+
+def test_throughput(cfg, link_config) -> None:
+    common_link_modes = link_config.common_link_modes
+    if not common_link_modes:
+        KsftSkipEx("No common link modes found")
+    if link_config.partner_netif == None:
+        KsftSkipEx("Partner interface name not available")
+    if link_config.check_autoneg_supported() and

link_config.check_autoneg_supported(remote=True):

tools/testing/selftests/drivers/net/hw/nic_performance.py line 98

Quoted 6 lines
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +6 -0
+        KsftSkipEx("Auto-negotiation not supported by local or remote")
+    cfg.require_cmd("iperf3", remote=True)
+    try:
+        """iperf3 server to be run in the remote pc"""
+        command = "iperf3 -s -D"
+        process = cmd(command, host=cfg.remote)
Quoted 7 lines

It's probably better use '--one-off' and run the command in background.

You should wait for the listener to be available with wait_port_listen()

Also you can consider extending the existing GenerateTraffic() class in

tools/testing/selftests/drivers/net/lib/py/load.py

As suggested, I will update the command to run in background with '--one-off' and wait for the listener. Extending existing GenerateTraffic() class would be beneficial. I will update it accordingly.

Quoted 11 lines

[...]

tools/testing/selftests/drivers/net/hw/nic_performance.py

Quoted 5 lines
tools/testing/selftests/drivers/net/hw/nic_performance.py new file +5 -0
+def main() -> None:
+    with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
+        link_config = LinkConfig(cfg)
+        ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg,
+link_config,))

Instead of having a single test with all proto and speeds, what about using a tests list, each of them using a given protocol and speed, so that the user see more fine grain results?

As suggested, test will be updated to use test list for testing the protocols with speeds separately.

You can find all the changes in the next revision.

Thanks,
Mohan Prasad J