netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
	willemdebruijn.kernel@gmail.com, ecree.xilinx@gmail.com,
	dw@davidwei.uk, przemyslaw.kitszel@intel.com,
	michael.chan@broadcom.com, andrew.gospodarek@broadcom.com,
	Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next v2 3/4] selftests: drv-net: add ability to wait for at least N packets to load gen
Date: Mon, 24 Jun 2024 18:02:09 -0700	[thread overview]
Message-ID: <20240625010210.2002310-4-kuba@kernel.org> (raw)
In-Reply-To: <20240625010210.2002310-1-kuba@kernel.org>

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"]
         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


  parent reply	other threads:[~2024-06-25  1:02 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-25  1:02 [PATCH net-next v2 0/4] selftests: drv-net: rss_ctx: add tests for RSS contexts Jakub Kicinski
2024-06-25  1:02 ` [PATCH net-next v2 1/4] selftests: drv-net: try to check if port is in use Jakub Kicinski
2024-06-25  6:57   ` Przemek Kitszel
2024-06-25  8:02   ` Breno Leitao
2024-06-25  1:02 ` [PATCH net-next v2 2/4] selftests: drv-net: add helper to wait for HW stats to sync Jakub Kicinski
2024-06-25 10:04   ` Petr Machata
2024-06-25  1:02 ` Jakub Kicinski [this message]
2024-06-25  8:05   ` [PATCH net-next v2 3/4] selftests: drv-net: add ability to wait for at least N packets to load gen Breno Leitao
2024-06-25  8:53   ` Willem de Bruijn
2024-06-25  1:02 ` [PATCH net-next v2 4/4] selftests: drv-net: rss_ctx: add tests for RSS configuration and contexts Jakub Kicinski
2024-06-25 10:42   ` Petr Machata
2024-06-25 13:50     ` Jakub Kicinski
2024-06-25 14:43       ` Petr Machata
2024-06-25 17:06         ` Jakub Kicinski
2024-06-25 17:41           ` Jakub Kicinski
2024-06-26  8:42           ` Petr Machata
2024-06-25  1:40 ` [PATCH net-next v2 0/4] selftests: drv-net: rss_ctx: add tests for RSS contexts Jakub Kicinski
2024-06-25  3:42   ` Michael Chan
2024-06-25  8:52 ` Willem de Bruijn

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=20240625010210.2002310-4-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=andrew.gospodarek@broadcom.com \
    --cc=davem@davemloft.net \
    --cc=dw@davidwei.uk \
    --cc=ecree.xilinx@gmail.com \
    --cc=edumazet@google.com \
    --cc=michael.chan@broadcom.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=willemdebruijn.kernel@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).