Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / tools / testing / selftests / rcutorture / bin / kvm-again.sh
blob88ca4e36848908272a9947c07ff6b6afc8224578
1 #!/bin/bash
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>
12 scriptname=$0
13 args="$*"
15 T="`mktemp -d ${TMPDIR-/tmp}/kvm-again.sh.XXXXXX`"
16 trap 'rm -rf $T' 0
18 if ! test -d tools/testing/selftests/rcutorture/bin
19 then
20 echo $scriptname must be run from top-level directory of kernel source tree.
21 exit 1
24 oldrun=$1
25 shift
26 if ! test -d "$oldrun"
27 then
28 echo "Usage: $scriptname /path/to/old/run [ options ]"
29 exit 1
31 if ! cp "$oldrun/scenarios" $T/scenarios.oldrun
32 then
33 # Later on, can reconstitute this from console.log files.
34 echo Prior run batches file does not exist: $oldrun/batches
35 exit 1
38 if test -f "$oldrun/torture_suite"
39 then
40 torture_suite="`cat $oldrun/torture_suite`"
41 elif test -f "$oldrun/TORTURE_SUITE"
42 then
43 torture_suite="`cat $oldrun/TORTURE_SUITE`"
44 else
45 echo "Prior run torture_suite file does not exist: $oldrun/{torture_suite,TORTURE_SUITE}"
46 exit 1
49 RCUTORTURE="`pwd`/tools/testing/selftests/rcutorture"; export RCUTORTURE
50 PATH=${RCUTORTURE}/bin:$PATH; export PATH
51 . functions.sh
53 bootargs=
54 dryrun=
55 dur=
56 default_link="cp -R"
57 resdir="`pwd`/tools/testing/selftests/rcutorture/res"
58 rundir="$resdir/`date +%Y.%m.%d-%H.%M.%S-again`"
59 got_datestamp=
60 got_rundir=
62 startdate="`date`"
63 starttime="`get_starttime`"
65 usage () {
66 echo "Usage: $scriptname $oldrun [ arguments ]:"
67 echo " --bootargs kernel-boot-arguments"
68 echo " --datestamp string"
69 echo " --dryrun"
70 echo " --duration minutes | <seconds>s | <hours>h | <days>d"
71 echo " --link hard|soft|copy"
72 echo " --remote"
73 echo " --rundir /new/res/path"
74 echo "Command line: $scriptname $args"
75 exit 1
78 while test $# -gt 0
80 case "$1" in
81 --bootargs|--bootarg)
82 checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
83 bootargs="$bootargs $2"
84 shift
86 --datestamp)
87 checkarg --datestamp "(relative pathname)" "$#" "$2" '^[a-zA-Z0-9._/-]*$' '^--'
88 if test -n "$got_rundir" || test -n "$got_datestamp"
89 then
90 echo Only one of --datestamp or --rundir may be specified
91 usage
93 got_datestamp=y
94 ds=$2
95 rundir="$resdir/$ds"
96 if test -e "$rundir"
97 then
98 echo "--datestamp $2: Already exists."
99 usage
101 shift
103 --dryrun)
104 dryrun=1
106 --duration)
107 checkarg --duration "(minutes)" $# "$2" '^[0-9][0-9]*\(s\|m\|h\|d\|\)$' '^error'
108 mult=60
109 if echo "$2" | grep -q 's$'
110 then
111 mult=1
112 elif echo "$2" | grep -q 'h$'
113 then
114 mult=3600
115 elif echo "$2" | grep -q 'd$'
116 then
117 mult=86400
119 ts=`echo $2 | sed -e 's/[smhd]$//'`
120 dur=$(($ts*mult))
121 shift
123 --link)
124 checkarg --link "hard|soft|copy" "$#" "$2" 'hard\|soft\|copy' '^--'
125 case "$2" in
126 copy)
127 arg_link="cp -R"
129 hard)
130 arg_link="cp -Rl"
132 soft)
133 arg_link="cp -Rs"
135 esac
136 shift
138 --remote)
139 arg_remote=1
140 default_link="cp -as"
142 --rundir)
143 checkarg --rundir "(absolute pathname)" "$#" "$2" '^/' '^error'
144 if test -n "$got_rundir" || test -n "$got_datestamp"
145 then
146 echo Only one of --datestamp or --rundir may be specified
147 usage
149 got_rundir=y
150 rundir=$2
151 if test -e "$rundir"
152 then
153 echo "--rundir $2: Already exists."
154 usage
156 shift
159 if test -n "$1"
160 then
161 echo Unknown argument $1
162 usage
165 esac
166 shift
167 done
168 if test -z "$arg_link"
169 then
170 arg_link="$default_link"
173 echo ---- Re-run results directory: $rundir
175 # Copy old run directory tree over and adjust.
176 mkdir -p "`dirname "$rundir"`"
177 if ! $arg_link "$oldrun" "$rundir"
178 then
179 echo "Cannot copy from $oldrun to $rundir."
180 usage
182 rm -f "$rundir"/*/{console.log,console.log.diags,qemu_pid,qemu-pid,qemu-retval,Warnings,kvm-test-1-run.sh.out,kvm-test-1-run-qemu.sh.out,vmlinux} "$rundir"/log
183 touch "$rundir/log"
184 echo $scriptname $args | tee -a "$rundir/log"
185 echo $oldrun > "$rundir/re-run"
186 if ! test -d "$rundir/../../bin"
187 then
188 $arg_link "$oldrun/../../bin" "$rundir/../.."
190 for i in $rundir/*/qemu-cmd
192 cp "$i" $T
193 qemu_cmd_dir="`dirname "$i"`"
194 kernel_dir="`echo $qemu_cmd_dir | sed -e 's/\.[0-9]\+$//'`"
195 jitter_dir="`dirname "$kernel_dir"`"
196 kvm-transform.sh "$kernel_dir/bzImage" "$qemu_cmd_dir/console.log" "$jitter_dir" "$dur" "$bootargs" < $T/qemu-cmd > $i
197 if test -n "$arg_remote"
198 then
199 echo "# TORTURE_KCONFIG_GDB_ARG=''" >> $i
201 done
203 # Extract settings from the last qemu-cmd file transformed above.
204 grep '^#' $i | sed -e 's/^# //' > $T/qemu-cmd-settings
205 . $T/qemu-cmd-settings
207 grep -v '^#' $T/scenarios.oldrun | awk '
209 curbatch = "";
210 for (i = 2; i <= NF; i++)
211 curbatch = curbatch " " $i;
212 print "kvm-test-1-run-batch.sh" curbatch;
213 }' > $T/runbatches.sh
215 if test -n "$dryrun"
216 then
217 echo ---- Dryrun complete, directory: $rundir | tee -a "$rundir/log"
218 else
219 ( cd "$rundir"; sh $T/runbatches.sh ) | tee -a "$rundir/log"
220 kvm-end-run-stats.sh "$rundir" "$starttime"