Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/run_kselftest.sh: Allow choosing per-test log directory

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>
Link: https://lore.kernel.org/r/20260320-selftests-fixes-v1-4-79144f76be01@suse.com
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Ricardo B. Marlière and committed by
Shuah Khan
d6ea9f40 a82e076f

+30 -3
+2 -1
tools/testing/selftests/kselftest/runner.sh
··· 6 6 export timeout_rc=124 7 7 export logfile=/dev/stdout 8 8 export per_test_logging= 9 + export per_test_log_dir=/tmp 9 10 export RUN_IN_NETNS= 10 11 11 12 # Defaults for "settings" file fields: ··· 197 196 BASENAME_TEST=$(basename $TEST) 198 197 test_num=$(( test_num + 1 )) 199 198 if [ -n "$per_test_logging" ]; then 200 - logfile="/tmp/$BASENAME_TEST" 199 + logfile="$per_test_log_dir/$BASENAME_TEST" 201 200 cat /dev/null > "$logfile" 202 201 fi 203 202 if [ -n "$RUN_IN_NETNS" ]; then
+28 -2
tools/testing/selftests/run_kselftest.sh
··· 22 22 cat <<EOF 23 23 Usage: $0 [OPTIONS] 24 24 -s | --summary Print summary with detailed log in output.log (conflict with -p) 25 - -p | --per-test-log Print test log in /tmp with each test name (conflict with -s) 25 + -p | --per-test-log [DIR] Print test log in /tmp or DIR with each test name (conflict with -s) 26 26 -t | --test COLLECTION:TEST Run TEST from COLLECTION 27 27 -S | --skip COLLECTION:TEST Skip TEST from COLLECTION 28 28 -c | --collection COLLECTION Run all tests from COLLECTION ··· 50 50 shift ;; 51 51 -p | --per-test-log) 52 52 per_test_logging=1 53 - shift ;; 53 + if [ -n "$2" ] && [ "${2#-}" = "$2" ]; then 54 + per_test_log_dir="$2" 55 + if [ -e "$per_test_log_dir" ] && [ ! -d "$per_test_log_dir" ]; then 56 + echo "Per-test log path is not a dir:" \ 57 + "$per_test_log_dir" >&2 58 + exit 1 59 + fi 60 + if [ ! -d "$per_test_log_dir" ] && \ 61 + ! mkdir -p "$per_test_log_dir"; then 62 + echo "Could not create log dir:" \ 63 + "$per_test_log_dir" >&2 64 + exit 1 65 + fi 66 + per_test_log_dir=$(cd "$per_test_log_dir" && pwd -P) 67 + if [ -z "$per_test_log_dir" ]; then 68 + echo "Could not resolve per-test log directory" >&2 69 + exit 1 70 + fi 71 + if [ ! -w "$per_test_log_dir" ]; then 72 + echo "Per-test log dir is not writable:" \ 73 + "$per_test_log_dir" >&2 74 + exit 1 75 + fi 76 + shift 2 77 + else 78 + shift 79 + fi ;; 54 80 -t | --test) 55 81 TESTS="$TESTS $2" 56 82 shift 2 ;;