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 CONFIGFRAG=${KVM}/configs/${TORTURE_SUITE}; export CONFIGFRAG
199 if test -z "$configs"
201 configs="`cat $CONFIGFRAG/CFLIST`"
209 # Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
214 [0-9]\**|[0-9][0-9]\**|[0-9][0-9][0-9]\**)
215 config_reps=`echo $CF | sed -e 's/\*.*$//'`
216 CF1=`echo $CF | sed -e 's/^[^*]*\*//'`
223 if test -f "$CONFIGFRAG/$CF1"
225 cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF1`
226 cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
227 cpu_count=`configfrag_boot_maxcpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
228 for ((cur_rep=0;cur_rep<$config_reps;cur_rep++))
230 echo $CF1 $cpu_count >> $T/cfgcpu
233 echo "The --configs file $CF1 does not exist, terminating."
237 sort -k2nr $T/cfgcpu -T="$T" > $T/cfgcpu.sort
239 # Use a greedy bin-packing algorithm, sorting the list accordingly.
240 awk < $T/cfgcpu.sort > $T/cfgcpu.pack -v ncpus=$cpus '
246 # Read file of tests and corresponding required numbers of CPUs.
256 # Each pass through the following loop creates on test batch
257 # that can be executed concurrently given ncpus. Note that a
258 # given test that requires more than the available CPUs will run in
259 # their own batch. Such tests just have to make do with what
261 while (nc != ncpus) {
265 # Each pass through the following loop considers one
266 # test for inclusion in the current batch.
267 for (i = 0; i < njobs; i++) {
269 continue; # Already part of a batch.
270 if (nc >= cpus[i] || nc == ncpus) {
272 # This test fits into the current batch.
276 break; # Too-big test in its own batch.
281 # Dump out the tests in batch order.
282 for (b = 1; b <= batch; b++)
283 for (i = 0; i < njobs; i++)
285 print cf[i], cpus[i];
288 # Generate a script to execute the tests in appropriate batches.
289 cat << ___EOF___ > $T/script
290 CONFIGFRAG="$CONFIGFRAG"; export CONFIGFRAG
291 KVM="$KVM"; export KVM
292 PATH="$PATH"; export PATH
293 TORTURE_BOOT_IMAGE="$TORTURE_BOOT_IMAGE"; export TORTURE_BOOT_IMAGE
294 TORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY
295 TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG
296 TORTURE_INITRD="$TORTURE_INITRD"; export TORTURE_INITRD
297 TORTURE_KCONFIG_ARG="$TORTURE_KCONFIG_ARG"; export TORTURE_KCONFIG_ARG
298 TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG
299 TORTURE_QEMU_CMD="$TORTURE_QEMU_CMD"; export TORTURE_QEMU_CMD
300 TORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE"; export TORTURE_QEMU_INTERACTIVE
301 TORTURE_QEMU_MAC="$TORTURE_QEMU_MAC"; export TORTURE_QEMU_MAC
302 TORTURE_QEMU_MEM="$TORTURE_QEMU_MEM"; export TORTURE_QEMU_MEM
303 TORTURE_SHUTDOWN_GRACE="$TORTURE_SHUTDOWN_GRACE"; export TORTURE_SHUTDOWN_GRACE
304 TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE
307 mkdir -p "$resdir" || :
310 echo Results directory: $resdir/$ds
311 echo $scriptname $args
312 touch $resdir/$ds/log
313 echo $scriptname $args >> $resdir/$ds/log
314 echo ${TORTURE_SUITE} > $resdir/$ds/TORTURE_SUITE
315 pwd > $resdir/$ds/testid.txt
318 git status >> $resdir/$ds/testid.txt
319 git rev-parse HEAD >> $resdir/$ds/testid.txt
320 git diff HEAD >> $resdir/$ds/testid.txt
323 awk < $T/cfgcpu.pack \
324 -v TORTURE_BUILDONLY="$TORTURE_BUILDONLY" \
325 -v CONFIGDIR="$CONFIGFRAG/" \
328 -v jitter="$jitter" \
331 -v TORTURE_QEMU_ARG="$TORTURE_QEMU_ARG" \
332 -v TORTURE_BOOTARGS="$TORTURE_BOOTARGS" \
343 # Dump out the scripting required to run one test batch.
344 function dump(first, pastlast, batchnum)
346 print "echo ----Start batch " batchnum ": `date` | tee -a " rd "log";
349 for (j = first; j < pastlast; j++) {
352 if (cfrep[cf[j]] == "") {
357 cfr[jn] = cf[j] "." cfrep[cf[j]];
359 if (cpusr[jn] > ncpus && ncpus != 0)
363 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` | tee -a " rd "log";
364 print "rm -f " builddir ".*";
365 print "touch " builddir ".wait";
366 print "mkdir " builddir " > /dev/null 2>&1 || :";
367 print "mkdir " rd cfr[jn] " || :";
368 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 &"
369 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` | tee -a " rd "log";
370 print "while test -f " builddir ".wait"
374 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` | tee -a " rd "log";
377 for (j = 1; j < jn; j++) {
379 print "rm -f " builddir ".ready"
380 print "if test -f \"" rd cfr[j] "/builtkernel\""
382 print "\techo ----", cfr[j], cpusr[j] ovf ": Kernel present. `date` | tee -a " rd "log";
383 print "\tneedqemurun=1"
388 if (ja[1] == -1 && ncpus == 0)
390 else if (ja[1] == -1)
394 if (TORTURE_BUILDONLY && njitter != 0) {
396 print "echo Build-only run, so suppressing jitter | tee -a " rd "log"
398 if (TORTURE_BUILDONLY) {
401 print "if test -n \"$needqemurun\""
403 print "\techo ---- Starting kernels. `date` | tee -a " rd "log";
404 for (j = 0; j < njitter; j++)
405 print "\tjitter.sh " j " " dur " " ja[2] " " ja[3] "&"
407 print "\techo ---- All kernel runs complete. `date` | tee -a " rd "log";
410 print "\techo ---- No kernel runs. `date` | tee -a " rd "log";
412 for (j = 1; j < jn; j++) {
414 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results: | tee -a " rd "log";
415 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out | tee -a " rd "log";
425 # Each pass through the following loop considers one test.
426 for (i = 0; i < njobs; i++) {
428 # Sequential test specified, each test its own batch.
429 dump(i, i + 1, batchnum);
432 } else if (nc < cpus[i] && i != 0) {
433 # Out of CPUs, dump out a batch.
434 dump(first, i, batchnum);
439 # Account for the CPUs needed by the current test.
442 # Dump the last batch.
444 dump(first, i, batchnum);
447 cat << ___EOF___ >> $T/script
450 echo " --- `date` Test summary:"
451 echo Results directory: $resdir/$ds
452 kvm-recheck.sh $resdir/$ds
455 if test "$dryrun" = script
459 elif test "$dryrun" = sched
461 # Extract the test run schedule from the script.
462 egrep 'Start batch|Starting build\.' $T/script |
464 sed -e 's/:.*$//' -e 's/^echo //'
467 # Not a dryrun, so run the script.
471 # 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