2 # SPDX-License-Identifier: GPL-2.0+
4 # Rerun a series of tests under KVM.
6 # Usage: kvm-again.sh /path/to/old/run [ options ]
8 # Copyright (C) 2021 Facebook, Inc.
10 # Authors: Paul E. McKenney <paulmck@kernel.org>
15 T=${TMPDIR-/tmp}/kvm-again.sh.$$
19 if ! test -d tools/testing/selftests/rcutorture/bin
21 echo $scriptname must be run from top-level directory of kernel source tree.
27 if ! test -d "$oldrun"
29 echo "Usage: $scriptname /path/to/old/run [ options ]"
32 if ! cp "$oldrun/scenarios" $T/scenarios.oldrun
34 # Later on, can reconstitute this from console.log files.
35 echo Prior run batches file does not exist: $oldrun/batches
39 if test -f "$oldrun/torture_suite"
41 torture_suite="`cat $oldrun/torture_suite`"
42 elif test -f "$oldrun/TORTURE_SUITE"
44 torture_suite="`cat $oldrun/TORTURE_SUITE`"
46 echo "Prior run torture_suite file does not exist: $oldrun/{torture_suite,TORTURE_SUITE}"
50 KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM
51 PATH=${KVM}/bin:$PATH; export PATH
57 rundir="`pwd`/tools/testing/selftests/rcutorture/res/`date +%Y.%m.%d-%H.%M.%S-again`"
60 starttime="`get_starttime`"
63 echo "Usage: $scriptname $oldrun [ arguments ]:"
65 echo " --duration minutes | <seconds>s | <hours>h | <days>d"
66 echo " --link hard|soft|copy"
68 echo " --rundir /new/res/path"
79 checkarg --duration "(minutes)" $# "$2" '^[0-9][0-9]*\(s\|m\|h\|d\|\)$' '^error'
81 if echo "$2" | grep -q 's$'
84 elif echo "$2" | grep -q 'h$'
87 elif echo "$2" | grep -q 'd$'
91 ts=`echo $2 | sed -e 's/[smhd]$//'`
96 checkarg --link "hard|soft|copy" "$#" "$2" 'hard\|soft\|copy' '^--'
112 default_link="cp -as"
115 checkarg --rundir "(absolute pathname)" "$#" "$2" '^/' '^error'
119 echo "--rundir $2: Already exists."
125 echo Unknown argument $1
131 if test -z "$arg_link"
133 arg_link="$default_link"
136 echo ---- Re-run results directory: $rundir
138 # Copy old run directory tree over and adjust.
139 mkdir -p "`dirname "$rundir"`"
140 if ! $arg_link "$oldrun" "$rundir"
142 echo "Cannot copy from $oldrun to $rundir."
145 rm -f "$rundir"/*/{console.log,console.log.diags,qemu_pid,qemu-retval,Warnings,kvm-test-1-run.sh.out,kvm-test-1-run-qemu.sh.out,vmlinux} "$rundir"/log
147 echo $scriptname $args | tee -a "$rundir/log"
148 echo $oldrun > "$rundir/re-run"
149 if ! test -d "$rundir/../../bin"
151 $arg_link "$oldrun/../../bin" "$rundir/../.."
153 for i in $rundir/*/qemu-cmd
156 qemu_cmd_dir="`dirname "$i"`"
157 kernel_dir="`echo $qemu_cmd_dir | sed -e 's/\.[0-9]\+$//'`"
158 jitter_dir="`dirname "$kernel_dir"`"
159 kvm-transform.sh "$kernel_dir/bzImage" "$qemu_cmd_dir/console.log" "$jitter_dir" $dur < $T/qemu-cmd > $i
160 if test -n "$arg_remote"
162 echo "# TORTURE_KCONFIG_GDB_ARG=''" >> $i
166 # Extract settings from the last qemu-cmd file transformed above.
167 grep '^#' $i | sed -e 's/^# //' > $T/qemu-cmd-settings
168 . $T/qemu-cmd-settings
170 grep -v '^#' $T/scenarios.oldrun | awk '
173 for (i = 2; i <= NF; i++)
174 curbatch = curbatch " " $i;
175 print "kvm-test-1-run-batch.sh" curbatch;
176 }' > $T/runbatches.sh
180 echo ---- Dryrun complete, directory: $rundir | tee -a "$rundir/log"
182 ( cd "$rundir"; sh $T/runbatches.sh )
183 kvm-end-run-stats.sh "$rundir" "$starttime"