From: "Ricardo B. Marlière" <rbm@suse.com>
To: Shuah Khan <shuah@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nicolas Schier <nsc@kernel.org>
Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kbuild@vger.kernel.org,
"Ricardo B. Marlière" <rbm@suse.com>
Subject: [PATCH 4/6] selftests/run_kselftest.sh: Allow choosing per-test log directory
Date: Fri, 20 Mar 2026 15:29:19 -0300 [thread overview]
Message-ID: <20260320-selftests-fixes-v1-4-79144f76be01@suse.com> (raw)
In-Reply-To: <20260320-selftests-fixes-v1-0-79144f76be01@suse.com>
The --per-test-log option currently hard-codes /tmp. However, the system
under test will most likely have tmpfs mounted there. Since it's not clear
which filenames the log files will have, the user should be able to specify
a persistent directory to store the logs. Keeping those logs are important
because the run_kselftest.sh runner will only yield KTAP output, trimming
information that is otherwise available through running individual tests
directly.
Allow --per-test-log to take an optional directory argument. Keep the
existing behaviour when the option is passed without an argument, but if
a directory is provided, create it if needed, reject non-directory paths
and non-writable directories, canonicalize it, and have runner.sh write
per-test logs there instead of /tmp.
This also makes relative paths safe by resolving them before the runner
changes into a collection directory.
Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
tools/testing/selftests/kselftest/runner.sh | 3 ++-
tools/testing/selftests/run_kselftest.sh | 30 +++++++++++++++++++++++++++--
2 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/kselftest/runner.sh b/tools/testing/selftests/kselftest/runner.sh
index 3a62039fa621..6e13818fe433 100644
--- a/tools/testing/selftests/kselftest/runner.sh
+++ b/tools/testing/selftests/kselftest/runner.sh
@@ -6,6 +6,7 @@ export skip_rc=4
export timeout_rc=124
export logfile=/dev/stdout
export per_test_logging=
+export per_test_log_dir=/tmp
export RUN_IN_NETNS=
# Defaults for "settings" file fields:
@@ -189,7 +190,7 @@ run_many()
BASENAME_TEST=$(basename $TEST)
test_num=$(( test_num + 1 ))
if [ -n "$per_test_logging" ]; then
- logfile="/tmp/$BASENAME_TEST"
+ logfile="$per_test_log_dir/$BASENAME_TEST"
cat /dev/null > "$logfile"
fi
if [ -n "$RUN_IN_NETNS" ]; then
diff --git a/tools/testing/selftests/run_kselftest.sh b/tools/testing/selftests/run_kselftest.sh
index 5f7bce9a640b..fdbbe5b8b079 100755
--- a/tools/testing/selftests/run_kselftest.sh
+++ b/tools/testing/selftests/run_kselftest.sh
@@ -22,7 +22,7 @@ usage()
cat <<EOF
Usage: $0 [OPTIONS]
-s | --summary Print summary with detailed log in output.log (conflict with -p)
- -p | --per-test-log Print test log in /tmp with each test name (conflict with -s)
+ -p | --per-test-log [DIR] Print test log in /tmp or DIR with each test name (conflict with -s)
-t | --test COLLECTION:TEST Run TEST from COLLECTION
-S | --skip COLLECTION:TEST Skip TEST from COLLECTION
-c | --collection COLLECTION Run all tests from COLLECTION
@@ -50,7 +50,33 @@ while true; do
shift ;;
-p | --per-test-log)
per_test_logging=1
- shift ;;
+ if [ -n "$2" ] && [ "${2#-}" = "$2" ]; then
+ per_test_log_dir="$2"
+ if [ -e "$per_test_log_dir" ] && [ ! -d "$per_test_log_dir" ]; then
+ echo "Per-test log path is not a dir:" \
+ "$per_test_log_dir" >&2
+ exit 1
+ fi
+ if [ ! -d "$per_test_log_dir" ] && \
+ ! mkdir -p "$per_test_log_dir"; then
+ echo "Could not create log dir:" \
+ "$per_test_log_dir" >&2
+ exit 1
+ fi
+ per_test_log_dir=$(cd "$per_test_log_dir" && pwd -P)
+ if [ -z "$per_test_log_dir" ]; then
+ echo "Could not resolve per-test log directory" >&2
+ exit 1
+ fi
+ if [ ! -w "$per_test_log_dir" ]; then
+ echo "Per-test log dir is not writable:" \
+ "$per_test_log_dir" >&2
+ exit 1
+ fi
+ shift 2
+ else
+ shift
+ fi ;;
-t | --test)
TESTS="$TESTS $2"
shift 2 ;;
--
2.53.0
next prev parent reply other threads:[~2026-03-20 18:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-20 18:29 [PATCH 0/6] selftests: run_kselftest.sh cleanup and fixes Ricardo B. Marlière
2026-03-20 18:29 ` [PATCH 1/6] selftests/run_kselftest.sh: Remove unused $ROOT Ricardo B. Marlière
2026-03-20 18:29 ` [PATCH 2/6] selftests/run_kselftest.sh: Add missing quotes Ricardo B. Marlière
2026-03-20 18:29 ` [PATCH 3/6] selftests/run_kselftest.sh: Resolve BASE_DIR with pwd -P Ricardo B. Marlière
2026-03-20 18:29 ` Ricardo B. Marlière [this message]
2026-03-20 18:29 ` [PATCH 5/6] selftests: Preserve subtarget failures in all/install Ricardo B. Marlière
2026-03-20 18:29 ` [PATCH 6/6] kbuild: remove kselftest output in mrproper Ricardo B. Marlière
2026-04-10 19:19 ` Shuah Khan
2026-04-11 12:49 ` Ricardo B. Marlière
2026-04-13 15:58 ` Shuah Khan
2026-04-13 16:22 ` Ricardo B. Marlière
2026-03-31 22:43 ` [PATCH 0/6] selftests: run_kselftest.sh cleanup and fixes Shuah Khan
2026-04-01 11:45 ` Ricardo B. Marlière
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=20260320-selftests-fixes-v1-4-79144f76be01@suse.com \
--to=rbm@suse.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=nathan@kernel.org \
--cc=nsc@kernel.org \
--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