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
44 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"
73 echo " --qemu-args qemu-system-..."
74 echo " --qemu-cmd qemu-system-..."
75 echo " --results absolute-pathname"
84 checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
89 checkarg --bootimage "(relative path to kernel boot image)" "$#" "$2" '[a-zA-Z0-9][a-zA-Z0-9_]*' '^--'
90 TORTURE_BOOT_IMAGE="$2"
97 checkarg --configs "(list of config files)" "$#" "$2" '^[^/]*$' '^--'
102 checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
107 checkarg --datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
112 checkarg --defconfig "defconfigtype" "$#" "$2" '^[^/][^/]*$' '^--'
117 checkarg --dryrun "sched|script" $# "$2" 'sched\|script' '^--'
122 checkarg --duration "(minutes)" $# "$2" '^[0-9]*$' '^error'
127 TORTURE_QEMU_INTERACTIVE=1; export TORTURE_QEMU_INTERACTIVE
130 checkarg --jitter "(# threads [ sleep [ spin ] ])" $# "$2" '^-\{,1\}[0-9]\+\( \+[0-9]\+\)\{,2\} *$' '^error$'
135 checkarg --kconfig "(Kconfig options)" $# "$2" '^CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\)\( CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\)\)*$' '^error$'
136 TORTURE_KCONFIG_ARG="$2"
140 checkarg --kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
141 TORTURE_KMAKE_ARG="$2"
145 checkarg --mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error
150 TORTURE_INITRD=""; export TORTURE_INITRD
152 --qemu-args|--qemu-arg)
153 checkarg --qemu-args "-qemu args" $# "$2" '^-' '^error'
154 TORTURE_QEMU_ARG="$2"
158 checkarg --qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
159 TORTURE_QEMU_CMD="$2"
163 checkarg --results "(absolute pathname)" "$#" "$2" '^/' '^error'
168 checkarg --shutdown-grace "(seconds)" "$#" "$2" '^[0-9]*$' '^error'
169 TORTURE_SHUTDOWN_GRACE=$2
173 checkarg --torture "(suite name)" "$#" "$2" '^\(lock\|rcu\|rcuperf\)$' '^--'
178 echo Unknown argument $1
185 CONFIGFRAG=${KVM}/configs/${TORTURE_SUITE}; export CONFIGFRAG
187 if test -z "$configs"
189 configs="`cat $CONFIGFRAG/CFLIST`"
197 # Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
202 [0-9]\**|[0-9][0-9]\**|[0-9][0-9][0-9]\**)
203 config_reps=`echo $CF | sed -e 's/\*.*$//'`
204 CF1=`echo $CF | sed -e 's/^[^*]*\*//'`
211 if test -f "$CONFIGFRAG/$CF1"
213 cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF1`
214 cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
215 cpu_count=`configfrag_boot_maxcpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
216 for ((cur_rep=0;cur_rep<$config_reps;cur_rep++))
218 echo $CF1 $cpu_count >> $T/cfgcpu
221 echo "The --configs file $CF1 does not exist, terminating."
225 sort -k2nr $T/cfgcpu > $T/cfgcpu.sort
227 # Use a greedy bin-packing algorithm, sorting the list accordingly.
228 awk < $T/cfgcpu.sort > $T/cfgcpu.pack -v ncpus=$cpus '
234 # Read file of tests and corresponding required numbers of CPUs.
245 # Each pass through the following loop creates on test batch
246 # that can be executed concurrently given ncpus. Note that a
247 # given test that requires more than the available CPUs will run in
248 # their own batch. Such tests just have to make do with what
250 while (nc != ncpus) {
254 # Each pass through the following loop considers one
255 # test for inclusion in the current batch.
256 for (i = 0; i < njobs; i++) {
258 continue; # Already part of a batch.
259 if (nc >= cpus[i] || nc == ncpus) {
261 # This test fits into the current batch.
265 break; # Too-big test in its own batch.
270 # Dump out the tests in batch order.
271 for (b = 1; b <= batch; b++)
272 for (i = 0; i < njobs; i++)
274 print cf[i], cpus[i];
277 # Generate a script to execute the tests in appropriate batches.
278 cat << ___EOF___ > $T/script
279 CONFIGFRAG="$CONFIGFRAG"; export CONFIGFRAG
280 KVM="$KVM"; export KVM
281 PATH="$PATH"; export PATH
282 TORTURE_BOOT_IMAGE="$TORTURE_BOOT_IMAGE"; export TORTURE_BOOT_IMAGE
283 TORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY
284 TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG
285 TORTURE_INITRD="$TORTURE_INITRD"; export TORTURE_INITRD
286 TORTURE_KCONFIG_ARG="$TORTURE_KCONFIG_ARG"; export TORTURE_KCONFIG_ARG
287 TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG
288 TORTURE_QEMU_CMD="$TORTURE_QEMU_CMD"; export TORTURE_QEMU_CMD
289 TORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE"; export TORTURE_QEMU_INTERACTIVE
290 TORTURE_QEMU_MAC="$TORTURE_QEMU_MAC"; export TORTURE_QEMU_MAC
291 TORTURE_SHUTDOWN_GRACE="$TORTURE_SHUTDOWN_GRACE"; export TORTURE_SHUTDOWN_GRACE
292 TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE
295 mkdir -p "$resdir" || :
298 echo Results directory: $resdir/$ds
299 echo $scriptname $args
300 touch $resdir/$ds/log
301 echo $scriptname $args >> $resdir/$ds/log
302 echo ${TORTURE_SUITE} > $resdir/$ds/TORTURE_SUITE
303 pwd > $resdir/$ds/testid.txt
306 git status >> $resdir/$ds/testid.txt
307 git rev-parse HEAD >> $resdir/$ds/testid.txt
308 git diff HEAD >> $resdir/$ds/testid.txt
311 awk < $T/cfgcpu.pack \
312 -v TORTURE_BUILDONLY="$TORTURE_BUILDONLY" \
313 -v CONFIGDIR="$CONFIGFRAG/" \
316 -v jitter="$jitter" \
319 -v TORTURE_QEMU_ARG="$TORTURE_QEMU_ARG" \
320 -v TORTURE_BOOTARGS="$TORTURE_BOOTARGS" \
331 # Dump out the scripting required to run one test batch.
332 function dump(first, pastlast, batchnum)
334 print "echo ----Start batch " batchnum ": `date`";
335 print "echo ----Start batch " batchnum ": `date` >> " rd "/log";
338 for (j = first; j < pastlast; j++) {
341 if (cfrep[cf[j]] == "") {
346 cfr[jn] = cf[j] "." cfrep[cf[j]];
348 if (cpusr[jn] > ncpus && ncpus != 0)
352 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date`";
353 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` >> " rd "/log";
354 print "rm -f " builddir ".*";
355 print "touch " builddir ".wait";
356 print "mkdir " builddir " > /dev/null 2>&1 || :";
357 print "mkdir " rd cfr[jn] " || :";
358 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 &"
359 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date`";
360 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` >> " rd "/log";
361 print "while test -f " builddir ".wait"
365 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date`";
366 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` >> " rd "/log";
369 for (j = 1; j < jn; j++) {
371 print "rm -f " builddir ".ready"
372 print "if test -f \"" rd cfr[j] "/builtkernel\""
374 print "\techo ----", cfr[j], cpusr[j] ovf ": Kernel present. `date`";
375 print "\techo ----", cfr[j], cpusr[j] ovf ": Kernel present. `date` >> " rd "/log";
376 print "\tneedqemurun=1"
381 if (ja[1] == -1 && ncpus == 0)
383 else if (ja[1] == -1)
387 if (TORTURE_BUILDONLY && njitter != 0) {
389 print "echo Build-only run, so suppressing jitter >> " rd "/log"
391 if (TORTURE_BUILDONLY) {
394 print "if test -n \"$needqemurun\""
396 print "\techo ---- Starting kernels. `date`";
397 print "\techo ---- Starting kernels. `date` >> " rd "/log";
398 for (j = 0; j < njitter; j++)
399 print "\tjitter.sh " j " " dur " " ja[2] " " ja[3] "&"
401 print "\techo ---- All kernel runs complete. `date`";
402 print "\techo ---- All kernel runs complete. `date` >> " rd "/log";
405 print "\techo ---- No kernel runs. `date`";
406 print "\techo ---- No kernel runs. `date` >> " rd "/log";
408 for (j = 1; j < jn; j++) {
410 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results:";
411 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results: >> " rd "/log";
412 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out";
413 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out >> " rd "/log";
423 # Each pass through the following loop considers one test.
424 for (i = 0; i < njobs; i++) {
426 # Sequential test specified, each test its own batch.
427 dump(i, i + 1, batchnum);
430 } else if (nc < cpus[i] && i != 0) {
431 # Out of CPUs, dump out a batch.
432 dump(first, i, batchnum);
437 # Account for the CPUs needed by the current test.
440 # Dump the last batch.
442 dump(first, i, batchnum);
445 cat << ___EOF___ >> $T/script
448 echo " --- `date` Test summary:"
449 echo Results directory: $resdir/$ds
450 kvm-recheck.sh $resdir/$ds
453 if test "$dryrun" = script
457 elif test "$dryrun" = sched
459 # Extract the test run schedule from the script.
460 egrep 'Start batch|Starting build\.' $T/script |
462 sed -e 's/:.*$//' -e 's/^echo //'
465 # Not a dryrun, so run the script.
469 # 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