diff mbox series

[net-next,v2,2/3] selftests: nic_basic_tests: Add selftest case for speed and duplex state checks

Message ID 20240917023525.2571082-3-mohan.prasad@microchip.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series nic_basic_tests: Add selftest for doing basic tests of NIC driver | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 7 this patch: 7
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 7 this patch: 7
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 64 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-09-17--15-00 (tests: 764)

Commit Message

Mohan Prasad J Sept. 17, 2024, 2:34 a.m. UTC
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 <mohan.prasad@microchip.com>
---
 .../drivers/net/hw/nic_basic_tests.py         | 46 +++++++++++++++++++
 1 file changed, 46 insertions(+)

Comments

Willem de Bruijn Sept. 18, 2024, 12:38 p.m. UTC | #1
Mohan Prasad J wrote:
> 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 <mohan.prasad@microchip.com>
> ---
>  .../drivers/net/hw/nic_basic_tests.py         | 46 +++++++++++++++++++
>  1 file changed, 46 insertions(+)
> 
> diff --git a/tools/testing/selftests/drivers/net/hw/nic_basic_tests.py b/tools/testing/selftests/drivers/net/hw/nic_basic_tests.py
> index 27f780032..ff46f2406 100644
> --- a/tools/testing/selftests/drivers/net/hw/nic_basic_tests.py
> +++ b/tools/testing/selftests/drivers/net/hw/nic_basic_tests.py
> @@ -42,6 +42,14 @@ from lib.py import ethtool
>  """Global variables"""
>  common_link_modes = []
>  
> +def check_autonegotiation(ifname: str) -> None:
> +    autoneg = get_ethtool_content(ifname, "Supports auto-negotiation:")
> +    partner_autoneg = get_ethtool_content(ifname, "Link partner advertised auto-negotiation:")
> +
> +    """Check if auto-neg supported by local and partner NIC"""
> +    if autoneg[0] != "Yes" or partner_autoneg[0] != "Yes":
> +        raise KsftSkipEx(f"Interface {ifname} or partner does not support auto-negotiation")
> +
>  def get_ethtool_content(ifname: str, field: str):
>      capture = False
>      content = []
> @@ -112,6 +120,25 @@ def verify_autonegotiation(ifname: str, expected_state: str) -> None:
>  
>      ksft_eq(actual_state, expected_state)
>  
> +def set_speed_and_duplex(ifname: str, speed: str, duplex: str) -> None:
> +    """Set the speed and duplex state for the interface"""
> +    process = ethtool(f"--change {ifname} speed {speed} duplex {duplex} autoneg on")
> +
> +    if process.ret != 0:
> +        raise KsftFailEx(f"Not able to set speed and duplex parameters for {ifname}")
> +    ksft_pr(f"Speed: {speed} Mbps, Duplex: {duplex} set for Interface: {ifname}")
> +
> +def verify_speed_and_duplex(ifname: str, expected_speed: str, expected_duplex: str) -> None:
> +    verify_link_up(ifname)
> +    """Verifying the speed and duplex state for the interface"""
> +    with open(f"/sys/class/net/{ifname}/speed", "r") as fp:
> +        actual_speed = fp.read().strip()
> +    with open(f"/sys/class/net/{ifname}/duplex", "r") as fp:
> +        actual_duplex = fp.read().strip()
> +
> +    ksft_eq(actual_speed, expected_speed)
> +    ksft_eq(actual_duplex, expected_duplex)
> +
>  def test_link_modes(cfg) -> None:
>      global common_link_modes
>      link_modes = get_ethtool_content(cfg.ifname, "Supported link modes:")
> @@ -136,6 +163,25 @@ def test_autonegotiation(cfg) -> None:
>      else:
>          raise KsftSkipEx(f"Auto-Negotiation is not supported for interface {cfg.ifname}")
>  
> +def test_network_speed(cfg) -> None:
> +    check_autonegotiation(cfg.ifname)
> +    if not common_link_modes:
> +        KsftSkipEx("No common link modes exist")
> +    speeds, duplex_modes = get_speed_duplex(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]
> +            set_speed_and_duplex(cfg.ifname, speed, duplex)
> +            time.sleep(sleep_time)
> +            verify_speed_and_duplex(cfg.ifname, speed, duplex)
> +    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")
> +

Do these tests reset configuration to their original state?

More high level: basic test is not very descriptive. Can they have a
more precise name? Perhaps link layer operations or link layer config?
Mohan Prasad J Sept. 20, 2024, 4:56 a.m. UTC | #2
Hi Willem,

Thanks for the review comments.

> EXTERNAL EMAIL: Do not click links or open attachments unless you know the
> content is safe
> 
> Mohan Prasad J wrote:
> > 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 <mohan.prasad@microchip.com>
> > ---
> >  .../drivers/net/hw/nic_basic_tests.py         | 46 +++++++++++++++++++
> >  1 file changed, 46 insertions(+)
> >
> > diff --git a/tools/testing/selftests/drivers/net/hw/nic_basic_tests.py
> > b/tools/testing/selftests/drivers/net/hw/nic_basic_tests.py
> > index 27f780032..ff46f2406 100644
> > --- a/tools/testing/selftests/drivers/net/hw/nic_basic_tests.py
> > +++ b/tools/testing/selftests/drivers/net/hw/nic_basic_tests.py
> > @@ -42,6 +42,14 @@ from lib.py import ethtool  """Global variables"""
> >  common_link_modes = []
> >
> > +def check_autonegotiation(ifname: str) -> None:
> > +    autoneg = get_ethtool_content(ifname, "Supports auto-negotiation:")
> > +    partner_autoneg = get_ethtool_content(ifname, "Link partner
> > +advertised auto-negotiation:")
> > +
> > +    """Check if auto-neg supported by local and partner NIC"""
> > +    if autoneg[0] != "Yes" or partner_autoneg[0] != "Yes":
> > +        raise KsftSkipEx(f"Interface {ifname} or partner does not
> > + support auto-negotiation")
> > +
> >  def get_ethtool_content(ifname: str, field: str):
> >      capture = False
> >      content = []
> > @@ -112,6 +120,25 @@ def verify_autonegotiation(ifname: str,
> expected_state: str) -> None:
> >
> >      ksft_eq(actual_state, expected_state)
> >
> > +def set_speed_and_duplex(ifname: str, speed: str, duplex: str) -> None:
> > +    """Set the speed and duplex state for the interface"""
> > +    process = ethtool(f"--change {ifname} speed {speed} duplex
> > +{duplex} autoneg on")
> > +
> > +    if process.ret != 0:
> > +        raise KsftFailEx(f"Not able to set speed and duplex parameters for
> {ifname}")
> > +    ksft_pr(f"Speed: {speed} Mbps, Duplex: {duplex} set for
> > + Interface: {ifname}")
> > +
> > +def verify_speed_and_duplex(ifname: str, expected_speed: str,
> expected_duplex: str) -> None:
> > +    verify_link_up(ifname)
> > +    """Verifying the speed and duplex state for the interface"""
> > +    with open(f"/sys/class/net/{ifname}/speed", "r") as fp:
> > +        actual_speed = fp.read().strip()
> > +    with open(f"/sys/class/net/{ifname}/duplex", "r") as fp:
> > +        actual_duplex = fp.read().strip()
> > +
> > +    ksft_eq(actual_speed, expected_speed)
> > +    ksft_eq(actual_duplex, expected_duplex)
> > +
> >  def test_link_modes(cfg) -> None:
> >      global common_link_modes
> >      link_modes = get_ethtool_content(cfg.ifname, "Supported link
> > modes:") @@ -136,6 +163,25 @@ def test_autonegotiation(cfg) -> None:
> >      else:
> >          raise KsftSkipEx(f"Auto-Negotiation is not supported for
> > interface {cfg.ifname}")
> >
> > +def test_network_speed(cfg) -> None:
> > +    check_autonegotiation(cfg.ifname)
> > +    if not common_link_modes:
> > +        KsftSkipEx("No common link modes exist")
> > +    speeds, duplex_modes = get_speed_duplex(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]
> > +            set_speed_and_duplex(cfg.ifname, speed, duplex)
> > +            time.sleep(sleep_time)
> > +            verify_speed_and_duplex(cfg.ifname, speed, duplex)
> > +    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")
> > +
> 
> Do these tests reset configuration to their original state?

Currently these tests do not reset configuration to their original state.
However resetting would be a good idea, I will either do it here (or) at the end of the tests.

> 
> More high level: basic test is not very descriptive. Can they have a more
> precise name? Perhaps link layer operations or link layer config?

I will have a check on the naming and update it accordingly.
diff mbox series

Patch

diff --git a/tools/testing/selftests/drivers/net/hw/nic_basic_tests.py b/tools/testing/selftests/drivers/net/hw/nic_basic_tests.py
index 27f780032..ff46f2406 100644
--- a/tools/testing/selftests/drivers/net/hw/nic_basic_tests.py
+++ b/tools/testing/selftests/drivers/net/hw/nic_basic_tests.py
@@ -42,6 +42,14 @@  from lib.py import ethtool
 """Global variables"""
 common_link_modes = []
 
+def check_autonegotiation(ifname: str) -> None:
+    autoneg = get_ethtool_content(ifname, "Supports auto-negotiation:")
+    partner_autoneg = get_ethtool_content(ifname, "Link partner advertised auto-negotiation:")
+
+    """Check if auto-neg supported by local and partner NIC"""
+    if autoneg[0] != "Yes" or partner_autoneg[0] != "Yes":
+        raise KsftSkipEx(f"Interface {ifname} or partner does not support auto-negotiation")
+
 def get_ethtool_content(ifname: str, field: str):
     capture = False
     content = []
@@ -112,6 +120,25 @@  def verify_autonegotiation(ifname: str, expected_state: str) -> None:
 
     ksft_eq(actual_state, expected_state)
 
+def set_speed_and_duplex(ifname: str, speed: str, duplex: str) -> None:
+    """Set the speed and duplex state for the interface"""
+    process = ethtool(f"--change {ifname} speed {speed} duplex {duplex} autoneg on")
+
+    if process.ret != 0:
+        raise KsftFailEx(f"Not able to set speed and duplex parameters for {ifname}")
+    ksft_pr(f"Speed: {speed} Mbps, Duplex: {duplex} set for Interface: {ifname}")
+
+def verify_speed_and_duplex(ifname: str, expected_speed: str, expected_duplex: str) -> None:
+    verify_link_up(ifname)
+    """Verifying the speed and duplex state for the interface"""
+    with open(f"/sys/class/net/{ifname}/speed", "r") as fp:
+        actual_speed = fp.read().strip()
+    with open(f"/sys/class/net/{ifname}/duplex", "r") as fp:
+        actual_duplex = fp.read().strip()
+
+    ksft_eq(actual_speed, expected_speed)
+    ksft_eq(actual_duplex, expected_duplex)
+
 def test_link_modes(cfg) -> None:
     global common_link_modes
     link_modes = get_ethtool_content(cfg.ifname, "Supported link modes:")
@@ -136,6 +163,25 @@  def test_autonegotiation(cfg) -> None:
     else:
         raise KsftSkipEx(f"Auto-Negotiation is not supported for interface {cfg.ifname}")
 
+def test_network_speed(cfg) -> None:
+    check_autonegotiation(cfg.ifname)
+    if not common_link_modes:
+        KsftSkipEx("No common link modes exist")
+    speeds, duplex_modes = get_speed_duplex(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]
+            set_speed_and_duplex(cfg.ifname, speed, duplex)
+            time.sleep(sleep_time)
+            verify_speed_and_duplex(cfg.ifname, speed, duplex)
+    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__) as cfg:
         ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg,))