From: Allison Henderson <achender@kernel.org>
To: netdev@vger.kernel.org, pabeni@redhat.com, edumazet@google.com,
kuba@kernel.org, horms@kernel.org, linux-rdma@vger.kernel.org,
achender@kernel.org, linux-kselftest@vger.kernel.org,
shuah@kernel.org
Subject: [PATCH net-next v3 05/10] selftests: rds: Add RDS_LOG_DIR env variable
Date: Sun, 3 May 2026 22:41:38 -0700 [thread overview]
Message-ID: <20260504054143.4027538-6-achender@kernel.org> (raw)
In-Reply-To: <20260504054143.4027538-1-achender@kernel.org>
This patch modifies the rds selftest to look for an env variable
RDS_LOG_DIR, and log all traces, pcaps and gcov collections to
the folder specified in RDS_LOG_DIR. If RDS_LOG_DIR is unset,
logs are not collected.
Signed-off-by: Allison Henderson <achender@kernel.org>
---
tools/testing/selftests/net/rds/README.txt | 19 +++++++--
tools/testing/selftests/net/rds/run.sh | 45 ++++++++++++----------
tools/testing/selftests/net/rds/test.py | 34 ++++++++--------
3 files changed, 59 insertions(+), 39 deletions(-)
diff --git a/tools/testing/selftests/net/rds/README.txt b/tools/testing/selftests/net/rds/README.txt
index be9c7e25694e..e629e08f04ef 100644
--- a/tools/testing/selftests/net/rds/README.txt
+++ b/tools/testing/selftests/net/rds/README.txt
@@ -15,7 +15,9 @@ USAGE:
[-u packet_duplicate] [-t timeout]
OPTIONS:
- -d Log directory. Defaults to tools/testing/selftests/net/rds/rds_logs
+ -d Log directory. If set, logs will be stored in the
+ given dir, or skipped if unset. Log dir can also be
+ set through the RDS_LOG_DIR env variable
-l Simulates a percentage of packet loss
@@ -25,6 +27,16 @@ OPTIONS:
-t Test timeout. Defaults to tools/testing/selftests/net/rds/settings
+ENV VARIABLES:
+ RDS_LOG_DIR Log directory. If set, logs will be stored in
+ the given dir, or skipped if unset. Log dir
+ can also be set with the -d flag.
+
+ Use with --rwdir on the CI path to retain logs after
+ test compleation. Log dir end point must be within
+ the specified --rwdir path for logs to persist on
+ the host.
+
EXAMPLE:
# Create a suitable gcov enabled .config
@@ -41,6 +53,7 @@ EXAMPLE:
# launch the tests in a VM
vng -v --rwdir ./ --run . --user root --cpus 4 -- \
- "export PYTHONPATH=tools/testing/selftests/net/; tools/testing/selftests/net/rds/run.sh"
+ "export PYTHONPATH=tools/testing/selftests/net/; \
+ export RDS_LOG_DIR=tools/testing/selftests/net/rds/rds_logs; \
+ tools/testing/selftests/net/rds/run.sh"
-An HTML coverage report will be output in tools/testing/selftests/net/rds/rds_logs/coverage/.
diff --git a/tools/testing/selftests/net/rds/run.sh b/tools/testing/selftests/net/rds/run.sh
index bc2e53126aab..edc021f4dec9 100755
--- a/tools/testing/selftests/net/rds/run.sh
+++ b/tools/testing/selftests/net/rds/run.sh
@@ -150,28 +150,26 @@ check_env()
fi
}
-LOG_DIR="$current_dir"/rds_logs
-PLOSS=0
-PCORRUPT=0
-PDUP=0
+LOG_DIR="${RDS_LOG_DIR:-}"
TIMEOUT=$timeout
GENERATE_GCOV_REPORT=1
+FLAGS=()
while getopts "d:l:c:u:t:" opt; do
case ${opt} in
d)
LOG_DIR=${OPTARG}
;;
l)
- PLOSS=${OPTARG}
+ FLAGS+=("-l" "${OPTARG}")
;;
c)
- PCORRUPT=${OPTARG}
+ FLAGS+=("-c" "${OPTARG}")
;;
t)
TIMEOUT=${OPTARG}
;;
u)
- PDUP=${OPTARG}
+ FLAGS+=("-u" "${OPTARG}")
;;
:)
echo "USAGE: run.sh [-d logdir] [-l packet_loss] [-c packet_corruption]" \
@@ -185,30 +183,37 @@ while getopts "d:l:c:u:t:" opt; do
esac
done
-
check_env
check_conf
check_gcov_conf
+TRACE_CMD=()
+if [[ -n "$LOG_DIR" ]]; then
+ rm -fr "$LOG_DIR"
+ FLAGS+=("-d" "$LOG_DIR")
+
+ TRACE_FILE="${LOG_DIR}/rds-strace.txt"
+ COVR_DIR="${LOG_DIR}/coverage/"
+ mkdir -p "$LOG_DIR"
+ mkdir -p "$COVR_DIR"
+
+ echo Traces will be logged to "${TRACE_FILE}"
+ rm -f "$TRACE_FILE"
-rm -fr "$LOG_DIR"
-TRACE_FILE="${LOG_DIR}/rds-strace.txt"
-COVR_DIR="${LOG_DIR}/coverage/"
-mkdir -p "$LOG_DIR"
-mkdir -p "$COVR_DIR"
+ TRACE_CMD=(strace -T -tt -o "${TRACE_FILE}")
+fi
set +e
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" \
- -u "$PDUP"
+"${TRACE_CMD[@]}" python3 "$(dirname "$0")/test.py" "${FLAGS[@]}" -t "$TIMEOUT"
test_rc=$?
-dmesg > "${LOG_DIR}/dmesg.out"
-if [ "$GENERATE_GCOV_REPORT" -eq 1 ]; then
+if [[ -n "$LOG_DIR" ]]; then
+ dmesg > "${LOG_DIR}/dmesg.out"
+fi
+
+if [[ -n "$LOG_DIR" ]] && [ "$GENERATE_GCOV_REPORT" -eq 1 ]; then
echo saving coverage data...
(set +x; cd /sys/kernel/debug/gcov; find ./* -name '*.gcda' | \
while read -r f
diff --git a/tools/testing/selftests/net/rds/test.py b/tools/testing/selftests/net/rds/test.py
index d48533505f0f..0ece8324d255 100755
--- a/tools/testing/selftests/net/rds/test.py
+++ b/tools/testing/selftests/net/rds/test.py
@@ -82,7 +82,7 @@ def signal_handler(_sig, _frame):
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")
+ help="directory to store logs", default=None)
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",
@@ -128,16 +128,17 @@ ip(f"-n {NET1} route add {addrs[0][0]}/32 dev {VETH1}")
# and communicating by doing a single ping
ip(f"netns exec {NET0} ping -c 1 {addrs[1][0]}")
-# Start a packet capture on each network
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])
- tcpdump_procs.append((p, pcap_tmp, pcap, fd))
+# Start a packet capture on each network
+if logdir is not None:
+ 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])
+ tcpdump_procs.append((p, pcap_tmp, pcap, fd))
# simulate packet loss, duplication and corruption
for net, iface in [(NET0, VETH0), (NET1, VETH1)]:
@@ -252,12 +253,13 @@ for s in sockets:
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)
+if logdir is not None:
+ 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)
# We're done sending and receiving stuff, now let's check if what
# we received is what we sent.
--
2.25.1
next prev parent reply other threads:[~2026-05-04 5:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-04 5:41 [PATCH net-next v3 00/10] selftests: rds: Log collection, TAP compliance and cleanups Allison Henderson
2026-05-04 5:41 ` [PATCH net-next v3 01/10] selftests: rds: Increase selftest timeout Allison Henderson
2026-05-04 5:41 ` [PATCH net-next v3 02/10] selftests: rds: Update USAGE string for run.sh Allison Henderson
2026-05-04 5:41 ` [PATCH net-next v3 03/10] selftests: rds: Fix more pylint errors Allison Henderson
2026-05-04 5:41 ` [PATCH net-next v3 04/10] selftests: rds: Add timeout flag to run.sh Allison Henderson
2026-05-04 5:41 ` Allison Henderson [this message]
2026-05-04 5:41 ` [PATCH net-next v3 06/10] selftests: rds: Add SUDO_USER env variable Allison Henderson
2026-05-04 5:41 ` [PATCH net-next v3 07/10] selftests: rds: Remove tmp pcaps Allison Henderson
2026-05-04 5:41 ` [PATCH net-next v3 08/10] selftests: rds: Stop tcpdump on timeout Allison Henderson
2026-05-04 5:41 ` [PATCH net-next v3 09/10] selftests: rds: Fix gcov collection Allison Henderson
2026-05-04 5:41 ` [PATCH net-next v3 10/10] selftests: rds: Make rds selftests TAP compliant Allison Henderson
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=20260504054143.4027538-6-achender@kernel.org \
--to=achender@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
/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