[PATCH net-next 3/3] selftests: lan743x: Add testcase to check throughput of lan743x

Mohan Prasad J posted 3 patches 1 year, 3 months ago
[PATCH net-next 3/3] selftests: lan743x: Add testcase to check throughput of lan743x
Posted by Mohan Prasad J 1 year, 3 months ago
Add testcase to check TCP throughput of lan743x network driver.
Test uses iperf3 to do performance testing of the driver.
TCP data at different speeds is sent, received and verified.

Signed-off-by: Mohan Prasad J <mohan.prasad@microchip.com>
---
 .../net/hw/microchip/lan743x/lan743x.py       | 33 +++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/tools/testing/selftests/drivers/net/hw/microchip/lan743x/lan743x.py b/tools/testing/selftests/drivers/net/hw/microchip/lan743x/lan743x.py
index 59f0be2a7..a3dcf7896 100755
--- a/tools/testing/selftests/drivers/net/hw/microchip/lan743x/lan743x.py
+++ b/tools/testing/selftests/drivers/net/hw/microchip/lan743x/lan743x.py
@@ -3,6 +3,7 @@
 
 import time
 import re
+import json
 from lib.py import ksft_run, ksft_exit, ksft_pr, ksft_eq
 from lib.py import KsftFailEx, KsftSkipEx
 from lib.py import NetDrvEpEnv
@@ -75,6 +76,38 @@ def test_network_speed(cfg) -> None:
             time.sleep(5)
             verify_speed_and_duplex(cfg.ifname, speed, duplex)
 
+def test_tcp_throughput(cfg) -> None:
+    speeds = ["10", "100", "1000"]
+    """Test duration in seconds"""
+    test_duration = 5
+    target_ip = cfg.remote_addr
+
+    for speed in speeds:
+        set_speed_and_duplex(cfg.ifname, speed, 'full')
+        time.sleep(5)
+        verify_link_up(cfg.ifname)
+        send_command=f"iperf3 -c {target_ip} -t {test_duration} --json"
+        receive_command=f"iperf3 -c {target_ip} -t {test_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 0.9 times the set speed"""
+        threshold = float(speed) * 0.9
+        if send_throughput < threshold or receive_throughput < threshold:
+            raise KsftFailEx("Throughput is below threshold")
+
 def main() -> None:
     with NetDrvEpEnv(__file__) as cfg:
         ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg,))
-- 
2.43.0
Re: [PATCH net-next 3/3] selftests: lan743x: Add testcase to check throughput of lan743x
Posted by Brett Creeley 1 year, 3 months ago

On 9/3/2024 3:15 PM, Mohan Prasad J wrote:
> Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
> 
> 
> Add testcase to check TCP throughput of lan743x network driver.
> Test uses iperf3 to do performance testing of the driver.
> TCP data at different speeds is sent, received and verified.
> 
> Signed-off-by: Mohan Prasad J <mohan.prasad@microchip.com>
> ---
>   .../net/hw/microchip/lan743x/lan743x.py       | 33 +++++++++++++++++++
>   1 file changed, 33 insertions(+)
> 
> diff --git a/tools/testing/selftests/drivers/net/hw/microchip/lan743x/lan743x.py b/tools/testing/selftests/drivers/net/hw/microchip/lan743x/lan743x.py
> index 59f0be2a7..a3dcf7896 100755
> --- a/tools/testing/selftests/drivers/net/hw/microchip/lan743x/lan743x.py
> +++ b/tools/testing/selftests/drivers/net/hw/microchip/lan743x/lan743x.py
> @@ -3,6 +3,7 @@
> 
>   import time
>   import re
> +import json
>   from lib.py import ksft_run, ksft_exit, ksft_pr, ksft_eq
>   from lib.py import KsftFailEx, KsftSkipEx
>   from lib.py import NetDrvEpEnv
> @@ -75,6 +76,38 @@ def test_network_speed(cfg) -> None:
>               time.sleep(5)
>               verify_speed_and_duplex(cfg.ifname, speed, duplex)
> 
> +def test_tcp_throughput(cfg) -> None:
> +    speeds = ["10", "100", "1000"]
> +    """Test duration in seconds"""
> +    test_duration = 5
> +    target_ip = cfg.remote_addr
> +
> +    for speed in speeds:
> +        set_speed_and_duplex(cfg.ifname, speed, 'full')
> +        time.sleep(5)
> +        verify_link_up(cfg.ifname)
> +        send_command=f"iperf3 -c {target_ip} -t {test_duration} --json"
> +        receive_command=f"iperf3 -c {target_ip} -t {test_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 0.9 times the set speed"""
> +        threshold = float(speed) * 0.9
> +        if send_throughput < threshold or receive_throughput < threshold:
> +            raise KsftFailEx("Throughput is below threshold")

IMO it would be best to do these checks separately so the failure is 
immediately obvious.

Thanks,

Brett
> +
>   def main() -> None:
>       with NetDrvEpEnv(__file__) as cfg:
>           ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg,))
> --
> 2.43.0
>