From: Cosmin Ratiu <cratiu@nvidia.com>
To: <netdev@vger.kernel.org>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Shuah Khan <shuah@kernel.org>, Simon Horman <horms@kernel.org>,
Cosmin Ratiu <cratiu@nvidia.com>, Petr Machata <petrm@nvidia.com>,
Breno Leitao <leitao@debian.org>, Nimrod Oren <noren@nvidia.com>,
Gal Pressman <gal@nvidia.com>,
Willem de Bruijn <willemb@google.com>,
Dimitri Daskalakis <dimitri.daskalakis1@gmail.com>,
<linux-kselftest@vger.kernel.org>
Subject: [PATCH net-next 2/3] selftests: Wrap remote command executions in PTYs
Date: Mon, 18 May 2026 12:36:52 +0300 [thread overview]
Message-ID: <20260518093653.551166-3-cratiu@nvidia.com> (raw)
In-Reply-To: <20260518093653.551166-1-cratiu@nvidia.com>
Remote commands (executed via ssh) left running in background are killed
with a Popen.terminate(), which kills the local ssh client, terminates
the ssh connection, and eventually the remote side cleans up the forked
remote process.
The next patch makes use of an ssh master connection to speed up test
execution. Terminating a remote command over the master connection
behaves differently: Popen.terminate() hangs while the remote sshd
politely asks the forked command to exit by closing its stdin. Most
backgrounded commands (e.g. iperf3) don't care about stdin and never
exit, hanging until the timeout expires.
In order to make that work, use pseudo-terminals for remote commands
which are backgrounded. Then, terminating the local ssh client using the
master connection results in the same result as today: sshd closes the
master PTY fd and the remote process receives a SIGHUP, which kills it.
This is done by extending the cmd() interface for both remote types with
a 'pty' argument (needed but does nothing for netns). When True, it
results in '-tt' being passed to the ssh client, which forces a PTY to
be used on the remove end.
Using PTYs results in 3 changes. none of which matter in practice:
1. PTYs merge stdout and stderr. None of the tests expect things in
stderr, it's only printed alongside stdout when things go south.
2. PTY line discipline uses \r\n\ instead of \n. Nothing in selftests
matches on full lines including line endings.
3. There are only /proc/sys/kernel/pty/max PTYs on a system, default
4096. This limits the number of concurrent remote commands being
executed on a single machine from selftests, but the limit is
probably unreachable in practice.
So this change should not result in any behavior change for any remote
command execution, but the next patch needs this to switch to using a
master ssh connection.
Signed-off-by: Cosmin Ratiu <cratiu@nvidia.com>
---
tools/testing/selftests/drivers/net/lib/py/remote_netns.py | 2 +-
tools/testing/selftests/drivers/net/lib/py/remote_ssh.py | 7 +++++--
tools/testing/selftests/net/lib/py/utils.py | 4 +++-
3 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/drivers/net/lib/py/remote_netns.py b/tools/testing/selftests/drivers/net/lib/py/remote_netns.py
index 7d5eeb0271bc..e010b3137e41 100644
--- a/tools/testing/selftests/drivers/net/lib/py/remote_netns.py
+++ b/tools/testing/selftests/drivers/net/lib/py/remote_netns.py
@@ -11,7 +11,7 @@ class Remote:
self.name = name
self.dir_path = dir_path
- def cmd(self, comm):
+ def cmd(self, comm, pty=False): # pty arg needed but ignored, netns is local
return subprocess.Popen(["ip", "netns", "exec", self.name, "bash", "-c", comm],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
diff --git a/tools/testing/selftests/drivers/net/lib/py/remote_ssh.py b/tools/testing/selftests/drivers/net/lib/py/remote_ssh.py
index b8c042689d20..427082561d00 100644
--- a/tools/testing/selftests/drivers/net/lib/py/remote_ssh.py
+++ b/tools/testing/selftests/drivers/net/lib/py/remote_ssh.py
@@ -19,8 +19,11 @@ class Remote:
cmd("rm -rf " + self._tmpdir, host=self)
self._tmpdir = None
- def cmd(self, comm):
- return subprocess.Popen(["ssh", "-q", self.name, comm],
+ def cmd(self, comm, pty=False):
+ args = ["ssh", "-q"]
+ if pty:
+ args += ["-tt"]
+ return subprocess.Popen(args + [self.name, comm],
stdin=subprocess.DEVNULL,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py
index be9408a77168..7d400290aa0b 100644
--- a/tools/testing/selftests/net/lib/py/utils.py
+++ b/tools/testing/selftests/net/lib/py/utils.py
@@ -58,7 +58,9 @@ class cmd:
self.comm = comm
if host:
- self.proc = host.cmd(comm)
+ # Remote commands get a PTY, which forces the remote process to
+ # exit in all circumstances when the local ssh client is terminated.
+ self.proc = host.cmd(comm, pty=background)
else:
# If user doesn't explicitly request shell try to avoid it.
if shell is None and isinstance(comm, str) and ' ' in comm:
--
2.53.0
next prev parent reply other threads:[~2026-05-18 9:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-18 9:36 [PATCH net-next 0/3] selftests: Use a master ssh connection for remote commands Cosmin Ratiu
2026-05-18 9:36 ` [PATCH net-next 1/3] selftests: Disable stdin for remote commands over ssh Cosmin Ratiu
2026-05-18 9:36 ` Cosmin Ratiu [this message]
2026-05-18 9:36 ` [PATCH net-next 3/3] selftests: Use a master ssh connection for remote commands Cosmin Ratiu
2026-05-19 23:08 ` Jakub Kicinski
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=20260518093653.551166-3-cratiu@nvidia.com \
--to=cratiu@nvidia.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=dimitri.daskalakis1@gmail.com \
--cc=edumazet@google.com \
--cc=gal@nvidia.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=leitao@debian.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=noren@nvidia.com \
--cc=pabeni@redhat.com \
--cc=petrm@nvidia.com \
--cc=shuah@kernel.org \
--cc=willemb@google.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