Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Mohan Prasad J <mohan.prasad@microchip.com>
To: <netdev@vger.kernel.org>, <davem@davemloft.net>, <kuba@kernel.org>
Cc: <shuah@kernel.org>, <bryan.whitehead@microchip.com>,
	<mohan.prasad@microchip.com>, <UNGLinuxDriver@microchip.com>,
	<edumazet@google.com>, <pabeni@redhat.com>,
	<linux-kernel@vger.kernel.org>, <linux-kselftest@vger.kernel.org>,
	<horms@kernel.org>, <brett.creeley@amd.com>, <rosenp@gmail.com>
Subject: [PATCH net-next 1/3] selftests: lan743x: Add testfile for lan743x network driver
Date: Wed, 4 Sep 2024 03:45:47 +0530	[thread overview]
Message-ID: <20240903221549.1215842-2-mohan.prasad@microchip.com> (raw)
In-Reply-To: <20240903221549.1215842-1-mohan.prasad@microchip.com>

Add testfile for lan743x network driver.
Testfile includes the verification of status of autonegotiation.
Ksft modules and ethtool are used for the testing.
net/lib libraries are included for testing.
Add the __init__.py file.
Include /microchip/lan743x as a target in Makefile.
Updated MAINTAINERS list.

Signed-off-by: Mohan Prasad J <mohan.prasad@microchip.com>
---
 MAINTAINERS                                   |  2 +
 tools/testing/selftests/Makefile              |  2 +-
 .../drivers/net/hw/microchip/lan743x/Makefile |  7 +++
 .../net/hw/microchip/lan743x/lan743x.py       | 51 +++++++++++++++++++
 .../hw/microchip/lan743x/lib/py/__init__.py   | 16 ++++++
 5 files changed, 77 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/drivers/net/hw/microchip/lan743x/Makefile
 create mode 100755 tools/testing/selftests/drivers/net/hw/microchip/lan743x/lan743x.py
 create mode 100644 tools/testing/selftests/drivers/net/hw/microchip/lan743x/lib/py/__init__.py

diff --git a/MAINTAINERS b/MAINTAINERS
index baf88e74c..461f94ae0 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -14960,10 +14960,12 @@ F:	net/dsa/tag_ksz.c
 
 MICROCHIP LAN743X ETHERNET DRIVER
 M:	Bryan Whitehead <bryan.whitehead@microchip.com>
+M:	Mohan Prasad J <mohan.prasad@microchip.com>
 M:	UNGLinuxDriver@microchip.com
 L:	netdev@vger.kernel.org
 S:	Maintained
 F:	drivers/net/ethernet/microchip/lan743x_*
+F:	tools/testing/selftests/drivers/net/hw/microchip/lan743x/
 
 MICROCHIP LAN87xx/LAN937x T1 PHY DRIVER
 M:	Arun Ramadoss <arun.ramadoss@microchip.com>
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index a5f1c0c27..8059529c9 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -122,7 +122,7 @@ TARGETS_HOTPLUG = cpu-hotplug
 TARGETS_HOTPLUG += memory-hotplug
 
 # Networking tests want the net/lib target, include it automatically
-ifneq ($(filter net drivers/net drivers/net/hw,$(TARGETS)),)
+ifneq ($(filter net drivers/net drivers/net/hw drivers/net/hw/microchip/lan743x,$(TARGETS)),)
 ifeq ($(filter net/lib,$(TARGETS)),)
 	INSTALL_DEP_TARGETS := net/lib
 endif
diff --git a/tools/testing/selftests/drivers/net/hw/microchip/lan743x/Makefile b/tools/testing/selftests/drivers/net/hw/microchip/lan743x/Makefile
new file mode 100644
index 000000000..542128678
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/hw/microchip/lan743x/Makefile
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0
+
+TEST_INCLUDES := $(wildcard lib/py/*.py ../../../lib/py/*.py)
+
+TEST_PROGS := lan743x.py
+
+include ../../../../../lib.mk
diff --git a/tools/testing/selftests/drivers/net/hw/microchip/lan743x/lan743x.py b/tools/testing/selftests/drivers/net/hw/microchip/lan743x/lan743x.py
new file mode 100755
index 000000000..f1ad97dc2
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/hw/microchip/lan743x/lan743x.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+import time
+import re
+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 cmd
+from lib.py import ethtool
+
+def verify_link_up(ifname: str) -> None:
+    """Verify whether the link is up initially"""
+    with open(f"/sys/class/net/{ifname}/operstate", "r") as fp:
+        link_state = fp.read().strip()
+
+    if link_state == "down":
+        raise KsftSkipEx(f"Link state of interface {ifname} is DOWN")
+
+def set_autonegotiation_state(ifname: str, state: str) -> None:
+    """Set the autonegotiation state for the interface"""
+    process = ethtool(f"-s {ifname} speed 10 duplex half autoneg {state}")
+    if process.ret != 0:
+        raise KsftFailEx(f"Not able to set autoneg parameter for {ifname}")
+    ksft_pr(f"Autoneg set as {state} for {ifname}")
+
+def verify_autonegotiation(ifname: str, expected_state: str) -> None:
+    verify_link_up(ifname)
+    """Verifying the autonegotiation state"""
+    output = ethtool(f"{ifname}")
+    autoneg_match = re.search(r'Auto-negotiation:\s+(\w+)', output.stdout)
+
+    if not autoneg_match:
+        raise KsftFailEx("Failed to find autonegotiation information in ethtool output.")
+
+    actual_state = autoneg_match.group(1)
+    ksft_eq(actual_state, expected_state)
+
+def test_autonegotiation(cfg) -> None:
+    for state in ["off", "on"]:
+        set_autonegotiation_state(cfg.ifname, state)
+        time.sleep(5)
+        verify_autonegotiation(cfg.ifname, state)
+
+def main() -> None:
+    with NetDrvEpEnv(__file__) as cfg:
+        ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg,))
+    ksft_exit()
+
+if __name__ == "__main__":
+    main()
diff --git a/tools/testing/selftests/drivers/net/hw/microchip/lan743x/lib/py/__init__.py b/tools/testing/selftests/drivers/net/hw/microchip/lan743x/lib/py/__init__.py
new file mode 100644
index 000000000..e571631af
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/hw/microchip/lan743x/lib/py/__init__.py
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: GPL-2.0
+
+import sys
+from pathlib import Path
+
+KSFT_DIR = (Path(__file__).parent / "../../../../../../..").resolve()
+
+try:
+    sys.path.append(KSFT_DIR.as_posix())
+    from net.lib.py import *
+    from drivers.net.lib.py import *
+except ModuleNotFoundError as e:
+    ksft_pr("Failed importing `net` library from kernel sources")
+    ksft_pr(str(e))
+    ktap_result(True, comment="SKIP")
+    sys.exit(4)
-- 
2.43.0


  reply	other threads:[~2024-09-04  5:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-03 22:15 [PATCH net-next 0/3] lan743x: This series of patches are for lan743x driver testing Mohan Prasad J
2024-09-03 22:15 ` Mohan Prasad J [this message]
2024-09-04 16:10   ` [PATCH net-next 1/3] selftests: lan743x: Add testfile for lan743x network driver Brett Creeley
2024-09-06  6:54     ` Mohan.Prasad
2024-09-03 22:15 ` [PATCH net-next 2/3] selftests: lan743x: Add testcase to check speed and duplex state of lan743x Mohan Prasad J
2024-09-04 16:05   ` Brett Creeley
2024-09-06  6:52     ` Mohan.Prasad
2024-09-03 22:15 ` [PATCH net-next 3/3] selftests: lan743x: Add testcase to check throughput " Mohan Prasad J
2024-09-04 16:15   ` Brett Creeley
2024-09-06  6:56     ` Mohan.Prasad
2024-09-04  5:30 ` [PATCH net-next 0/3] lan743x: This series of patches are for lan743x driver testing Andrew Lunn
2024-09-06  6:45   ` Mohan.Prasad
2024-09-06 12:08     ` Andrew Lunn
2024-09-09  6:42       ` Mohan.Prasad
2024-09-09 13:24         ` Andrew Lunn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240903221549.1215842-2-mohan.prasad@microchip.com \
    --to=mohan.prasad@microchip.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=brett.creeley@amd.com \
    --cc=bryan.whitehead@microchip.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rosenp@gmail.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox