Skip to contentSkip to conversation

selftests: rds: Log collection, TAP compliance and cleanups

PATCH Superseded Allison Henderson 2 participants 15 messages Apr 28 – May 3

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Allison Henderson

author maintainer
#0 lore raw

v2 cover selftests: rds: Log collection, TAP compliance and cleanups

This series is a set of bug fixes and improvements for the rds selftests.

Patch 1 bumps the kselftest timeout from 400s to 800s. The original limit was developed against a lean config, but the kselftest harness counts boot time and gcov log collection against the limit, so a default config with gcov enabled needs more headroom.

Patch 2 corrects some typos in the run.sh USAGE string and removes an unused "-g" flag.

Patch 3 silences a handful of pylint warnings in test.py: it adds a module docstring, suppresses the warnings tied to the sys.path.append import trick, marks the long lived tcpdump Popen with disable-next consider-using-with, and drops unused exception variables from two BlockingIOError except clauses.

Patch 4 adds a -t flag to run.sh so the timeout can be overridden if needed.

Patch 5 fixes log collection under vng. The vng guest inherits the host's systemd config, so tmp and debugfs may not be mounted by default; without them tcpdump can't write pcaps and gcov data is silently dropped. The patch mounts each filesystem when it isn't already mounted, and also specifies the --root folder so that gcov can still find the kernel source when it is run from the ksft test directory.

Patch 6 hoists pcap collection into a helper and calls it from the timeout signal handler so dumps are preserved when a test times out.

Patch 7 makes the test output TAP compliant so the kselftest runner parses results correctly.

Questions, comments and feedback appreciated!

Thanks everyone!
Allison

Change log:
v2:
[PATCH net-next v2 3/7] selftests: rds: Fix more pylint errors
NEW

[PATCH net-next v2 6/7] selftests: rds: Collect pcaps on timeout
Fixed pylint errors in collect_pcaps()

[PATCH net-next v2 7/7] selftests: rds: Make rds selftests TAP compliant
Fixed pylint errors from ksft import

Allison Henderson (7):
selftests: rds: Increase selftest timeout
selftests: rds: Update USAGE string for run.sh
selftests: rds: Fix more pylint errors
selftests: rds: Add timeout flag to run.sh
selftests: rds: Fix gcov and pcap collection
selftests: rds: Collect pcaps on timeout
selftests: rds: Make rds selftests TAP compliant

 tools/testing/selftests/net/rds/run.sh   | 42 ++++++++----
 tools/testing/selftests/net/rds/settings |  2 +-
 tools/testing/selftests/net/rds/test.py  | 83 +++++++++++++++---------
 3 files changed, 86 insertions(+), 41 deletions(-)
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH v2 1/7 selftests: rds: Increase selftest timeout

The 400s time out was originally developed under a leaner kernel config that booted much faster than a default config. Boot up is included as part of the over all test runtime, as well as any log collection done when the test is complete. A slower config combined with the gcov enabled test means we'll need more time to accommodate the boot up and log collection. So, bump time out to 800s.

---
 tools/testing/selftests/net/rds/settings | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/net/rds/settings +1 -1
index d2009a64589c..8cb41e6a83cc 100644
@@ -1 +1 @@
-timeout=400
+timeout=800
Signature · 1 line
2.25.1
author maintainer
#2 lore raw

PATCH v2 2/7 selftests: rds: Update USAGE string for run.sh

In reply to Allison Henderson

The run.sh script does not have a -g flag. Update USAGE string with correct flags. Aslo fix typo packet_duplcate -> packet_duplicate

---
 tools/testing/selftests/net/rds/run.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/net/rds/run.sh +1 -1
index 897d17d1b8db..73a9b986b0ef 100755
@@ -171,7 +171,7 @@ while getopts "d:l:c:u:" opt; do
       ;;
     :)
       echo "USAGE: run.sh [-d logdir] [-l packet_loss] [-c packet_corruption]" \
-           "[-u packet_duplcate] [-g]"
+           "[-u packet_duplicate]"
       exit 1
       ;;
     ?)
Signature · 1 line
2.25.1
author maintainer
#3 lore raw

PATCH v2 3/7 selftests: rds: Fix more pylint errors

In reply to Allison Henderson

This patch fixes a few pylint errors in test.py. Remove unused exception variables from except blocks, and disable warnings for imports that cannot appear at the start of the module. Also disable warnings for the tcpdump processes. The suggestion to use a with block does not apply here since the process needs to outlive the parent to collect the dumps. Lastly add the module docstring at the top of the module.

---
 tools/testing/selftests/net/rds/test.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
tools/testing/selftests/net/rds/test.py +8 -3
index 93e23e8b256c..4b6ffbb3a81c 100755
@@ -1,5 +1,8 @@
 #! /usr/bin/env python3
 # SPDX-License-Identifier: GPL-2.0
+"""
+This module provides functional testing for the net/rds component.
+"""
 
 import argparse
 import ctypes
@@ -17,7 +20,8 @@ import shutil
 # Allow utils module to be imported from different directory
 this_dir = os.path.dirname(os.path.realpath(__file__))
 sys.path.append(os.path.join(this_dir, "../"))
-from lib.py.utils import ip
+# pylint: disable-next=wrong-import-position,import-error,no-name-in-module
+from lib.py.utils import ip # noqa: E402
 
 libc = ctypes.cdll.LoadLibrary('libc.so.6')
 setns = libc.setns
@@ -129,6 +133,7 @@ tcpdump_procs = []
 for net in [NET0, NET1]:
     pcap = logdir+'/'+net+'.pcap'
     fd, pcap_tmp = tempfile.mkstemp(suffix=".pcap", prefix=f"{net}-", dir="/tmp")
+    # pylint: disable-next=consider-using-with
     p = subprocess.Popen(
         ['ip', 'netns', 'exec', net,
          '/usr/sbin/tcpdump', '-i', 'any', '-w', pcap_tmp])
@@ -192,7 +197,7 @@ while nr_send < NUM_PACKETS:
             send_hashes.setdefault((sender.fileno(), receiver.fileno()),
                     hashlib.sha256()).update(f'<{send_data}>'.encode('utf-8'))
             nr_send = nr_send + 1
-        except BlockingIOError as e:
+        except BlockingIOError:
             break
         except OSError as e:
             if e.errno in [errno.ENOBUFS, errno.ECONNRESET, errno.EPIPE]:
@@ -214,7 +219,7 @@ while nr_send < NUM_PACKETS:
                             receiver.fileno()), hashlib.sha256()).update(
                                     f'<{recv_data}>'.encode('utf-8'))
                         nr_recv = nr_recv + 1
-                    except BlockingIOError as e:
+                    except BlockingIOError:
                         break
 
     # exercise net/rds/tcp.c:rds_tcp_sysctl_reset()
Signature · 1 line
2.25.1
author maintainer
#4 lore raw

PATCH v2 4/7 selftests: rds: Add timeout flag to run.sh

In reply to Allison Henderson

Add a -t flag to run.sh to optionally override the default timeout. The --timeout flag is already supported in test.py, so just add the shorthand -t flag

---
 tools/testing/selftests/net/rds/run.sh  | 11 ++++++++---
 tools/testing/selftests/net/rds/test.py |  2 +-
 2 files changed, 9 insertions(+), 4 deletions(-)
tools/testing/selftests/net/rds/run.sh +8 -3
index 73a9b986b0ef..bc2e53126aab 100755
@@ -154,8 +154,9 @@ LOG_DIR="$current_dir"/rds_logs
 PLOSS=0
 PCORRUPT=0
 PDUP=0
+TIMEOUT=$timeout
 GENERATE_GCOV_REPORT=1
-while getopts "d:l:c:u:" opt; do
+while getopts "d:l:c:u:t:" opt; do
   case ${opt} in
     d)
       LOG_DIR=${OPTARG}
@@ -166,12 +167,15 @@ while getopts "d:l:c:u:" opt; do
     c)
       PCORRUPT=${OPTARG}
       ;;
+    t)
+      TIMEOUT=${OPTARG}
+      ;;
     u)
       PDUP=${OPTARG}
       ;;
     :)
       echo "USAGE: run.sh [-d logdir] [-l packet_loss] [-c packet_corruption]" \
-           "[-u packet_duplicate]"
+           "[-u packet_duplicate] [-t timeout]"
       exit 1
       ;;
     ?)
@@ -198,7 +202,8 @@ echo running RDS tests...
 echo Traces will be logged to "$TRACE_FILE"
 rm -f "$TRACE_FILE"
 strace -T -tt -o "$TRACE_FILE" python3 "$(dirname "$0")/test.py" \
-	--timeout "$timeout" -d "$LOG_DIR" -l "$PLOSS" -c "$PCORRUPT" -u "$PDUP"
+	-t "$TIMEOUT" -d "$LOG_DIR" -l "$PLOSS" -c "$PCORRUPT" \
+	-u "$PDUP"
 
 test_rc=$?
 dmesg > "${LOG_DIR}/dmesg.out"
tools/testing/selftests/net/rds/test.py +1 -1
index 4b6ffbb3a81c..d48533505f0f 100755
@@ -83,7 +83,7 @@ parser = argparse.ArgumentParser(description="init script args",
                   formatter_class=argparse.ArgumentDefaultsHelpFormatter)
 parser.add_argument("-d", "--logdir", action="store",
                     help="directory to store logs", default="/tmp")
-parser.add_argument('--timeout', help="timeout to terminate hung test",
+parser.add_argument('-t', '--timeout', help="timeout to terminate hung test",
                     type=int, default=0)
 parser.add_argument('-l', '--loss', help="Simulate tcp packet loss",
                     type=int, default=0)
Signature · 1 line
2.25.1
author maintainer
#5 lore raw

PATCH v2 5/7 selftests: rds: Fix gcov and pcap collection

In reply to Allison Henderson

The vng guest shares the host filesystem via 9p and runs a minimal systemd inherited from the host's /lib/systemd/system/. As a result, which filesystems get auto-mounted in the guest depends on the host OS and its systemd version.

The tcpdump pcaps are initially saved to /tmp because 9p does not support chown which tcpdump requires. But whether /tmp is already a tmpfs depends on the host's systemd configuration and may still sometimes fail if /tmp is not mounted by default. Fix this by mounting tmpfs on /tmp in run.sh when it is not already a separately mounted filesystem.

A similar dependency exists for gcov. debugfs is not mounted automatically in vng guest, so the gcov data copy from /sys/kernel/debug/gcov/ silently finds nothing depending on whether debugfs is mounted by default on the host OS. Fix this by mounting debugfs in run.sh before copying the gcda files.

Finally, when invoked through the kselftest runner, the working directory is the test directory rather than the kernel source root. gcovr defaults --root to the current working directory, causing it to filter out all coverage data for files under net/rds/ since they are not under the test directory. Fix this by passing --root to gcovr explicitly.

---
 tools/testing/selftests/net/rds/run.sh | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
tools/testing/selftests/net/rds/run.sh +14 -1
index bc2e53126aab..3fc116d23410 100755
@@ -197,6 +197,13 @@ COVR_DIR="${LOG_DIR}/coverage/"
 mkdir -p  "$LOG_DIR"
 mkdir -p "$COVR_DIR"
 
+# tcpdump saves pcaps to /tmp because it requires chown to save the
+# pcap but chown is not supported by 9p.  Mount tmpfs on /tmp if it is
+# not already a separate filesystem
+if ! mountpoint -q /tmp 2>/dev/null; then
+	mount -t tmpfs tmpfs /tmp
+fi
+
 set +e
 echo running RDS tests...
 echo Traces will be logged to "$TRACE_FILE"
@@ -210,6 +217,12 @@ dmesg > "${LOG_DIR}/dmesg.out"
 
 if [ "$GENERATE_GCOV_REPORT" -eq 1 ]; then
        echo saving coverage data...
+
+       # Ensure debugfs is mounted
+       if ! test -d /sys/kernel/debug/gcov; then
+               mount -t debugfs debugfs /sys/kernel/debug 2>/dev/null || true
+       fi
+
        (set +x; cd /sys/kernel/debug/gcov; find ./* -name '*.gcda' | \
        while read -r f
        do
@@ -218,7 +231,7 @@ if [ "$GENERATE_GCOV_REPORT" -eq 1 ]; then
 
        echo running gcovr...
        gcovr -s --html-details --gcov-executable "$GCOV_CMD" --gcov-ignore-parse-errors \
-             -o "${COVR_DIR}/gcovr" "${ksrc_dir}/net/rds/"
+             --root "${ksrc_dir}" -o "${COVR_DIR}/gcovr" "${ksrc_dir}/net/rds/"
 else
        echo "Coverage report will be skipped"
 fi
Signature · 1 line
2.25.1
author maintainer
#11 lore raw

PATCH v2 6/7 selftests: rds: Collect pcaps on timeout

In reply to Allison Henderson

The timeout signal handler for the rds selftests currently just exits when the time limit is exceeded, and forgets to collect the network dumps. Which can be valueable for discerning why the test timed out in the first place. Fix this by hoisting the network dump collection into a helper function, and call it from the signal handler before exiting

---
 tools/testing/selftests/net/rds/test.py | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
tools/testing/selftests/net/rds/test.py +11 -7
index d48533505f0f..1c7aebddeb61 100755
@@ -70,11 +70,21 @@ def netns_socket(netns, *sock_args):
     u1.close()
     return socket.fromfd(fds[0], *sock_args)
 
+def collect_pcaps():
+    """Stop tcpdump processes and move their pcaps into the log dir."""
+    print("Stopping network packet captures")
+    for proc, tmp_path, dest_path, fno in tcpdump_procs:
+        proc.terminate()
+        proc.wait()
+        os.close(fno)
+        shutil.move(tmp_path, dest_path)
+
 def signal_handler(_sig, _frame):
     """
     Test timed out signal handler
     """
     print('Test timed out')
+    collect_pcaps()
     sys.exit(1)
 
 #Parse out command line arguments.  We take an optional
@@ -251,13 +261,7 @@ for s in sockets:
                 pass
 
 print(f"getsockopt(): {nr_success}/{nr_error}")
-
-print("Stopping network packet captures")
-for p, pcap_tmp, pcap, fd in tcpdump_procs:
-    p.terminate()
-    p.wait()
-    os.close(fd)
-    shutil.move(pcap_tmp, pcap)
+collect_pcaps()
 
 # We're done sending and receiving stuff, now let's check if what
 # we received is what we sent.
Signature · 1 line
2.25.1
author maintainer
#14 lore raw

PATCH v2 7/7 selftests: rds: Make rds selftests TAP compliant

In reply to Allison Henderson

This patch updates the rds selftests output to be TAP compliant.

Use ksft_pr() to mark debug output with a leading '# ' so that TAP parsers treat it as commentary, and convert all informational print() calls to use ksft_pr(). sys.exit(0) is changed to os._exit(0) to avoid duplicate prints from the buffered TAP output. The console output from the tcpdump subprocess is silenced, and the gcov console output is redirected to a gcovr.log.

Finally adjust the exit path so that the hash check loop sets a return code instead exiting directly. Then print the TAP results and totals lines before exiting.

---
 tools/testing/selftests/net/rds/run.sh  | 18 +++++----
 tools/testing/selftests/net/rds/test.py | 54 ++++++++++++++++---------
 2 files changed, 45 insertions(+), 27 deletions(-)
tools/testing/selftests/net/rds/run.sh +10 -8
index 3fc116d23410..805cd0915585 100755
@@ -205,8 +205,8 @@ if ! mountpoint -q /tmp 2>/dev/null; then
 fi
 
 set +e
-echo running RDS tests...
-echo Traces will be logged to "$TRACE_FILE"
+echo "# running RDS tests..."
+echo "# Traces will be logged to $TRACE_FILE"
 rm -f "$TRACE_FILE"
 strace -T -tt -o "$TRACE_FILE" python3 "$(dirname "$0")/test.py" \
 	-t "$TIMEOUT" -d "$LOG_DIR" -l "$PLOSS" -c "$PCORRUPT" \
@@ -216,7 +216,7 @@ test_rc=$?
 dmesg > "${LOG_DIR}/dmesg.out"
 
 if [ "$GENERATE_GCOV_REPORT" -eq 1 ]; then
-       echo saving coverage data...
+       echo "# saving coverage data..."
 
        # Ensure debugfs is mounted
        if ! test -d /sys/kernel/debug/gcov; then
@@ -229,17 +229,19 @@ if [ "$GENERATE_GCOV_REPORT" -eq 1 ]; then
                cat < "/sys/kernel/debug/gcov/$f" > "/$f"
        done)
 
-       echo running gcovr...
+       echo "# running gcovr..."
        gcovr -s --html-details --gcov-executable "$GCOV_CMD" --gcov-ignore-parse-errors \
-             --root "${ksrc_dir}" -o "${COVR_DIR}/gcovr" "${ksrc_dir}/net/rds/"
+             --root "${ksrc_dir}" -o "${COVR_DIR}/gcovr" "${ksrc_dir}/net/rds/" \
+             > "${LOG_DIR}/gcovr.log" 2>&1
+       echo "# gcovr log: ${LOG_DIR}/gcovr.log"
 else
-       echo "Coverage report will be skipped"
+       echo "# Coverage report will be skipped"
 fi
 
 if [ "$test_rc" -eq 0 ]; then
-	echo "PASS: Test completed successfully"
+	echo "# PASS: Test completed successfully"
 else
-	echo "FAIL: Test failed"
+	echo "# FAIL: Test failed"
 fi
 
 exit "$test_rc"
tools/testing/selftests/net/rds/test.py +35 -19

122 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer
#6 lore raw

Re: [PATCH net-next v2 5/7] selftests: rds: Fix gcov and pcap collection

In reply to Allison Henderson

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
selftests: rds: Fix gcov and pcap collection

This commit addresses dependencies on host systemd configurations in the vng guest. It adds mounts for tmpfs on /tmp and debugfs to ensure pcap and gcov data collection work, and updates the gcovr root path.

Quoted 5 lines
tools/testing/selftests/net/rds/run.sh +0 -0
index bc2e53126aab..3fc116d23410 100755

tools/testing/selftests/net/rds/run.sh COVR_DIR="${LOG_DIR}/coverage/" · line 206

Quoted 10 lines
tools/testing/selftests/net/rds/run.sh +7 -0
@@ -197,6 +197,13 @@ COVR_DIR="${LOG_DIR}/coverage/"
 mkdir -p  "$LOG_DIR"
 mkdir -p "$COVR_DIR"
 
+# tcpdump saves pcaps to /tmp because it requires chown to save the
+# pcap but chown is not supported by 9p.  Mount tmpfs on /tmp if it is
+# not already a separate filesystem
+if ! mountpoint -q /tmp 2>/dev/null; then
+	mount -t tmpfs tmpfs /tmp
+fi
+

Could this introduce a regression when the test is run directly on a host workstation rather than inside an isolated VM?

If /tmp is a regular directory on the root filesystem, mounting tmpfs over it will instantly hide all existing files and UNIX domain sockets in /tmp.

Since there is no cleanup trap to unmount it on exit or failure, does this leave the host system in a degraded state?

[ ... ]

tools/testing/selftests/net/rds/run.sh dmesg > "${LOG_DIR}/dmesg.out" · line 225

Quoted 8 lines
tools/testing/selftests/net/rds/run.sh +6 -0
 if [ "$GENERATE_GCOV_REPORT" -eq 1 ]; then
        echo saving coverage data...
+
+       # Ensure debugfs is mounted
+       if ! test -d /sys/kernel/debug/gcov; then
+               mount -t debugfs debugfs /sys/kernel/debug 2>/dev/null || true
+       fi
+

If the test is run against a kernel that does not have CONFIG_GCOV_KERNEL enabled, the gcov directory will not exist even when debugfs is correctly mounted.

Will this condition cause a regression where the script repeatedly mounts debugfs on every run, stacking redundant shadow mounts over /sys/kernel/debug since they are never unmounted?

Signature · 1 line
pw-bot: cr
maintainer
#12 lore raw

Re: [PATCH net-next v2 6/7] selftests: rds: Collect pcaps on timeout

In reply to Allison Henderson

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
selftests: rds: Collect pcaps on timeout

This commit updates the RDS selftest to collect network packet captures when a timeout occurs. It moves the packet capture cleanup logic into a new helper function and calls it from the signal handler before exiting.

Quoted 3 lines
tools/testing/selftests/net/rds/test.py +0 -0

[ ... ]

tools/testing/selftests/net/rds/test.py def netns_socket(netns, *sock_args): · line 78

Quoted 10 lines
tools/testing/selftests/net/rds/test.py +6 -0
@@ -70,11 +70,21 @@ def netns_socket(netns, *sock_args):
     u1.close()
     return socket.fromfd(fds[0], *sock_args)
 
+def collect_pcaps():
+    """Stop tcpdump processes and move their pcaps into the log dir."""
+    print("Stopping network packet captures")
+    for proc, tmp_path, dest_path, fno in tcpdump_procs:
+        proc.terminate()
+        proc.wait()

Could this proc.wait() block indefinitely and defeat the test timeout?

If a child process is unresponsive, the timeout signal handler will get stuck waiting for it. Using proc.wait(timeout=...) might ensure the timeout path remains robust and doesn't hang the test infrastructure.

tools/testing/selftests/net/rds/test.py def netns_socket(netns, *sock_args): · line 80

Quoted 2 lines
tools/testing/selftests/net/rds/test.py +2 -0
+        os.close(fno)
+        shutil.move(tmp_path, dest_path)

Can this cause unhandled exceptions if the timeout triggers during or after the normal script cleanup phase?

Because collect_pcaps() is called from both the normal execution path and the timeout signal handler, it might be executed twice. Since it loops over the global tcpdump_procs list without clearing processed items, a second run will attempt to close already closed file descriptors and move already moved files.

In Python, this raises OSError (EBADF) and FileNotFoundError, which would abort the signal handler with a traceback instead of executing the clean sys.exit(1).

maintainer
#7 lore raw

Re: [PATCH net-next v2 5/7] selftests: rds: Fix gcov and pcap collection

In reply to Jakub Kicinski
Quoted 11 lines · On Wed, 29 Apr 2026 19:42:06 -0700 Jakub Kicinski wrote:

tools/testing/selftests/net/rds/run.sh COVR_DIR="${LOG_DIR}/coverage/" · line 206

Quoted 7 lines
tools/testing/selftests/net/rds/run.sh +7 -0
+# tcpdump saves pcaps to /tmp because it requires chown to save the
+# pcap but chown is not supported by 9p.  Mount tmpfs on /tmp if it is
+# not already a separate filesystem
+if ! mountpoint -q /tmp 2>/dev/null; then
+	mount -t tmpfs tmpfs /tmp
+fi
+  

Could this introduce a regression when the test is run directly on a host workstation rather than inside an isolated VM?

Quoted 5 lines

If /tmp is a regular directory on the root filesystem, mounting tmpfs over it will instantly hide all existing files and UNIX domain sockets in /tmp.

Since there is no cleanup trap to unmount it on exit or failure, does this leave the host system in a degraded state?

I share Sashiko's mixed feelings here. Do other tests mount /tmp ? Seems like something that belongs in the "CI setup", external to ksft itself.

point #2 my vng does have an overlayfs mounted over /tmp so the mountpoint check doesn't trigger IDK if this is what you meant or I have a different version.

author maintainer
#13 lore raw

Re: [PATCH net-next v2 6/7] selftests: rds: Collect pcaps on timeout

In reply to Jakub Kicinski
Quoted 26 lines · Jakub Kicinski

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
selftests: rds: Collect pcaps on timeout

This commit updates the RDS selftest to collect network packet captures when a timeout occurs. It moves the packet capture cleanup logic into a new helper function and calls it from the signal handler before exiting.

Quoted 3 lines
tools/testing/selftests/net/rds/test.py +0 -0

[ ... ]

tools/testing/selftests/net/rds/test.py def netns_socket(netns, *sock_args): · line 78

Quoted 10 lines
tools/testing/selftests/net/rds/test.py +6 -0
@@ -70,11 +70,21 @@ def netns_socket(netns, *sock_args):
     u1.close()
     return socket.fromfd(fds[0], *sock_args)
 
+def collect_pcaps():
+    """Stop tcpdump processes and move their pcaps into the log dir."""
+    print("Stopping network packet captures")
+    for proc, tmp_path, dest_path, fno in tcpdump_procs:
+        proc.terminate()
+        proc.wait()

Could this proc.wait() block indefinitely and defeat the test timeout?

Quoted 3 lines

If a child process is unresponsive, the timeout signal handler will get stuck waiting for it. Using proc.wait(timeout=...) might ensure the timeout path remains robust and doesn't hang the test infrastructure.

Good catch, I will add a timeout

Quoted 13 lines

tools/testing/selftests/net/rds/test.py def netns_socket(netns, *sock_args): · line 80

Quoted 3 lines
tools/testing/selftests/net/rds/test.py +2 -0
+        os.close(fno)
+        shutil.move(tmp_path, dest_path)

Can this cause unhandled exceptions if the timeout triggers during or after the normal script cleanup phase?

Because collect_pcaps() is called from both the normal execution path and the timeout signal handler, it might be executed twice. Since it loops over the global tcpdump_procs list without clearing processed items, a second run will attempt to close already closed file descriptors and move already moved files.

Quoted 3 lines

In Python, this raises OSError (EBADF) and FileNotFoundError, which would abort the signal handler with a traceback instead of executing the clean sys.exit(1).

I see, I think if we change the for loop to a while loop that pop() items out of tcpdump_procs, that should make it safe to call twice, if the timeout fires during or after normal cleanup.

If that sounds good, I can send that in a v3.

Thanks!
Allison

author maintainer
#8 lore raw

Re: [PATCH net-next v2 5/7] selftests: rds: Fix gcov and pcap collection

In reply to Jakub Kicinski
Quoted 15 lines · Jakub Kicinski
Quoted 14 lines · On Wed, 29 Apr 2026 19:42:06 -0700 Jakub Kicinski wrote:

tools/testing/selftests/net/rds/run.sh COVR_DIR="${LOG_DIR}/coverage/" · line 206

Quoted 7 lines
tools/testing/selftests/net/rds/run.sh +7 -0
+# tcpdump saves pcaps to /tmp because it requires chown to save the
+# pcap but chown is not supported by 9p.  Mount tmpfs on /tmp if it is
+# not already a separate filesystem
+if ! mountpoint -q /tmp 2>/dev/null; then
+	mount -t tmpfs tmpfs /tmp
+fi
+  

Could this introduce a regression when the test is run directly on a host workstation rather than inside an isolated VM?

If /tmp is a regular directory on the root filesystem, mounting tmpfs over it will instantly hide all existing files and UNIX domain sockets in /tmp.

Quoted 6 lines
Quoted 2 lines

Since there is no cleanup trap to unmount it on exit or failure, does this leave the host system in a degraded state?

I share Sashiko's mixed feelings here. Do other tests mount /tmp ? Seems like something that belongs in the "CI setup", external to ksft itself.

Ok, I did some looking around, and while I dont see any tests that mount /tmp, I did notice that mptcp_join.sh and simult_flows.sh use a $SUDO_USER, presumably to get away from the chown issue. But without getting off the 9p fs with some sort of scratch area, we still end up with empty pcaps.

Quoted 4 lines

point #2 my vng does have an overlayfs mounted over /tmp so the mountpoint check doesn't trigger IDK if this is what you meant or I have a different version.

I did try using --overlay-rwdir, and I think that gives rw to the guest, but it's ro to the host, so we dont get to keep the pcaps post mortem.

What we can do, if it sounds ok to you, is set up a temp scratch area in the rds_logs folder so it's not mounting over /tmp, and then run.sh can handle the mount with a cleanup trap addressing Sashiko's concern

Let me know what you think?

Thank you for the reviews!
Allison

maintainer
#9 lore raw

Re: [PATCH net-next v2 5/7] selftests: rds: Fix gcov and pcap collection

Quoted 8 lines · On Fri, 01 May 2026 22:43:04 -0700 Allison Henderson wrote:
Quoted 3 lines

point #2 my vng does have an overlayfs mounted over /tmp so the mountpoint check doesn't trigger IDK if this is what you meant or I have a different version.

I did try using --overlay-rwdir, and I think that gives rw to the guest, but it's ro to the host, so we dont get to keep the pcaps post mortem.

Quoted 6 lines

What we can do, if it sounds ok to you, is set up a temp scratch area in the rds_logs folder so it's not mounting over /tmp, and then run.sh can handle the mount with a cleanup trap addressing Sashiko's concern

Let me know what you think?

Oh, you need these files for a post mortem analysis? I missed that point. IDK if there's a well established way to save extra debug info from the tests. runner has per_test_log_dir but I don't think it's exposed to tests? Until ksft has such a thing I'd probably go with an extra env variable to point the test to a specific dir. Which dir will depend on the CI harness. If var is not set - don't output the logs or use /tmp and clean up when test exits.

author maintainer
#10 lore raw

Re: [PATCH net-next v2 5/7] selftests: rds: Fix gcov and pcap collection

Quoted 16 lines · Jakub Kicinski
Quoted 8 lines · On Fri, 01 May 2026 22:43:04 -0700 Allison Henderson wrote:
Quoted 3 lines

point #2 my vng does have an overlayfs mounted over /tmp so the mountpoint check doesn't trigger IDK if this is what you meant or I have a different version.

I did try using --overlay-rwdir, and I think that gives rw to the guest, but it's ro to the host, so we dont get to keep the pcaps post mortem.

Quoted 6 lines

What we can do, if it sounds ok to you, is set up a temp scratch area in the rds_logs folder so it's not mounting over /tmp, and then run.sh can handle the mount with a cleanup trap addressing Sashiko's concern

Let me know what you think?

Quoted 7 lines

Oh, you need these files for a post mortem analysis? I missed that point. IDK if there's a well established way to save extra debug info from the tests. runner has per_test_log_dir but I don't think it's exposed to tests? Until ksft has such a thing I'd probably go with an extra env variable to point the test to a specific dir. Which dir will depend on the CI harness. If var is not set - don't output the logs or use /tmp and clean up when test exits.

Ok, I will see if I can do some refactoring and pull the log dir out of the test scripts and into an environment variable. I think that should work if I adopt the $SUDO_USER pattern the other tests use.

Thank you for the reviews!
Allison