3 # Run a series of tests under KVM. By default, this series is specified
4 # by the relevant CFLIST file, but can be overridden by the --configs
5 # command-line argument.
7 # Usage: kvm.sh [ options ]
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, you can access it online at
21 # http://www.gnu.org/licenses/gpl-2.0.html.
23 # Copyright (C) IBM Corporation, 2011
25 # Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
30 T=${TMPDIR-/tmp}/kvm.sh.$$
34 cd `dirname $scriptname`/../../../../../
38 KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM
39 PATH=${KVM}/bin:$PATH; export PATH
40 TORTURE_DEFCONFIG=defconfig
42 TORTURE_INITRD="$KVM/initrd"; export TORTURE_INITRD
43 TORTURE_KCONFIG_ARG=""
46 TORTURE_SHUTDOWN_GRACE=180
51 ds=`date +%Y.%m.%d-%H:%M:%S`
57 echo "Usage: $scriptname optional arguments:"
58 echo " --bootargs kernel-boot-arguments"
59 echo " --bootimage relative-path-to-kernel-boot-image"
61 echo " --configs \"config-file list w/ repeat factor (3*TINY01)\""
63 echo " --datestamp string"
64 echo " --defconfig string"
65 echo " --dryrun sched|script"
66 echo " --duration minutes"
68 echo " --jitter N [ maxsleep (us) [ maxspin (us) ] ]"
69 echo " --kconfig Kconfig-options"
70 echo " --kmake-arg kernel-make-arguments"
71 echo " --mac nn:nn:nn:nn:nn:nn"
72 echo " --memory megabytes | nnnG"
74 echo " --qemu-args qemu-arguments"
75 echo " --qemu-cmd qemu-system-..."
76 echo " --results absolute-pathname"
85 checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
90 checkarg --bootimage "(relative path to kernel boot image)" "$#" "$2" '[a-zA-Z0-9][a-zA-Z0-9_]*' '^--'
91 TORTURE_BOOT_IMAGE="$2"
98 checkarg --configs "(list of config files)" "$#" "$2" '^[^/]*$' '^--'
103 checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
108 checkarg --datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
113 checkarg --defconfig "defconfigtype" "$#" "$2" '^[^/][^/]*$' '^--'
118 checkarg --dryrun "sched|script" $# "$2" 'sched\|script' '^--'
123 checkarg --duration "(minutes)" $# "$2" '^[0-9]*$' '^error'
128 TORTURE_QEMU_INTERACTIVE=1; export TORTURE_QEMU_INTERACTIVE
131 checkarg --jitter "(# threads [ sleep [ spin ] ])" $# "$2" '^-\{,1\}[0-9]\+\( \+[0-9]\+\)\{,2\} *$' '^error$'
136 checkarg --kconfig "(Kconfig options)" $# "$2" '^CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\)\( CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\)\)*$' '^error$'
137 TORTURE_KCONFIG_ARG="$2"
141 checkarg --kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
142 TORTURE_KMAKE_ARG="$2"
146 checkarg --mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error
151 checkarg --memory "(memory size)" $# "$2" '^[0-9]\+[MG]\?$' error
156 TORTURE_INITRD=""; export TORTURE_INITRD
158 --qemu-args|--qemu-arg)
159 checkarg --qemu-args "(qemu arguments)" $# "$2" '^-' '^error'
160 TORTURE_QEMU_ARG="$2"
164 checkarg --qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
165 TORTURE_QEMU_CMD="$2"
169 checkarg --results "(absolute pathname)" "$#" "$2" '^/' '^error'
174 checkarg --shutdown-grace "(seconds)" "$#" "$2" '^[0-9]*$' '^error'
175 TORTURE_SHUTDOWN_GRACE=$2
179 checkarg --torture "(suite name)" "$#" "$2" '^\(lock\|rcu\|rcuperf\)$' '^--'
182 if test "$TORTURE_SUITE" = rcuperf
184 # If you really want jitter for rcuperf, specify
185 # it after specifying rcuperf. (But why?)
190 echo Unknown argument $1
197 if test -z "$TORTURE_INITRD" || tools/testing/selftests/rcutorture/bin/mkinitrd.sh
201 echo No initrd and unable to create one, aborting test >&2
205 CONFIGFRAG=${KVM}/configs/${TORTURE_SUITE}; export CONFIGFRAG
207 if test -z "$configs"
209 configs="`cat $CONFIGFRAG/CFLIST`"
217 # Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
222 [0-9]\**|[0-9][0-9]\**|[0-9][0-9][0-9]\**)
223 config_reps=`echo $CF | sed -e 's/\*.*$//'`
224 CF1=`echo $CF | sed -e 's/^[^*]*\*//'`
231 if test -f "$CONFIGFRAG/$CF1"
233 cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF1`
234 cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
235 cpu_count=`configfrag_boot_maxcpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
236 for ((cur_rep=0;cur_rep<$config_reps;cur_rep++))
238 echo $CF1 $cpu_count >> $T/cfgcpu
241 echo "The --configs file $CF1 does not exist, terminating."
245 sort -k2nr $T/cfgcpu -T="$T" > $T/cfgcpu.sort
247 # Use a greedy bin-packing algorithm, sorting the list accordingly.
248 awk < $T/cfgcpu.sort > $T/cfgcpu.pack -v ncpus=$cpus '
254 # Read file of tests and corresponding required numbers of CPUs.
264 # Each pass through the following loop creates on test batch
265 # that can be executed concurrently given ncpus. Note that a
266 # given test that requires more than the available CPUs will run in
267 # their own batch. Such tests just have to make do with what
269 while (nc != ncpus) {
273 # Each pass through the following loop considers one
274 # test for inclusion in the current batch.
275 for (i = 0; i < njobs; i++) {
277 continue; # Already part of a batch.
278 if (nc >= cpus[i] || nc == ncpus) {
280 # This test fits into the current batch.
284 break; # Too-big test in its own batch.
289 # Dump out the tests in batch order.
290 for (b = 1; b <= batch; b++)
291 for (i = 0; i < njobs; i++)
293 print cf[i], cpus[i];
296 # Generate a script to execute the tests in appropriate batches.
297 cat << ___EOF___ > $T/script
298 CONFIGFRAG="$CONFIGFRAG"; export CONFIGFRAG
299 KVM="$KVM"; export KVM
300 PATH="$PATH"; export PATH
301 TORTURE_BOOT_IMAGE="$TORTURE_BOOT_IMAGE"; export TORTURE_BOOT_IMAGE
302 TORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY
303 TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG
304 TORTURE_INITRD="$TORTURE_INITRD"; export TORTURE_INITRD
305 TORTURE_KCONFIG_ARG="$TORTURE_KCONFIG_ARG"; export TORTURE_KCONFIG_ARG
306 TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG
307 TORTURE_QEMU_CMD="$TORTURE_QEMU_CMD"; export TORTURE_QEMU_CMD
308 TORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE"; export TORTURE_QEMU_INTERACTIVE
309 TORTURE_QEMU_MAC="$TORTURE_QEMU_MAC"; export TORTURE_QEMU_MAC
310 TORTURE_QEMU_MEM="$TORTURE_QEMU_MEM"; export TORTURE_QEMU_MEM
311 TORTURE_SHUTDOWN_GRACE="$TORTURE_SHUTDOWN_GRACE"; export TORTURE_SHUTDOWN_GRACE
312 TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE
315 mkdir -p "$resdir" || :
318 echo Results directory: $resdir/$ds
319 echo $scriptname $args
320 touch $resdir/$ds/log
321 echo $scriptname $args >> $resdir/$ds/log
322 echo ${TORTURE_SUITE} > $resdir/$ds/TORTURE_SUITE
323 pwd > $resdir/$ds/testid.txt
326 git status >> $resdir/$ds/testid.txt
327 git rev-parse HEAD >> $resdir/$ds/testid.txt
328 git diff HEAD >> $resdir/$ds/testid.txt
331 awk < $T/cfgcpu.pack \
332 -v TORTURE_BUILDONLY="$TORTURE_BUILDONLY" \
333 -v CONFIGDIR="$CONFIGFRAG/" \
336 -v jitter="$jitter" \
339 -v TORTURE_QEMU_ARG="$TORTURE_QEMU_ARG" \
340 -v TORTURE_BOOTARGS="$TORTURE_BOOTARGS" \
351 # Dump out the scripting required to run one test batch.
352 function dump(first, pastlast, batchnum)
354 print "echo ----Start batch " batchnum ": `date` | tee -a " rd "log";
357 for (j = first; j < pastlast; j++) {
360 if (cfrep[cf[j]] == "") {
365 cfr[jn] = cf[j] "." cfrep[cf[j]];
367 if (cpusr[jn] > ncpus && ncpus != 0)
371 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` | tee -a " rd "log";
372 print "rm -f " builddir ".*";
373 print "touch " builddir ".wait";
374 print "mkdir " builddir " > /dev/null 2>&1 || :";
375 print "mkdir " rd cfr[jn] " || :";
376 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 &"
377 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` | tee -a " rd "log";
378 print "while test -f " builddir ".wait"
382 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` | tee -a " rd "log";
385 for (j = 1; j < jn; j++) {
387 print "rm -f " builddir ".ready"
388 print "if test -f \"" rd cfr[j] "/builtkernel\""
390 print "\techo ----", cfr[j], cpusr[j] ovf ": Kernel present. `date` | tee -a " rd "log";
391 print "\tneedqemurun=1"
396 if (ja[1] == -1 && ncpus == 0)
398 else if (ja[1] == -1)
402 if (TORTURE_BUILDONLY && njitter != 0) {
404 print "echo Build-only run, so suppressing jitter | tee -a " rd "log"
406 if (TORTURE_BUILDONLY) {
409 print "if test -n \"$needqemurun\""
411 print "\techo ---- Starting kernels. `date` | tee -a " rd "log";
412 for (j = 0; j < njitter; j++)
413 print "\tjitter.sh " j " " dur " " ja[2] " " ja[3] "&"
415 print "\techo ---- All kernel runs complete. `date` | tee -a " rd "log";
418 print "\techo ---- No kernel runs. `date` | tee -a " rd "log";
420 for (j = 1; j < jn; j++) {
422 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results: | tee -a " rd "log";
423 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out | tee -a " rd "log";
433 # Each pass through the following loop considers one test.
434 for (i = 0; i < njobs; i++) {
436 # Sequential test specified, each test its own batch.
437 dump(i, i + 1, batchnum);
440 } else if (nc < cpus[i] && i != 0) {
441 # Out of CPUs, dump out a batch.
442 dump(first, i, batchnum);
447 # Account for the CPUs needed by the current test.
450 # Dump the last batch.
452 dump(first, i, batchnum);
455 cat << ___EOF___ >> $T/script
458 echo " --- `date` Test summary:"
459 echo Results directory: $resdir/$ds
460 kvm-recheck.sh $resdir/$ds
463 if test "$dryrun" = script
467 elif test "$dryrun" = sched
469 # Extract the test run schedule from the script.
470 egrep 'Start batch|Starting build\.' $T/script |
472 sed -e 's/:.*$//' -e 's/^echo //'
475 # Not a dryrun, so run the script.
479 # 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