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,
	andrew+netdev@lunn.ch, horms@kernel.org,
	willemdebruijn.kernel@gmail.com, shuah@kernel.org,
	sdf@fomichev.me, krakauer@google.com,
	linux-kselftest@vger.kernel.org, petrm@nvidia.com,
	matttbe@kernel.org, Jakub Kicinski <kuba@kernel.org>,
	Willem de Bruijn <willemb@google.com>,
	leitao@debian.org
Subject: [PATCH net-next v3 06/12] selftests: net: py: support ksft ready without wait
Date: Wed, 19 Nov 2025 18:10:18 -0800	[thread overview]
Message-ID: <20251120021024.2944527-7-kuba@kernel.org> (raw)
In-Reply-To: <20251120021024.2944527-1-kuba@kernel.org>

There's a common synchronization problem when a script (Python test)
uses a C program to set up some state (usually start a receiving
process for traffic). The script needs to know when the process
has fully initialized. The inverse of the problem exists for shutting
the process down - we need a reliable way to tell the process to exit.

We added helpers to do this safely in
commit 71477137994f ("selftests: drv-net: add a way to wait for a local process")
unfortunately the two operations (wait for init, and shutdown) are
controlled by a single parameter (ksft_wait). Add support for using
ksft_ready without using the second fd for exit.

This is useful for programs which wait for a specific number of packets
to rx so exit_wait is a good match, but we still need to wait for init.

Reviewed-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
cc: leitao@debian.org
---
 tools/testing/selftests/net/lib/py/utils.py | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py
index cb40ecef9456..106ee1f2df86 100644
--- a/tools/testing/selftests/net/lib/py/utils.py
+++ b/tools/testing/selftests/net/lib/py/utils.py
@@ -32,7 +32,7 @@ import time
     Use bkg() instead to run a command in the background.
     """
     def __init__(self, comm, shell=None, fail=True, ns=None, background=False,
-                 host=None, timeout=5, ksft_wait=None):
+                 host=None, timeout=5, ksft_ready=None, ksft_wait=None):
         if ns:
             comm = f'ip netns exec {ns} ' + comm
 
@@ -52,21 +52,25 @@ import time
             # ksft_wait lets us wait for the background process to fully start,
             # we pass an FD to the child process, and wait for it to write back.
             # Similarly term_fd tells child it's time to exit.
-            pass_fds = ()
+            pass_fds = []
             env = os.environ.copy()
             if ksft_wait is not None:
-                rfd, ready_fd = os.pipe()
                 wait_fd, self.ksft_term_fd = os.pipe()
-                pass_fds = (ready_fd, wait_fd, )
-                env["KSFT_READY_FD"] = str(ready_fd)
+                pass_fds.append(wait_fd)
                 env["KSFT_WAIT_FD"]  = str(wait_fd)
+                ksft_ready = True  # ksft_wait implies ready
+            if ksft_ready is not None:
+                rfd, ready_fd = os.pipe()
+                pass_fds.append(ready_fd)
+                env["KSFT_READY_FD"] = str(ready_fd)
 
             self.proc = subprocess.Popen(comm, shell=shell, stdout=subprocess.PIPE,
                                          stderr=subprocess.PIPE, pass_fds=pass_fds,
                                          env=env)
             if ksft_wait is not None:
-                os.close(ready_fd)
                 os.close(wait_fd)
+            if ksft_ready is not None:
+                os.close(ready_fd)
                 msg = fd_read_timeout(rfd, ksft_wait)
                 os.close(rfd)
                 if not msg:
@@ -116,10 +120,10 @@ import time
         with bkg("my_binary", ksft_wait=5):
     """
     def __init__(self, comm, shell=None, fail=None, ns=None, host=None,
-                 exit_wait=False, ksft_wait=None):
+                 exit_wait=False, ksft_ready=None, ksft_wait=None):
         super().__init__(comm, background=True,
                          shell=shell, fail=fail, ns=ns, host=host,
-                         ksft_wait=ksft_wait)
+                         ksft_ready=ksft_ready, ksft_wait=ksft_wait)
         self.terminate = not exit_wait and not ksft_wait
         self._exit_wait = exit_wait
         self.check_fail = fail
-- 
2.51.1


  parent reply	other threads:[~2025-11-20  2:10 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-20  2:10 [PATCH net-next v3 00/12] selftests: drv-net: convert GRO and Toeplitz tests to work for drivers in NIPA Jakub Kicinski
2025-11-20  2:10 ` [PATCH net-next v3 01/12] selftests: net: py: coding style improvements Jakub Kicinski
2025-11-20  8:54   ` Petr Machata
2025-11-20  2:10 ` [PATCH net-next v3 02/12] selftests: net: py: extract the case generation logic Jakub Kicinski
2025-11-20  2:10 ` [PATCH net-next v3 03/12] selftests: net: py: add test variants Jakub Kicinski
2025-11-20  8:55   ` Petr Machata
2025-11-20  2:10 ` [PATCH net-next v3 04/12] selftests: drv-net: xdp: use variants for qstat tests Jakub Kicinski
2025-11-20  2:10 ` [PATCH net-next v3 05/12] selftests: net: relocate gro and toeplitz tests to drivers/net Jakub Kicinski
2025-11-20  2:10 ` Jakub Kicinski [this message]
2025-11-20 10:03   ` [PATCH net-next v3 06/12] selftests: net: py: support ksft ready without wait Breno Leitao
2025-11-20  2:10 ` [PATCH net-next v3 07/12] selftests: net: py: read ip link info about remote dev Jakub Kicinski
2025-11-20  2:10 ` [PATCH net-next v3 08/12] netdevsim: pass packets thru GRO on Rx Jakub Kicinski
2025-11-20  2:10 ` [PATCH net-next v3 09/12] selftests: drv-net: add a Python version of the GRO test Jakub Kicinski
2025-11-20  2:10 ` [PATCH net-next v3 10/12] selftests: drv-net: hw: convert the Toeplitz test to Python Jakub Kicinski
2025-11-20  2:10 ` [PATCH net-next v3 11/12] netdevsim: add loopback support Jakub Kicinski
2025-11-20  2:10 ` [PATCH net-next v3 12/12] selftests: net: remove old setup_* scripts Jakub Kicinski
2025-11-21  2:30 ` [PATCH net-next v3 00/12] selftests: drv-net: convert GRO and Toeplitz tests to work for drivers in NIPA patchwork-bot+netdevbpf

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=20251120021024.2944527-7-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=krakauer@google.com \
    --cc=leitao@debian.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=matttbe@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=petrm@nvidia.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=willemb@google.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).