torture: Rename RCU_QEMU_ARG to TORTURE_QEMU_ARG
[linux-2.6-block.git] / tools / testing / selftests / rcutorture / bin / kvm.sh
CommitLineData
c87b9c60
PM
1#!/bin/bash
2#
3# Run a series of 14 tests under KVM. These are not particularly
4# well-selected or well-tuned, but are the current set. Run from the
5# top level of the source tree.
6#
7# Edit the definitions below to set the locations of the various directories,
8# as well as the test duration.
9#
10# Usage: sh kvm.sh [ options ]
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version.
16#
17# This program is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
0e342a87
PM
23# along with this program; if not, you can access it online at
24# http://www.gnu.org/licenses/gpl-2.0.html.
c87b9c60
PM
25#
26# Copyright (C) IBM Corporation, 2011
27#
28# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
29
30scriptname=$0
330a76f1 31args="$*"
c87b9c60 32
43e38ab3
PM
33T=/tmp/kvm.sh.$$
34trap 'rm -rf $T' 0
35mkdir $T
36
c87b9c60 37dur=30
a7582815 38dryrun=""
73931b5e 39KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM
32caccb8 40PATH=${KVM}/bin:$PATH; export PATH
8c55f227 41TORTURE_DEFCONFIG=defconfig
2f66dbc1 42TORTURE_INITRD="$KVM/initrd"; export TORTURE_INITRD
58d280bd 43TORTURE_KMAKE_ARG=""
61010e74 44TORTURE_SUITE=rcu
c87b9c60 45resdir=""
4275be83 46configs=""
43e38ab3 47cpus=0
847bfd25 48ds=`date +%Y.%m.%d-%H:%M:%S`
bb918535 49kversion=""
c87b9c60 50
32caccb8
PM
51. functions.sh
52
c87b9c60
PM
53usage () {
54 echo "Usage: $scriptname optional arguments:"
7dca9273 55 echo " --bootargs kernel-boot-arguments"
11274813 56 echo " --buildonly"
c87b9c60 57 echo " --configs \"config-file list\""
43e38ab3 58 echo " --cpus N"
847bfd25 59 echo " --datestamp string"
8c55f227 60 echo " --defconfig string"
a7582815 61 echo " --dryrun sched|script"
c87b9c60 62 echo " --duration minutes"
315c540d 63 echo " --interactive"
74878fb6 64 echo " --kmake-arg kernel-make-arguments"
bb918535 65 echo " --kversion vN.NN"
315c540d 66 echo " --mac nn:nn:nn:nn:nn:nn"
73931b5e 67 echo " --no-initrd"
e9ce6400 68 echo " --qemu-args qemu-system-..."
4f8a0312 69 echo " --qemu-cmd qemu-system-..."
61010e74
PM
70 echo " --results absolute-pathname"
71 echo " --torture rcu"
c87b9c60
PM
72 exit 1
73}
74
c87b9c60
PM
75while test $# -gt 0
76do
c87b9c60 77 case "$1" in
7dca9273
PM
78 --bootargs)
79 checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
98bc8cc8 80 TORTURE_BOOTARGS="$2"
7dca9273
PM
81 shift
82 ;;
11274813 83 --buildonly)
805ffee2 84 TORTURE_BUILDONLY=1
11274813 85 ;;
c87b9c60
PM
86 --configs)
87 checkarg --configs "(list of config files)" "$#" "$2" '^[^/]*$' '^--'
88 configs="$2"
89 shift
90 ;;
43e38ab3
PM
91 --cpus)
92 checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
93 cpus=$2
94 shift
95 ;;
847bfd25
PM
96 --datestamp)
97 checkarg --datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
98 ds=$2
99 shift
100 ;;
8c55f227
PM
101 --defconfig)
102 checkarg --defconfig "defconfigtype" "$#" "$2" '^[^/][^/]*$' '^--'
103 TORTURE_DEFCONFIG=$2
104 shift
105 ;;
a7582815
PM
106 --dryrun)
107 checkarg --dryrun "sched|script" $# "$2" 'sched\|script' '^--'
108 dryrun=$2
109 shift
110 ;;
c87b9c60 111 --duration)
e9ce6400 112 checkarg --duration "(minutes)" $# "$2" '^[0-9]*$' '^error'
c87b9c60
PM
113 dur=$2
114 shift
115 ;;
315c540d 116 --interactive)
a0edd47c 117 TORTURE_QEMU_INTERACTIVE=1; export TORTURE_QEMU_INTERACTIVE
315c540d 118 ;;
74878fb6
PM
119 --kmake-arg)
120 checkarg --kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
58d280bd 121 TORTURE_KMAKE_ARG="$2"
74878fb6
PM
122 shift
123 ;;
bb918535 124 --kversion)
e9ce6400 125 checkarg --kversion "(kernel version)" $# "$2" '^v[0-9.]*$' '^error'
bb918535
PM
126 kversion=$2
127 shift
128 ;;
315c540d
PM
129 --mac)
130 checkarg --mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error
58f724f7 131 TORTURE_QEMU_MAC=$2
315c540d
PM
132 shift
133 ;;
73931b5e 134 --no-initrd)
2f66dbc1 135 TORTURE_INITRD=""; export TORTURE_INITRD
73931b5e 136 ;;
e9ce6400
PM
137 --qemu-args)
138 checkarg --qemu-args "-qemu args" $# "$2" '^-' '^error'
d1b1e517 139 TORTURE_QEMU_ARG="$2"
e9ce6400
PM
140 shift
141 ;;
4f8a0312
PM
142 --qemu-cmd)
143 checkarg --qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
144 RCU_QEMU_CMD="$2"; export RCU_QEMU_CMD
145 shift
146 ;;
c87b9c60 147 --results)
e9ce6400 148 checkarg --results "(absolute pathname)" "$#" "$2" '^/' '^error'
c87b9c60
PM
149 resdir=$2
150 shift
151 ;;
61010e74 152 --torture)
9dfa5b35 153 checkarg --torture "(suite name)" "$#" "$2" '^\(lock\|rcu\)$' '^--'
61010e74
PM
154 TORTURE_SUITE=$2
155 shift
156 ;;
c87b9c60 157 *)
2bcdf4e3 158 echo Unknown argument $1
c87b9c60
PM
159 usage
160 ;;
161 esac
162 shift
163done
164
61010e74 165CONFIGFRAG=${KVM}/configs/${TORTURE_SUITE}; export CONFIGFRAG
4275be83
PM
166KVPATH=${CONFIGFRAG}/$kversion; export KVPATH
167
168if test -z "$configs"
169then
170 configs="`cat $CONFIGFRAG/$kversion/CFLIST`"
171fi
c87b9c60
PM
172
173if test -z "$resdir"
174then
175 resdir=$KVM/res
daeda23d
PM
176fi
177
178if test "$dryrun" = ""
179then
330a76f1
PM
180 if ! test -e $resdir
181 then
182 mkdir -p "$resdir" || :
183 fi
daeda23d
PM
184 mkdir $resdir/$ds
185
78ad0693 186 # Be noisy only if running the script.
a7582815
PM
187 echo Results directory: $resdir/$ds
188 echo $scriptname $args
847bfd25 189
daeda23d
PM
190 touch $resdir/$ds/log
191 echo $scriptname $args >> $resdir/$ds/log
61010e74 192 echo ${TORTURE_SUITE} > $resdir/$ds/TORTURE_SUITE
daeda23d
PM
193
194 pwd > $resdir/$ds/testid.txt
195 if test -d .git
196 then
197 git status >> $resdir/$ds/testid.txt
198 git rev-parse HEAD >> $resdir/$ds/testid.txt
199 fi
c87b9c60 200fi
c87b9c60 201
78ad0693 202# Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
43e38ab3 203touch $T/cfgcpu
c87b9c60
PM
204for CF in $configs
205do
43e38ab3 206 if test -f "$CONFIGFRAG/$kversion/$CF"
f43f8f73 207 then
43e38ab3
PM
208 echo $CF `configNR_CPUS.sh $CONFIGFRAG/$kversion/$CF` >> $T/cfgcpu
209 else
210 echo "The --configs file $CF does not exist, terminating."
211 exit 1
f43f8f73 212 fi
c87b9c60 213done
43e38ab3
PM
214sort -k2nr $T/cfgcpu > $T/cfgcpu.sort
215
78ad0693 216# Use a greedy bin-packing algorithm, sorting the list accordingly.
53954671
PM
217awk < $T/cfgcpu.sort > $T/cfgcpu.pack -v ncpus=$cpus '
218BEGIN {
219 njobs = 0;
220}
221
222{
78ad0693 223 # Read file of tests and corresponding required numbers of CPUs.
53954671
PM
224 cf[njobs] = $1;
225 cpus[njobs] = $2;
226 njobs++;
227}
228
229END {
230 alldone = 0;
231 batch = 0;
232 nc = -1;
78ad0693
PM
233
234 # Each pass through the following loop creates on test batch
235 # that can be executed concurrently given ncpus. Note that a
236 # given test that requires more than the available CPUs will run in
237 # their own batch. Such tests just have to make do with what
238 # is available.
53954671
PM
239 while (nc != ncpus) {
240 batch++;
241 nc = ncpus;
78ad0693
PM
242
243 # Each pass through the following loop considers one
244 # test for inclusion in the current batch.
53954671
PM
245 for (i = 0; i < njobs; i++) {
246 if (done[i])
78ad0693 247 continue; # Already part of a batch.
53954671 248 if (nc >= cpus[i] || nc == ncpus) {
78ad0693
PM
249
250 # This test fits into the current batch.
53954671
PM
251 done[i] = batch;
252 nc -= cpus[i];
253 if (nc <= 0)
78ad0693 254 break; # Too-big test in its own batch.
53954671
PM
255 }
256 }
257 }
78ad0693
PM
258
259 # Dump out the tests in batch order.
53954671
PM
260 for (b = 1; b <= batch; b++)
261 for (i = 0; i < njobs; i++)
262 if (done[i] == b)
263 print cf[i], cpus[i];
264}'
265
78ad0693 266# Generate a script to execute the tests in appropriate batches.
61010e74
PM
267cat << ___EOF___ > $T/script
268TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE
8c55f227 269TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG
61010e74 270___EOF___
53954671 271awk < $T/cfgcpu.pack \
43e38ab3
PM
272 -v CONFIGDIR="$CONFIGFRAG/$kversion/" \
273 -v KVM="$KVM" \
274 -v ncpus=$cpus \
275 -v rd=$resdir/$ds/ \
276 -v dur=$dur \
d1b1e517 277 -v TORTURE_QEMU_ARG=$TORTURE_QEMU_ARG \
98bc8cc8 278 -v TORTURE_BOOTARGS=$TORTURE_BOOTARGS \
43e38ab3
PM
279'BEGIN {
280 i = 0;
281}
282
283{
284 cf[i] = $1;
285 cpus[i] = $2;
286 i++;
287}
288
78ad0693 289# Dump out the scripting required to run one test batch.
43e38ab3
PM
290function dump(first, pastlast)
291{
73fa867e
PM
292 print "echo ----Start batch: `date`";
293 print "echo ----Start batch: `date` >> " rd "/log";
43e38ab3
PM
294 jn=1
295 for (j = first; j < pastlast; j++) {
296 builddir=KVM "/b" jn
0ae3f73a 297 cpusr[jn] = cpus[j];
43e38ab3 298 if (cfrep[cf[j]] == "") {
0ae3f73a 299 cfr[jn] = cf[j];
43e38ab3
PM
300 cfrep[cf[j]] = 1;
301 } else {
302 cfrep[cf[j]]++;
0ae3f73a 303 cfr[jn] = cf[j] "." cfrep[cf[j]];
43e38ab3 304 }
df1cc81b
PM
305 if (cpusr[jn] > ncpus && ncpus != 0)
306 ovf = "(!)";
307 else
308 ovf = "";
3c626237 309 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date`";
73fa867e 310 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` >> " rd "/log";
0ae3f73a
PM
311 print "rm -f " builddir ".*";
312 print "touch " builddir ".wait";
313 print "mkdir " builddir " > /dev/null 2>&1 || :";
314 print "mkdir " rd cfr[jn] " || :";
d1b1e517 315 print "kvm-test-1-run.sh " CONFIGDIR cf[j], builddir, rd cfr[jn], dur " \"" TORTURE_QEMU_ARG "\" \"" TORTURE_BOOTARGS "\" > " rd cfr[jn] "/kvm-test-1-run.sh.out 2>&1 &"
73fa867e
PM
316 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date`";
317 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` >> " rd "/log";
43e38ab3
PM
318 print "while test -f " builddir ".wait"
319 print "do"
320 print "\tsleep 1"
321 print "done"
73fa867e
PM
322 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date`";
323 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` >> " rd "/log";
43e38ab3
PM
324 jn++;
325 }
43e38ab3
PM
326 for (j = 1; j < jn; j++) {
327 builddir=KVM "/b" j
328 print "rm -f " builddir ".ready"
73fa867e
PM
329 print "echo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date`";
330 print "echo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date` >> " rd "/log";
43e38ab3
PM
331 }
332 print "wait"
73fa867e
PM
333 print "echo ---- All kernel runs complete. `date`";
334 print "echo ---- All kernel runs complete. `date` >> " rd "/log";
43e38ab3
PM
335 for (j = 1; j < jn; j++) {
336 builddir=KVM "/b" j
73fa867e
PM
337 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results:";
338 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results: >> " rd "/log";
339 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out";
340 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out >> " rd "/log";
43e38ab3
PM
341 }
342}
343
344END {
345 njobs = i;
346 nc = ncpus;
347 first = 0;
78ad0693
PM
348
349 # Each pass through the following loop considers one test.
43e38ab3
PM
350 for (i = 0; i < njobs; i++) {
351 if (ncpus == 0) {
78ad0693 352 # Sequential test specified, each test its own batch.
43e38ab3
PM
353 dump(i, i + 1);
354 first = i;
355 } else if (nc < cpus[i] && i != 0) {
78ad0693 356 # Out of CPUs, dump out a batch.
43e38ab3
PM
357 dump(first, i);
358 first = i;
359 nc = ncpus;
360 }
78ad0693 361 # Account for the CPUs needed by the current test.
43e38ab3
PM
362 nc -= cpus[i];
363 }
78ad0693 364 # Dump the last batch.
43e38ab3
PM
365 if (ncpus != 0)
366 dump(first, i);
61010e74 367}' >> $T/script
43e38ab3 368
a7582815
PM
369if test "$dryrun" = script
370then
78ad0693
PM
371 # Dump out the script, but define the environment variables that
372 # it needs to run standalone.
a7582815
PM
373 echo CONFIGFRAG="$CONFIGFRAG; export CONFIGFRAG"
374 echo KVM="$KVM; export KVM"
375 echo KVPATH="$KVPATH; export KVPATH"
376 echo PATH="$PATH; export PATH"
805ffee2 377 echo TORTURE_BUILDONLY="$TORTURE_BUILDONLY; export TORTURE_BUILDONLY"
2f66dbc1 378 echo TORTURE_INITRD="$TORTURE_INITRD; export TORTURE_INITRD"
58d280bd 379 echo TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG; export TORTURE_KMAKE_ARG"
a7582815 380 echo RCU_QEMU_CMD="$RCU_QEMU_CMD; export RCU_QEMU_CMD"
a0edd47c 381 echo TORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE; export TORTURE_QEMU_INTERACTIVE"
58f724f7 382 echo TORTURE_QEMU_MAC="$TORTURE_QEMU_MAC; export TORTURE_QEMU_MAC"
daeda23d
PM
383 echo "mkdir -p "$resdir" || :"
384 echo "mkdir $resdir/$ds"
a7582815
PM
385 cat $T/script
386 exit 0
387elif test "$dryrun" = sched
388then
78ad0693 389 # Extract the test run schedule from the script.
9352ad13
PM
390 egrep 'Start batch|Starting build\.' $T/script |
391 grep -v ">>" |
a7582815
PM
392 sed -e 's/:.*$//' -e 's/^echo //'
393 exit 0
394else
78ad0693 395 # Not a dryru, so run the script.
a7582815
PM
396 sh $T/script
397fi
43e38ab3 398
782ab4cd 399# Tracing: trace_event=rcu:rcu_grace_period,rcu:rcu_future_grace_period,rcu:rcu_grace_period_init,rcu:rcu_nocb_wake,rcu:rcu_preempt_task,rcu:rcu_unlock_preempted_task,rcu:rcu_quiescent_state_report,rcu:rcu_fqs,rcu:rcu_callback,rcu:rcu_kfree_callback,rcu:rcu_batch_start,rcu:rcu_invoke_callback,rcu:rcu_invoke_kfree_callback,rcu:rcu_batch_end,rcu:rcu_torture_read,rcu:rcu_barrier
e1362651 400
ec256c0f
PM
401echo
402echo
e1362651 403echo " --- `date` Test summary:"
ec256c0f 404echo Results directory: $resdir/$ds
805ffee2
PM
405if test -n "$TORTURE_BUILDONLY"
406then
407 kvm-recheck.sh $resdir/$ds
408fi