diff mbox series

[net-next,v2,3/3] selftests: nic_basic_tests: Add selftest case for throughput check

Message ID 20240917023525.2571082-4-mohan.prasad@microchip.com (mailing list archive)
State New
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, 45 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 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 <mohan.prasad@microchip.com>
---
 .../drivers/net/hw/nic_basic_tests.py         | 39 +++++++++++++++++++
 1 file changed, 39 insertions(+)
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 ff46f2406..ec1f5b6a2 100644
--- a/tools/testing/selftests/drivers/net/hw/nic_basic_tests.py
+++ b/tools/testing/selftests/drivers/net/hw/nic_basic_tests.py
@@ -182,6 +182,45 @@  def test_network_speed(cfg) -> None:
         else:
             KsftSkipEx("Mismatch in the number of speeds and duplex modes")
 
+def test_tcp_throughput(cfg) -> None:
+    check_autonegotiation(cfg.ifname)
+    if not common_link_modes:
+        KsftSkipEx("No common link modes found")
+    cfg.require_cmd("iperf3", remote=True)
+    """iperf3 server to be run in the partner pc"""
+    speeds, duplex_modes = get_speed_duplex(common_link_modes)
+    """Test duration in seconds"""
+    duration = test_duration
+    target_ip = cfg.remote_addr
+
+    for idx in range(len(speeds)-1, -1, -1):
+        set_speed_and_duplex(cfg.ifname, speeds[idx], duplex_modes[idx])
+        time.sleep(sleep_time)
+        verify_link_up(cfg.ifname)
+        send_command=f"iperf3 -c {target_ip} -t {duration} --json"
+        receive_command=f"iperf3 -c {target_ip} -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("No server is running")
+
+        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 = round(send_data['end']['sum_sent']['bits_per_second'] / 1e6, 2)
+        receive_throughput = round(receive_data['end']['sum_received']['bits_per_second'] / 1e6, 2)
+
+        ksft_pr(f"Send throughput: {send_throughput} Mbps, Receive throughput: {receive_throughput} Mbps")
+        """Check whether throughput is not below the threshold (default:80% of set speed)"""
+        threshold = float(speeds[idx]) * float(throughput_threshold)
+        if send_throughput < threshold:
+            raise KsftFailEx("Send throughput is below threshold")
+        elif receive_throughput < threshold:
+            raise KsftFailEx("Receive throughput is below threshold")
+
 def main() -> None:
     with NetDrvEpEnv(__file__) as cfg:
         ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg,))