diff mbox series

[net-next,v2,3/4] selftests: drv-net: add ability to wait for at least N packets to load gen

Message ID 20240625010210.2002310-4-kuba@kernel.org (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series selftests: drv-net: rss_ctx: add tests for RSS contexts | 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: 8 this patch: 8
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 2 maintainers not CCed: shuah@kernel.org linux-kselftest@vger.kernel.org
netdev/build_clang success Errors and warnings before: 8 this patch: 8
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: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 38 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-06-25--09-00 (tests: 662)

Commit Message

Jakub Kicinski June 25, 2024, 1:02 a.m. UTC
Teach the load generator how to wait for at least given number
of packets to be received. This will be useful for filtering
where we'll want to send a non-trivial number of packets and
make sure they landed in right queues.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
v2:
 - add comment that pps or pkt_cnt are mutually exclusive (David)
 - rename variables (David)
---
 .../selftests/drivers/net/lib/py/load.py      | 30 ++++++++++++++-----
 1 file changed, 23 insertions(+), 7 deletions(-)

Comments

Breno Leitao June 25, 2024, 8:05 a.m. UTC | #1
On Mon, Jun 24, 2024 at 06:02:09PM -0700, Jakub Kicinski wrote:
> Teach the load generator how to wait for at least given number
> of packets to be received. This will be useful for filtering
> where we'll want to send a non-trivial number of packets and
> make sure they landed in right queues.
> 
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Reviwed-by: Breno Leitao <leitao@debian.org>
Willem de Bruijn June 25, 2024, 8:53 a.m. UTC | #2
Jakub Kicinski wrote:
> Teach the load generator how to wait for at least given number
> of packets to be received. This will be useful for filtering
> where we'll want to send a non-trivial number of packets and
> make sure they landed in right queues.
> 
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
> v2:
>  - add comment that pps or pkt_cnt are mutually exclusive (David)
>  - rename variables (David)
> ---
>  .../selftests/drivers/net/lib/py/load.py      | 30 ++++++++++++++-----
>  1 file changed, 23 insertions(+), 7 deletions(-)
> 
> diff --git a/tools/testing/selftests/drivers/net/lib/py/load.py b/tools/testing/selftests/drivers/net/lib/py/load.py
> index abdb677bdb1c..31f82f1e32c1 100644
> --- a/tools/testing/selftests/drivers/net/lib/py/load.py
> +++ b/tools/testing/selftests/drivers/net/lib/py/load.py
> @@ -18,15 +18,31 @@ from lib.py import ksft_pr, cmd, ip, rand_port, wait_port_listen
>                                   background=True, host=env.remote)
>  
>          # Wait for traffic to ramp up
> -        pkt = ip("-s link show dev " + env.ifname, json=True)[0]["stats64"]["rx"]["packets"]
> +        if not self._wait_pkts(pps=1000):
> +            self.stop(verbose=True)
> +            raise Exception("iperf3 traffic did not ramp up")
> +
> +    def _wait_pkts(self, pkt_cnt=None, pps=None):
> +        """
> +        Wait until we've seen pkt_cnt or until traffic ramps up to pps.
> +        Only one of pkt_cnt or pss can be specified.
> +        """
> +        pkt_end = ip("-s link show dev " + self.env.ifname, json=True)[0]["stats64"]["rx"]["packets"]

nit: kind of confusing that the first reading is called pkt_end.

I'd s/pkt_end/pkt_start and pkt_start/pkt_now.

Obviously only bikeshedding at this point. Feel free to ignore.

>          for _ in range(50):
>              time.sleep(0.1)
> -            now = ip("-s link show dev " + env.ifname, json=True)[0]["stats64"]["rx"]["packets"]
> -            if now - pkt > 1000:
> -                return
> -            pkt = now
> -        self.stop(verbose=True)
> -        raise Exception("iperf3 traffic did not ramp up")
> +            pkt_start = ip("-s link show dev " + self.env.ifname, json=True)[0]["stats64"]["rx"]["packets"]
> +            if pps:
> +                if pkt_start - pkt_end > pps / 10:
> +                    return True
> +                pkt_end = pkt_start
> +            elif pkt_cnt:
> +                if pkt_start - pkt_end > pkt_cnt:
> +                    return True
> +        return False
> +
> +    def wait_pkts_and_stop(self, pkt_cnt):
> +        failed = not self._wait_pkts(pkt_cnt=pkt_cnt)
> +        self.stop(verbose=failed)
>  
>      def stop(self, verbose=None):
>          self._iperf_client.process(terminate=True)
> -- 
> 2.45.2
>
diff mbox series

Patch

diff --git a/tools/testing/selftests/drivers/net/lib/py/load.py b/tools/testing/selftests/drivers/net/lib/py/load.py
index abdb677bdb1c..31f82f1e32c1 100644
--- a/tools/testing/selftests/drivers/net/lib/py/load.py
+++ b/tools/testing/selftests/drivers/net/lib/py/load.py
@@ -18,15 +18,31 @@  from lib.py import ksft_pr, cmd, ip, rand_port, wait_port_listen
                                  background=True, host=env.remote)
 
         # Wait for traffic to ramp up
-        pkt = ip("-s link show dev " + env.ifname, json=True)[0]["stats64"]["rx"]["packets"]
+        if not self._wait_pkts(pps=1000):
+            self.stop(verbose=True)
+            raise Exception("iperf3 traffic did not ramp up")
+
+    def _wait_pkts(self, pkt_cnt=None, pps=None):
+        """
+        Wait until we've seen pkt_cnt or until traffic ramps up to pps.
+        Only one of pkt_cnt or pss can be specified.
+        """
+        pkt_end = ip("-s link show dev " + self.env.ifname, json=True)[0]["stats64"]["rx"]["packets"]
         for _ in range(50):
             time.sleep(0.1)
-            now = ip("-s link show dev " + env.ifname, json=True)[0]["stats64"]["rx"]["packets"]
-            if now - pkt > 1000:
-                return
-            pkt = now
-        self.stop(verbose=True)
-        raise Exception("iperf3 traffic did not ramp up")
+            pkt_start = ip("-s link show dev " + self.env.ifname, json=True)[0]["stats64"]["rx"]["packets"]
+            if pps:
+                if pkt_start - pkt_end > pps / 10:
+                    return True
+                pkt_end = pkt_start
+            elif pkt_cnt:
+                if pkt_start - pkt_end > pkt_cnt:
+                    return True
+        return False
+
+    def wait_pkts_and_stop(self, pkt_cnt):
+        failed = not self._wait_pkts(pkt_cnt=pkt_cnt)
+        self.stop(verbose=failed)
 
     def stop(self, verbose=None):
         self._iperf_client.process(terminate=True)