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
49 ds=`date +%Y.%m.%d-%H:%M:%S`
54 echo "Usage: $scriptname optional arguments:"
55 echo " --bootargs kernel-boot-arguments"
56 echo " --bootimage relative-path-to-kernel-boot-image"
58 echo " --configs \"config-file list w/ repeat factor (3*TINY01)\""
60 echo " --datestamp string"
61 echo " --defconfig string"
62 echo " --dryrun sched|script"
63 echo " --duration minutes"
65 echo " --kmake-arg kernel-make-arguments"
66 echo " --mac nn:nn:nn:nn:nn:nn"
68 echo " --qemu-args qemu-system-..."
69 echo " --qemu-cmd qemu-system-..."
70 echo " --results absolute-pathname"
79 checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
84 checkarg --bootimage "(relative path to kernel boot image)" "$#" "$2" '[a-zA-Z0-9][a-zA-Z0-9_]*' '^--'
85 TORTURE_BOOT_IMAGE="$2"
92 checkarg --configs "(list of config files)" "$#" "$2" '^[^/]*$' '^--'
97 checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
102 checkarg --datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
107 checkarg --defconfig "defconfigtype" "$#" "$2" '^[^/][^/]*$' '^--'
112 checkarg --dryrun "sched|script" $# "$2" 'sched\|script' '^--'
117 checkarg --duration "(minutes)" $# "$2" '^[0-9]*$' '^error'
122 TORTURE_QEMU_INTERACTIVE=1; export TORTURE_QEMU_INTERACTIVE
125 checkarg --kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
126 TORTURE_KMAKE_ARG="$2"
130 checkarg --mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error
135 TORTURE_INITRD=""; export TORTURE_INITRD
137 --qemu-args|--qemu-arg)
138 checkarg --qemu-args "-qemu args" $# "$2" '^-' '^error'
139 TORTURE_QEMU_ARG="$2"
143 checkarg --qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
144 TORTURE_QEMU_CMD="$2"
148 checkarg --results "(absolute pathname)" "$#" "$2" '^/' '^error'
153 checkarg --torture "(suite name)" "$#" "$2" '^\(lock\|rcu\)$' '^--'
158 echo Unknown argument $1
165 CONFIGFRAG=${KVM}/configs/${TORTURE_SUITE}; export CONFIGFRAG
167 if test -z "$configs"
169 configs="`cat $CONFIGFRAG/CFLIST`"
177 # Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
182 [0-9]\**|[0-9][0-9]\**|[0-9][0-9][0-9]\**)
183 config_reps=`echo $CF | sed -e 's/\*.*$//'`
184 CF1=`echo $CF | sed -e 's/^[^*]*\*//'`
191 if test -f "$CONFIGFRAG/$CF1"
193 cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF1`
194 cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
195 for ((cur_rep=0;cur_rep<$config_reps;cur_rep++))
197 echo $CF1 $cpu_count >> $T/cfgcpu
200 echo "The --configs file $CF1 does not exist, terminating."
204 sort -k2nr $T/cfgcpu > $T/cfgcpu.sort
206 # Use a greedy bin-packing algorithm, sorting the list accordingly.
207 awk < $T/cfgcpu.sort > $T/cfgcpu.pack -v ncpus=$cpus '
213 # Read file of tests and corresponding required numbers of CPUs.
224 # Each pass through the following loop creates on test batch
225 # that can be executed concurrently given ncpus. Note that a
226 # given test that requires more than the available CPUs will run in
227 # their own batch. Such tests just have to make do with what
229 while (nc != ncpus) {
233 # Each pass through the following loop considers one
234 # test for inclusion in the current batch.
235 for (i = 0; i < njobs; i++) {
237 continue; # Already part of a batch.
238 if (nc >= cpus[i] || nc == ncpus) {
240 # This test fits into the current batch.
244 break; # Too-big test in its own batch.
249 # Dump out the tests in batch order.
250 for (b = 1; b <= batch; b++)
251 for (i = 0; i < njobs; i++)
253 print cf[i], cpus[i];
256 # Generate a script to execute the tests in appropriate batches.
257 cat << ___EOF___ > $T/script
258 CONFIGFRAG="$CONFIGFRAG"; export CONFIGFRAG
259 KVM="$KVM"; export KVM
260 PATH="$PATH"; export PATH
261 TORTURE_BOOT_IMAGE="$TORTURE_BOOT_IMAGE"; export TORTURE_BOOT_IMAGE
262 TORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY
263 TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG
264 TORTURE_INITRD="$TORTURE_INITRD"; export TORTURE_INITRD
265 TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG
266 TORTURE_QEMU_CMD="$TORTURE_QEMU_CMD"; export TORTURE_QEMU_CMD
267 TORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE"; export TORTURE_QEMU_INTERACTIVE
268 TORTURE_QEMU_MAC="$TORTURE_QEMU_MAC"; export TORTURE_QEMU_MAC
269 TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE
272 mkdir -p "$resdir" || :
275 echo Results directory: $resdir/$ds
276 echo $scriptname $args
277 touch $resdir/$ds/log
278 echo $scriptname $args >> $resdir/$ds/log
279 echo ${TORTURE_SUITE} > $resdir/$ds/TORTURE_SUITE
280 pwd > $resdir/$ds/testid.txt
283 git status >> $resdir/$ds/testid.txt
284 git rev-parse HEAD >> $resdir/$ds/testid.txt
285 if ! git diff HEAD > $T/git-diff 2>&1
287 cp $T/git-diff $resdir/$ds
291 awk < $T/cfgcpu.pack \
292 -v CONFIGDIR="$CONFIGFRAG/" \
297 -v TORTURE_QEMU_ARG="$TORTURE_QEMU_ARG" \
298 -v TORTURE_BOOTARGS="$TORTURE_BOOTARGS" \
309 # Dump out the scripting required to run one test batch.
310 function dump(first, pastlast)
312 print "echo ----Start batch: `date`";
313 print "echo ----Start batch: `date` >> " rd "/log";
315 for (j = first; j < pastlast; j++) {
318 if (cfrep[cf[j]] == "") {
323 cfr[jn] = cf[j] "." cfrep[cf[j]];
325 if (cpusr[jn] > ncpus && ncpus != 0)
329 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date`";
330 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` >> " rd "/log";
331 print "rm -f " builddir ".*";
332 print "touch " builddir ".wait";
333 print "mkdir " builddir " > /dev/null 2>&1 || :";
334 print "mkdir " rd cfr[jn] " || :";
335 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 &"
336 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date`";
337 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` >> " rd "/log";
338 print "while test -f " builddir ".wait"
342 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date`";
343 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` >> " rd "/log";
346 for (j = 1; j < jn; j++) {
348 print "rm -f " builddir ".ready"
349 print "if test -z \"$TORTURE_BUILDONLY\""
351 print "\techo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date`";
352 print "\techo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date` >> " rd "/log";
356 print "if test -z \"$TORTURE_BUILDONLY\""
358 print "\techo ---- All kernel runs complete. `date`";
359 print "\techo ---- All kernel runs complete. `date` >> " rd "/log";
361 for (j = 1; j < jn; j++) {
363 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results:";
364 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results: >> " rd "/log";
365 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out";
366 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out >> " rd "/log";
375 # Each pass through the following loop considers one test.
376 for (i = 0; i < njobs; i++) {
378 # Sequential test specified, each test its own batch.
381 } else if (nc < cpus[i] && i != 0) {
382 # Out of CPUs, dump out a batch.
387 # Account for the CPUs needed by the current test.
390 # Dump the last batch.
395 cat << ___EOF___ >> $T/script
398 echo " --- `date` Test summary:"
399 echo Results directory: $resdir/$ds
400 kvm-recheck.sh $resdir/$ds
403 if test "$dryrun" = script
407 elif test "$dryrun" = sched
409 # Extract the test run schedule from the script.
410 egrep 'Start batch|Starting build\.' $T/script |
412 sed -e 's/:.*$//' -e 's/^echo //'
415 # Not a dryrun, so run the script.
419 # 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