Merge tag 'locks-v5.15' of git://git.kernel.org/pub/scm/linux/kernel/git/jlayton...
[linux-2.6-microblaze.git] / tools / testing / selftests / rcutorture / bin / kvm-again.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0+
3 #
4 # Rerun a series of tests under KVM.
5 #
6 # Usage: kvm-again.sh /path/to/old/run [ options ]
7 #
8 # Copyright (C) 2021 Facebook, Inc.
9 #
10 # Authors: Paul E. McKenney <paulmck@kernel.org>
11
12 scriptname=$0
13 args="$*"
14
15 T=${TMPDIR-/tmp}/kvm-again.sh.$$
16 trap 'rm -rf $T' 0
17 mkdir $T
18
19 if ! test -d tools/testing/selftests/rcutorture/bin
20 then
21         echo $scriptname must be run from top-level directory of kernel source tree.
22         exit 1
23 fi
24
25 oldrun=$1
26 shift
27 if ! test -d "$oldrun"
28 then
29         echo "Usage: $scriptname /path/to/old/run [ options ]"
30         exit 1
31 fi
32 if ! cp "$oldrun/scenarios" $T/scenarios.oldrun
33 then
34         # Later on, can reconstitute this from console.log files.
35         echo Prior run batches file does not exist: $oldrun/batches
36         exit 1
37 fi
38
39 if test -f "$oldrun/torture_suite"
40 then
41         torture_suite="`cat $oldrun/torture_suite`"
42 elif test -f "$oldrun/TORTURE_SUITE"
43 then
44         torture_suite="`cat $oldrun/TORTURE_SUITE`"
45 else
46         echo "Prior run torture_suite file does not exist: $oldrun/{torture_suite,TORTURE_SUITE}"
47         exit 1
48 fi
49
50 KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM
51 PATH=${KVM}/bin:$PATH; export PATH
52 . functions.sh
53
54 dryrun=
55 dur=
56 default_link="cp -R"
57 rundir="`pwd`/tools/testing/selftests/rcutorture/res/`date +%Y.%m.%d-%H.%M.%S-again`"
58
59 startdate="`date`"
60 starttime="`get_starttime`"
61
62 usage () {
63         echo "Usage: $scriptname $oldrun [ arguments ]:"
64         echo "       --dryrun"
65         echo "       --duration minutes | <seconds>s | <hours>h | <days>d"
66         echo "       --link hard|soft|copy"
67         echo "       --remote"
68         echo "       --rundir /new/res/path"
69         exit 1
70 }
71
72 while test $# -gt 0
73 do
74         case "$1" in
75         --dryrun)
76                 dryrun=1
77                 ;;
78         --duration)
79                 checkarg --duration "(minutes)" $# "$2" '^[0-9][0-9]*\(s\|m\|h\|d\|\)$' '^error'
80                 mult=60
81                 if echo "$2" | grep -q 's$'
82                 then
83                         mult=1
84                 elif echo "$2" | grep -q 'h$'
85                 then
86                         mult=3600
87                 elif echo "$2" | grep -q 'd$'
88                 then
89                         mult=86400
90                 fi
91                 ts=`echo $2 | sed -e 's/[smhd]$//'`
92                 dur=$(($ts*mult))
93                 shift
94                 ;;
95         --link)
96                 checkarg --link "hard|soft|copy" "$#" "$2" 'hard\|soft\|copy' '^--'
97                 case "$2" in
98                 copy)
99                         arg_link="cp -R"
100                         ;;
101                 hard)
102                         arg_link="cp -Rl"
103                         ;;
104                 soft)
105                         arg_link="cp -Rs"
106                         ;;
107                 esac
108                 shift
109                 ;;
110         --remote)
111                 arg_remote=1
112                 default_link="cp -as"
113                 ;;
114         --rundir)
115                 checkarg --rundir "(absolute pathname)" "$#" "$2" '^/' '^error'
116                 rundir=$2
117                 if test -e "$rundir"
118                 then
119                         echo "--rundir $2: Already exists."
120                         usage
121                 fi
122                 shift
123                 ;;
124         *)
125                 echo Unknown argument $1
126                 usage
127                 ;;
128         esac
129         shift
130 done
131 if test -z "$arg_link"
132 then
133         arg_link="$default_link"
134 fi
135
136 echo ---- Re-run results directory: $rundir
137
138 # Copy old run directory tree over and adjust.
139 mkdir -p "`dirname "$rundir"`"
140 if ! $arg_link "$oldrun" "$rundir"
141 then
142         echo "Cannot copy from $oldrun to $rundir."
143         usage
144 fi
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
146 touch "$rundir/log"
147 echo $scriptname $args | tee -a "$rundir/log"
148 echo $oldrun > "$rundir/re-run"
149 if ! test -d "$rundir/../../bin"
150 then
151         $arg_link "$oldrun/../../bin" "$rundir/../.."
152 fi
153 for i in $rundir/*/qemu-cmd
154 do
155         cp "$i" $T
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"
161         then
162                 echo "# TORTURE_KCONFIG_GDB_ARG=''" >> $i
163         fi
164 done
165
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
169
170 grep -v '^#' $T/scenarios.oldrun | awk '
171 {
172         curbatch = "";
173         for (i = 2; i <= NF; i++)
174                 curbatch = curbatch " " $i;
175         print "kvm-test-1-run-batch.sh" curbatch;
176 }' > $T/runbatches.sh
177
178 if test -n "$dryrun"
179 then
180         echo ---- Dryrun complete, directory: $rundir | tee -a "$rundir/log"
181 else
182         ( cd "$rundir"; sh $T/runbatches.sh )
183         kvm-end-run-stats.sh "$rundir" "$starttime"
184 fi