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.
7 # Edit the definitions below to set the locations of the various directories,
8 # as well as the test duration.
10 # Usage: kvm.sh [ options ]
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.
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.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, you can access it online at
24 # http://www.gnu.org/licenses/gpl-2.0.html.
26 # Copyright (C) IBM Corporation, 2011
28 # Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
39 KVM
="`pwd`/tools/testing/selftests/rcutorture"; export KVM
40 PATH
=${KVM}/bin
:$PATH; export PATH
41 TORTURE_DEFCONFIG
=defconfig
43 TORTURE_INITRD
="$KVM/initrd"; export TORTURE_INITRD
45 TORTURE_SHUTDOWN_GRACE
=180
50 ds
=`date +%Y.%m.%d-%H:%M:%S`
56 echo "Usage: $scriptname optional arguments:"
57 echo " --bootargs kernel-boot-arguments"
58 echo " --bootimage relative-path-to-kernel-boot-image"
60 echo " --configs \"config-file list w/ repeat factor (3*TINY01)\""
62 echo " --datestamp string"
63 echo " --defconfig string"
64 echo " --dryrun sched|script"
65 echo " --duration minutes"
67 echo " --jitter N [ maxsleep (us) [ maxspin (us) ] ]"
68 echo " --kmake-arg kernel-make-arguments"
69 echo " --mac nn:nn:nn:nn:nn:nn"
71 echo " --qemu-args qemu-system-..."
72 echo " --qemu-cmd qemu-system-..."
73 echo " --results absolute-pathname"
82 checkarg
--bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
87 checkarg
--bootimage "(relative path to kernel boot image)" "$#" "$2" '[a-zA-Z0-9][a-zA-Z0-9_]*' '^--'
88 TORTURE_BOOT_IMAGE
="$2"
95 checkarg
--configs "(list of config files)" "$#" "$2" '^[^/]*$' '^--'
100 checkarg
--cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
105 checkarg
--datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
110 checkarg
--defconfig "defconfigtype" "$#" "$2" '^[^/][^/]*$' '^--'
115 checkarg
--dryrun "sched|script" $# "$2" 'sched\|script' '^--'
120 checkarg
--duration "(minutes)" $# "$2" '^[0-9]*$' '^error'
125 TORTURE_QEMU_INTERACTIVE
=1; export TORTURE_QEMU_INTERACTIVE
128 checkarg
--jitter "(# threads [ sleep [ spin ] ])" $# "$2" '^-\{,1\}[0-9]\+\( \+[0-9]\+\)\{,2\} *$' '^error$'
133 checkarg
--kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
134 TORTURE_KMAKE_ARG
="$2"
138 checkarg
--mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error
143 TORTURE_INITRD
=""; export TORTURE_INITRD
145 --qemu-args|
--qemu-arg)
146 checkarg
--qemu-args "-qemu args" $# "$2" '^-' '^error'
147 TORTURE_QEMU_ARG
="$2"
151 checkarg
--qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
152 TORTURE_QEMU_CMD
="$2"
156 checkarg
--results "(absolute pathname)" "$#" "$2" '^/' '^error'
161 checkarg
--shutdown-grace "(seconds)" "$#" "$2" '^[0-9]*$' '^error'
162 TORTURE_SHUTDOWN_GRACE
=$2
166 checkarg
--torture "(suite name)" "$#" "$2" '^\(lock\|rcu\|rcuperf\)$' '^--'
171 echo Unknown argument
$1
178 CONFIGFRAG
=${KVM}/configs
/${TORTURE_SUITE}; export CONFIGFRAG
180 if test -z "$configs"
182 configs
="`cat $CONFIGFRAG/CFLIST`"
190 # Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
195 [0-9]\
**|
[0-9][0-9]\
**|
[0-9][0-9][0-9]\
**)
196 config_reps
=`echo $CF | sed -e 's/\*.*$//'`
197 CF1
=`echo $CF | sed -e 's/^[^*]*\*//'`
204 if test -f "$CONFIGFRAG/$CF1"
206 cpu_count
=`configNR_CPUS.sh $CONFIGFRAG/$CF1`
207 cpu_count
=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
208 for ((cur_rep
=0;cur_rep
<$config_reps;cur_rep
++))
210 echo $CF1 $cpu_count >> $T/cfgcpu
213 echo "The --configs file $CF1 does not exist, terminating."
217 sort -k2nr $T/cfgcpu
> $T/cfgcpu.
sort
219 # Use a greedy bin-packing algorithm, sorting the list accordingly.
220 awk < $T/cfgcpu.
sort > $T/cfgcpu.pack
-v ncpus
=$cpus '
226 # Read file of tests and corresponding required numbers of CPUs.
237 # Each pass through the following loop creates on test batch
238 # that can be executed concurrently given ncpus. Note that a
239 # given test that requires more than the available CPUs will run in
240 # their own batch. Such tests just have to make do with what
242 while (nc != ncpus) {
246 # Each pass through the following loop considers one
247 # test for inclusion in the current batch.
248 for (i = 0; i < njobs; i++) {
250 continue; # Already part of a batch.
251 if (nc >= cpus[i] || nc == ncpus) {
253 # This test fits into the current batch.
257 break; # Too-big test in its own batch.
262 # Dump out the tests in batch order.
263 for (b = 1; b <= batch; b++)
264 for (i = 0; i < njobs; i++)
266 print cf[i], cpus[i];
269 # Generate a script to execute the tests in appropriate batches.
270 cat << ___EOF___ > $T/script
271 CONFIGFRAG="$CONFIGFRAG"; export CONFIGFRAG
272 KVM="$KVM"; export KVM
273 PATH="$PATH"; export PATH
274 TORTURE_BOOT_IMAGE="$TORTURE_BOOT_IMAGE"; export TORTURE_BOOT_IMAGE
275 TORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY
276 TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG
277 TORTURE_INITRD="$TORTURE_INITRD"; export TORTURE_INITRD
278 TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG
279 TORTURE_QEMU_CMD="$TORTURE_QEMU_CMD"; export TORTURE_QEMU_CMD
280 TORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE"; export TORTURE_QEMU_INTERACTIVE
281 TORTURE_QEMU_MAC="$TORTURE_QEMU_MAC"; export TORTURE_QEMU_MAC
282 TORTURE_SHUTDOWN_GRACE="$TORTURE_SHUTDOWN_GRACE"; export TORTURE_SHUTDOWN_GRACE
283 TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE
286 mkdir -p "$resdir" || :
289 echo Results directory: $resdir/$ds
290 echo $scriptname $args
291 touch $resdir/$ds/log
292 echo $scriptname $args >> $resdir/$ds/log
293 echo ${TORTURE_SUITE} > $resdir/$ds/TORTURE_SUITE
294 pwd > $resdir/$ds/testid.txt
297 git status >> $resdir/$ds/testid.txt
298 git rev-parse HEAD >> $resdir/$ds/testid.txt
299 if ! git diff HEAD > $T/git-diff 2>&1
301 cp $T/git-diff $resdir/$ds
305 awk < $T/cfgcpu.pack \
306 -v CONFIGDIR
="$CONFIGFRAG/" \
309 -v jitter
="$jitter" \
312 -v TORTURE_QEMU_ARG
="$TORTURE_QEMU_ARG" \
313 -v TORTURE_BOOTARGS
="$TORTURE_BOOTARGS" \
324 # Dump out the scripting required to run one test batch.
325 function dump(first, pastlast, batchnum)
327 print "echo ----Start batch " batchnum ": `date`";
328 print "echo ----Start batch " batchnum ": `date` >> " rd "/log";
330 for (j = first; j < pastlast; j++) {
333 if (cfrep[cf[j]] == "") {
338 cfr[jn] = cf[j] "." cfrep[cf[j]];
340 if (cpusr[jn] > ncpus && ncpus != 0)
344 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date`";
345 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` >> " rd "/log";
346 print "rm -f " builddir ".*";
347 print "touch " builddir ".wait";
348 print "mkdir " builddir " > /dev/null 2>&1 || :";
349 print "mkdir " rd cfr[jn] " || :";
350 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 &"
351 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date`";
352 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` >> " rd "/log";
353 print "while test -f " builddir ".wait"
357 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date`";
358 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` >> " rd "/log";
361 for (j = 1; j < jn; j++) {
363 print "rm -f " builddir ".ready"
364 print "if test -z \"$TORTURE_BUILDONLY\""
366 print "\techo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date`";
367 print "\techo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date` >> " rd "/log";
372 if (ja[1] == -1 && ncpus == 0)
374 else if (ja[1] == -1)
378 for (j = 0; j < njitter; j++)
379 print "jitter.sh " j " " dur " " ja[2] " " ja[3] "&"
381 print "if test -z \"$TORTURE_BUILDONLY\""
383 print "\techo ---- All kernel runs complete. `date`";
384 print "\techo ---- All kernel runs complete. `date` >> " rd "/log";
386 for (j = 1; j < jn; j++) {
388 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results:";
389 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results: >> " rd "/log";
390 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out";
391 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out >> " rd "/log";
401 # Each pass through the following loop considers one test.
402 for (i = 0; i < njobs; i++) {
404 # Sequential test specified, each test its own batch.
405 dump(i, i + 1, batchnum);
408 } else if (nc < cpus[i] && i != 0) {
409 # Out of CPUs, dump out a batch.
410 dump(first, i, batchnum);
415 # Account for the CPUs needed by the current test.
418 # Dump the last batch.
420 dump(first, i, batchnum);
423 cat << ___EOF___ >> $T/script
426 echo " --- `date` Test summary:"
427 echo Results directory: $resdir/$ds
428 kvm-recheck.sh $resdir/$ds
431 if test "$dryrun" = script
435 elif test "$dryrun" = sched
437 # Extract the test run schedule from the script.
438 egrep 'Start batch|Starting build\.' $T/script |
440 sed -e 's/:.*$//' -e 's/^echo //'
443 # Not a dryrun, so run the script.
447 # 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